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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.438   ! raeburn     4: # $Id: domainprefs.pm,v 1.437 2024/03/03 00:08:37 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
1.286     raeburn    22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
1.1       raeburn    24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: #
                     29: ###############################################################
1.297     raeburn    30: ###############################################################
1.1       raeburn    31: 
1.101     raeburn    32: =pod
                     33: 
                     34: =head1 NAME
                     35: 
                     36: Apache::domainprefs.pm
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Handles configuration of a LON-CAPA domain.  
                     41: 
                     42: This is part of the LearningOnline Network with CAPA project
                     43: described at http://www.lon-capa.org.
                     44: 
                     45: 
                     46: =head1 OVERVIEW
                     47: 
                     48: Each institution using LON-CAPA will typically have a single domain designated 
1.183     bisitz     49: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    50: may define a default set of logos and a color scheme which can be used to "brand"
                     51: the LON-CAPA instance. In addition, an institution will typically have a language
                     52: and timezone which are used for the majority of courses.
                     53: 
                     54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     55: host of other domain-wide settings which determine the types of functionality
                     56: available to users and courses in the domain.
                     57: 
                     58: There is also a mechanism to configure cataloging of courses in the domain, and
                     59: controls on the operation of automated processes which govern such things as
                     60: roster updates, user directory updates and processing of course requests.
                     61: 
                     62: The domain coordination manual which is built dynamically on install/update of 
                     63: LON-CAPA from the relevant help items provides more information about domain 
                     64: configuration.
                     65: 
                     66: Most of the domain settings are stored in the configuration.db GDBM file which is
                     67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     68: where $dom is the domain.  The configuration.db stores settings in a number of 
                     69: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     70: the domain as files (e.g., image files for logos etc., or plain text files for
                     71: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     72: session hosted on the primary library server in the domain, as these files are 
                     73: stored in author space belonging to a special $dom-domainconfig user.   
                     74: 
                     75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     76: the current settings, and provides an interface to make modifications.
                     77: 
                     78: =head1 SUBROUTINES
                     79: 
                     80: =over
                     81: 
                     82: =item print_quotas()
                     83: 
                     84: Inputs: 4 
                     85: 
                     86: $dom,$settings,$rowtotal,$action.
                     87: 
                     88: $dom is the domain, $settings is a reference to a hash of current settings for
                     89: the current context, $rowtotal is a reference to the scalar used to record the 
1.210     raeburn    90: number of rows displayed on the page, and $action is the context (quotas, 
1.163     raeburn    91: requestcourses or requestauthor).
1.101     raeburn    92: 
                     93: The print_quotas routine was orginally created to display/store information
                     94: about default quota sizes for portfolio spaces for the different types of 
                     95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     96: but is now also used to manage availability of user tools: 
                     97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429     raeburn    98: used by course owners to request creation of a course.
1.101     raeburn    99: 
                    100: Outputs: 1
                    101: 
                    102: $datatable  - HTML containing form elements which allow settings to be changed. 
                    103: 
                    104: In the case of course requests, radio buttons are displayed for each institutional
                    105: affiliate type (and also default, and _LC_adv) for each of the course types 
1.325     raeburn   106: (official, unofficial, community, textbook, placement, and lti).  
1.425     raeburn   107: In each case the radio buttons allow the selection of one of four values:
1.101     raeburn   108: 
1.104     raeburn   109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   110: which have the following effects:
                    111: 
                    112: 0
                    113: 
                    114: =over
                    115: 
                    116: - course requests are not allowed for this course types/affiliation
                    117: 
                    118: =back
                    119: 
1.104     raeburn   120: approval 
1.101     raeburn   121: 
                    122: =over 
                    123: 
                    124: - course requests must be approved by a Doman Coordinator in the 
                    125: course's domain
                    126: 
                    127: =back
                    128: 
                    129: validate 
                    130: 
                    131: =over
                    132: 
                    133: - an institutional validation (e.g., check requestor is instructor
                    134: of record) needs to be passed before the course will be created.  The required
                    135: validation is in localenroll.pm on the primary library server for the course 
                    136: domain.
                    137: 
                    138: =back
                    139: 
                    140: autolimit 
                    141: 
                    142: =over
                    143:  
1.143     raeburn   144: - course requests will be processed automatically up to a limit of
1.101     raeburn   145: N requests for the course type for the particular requestor.
                    146: If N is undefined, there is no limit to the number of course requests
                    147: which a course owner may submit and have processed automatically. 
                    148: 
                    149: =back
                    150: 
                    151: =item modify_quotas() 
                    152: 
                    153: =back
                    154: 
                    155: =cut
                    156: 
1.1       raeburn   157: package Apache::domainprefs;
                    158: 
                    159: use strict;
                    160: use Apache::Constants qw(:common :http);
                    161: use Apache::lonnet;
                    162: use Apache::loncommon();
                    163: use Apache::lonhtmlcommon();
                    164: use Apache::lonlocal;
1.43      raeburn   165: use Apache::lonmsg();
1.91      raeburn   166: use Apache::lonconfigsettings;
1.232     raeburn   167: use Apache::lonuserutils();
1.235     raeburn   168: use Apache::loncoursequeueadmin();
1.419     raeburn   169: use Apache::courseprefs();
1.69      raeburn   170: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   171: use LONCAPA::Enrollment;
1.81      raeburn   172: use LONCAPA::lonauthcgi();
1.275     raeburn   173: use LONCAPA::SSL;
1.9       raeburn   174: use File::Copy;
1.43      raeburn   175: use Locale::Language;
1.62      raeburn   176: use DateTime::TimeZone;
1.68      raeburn   177: use DateTime::Locale;
1.267     raeburn   178: use Time::HiRes qw( sleep );
1.373     raeburn   179: use Net::CIDR;
1.424     raeburn   180: use Crypt::CBC;
1.1       raeburn   181: 
1.155     raeburn   182: my $registered_cleanup;
                    183: my $modified_urls;
                    184: 
1.1       raeburn   185: sub handler {
                    186:     my $r=shift;
                    187:     if ($r->header_only) {
                    188:         &Apache::loncommon::content_type($r,'text/html');
                    189:         $r->send_http_header;
                    190:         return OK;
                    191:     }
                    192: 
1.91      raeburn   193:     my $context = 'domain';
1.1       raeburn   194:     my $dom = $env{'request.role.domain'};
1.5       albertel  195:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   196:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    197:         &Apache::loncommon::content_type($r,'text/html');
                    198:         $r->send_http_header;
                    199:     } else {
                    200:         $env{'user.error.msg'}=
                    201:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    202:         return HTTP_NOT_ACCEPTABLE;
                    203:     }
1.155     raeburn   204: 
                    205:     $registered_cleanup=0;
                    206:     @{$modified_urls}=();
                    207: 
1.1       raeburn   208:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    209:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   210:                                             ['phase','actions']);
1.30      raeburn   211:     my $phase = 'pickactions';
1.3       raeburn   212:     if ( exists($env{'form.phase'}) ) {
                    213:         $phase = $env{'form.phase'};
                    214:     }
1.150     raeburn   215:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   216:     my %domconfig =
1.6       raeburn   217:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   218:                 'quotas','autoenroll','autoupdate','autocreate',
                    219:                 'directorysrch','usercreation','usermodification',
                    220:                 'contacts','defaults','scantron','coursecategories',
                    221:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   222:                 'coursedefaults','usersessions','loadbalancing',
1.267     raeburn   223:                 'requestauthor','selfenrollment','inststatus',
1.421     raeburn   224:                 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.429     raeburn   225:                 'privacy','passwords','proctoring','wafproxy',
                    226:                 'ipaccess','authordefaults'],$dom);
1.320     raeburn   227:     my %encconfig =
1.405     raeburn   228:         &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.424     raeburn   229:     my ($checked_is_home,$is_home);
1.297     raeburn   230:     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    231:         if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423     raeburn   232:             my $home = &Apache::lonnet::domain($dom,'primary');
                    233:             unless (($home eq 'no_host') || ($home eq '')) {
                    234:                 my @ids=&Apache::lonnet::current_machine_ids();
                    235:                 if (grep(/^\Q$home\E$/,@ids)) {
                    236:                     $is_home = 1;
                    237:                 }
                    238:             }
1.425     raeburn   239:             $checked_is_home = 1;
1.297     raeburn   240:             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320     raeburn   241:                 if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
                    242:                     (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421     raeburn   243:                     $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423     raeburn   244:                     if (($is_home) && ($phase eq 'process')) {
                    245:                         $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
                    246:                     }
1.297     raeburn   247:                 }
                    248:             }
                    249:         }
                    250:     }
1.320     raeburn   251:     if (ref($domconfig{'lti'}) eq 'HASH') {
                    252:         if (ref($encconfig{'lti'}) eq 'HASH') {
1.424     raeburn   253:             unless ($checked_is_home) {
                    254:                 my $home = &Apache::lonnet::domain($dom,'primary');
                    255:                 unless (($home eq 'no_host') || ($home eq '')) {
                    256:                     my @ids=&Apache::lonnet::current_machine_ids();
                    257:                     if (grep(/^\Q$home\E$/,@ids)) {
                    258:                         $is_home = 1;
                    259:                     }
                    260:                 }
                    261:                 $checked_is_home = 1;
                    262:             }
1.320     raeburn   263:             foreach my $id (keys(%{$domconfig{'lti'}})) {
                    264:                 if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
                    265:                     (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424     raeburn   266:                     $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
                    267:                     if (($is_home) && ($phase eq 'process')) {
                    268:                         $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320     raeburn   269:                     }
                    270:                 }
                    271:             }
                    272:         }
                    273:     }
1.405     raeburn   274:     if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406     raeburn   275:         if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405     raeburn   276:             if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406     raeburn   277:                 foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
                    278:                     unless ($id =~ /^\d+$/) {
                    279:                         delete($domconfig{'ltisec'}{'linkprot'}{$id});
                    280:                     }
                    281:                     if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405     raeburn   282:                         (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
                    283:                         foreach my $item ('key','secret') {
1.406     raeburn   284:                             $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405     raeburn   285:                         }
                    286:                     }
                    287:                 }
                    288:             }
                    289:         }
                    290:     }
1.372     raeburn   291:     if (ref($domconfig{'proctoring'}) eq 'HASH') {
                    292:         if (ref($encconfig{'proctoring'}) eq 'HASH') {
                    293:             foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
                    294:                 if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
                    295:                     (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
                    296:                     foreach my $item ('key','secret') {
                    297:                         $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
                    298:                     }
                    299:                 }
                    300:             }
                    301:         }
                    302:     }
1.394     raeburn   303:     my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
                    304:                        'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373     raeburn   305:                        'contacts','privacy','usercreation','selfcreation',
1.374     raeburn   306:                        'usermodification','scantron','requestcourses','requestauthor',
1.373     raeburn   307:                        'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.429     raeburn   308:                        'authordefaults','ltitools','proctoring','selfenrollment',
                    309:                        'usersessions','ssl','trust','lti');
1.171     raeburn   310:     my %existing;
                    311:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    312:         %existing = %{$domconfig{'loadbalancing'}};
                    313:     }
                    314:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   315:         push(@prefs_order,'loadbalancing');
                    316:     }
1.30      raeburn   317:     my %prefs = (
                    318:         'rolecolors' =>
                    319:                    { text => 'Default color schemes',
1.67      raeburn   320:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   321:                      header => [{col1 => 'Student Settings',
                    322:                                  col2 => '',},
                    323:                                 {col1 => 'Coordinator Settings',
                    324:                                  col2 => '',},
                    325:                                 {col1 => 'Author Settings',
                    326:                                  col2 => '',},
                    327:                                 {col1 => 'Administrator Settings',
                    328:                                  col2 => '',}],
1.230     raeburn   329:                       print => \&print_rolecolors,
                    330:                       modify => \&modify_rolecolors,
1.30      raeburn   331:                     },
1.110     raeburn   332:         'login' =>
1.30      raeburn   333:                     { text => 'Log-in page options',
1.67      raeburn   334:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   335:                       header => [{col1 => 'Log-in Page Items',
                    336:                                   col2 => '',},
                    337:                                  {col1 => 'Log-in Help',
1.256     raeburn   338:                                   col2 => 'Value'},
                    339:                                  {col1 => 'Custom HTML in document head',
1.386     raeburn   340:                                   col2 => 'Value'},
                    341:                                  {col1 => 'SSO',
                    342:                                   col2 => 'Dual login: SSO and non-SSO options'},
                    343:                                 ],
1.230     raeburn   344:                       print => \&print_login,
                    345:                       modify => \&modify_login,
1.30      raeburn   346:                     },
1.43      raeburn   347:         'defaults' => 
1.236     raeburn   348:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   349:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   350:                       header => [{col1 => 'Setting',
1.236     raeburn   351:                                   col2 => 'Value'},
                    352:                                  {col1 => 'Institutional user types',
1.409     raeburn   353:                                   col2 => 'Name displayed'},
                    354:                                  {col1 => 'Mapping for missing usernames via standard log-in',
                    355:                                   col2 => 'Rules in use'}],
1.230     raeburn   356:                       print => \&print_defaults,
                    357:                       modify => \&modify_defaults,
1.43      raeburn   358:                     },
1.381     raeburn   359:         'wafproxy' =>
                    360:                     { text => 'Web Application Firewall/Reverse Proxy',
1.373     raeburn   361:                       help => 'Domain_Configuration_WAF_Proxy',
1.381     raeburn   362:                       header => [{col1 => 'Domain(s)',
                    363:                                   col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373     raeburn   364:                                  },
1.381     raeburn   365:                                  {col1 => 'Domain(s)',
                    366:                                   col2 => 'WAF Configuration',}],
1.373     raeburn   367:                       print => \&print_wafproxy,
1.381     raeburn   368:                       modify => \&modify_wafproxy,
1.373     raeburn   369:                     },
1.354     raeburn   370:         'passwords' =>
                    371:                     { text => 'Passwords (Internal authentication)',
                    372:                       help => 'Domain_Configuration_Passwords',
                    373:                       header => [{col1 => 'Resetting Forgotten Password',
                    374:                                   col2 => 'Settings'},
                    375:                                  {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                    376:                                   col2 => 'Settings'},
                    377:                                  {col1 => 'Rules for LON-CAPA Passwords',
                    378:                                   col2 => 'Settings'},
                    379:                                  {col1 => 'Course Owner Changing Student Passwords',
                    380:                                   col2 => 'Settings'}],
                    381:                       print => \&print_passwords,
                    382:                       modify => \&modify_passwords,
                    383:                     },
1.30      raeburn   384:         'quotas' => 
1.429     raeburn   385:                     { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67      raeburn   386:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   387:                       header => [{col1 => 'User affiliation',
1.72      raeburn   388:                                   col2 => 'Available tools',
1.435     raeburn   389:                                   col3 => 'Portfolio quota (MB)',}],
1.230     raeburn   390:                       print => \&print_quotas,
                    391:                       modify => \&modify_quotas,
1.30      raeburn   392:                     },
                    393:         'autoenroll' =>
                    394:                    { text => 'Auto-enrollment settings',
1.67      raeburn   395:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   396:                      header => [{col1 => 'Configuration setting',
                    397:                                  col2 => 'Value(s)'}],
1.230     raeburn   398:                      print => \&print_autoenroll,
                    399:                      modify => \&modify_autoenroll,
1.30      raeburn   400:                    },
                    401:         'autoupdate' => 
                    402:                    { text => 'Auto-update settings',
1.67      raeburn   403:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   404:                      header => [{col1 => 'Setting',
                    405:                                  col2 => 'Value',},
1.131     raeburn   406:                                 {col1 => 'Setting',
                    407:                                  col2 => 'Affiliation'},
1.43      raeburn   408:                                 {col1 => 'User population',
1.227     bisitz    409:                                  col2 => 'Updatable user data'}],
1.230     raeburn   410:                      print => \&print_autoupdate,
                    411:                      modify => \&modify_autoupdate,
1.30      raeburn   412:                   },
1.125     raeburn   413:         'autocreate' => 
                    414:                   { text => 'Auto-course creation settings',
                    415:                      help => 'Domain_Configuration_Auto_Creation',
                    416:                      header => [{col1 => 'Configuration Setting',
                    417:                                  col2 => 'Value',}],
1.230     raeburn   418:                      print => \&print_autocreate,
                    419:                      modify => \&modify_autocreate,
1.125     raeburn   420:                   },
1.30      raeburn   421:         'directorysrch' => 
1.277     raeburn   422:                   { text => 'Directory searches',
1.67      raeburn   423:                     help => 'Domain_Configuration_InstDirectory_Search',
1.277     raeburn   424:                     header => [{col1 => 'Institutional Directory Setting',
                    425:                                 col2 => 'Value',},
                    426:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   427:                                 col2 => 'Value',}],
1.230     raeburn   428:                     print => \&print_directorysrch,
                    429:                     modify => \&modify_directorysrch,
1.30      raeburn   430:                   },
                    431:         'contacts' =>
1.286     raeburn   432:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   433:                     help => 'Domain_Configuration_Contact_Info',
1.286     raeburn   434:                     header => [{col1 => 'Default e-mail addresses',
                    435:                                 col2 => 'Value',},
                    436:                                {col1 => 'Recipient(s) for notifications',
                    437:                                 col2 => 'Value',},
1.340     raeburn   438:                                {col1 => 'Nightly status check e-mail',
                    439:                                 col2 => 'Settings',},
1.286     raeburn   440:                                {col1 => 'Ask helpdesk form settings',
                    441:                                 col2 => 'Value',},],
1.230     raeburn   442:                     print => \&print_contacts,
                    443:                     modify => \&modify_contacts,
1.30      raeburn   444:                   },
                    445:         'usercreation' => 
                    446:                   { text => 'User creation',
1.67      raeburn   447:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   448:                     header => [{col1 => 'Format rule type',
                    449:                                 col2 => 'Format rules in force'},
1.34      raeburn   450:                                {col1 => 'User account creation',
                    451:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   452:                                {col1 => 'Context',
1.43      raeburn   453:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   454:                     print => \&print_usercreation,
                    455:                     modify => \&modify_usercreation,
1.30      raeburn   456:                   },
1.224     raeburn   457:         'selfcreation' => 
                    458:                   { text => 'Users self-creating accounts',
                    459:                     help => 'Domain_Configuration_Self_Creation', 
                    460:                     header => [{col1 => 'Self-creation with institutional username',
                    461:                                 col2 => 'Enabled?'},
                    462:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    463:                                 col2 => 'Information user can enter'},
1.303     raeburn   464:                                {col1 => 'Self-creation with e-mail verification',
1.224     raeburn   465:                                 col2 => 'Settings'}],
1.230     raeburn   466:                     print => \&print_selfcreation,
                    467:                     modify => \&modify_selfcreation,
1.224     raeburn   468:                   },
1.69      raeburn   469:         'usermodification' =>
1.33      raeburn   470:                   { text => 'User modification',
1.67      raeburn   471:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   472:                     header => [{col1 => 'Target user has role',
1.227     bisitz    473:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   474:                                {col1 => 'Target user has role',
1.227     bisitz    475:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   476:                     print => \&print_usermodification,
                    477:                     modify => \&modify_usermodification,
1.33      raeburn   478:                   },
1.69      raeburn   479:         'scantron' =>
1.346     raeburn   480:                   { text => 'Bubblesheet format',
1.67      raeburn   481:                     help => 'Domain_Configuration_Scantron_Format',
1.346     raeburn   482:                     header => [ {col1 => 'Bubblesheet format file',
                    483:                                  col2 => ''},
                    484:                                 {col1 => 'Bubblesheet data upload formats',
                    485:                                  col2 => 'Settings'}],
1.230     raeburn   486:                     print => \&print_scantron,
                    487:                     modify => \&modify_scantron,
1.46      raeburn   488:                   },
1.86      raeburn   489:         'requestcourses' => 
                    490:                  {text => 'Request creation of courses',
                    491:                   help => 'Domain_Configuration_Request_Courses',
                    492:                   header => [{col1 => 'User affiliation',
1.102     raeburn   493:                               col2 => 'Availability/Processing of requests',},
                    494:                              {col1 => 'Setting',
1.216     raeburn   495:                               col2 => 'Value'},
                    496:                              {col1 => 'Available textbooks',
1.235     raeburn   497:                               col2 => ''},
1.242     raeburn   498:                              {col1 => 'Available templates',
                    499:                               col2 => ''},
1.235     raeburn   500:                              {col1 => 'Validation (not official courses)',
                    501:                               col2 => 'Value'},],
1.230     raeburn   502:                   print => \&print_quotas,
                    503:                   modify => \&modify_quotas,
1.86      raeburn   504:                  },
1.163     raeburn   505:         'requestauthor' =>
1.223     bisitz    506:                  {text => 'Request Authoring Space',
1.163     raeburn   507:                   help => 'Domain_Configuration_Request_Author',
                    508:                   header => [{col1 => 'User affiliation',
                    509:                               col2 => 'Availability/Processing of requests',},
                    510:                              {col1 => 'Setting',
                    511:                               col2 => 'Value'}],
1.230     raeburn   512:                   print => \&print_quotas,
                    513:                   modify => \&modify_quotas,
1.163     raeburn   514:                  },
1.69      raeburn   515:         'coursecategories' =>
1.120     raeburn   516:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   517:                     help => 'Domain_Configuration_Cataloging_Courses',
1.238     raeburn   518:                     header => [{col1 => 'Catalog type/availability',
                    519:                                 col2 => '',},
                    520:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   521:                                 col2 => '',},
                    522:                                {col1 => 'Categories',
                    523:                                 col2 => '',
                    524:                                }],
1.230     raeburn   525:                     print => \&print_coursecategories,
                    526:                     modify => \&modify_coursecategories,
1.69      raeburn   527:                   },
                    528:         'serverstatuses' =>
1.77      raeburn   529:                  {text   => 'Access to server status pages',
1.69      raeburn   530:                   help   => 'Domain_Configuration_Server_Status',
                    531:                   header => [{col1 => 'Status Page',
                    532:                               col2 => 'Other named users',
                    533:                               col3 => 'Specific IPs',
                    534:                             }],
1.230     raeburn   535:                   print => \&print_serverstatuses,
                    536:                   modify => \&modify_serverstatuses,
1.69      raeburn   537:                  },
1.118     jms       538:         'helpsettings' =>
1.282     raeburn   539:                  {text   => 'Support settings',
1.118     jms       540:                   help   => 'Domain_Configuration_Help_Settings',
1.282     raeburn   541:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    542:                               col2 => 'Value'},
                    543:                              {col1 => 'Helpdesk Roles',
                    544:                               col2 => 'Settings'},],
1.230     raeburn   545:                   print  => \&print_helpsettings,
                    546:                   modify => \&modify_helpsettings,
1.118     jms       547:                  },
1.121     raeburn   548:         'coursedefaults' => 
                    549:                  {text => 'Course/Community defaults',
                    550:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   551:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    552:                               col2 => 'Value',},
                    553:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    554:                               col2 => 'Value',},],
1.230     raeburn   555:                   print => \&print_coursedefaults,
                    556:                   modify => \&modify_coursedefaults,
1.121     raeburn   557:                  },
1.231     raeburn   558:         'selfenrollment' => 
                    559:                  {text   => 'Self-enrollment in Course/Community',
                    560:                   help   => 'Domain_Configuration_Selfenrollment',
                    561:                   header => [{col1 => 'Configuration Rights',
                    562:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    563:                              {col1 => 'Defaults',
                    564:                               col2 => 'Value'},
                    565:                              {col1 => 'Self-enrollment validation (optional)',
                    566:                               col2 => 'Value'},],
                    567:                   print => \&print_selfenrollment,
                    568:                   modify => \&modify_selfenrollment,
                    569:                  },
1.120     raeburn   570:         'privacy' => 
1.427     raeburn   571:                  {text   => 'Role assignments and user privacy',
1.120     raeburn   572:                   help   => 'Domain_Configuration_User_Privacy',
1.357     raeburn   573:                   header => [{col1 => 'Role assigned in different domain',
                    574:                               col2 => 'Approval options'},
                    575:                              {col1 => 'Role assigned in different domain to user of type',
                    576:                               col2 => 'User information available in that domain'},
                    577:                              {col1 => "Role assigned in user's domain",
                    578:                               col2 => 'Information viewable by privileged user'},
                    579:                              {col1 => "Role assigned in user's domain",
                    580:                               col2 => 'Information viewable by unprivileged user'}],
1.230     raeburn   581:                   print => \&print_privacy,
                    582:                   modify => \&modify_privacy,
1.120     raeburn   583:                  },
1.141     raeburn   584:         'usersessions' =>
1.145     raeburn   585:                  {text  => 'User session hosting/offloading',
1.137     raeburn   586:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   587:                   header => [{col1 => 'Domain server',
                    588:                               col2 => 'Servers to offload sessions to when busy'},
                    589:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   590:                               col2 => 'Rules'},
                    591:                              {col1 => "Hosting domain's own users elsewhere",
                    592:                               col2 => 'Rules'}],
1.230     raeburn   593:                   print => \&print_usersessions,
                    594:                   modify => \&modify_usersessions,
1.137     raeburn   595:                  },
1.279     raeburn   596:         'loadbalancing' =>
1.185     raeburn   597:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   598:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   599:                   header => [{col1 => 'Balancers',
1.150     raeburn   600:                               col2 => 'Default destinations',
1.183     bisitz    601:                               col3 => 'User affiliation',
1.150     raeburn   602:                               col4 => 'Overrides'},
                    603:                             ],
1.230     raeburn   604:                   print => \&print_loadbalancing,
                    605:                   modify => \&modify_loadbalancing,
1.150     raeburn   606:                  },
1.425     raeburn   607:         'ltitools' =>
1.267     raeburn   608:                  {text => 'External Tools (LTI)',
1.296     raeburn   609:                   help => 'Domain_Configuration_LTI_Tools',
1.421     raeburn   610:                   header => [{col1 => 'Encryption of shared secrets',
                    611:                               col2 => 'Settings'},
                    612:                              {col1 => 'Rules for shared secrets',
                    613:                               col2 => 'Settings'},
                    614:                              {col1 => 'Providers',
                    615:                               col2 => 'Settings',}],
1.267     raeburn   616:                   print => \&print_ltitools,
                    617:                   modify => \&modify_ltitools,
                    618:                  },
1.372     raeburn   619:         'proctoring' =>
                    620:                  {text => 'Remote Proctoring Integration',
                    621:                   help => 'Domain_Configuration_Proctoring',
                    622:                   header => [{col1 => 'Name',
                    623:                               col2 => 'Configuration'}],
                    624:                   print => \&print_proctoring,
                    625:                   modify => \&modify_proctoring,
                    626:                  },
1.279     raeburn   627:         'ssl' =>
1.275     raeburn   628:                  {text  => 'LON-CAPA Network (SSL)',
                    629:                   help  => 'Domain_Configuration_Network_SSL',
                    630:                   header => [{col1 => 'Server',
                    631:                               col2 => 'Certificate Status'},
                    632:                              {col1 => 'Connections to other servers',
                    633:                               col2 => 'Rules'},
1.293     raeburn   634:                              {col1 => 'Connections from other servers',
                    635:                               col2 => 'Rules'},
1.275     raeburn   636:                              {col1 => "Replicating domain's published content",
                    637:                               col2 => 'Rules'}],
                    638:                   print => \&print_ssl,
                    639:                   modify => \&modify_ssl,
                    640:                  },
1.279     raeburn   641:         'trust' =>
                    642:                  {text   => 'Trust Settings',
                    643:                   help   => 'Domain_Configuration_Trust',
                    644:                   header => [{col1 => "Access to this domain's content by others",
                    645:                               col2 => 'Rules'},
                    646:                              {col1 => "Access to other domain's content by this domain",
                    647:                               col2 => 'Rules'},
                    648:                              {col1 => "Enrollment in this domain's courses by others",
                    649:                               col2 => 'Rules',},
                    650:                              {col1 => "Co-author roles in this domain for others",
                    651:                               col2 => 'Rules',},
                    652:                              {col1 => "Co-author roles for this domain's users elsewhere",
                    653:                               col2 => 'Rules',},
                    654:                              {col1 => "Domain roles in this domain assignable to others",
                    655:                               col2 => 'Rules'},
                    656:                              {col1 => "Course catalog for this domain displayed elsewhere",
                    657:                               col2 => 'Rules'},
                    658:                              {col1 => "Requests for creation of courses in this domain by others",
                    659:                               col2 => 'Rules'},
                    660:                              {col1 => "Users in other domains can send messages to this domain",
                    661:                               col2 => 'Rules'},],
                    662:                   print => \&print_trust,
                    663:                   modify => \&modify_trust,
                    664:                  },
1.425     raeburn   665:         'lti' =>
1.405     raeburn   666:                  {text => 'LTI Link Protection and LTI Consumers',
1.320     raeburn   667:                   help => 'Domain_Configuration_LTI_Provider',
1.405     raeburn   668:                   header => [{col1 => 'Encryption of shared secrets',
                    669:                               col2 => 'Settings'},
1.425     raeburn   670:                              {col1 => 'Rules for shared secrets',
1.405     raeburn   671:                               col2 => 'Settings'},
1.434     raeburn   672:                              {col1 => 'Link Protectors in Courses',
1.436     raeburn   673:                               col2 => 'Values'},
1.406     raeburn   674:                              {col1 => 'Link Protectors',
1.405     raeburn   675:                               col2 => 'Settings'},
                    676:                              {col1 => 'Consumers',
                    677:                               col2 => 'Settings'},],
1.320     raeburn   678:                   print => \&print_lti,
                    679:                   modify => \&modify_lti,
                    680:                  },
1.425     raeburn   681:         'ipaccess' =>
1.394     raeburn   682:                        {text => 'IP-based access control',
                    683:                         help => 'Domain_Configuration_IP_Access',
                    684:                         header => [{col1 => 'Setting',
                    685:                                     col2 => 'Value'},],
                    686:                         print  => \&print_ipaccess,
                    687:                         modify => \&modify_ipaccess,
                    688:                        },
1.436     raeburn   689:         'authordefaults' =>
1.429     raeburn   690:                             {text => 'Authoring Space defaults',
                    691:                              help => 'Domain_Configuration_Author_Defaults',
                    692:                              header => [{col1 => 'Defaults which can be overridden by Author',
                    693:                                          col2 => 'Settings',},
                    694:                                         {col1 => 'Defaults which can be overridden by a Dom. Coord.',
                    695:                                          col2 => 'Settings',},],
                    696:                              print => \&print_authordefaults,
                    697:                              modify => \&modify_authordefaults,
                    698:                             },
1.3       raeburn   699:     );
1.110     raeburn   700:     if (keys(%servers) > 1) {
                    701:         $prefs{'login'}  = { text   => 'Log-in page options',
                    702:                              help   => 'Domain_Configuration_Login_Page',
                    703:                             header => [{col1 => 'Log-in Service',
                    704:                                         col2 => 'Server Setting',},
                    705:                                        {col1 => 'Log-in Page Items',
1.405     raeburn   706:                                         col2 => 'Settings'},
1.168     raeburn   707:                                        {col1 => 'Log-in Help',
1.256     raeburn   708:                                         col2 => 'Value'},
                    709:                                        {col1 => 'Custom HTML in document head',
1.386     raeburn   710:                                         col2 => 'Value'},
                    711:                                        {col1 => 'SSO',
                    712:                                         col2 => 'Dual login: SSO and non-SSO options'},
                    713:                                       ],
1.230     raeburn   714:                             print => \&print_login,
                    715:                             modify => \&modify_login,
1.110     raeburn   716:                            };
                    717:     }
1.174     foxr      718: 
1.6       raeburn   719:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   720:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   721:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   722:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   723:       text=>"Settings to display/modify"});
1.9       raeburn   724:     my $confname = $dom.'-domainconfig';
1.174     foxr      725: 
1.3       raeburn   726:     if ($phase eq 'process') {
1.212     raeburn   727:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    728:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   729:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   730:             $r->rflush();
1.212     raeburn   731:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   732:         }
1.30      raeburn   733:     } elsif ($phase eq 'display') {
1.192     raeburn   734:         my $js = &recaptcha_js().
1.236     raeburn   735:                  &toggle_display_js();
1.171     raeburn   736:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   737:             my ($othertitle,$usertypes,$types) =
                    738:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   739:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    740:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   741:                    &new_spares_js().
                    742:                    &common_domprefs_js().
                    743:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   744:         }
1.216     raeburn   745:         if (grep(/^requestcourses$/,@actions)) {
                    746:             my $javascript_validations;
                    747:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    748:             $js .= <<END;
                    749: <script type="text/javascript">
                    750: $javascript_validations
                    751: </script>
                    752: $coursebrowserjs
                    753: END
1.394     raeburn   754:         } elsif (grep(/^ipaccess$/,@actions)) {
                    755:             $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216     raeburn   756:         }
1.305     raeburn   757:         if (grep(/^selfcreation$/,@actions)) {
                    758:             $js .= &selfcreate_javascript();
                    759:         }
1.286     raeburn   760:         if (grep(/^contacts$/,@actions)) {
                    761:             $js .= &contacts_javascript();
                    762:         }
1.346     raeburn   763:         if (grep(/^scantron$/,@actions)) {
                    764:             $js .= &scantron_javascript();
                    765:         }
1.150     raeburn   766:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   767:     } else {
1.180     raeburn   768: # check if domconfig user exists for the domain.
                    769:         my $servadm = $r->dir_config('lonAdmEMail');
                    770:         my ($configuserok,$author_ok,$switchserver) =
                    771:             &config_check($dom,$confname,$servadm);
                    772:         unless ($configuserok eq 'ok') {
1.181     raeburn   773:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    774:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   775:                           $confname).
1.181     raeburn   776:                       '<br />'
                    777:             );
1.180     raeburn   778:             if ($switchserver) {
1.181     raeburn   779:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    780:                           '<br />'.
                    781:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    782:                           '<br />'.
                    783:                           &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
                    784:                           '<br />'.
                    785:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    786:                 );
                    787:             } else {
                    788:                 $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
                    789:                           '<br />'.
                    790:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    791:                 );
1.180     raeburn   792:             }
                    793:             $r->print(&Apache::loncommon::end_page());
                    794:             return OK;
                    795:         }
1.21      raeburn   796:         if (keys(%domconfig) == 0) {
                    797:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   798:             my @ids=&Apache::lonnet::current_machine_ids();
                    799:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   800:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   801:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   802:                 my $custom_img_count = 0;
                    803:                 foreach my $img (@loginimages) {
                    804:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    805:                         $custom_img_count ++;
                    806:                     }
                    807:                 }
                    808:                 foreach my $role (@roles) {
                    809:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    810:                         $custom_img_count ++;
                    811:                     }
                    812:                 }
                    813:                 if ($custom_img_count > 0) {
1.94      raeburn   814:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   815:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   816:                     $r->print(
                    817:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    818:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    819:     &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 />'.
                    820:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    821:                     if ($switch_server) {
1.30      raeburn   822:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   823:                     }
1.91      raeburn   824:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   825:                     return OK;
                    826:                 }
                    827:             }
                    828:         }
1.91      raeburn   829:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   830:     }
                    831:     return OK;
                    832: }
                    833: 
                    834: sub process_changes {
1.205     raeburn   835:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   836:     my %domconfig;
                    837:     if (ref($values) eq 'HASH') {
                    838:         %domconfig = %{$values};
                    839:     }
1.3       raeburn   840:     my $output;
                    841:     if ($action eq 'login') {
1.205     raeburn   842:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   843:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   844:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   845:                                      $lastactref,%domconfig);
1.3       raeburn   846:     } elsif ($action eq 'quotas') {
1.216     raeburn   847:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   848:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   849:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   850:     } elsif ($action eq 'autoupdate') {
                    851:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   852:     } elsif ($action eq 'autocreate') {
                    853:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   854:     } elsif ($action eq 'directorysrch') {
1.295     raeburn   855:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   856:     } elsif ($action eq 'usercreation') {
1.28      raeburn   857:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   858:     } elsif ($action eq 'selfcreation') {
1.305     raeburn   859:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   860:     } elsif ($action eq 'usermodification') {
                    861:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   862:     } elsif ($action eq 'contacts') {
1.205     raeburn   863:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   864:     } elsif ($action eq 'defaults') {
1.212     raeburn   865:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   866:     } elsif ($action eq 'scantron') {
1.205     raeburn   867:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   868:     } elsif ($action eq 'coursecategories') {
1.239     raeburn   869:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   870:     } elsif ($action eq 'serverstatuses') {
                    871:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   872:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   873:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   874:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   875:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       876:     } elsif ($action eq 'helpsettings') {
1.285     raeburn   877:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121     raeburn   878:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   879:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   880:     } elsif ($action eq 'selfenrollment') {
                    881:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   882:     } elsif ($action eq 'usersessions') {
1.212     raeburn   883:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   884:     } elsif ($action eq 'loadbalancing') {
                    885:         $output = &modify_loadbalancing($dom,%domconfig);
1.267     raeburn   886:     } elsif ($action eq 'ltitools') {
                    887:         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372     raeburn   888:     } elsif ($action eq 'proctoring') {
                    889:         $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275     raeburn   890:     } elsif ($action eq 'ssl') {
                    891:         $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279     raeburn   892:     } elsif ($action eq 'trust') {
                    893:         $output = &modify_trust($dom,$lastactref,%domconfig);
1.320     raeburn   894:     } elsif ($action eq 'lti') {
                    895:         $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357     raeburn   896:     } elsif ($action eq 'privacy') {
1.427     raeburn   897:         $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354     raeburn   898:     } elsif ($action eq 'passwords') {
                    899:         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373     raeburn   900:     } elsif ($action eq 'wafproxy') {
                    901:         $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394     raeburn   902:     } elsif ($action eq 'ipaccess') {
                    903:         $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429     raeburn   904:     } elsif ($action eq 'authordefaults') {
                    905:         $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3       raeburn   906:     }
                    907:     return $output;
                    908: }
                    909: 
                    910: sub print_config_box {
1.9       raeburn   911:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   912:     my $rowtotal = 0;
1.49      raeburn   913:     my $output;
                    914:     if ($action eq 'coursecategories') {
                    915:         $output = &coursecategories_javascript($settings);
1.236     raeburn   916:     } elsif ($action eq 'defaults') {
                    917:         $output = &defaults_javascript($settings); 
1.354     raeburn   918:     } elsif ($action eq 'passwords') {
1.405     raeburn   919:         $output = &passwords_javascript($action);
1.282     raeburn   920:     } elsif ($action eq 'helpsettings') {
                    921:         my (%privs,%levelscurrent);
                    922:         my %full=();
                    923:         my %levels=(
                    924:                      course => {},
                    925:                      domain => {},
                    926:                      system => {},
                    927:                    );
                    928:         my $context = 'domain';
                    929:         my $crstype = 'Course';
                    930:         my $formname = 'display';
                    931:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    932:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    933:         $output =
1.425     raeburn   934:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282     raeburn   935:                                                       \@templateroles);
1.334     raeburn   936:     } elsif ($action eq 'ltitools') {
1.421     raeburn   937:         $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334     raeburn   938:     } elsif ($action eq 'lti') {
1.421     raeburn   939:         $output .= &passwords_javascript('ltisecrets')."\n".
1.405     raeburn   940:                    &lti_javascript($dom,$settings);
1.372     raeburn   941:     } elsif ($action eq 'proctoring') {
                    942:         $output .= &proctoring_javascript($settings);
1.381     raeburn   943:     } elsif ($action eq 'wafproxy') {
                    944:         $output .= &wafproxy_javascript($dom);
1.385     raeburn   945:     } elsif ($action eq 'autoupdate') {
                    946:         $output .= &autoupdate_javascript();
1.399     raeburn   947:     } elsif ($action eq 'autoenroll') {
                    948:         $output .= &autoenroll_javascript();
1.386     raeburn   949:     } elsif ($action eq 'login') {
                    950:         $output .= &saml_javascript();
1.394     raeburn   951:     } elsif ($action eq 'ipaccess') {
                    952:         $output .= &ipaccess_javascript($settings);
1.429     raeburn   953:     } elsif ($action eq 'authordefaults') {
                    954:         $output .= &authordefaults_javascript();
1.91      raeburn   955:     }
1.236     raeburn   956:     $output .=
1.30      raeburn   957:          '<table class="LC_nested_outer">
1.3       raeburn   958:           <tr>
1.306     raeburn   959:            <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66      raeburn   960:            &mt($item->{text}).'&nbsp;'.
                    961:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    962:           '</tr>';
1.30      raeburn   963:     $rowtotal ++;
1.110     raeburn   964:     my $numheaders = 1;
                    965:     if (ref($item->{'header'}) eq 'ARRAY') {
                    966:         $numheaders = scalar(@{$item->{'header'}});
                    967:     }
                    968:     if ($numheaders > 1) {
1.64      raeburn   969:         my $colspan = '';
1.145     raeburn   970:         my $rightcolspan = '';
1.369     raeburn   971:         my $leftnobr = '';
1.238     raeburn   972:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   973:             ($action eq 'directorysrch') ||
1.386     raeburn   974:             (($action eq 'login') && ($numheaders < 5))) {
1.64      raeburn   975:             $colspan = ' colspan="2"';
                    976:         }
1.145     raeburn   977:         if ($action eq 'usersessions') {
                    978:             $rightcolspan = ' colspan="3"'; 
                    979:         }
1.369     raeburn   980:         if ($action eq 'passwords') {
                    981:             $leftnobr = ' LC_nobreak';
                    982:         }
1.30      raeburn   983:         $output .= '
1.3       raeburn   984:           <tr>
                    985:            <td>
                    986:             <table class="LC_nested">
                    987:              <tr class="LC_info_row">
1.369     raeburn   988:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   989:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   990:              </tr>';
1.69      raeburn   991:         $rowtotal ++;
1.230     raeburn   992:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   993:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   994:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286     raeburn   995:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421     raeburn   996:             ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429     raeburn   997:             ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230     raeburn   998:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354     raeburn   999:         } elsif ($action eq 'passwords') {
                   1000:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn  1001:         } elsif ($action eq 'coursecategories') {
1.230     raeburn  1002:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346     raeburn  1003:         } elsif ($action eq 'scantron') {
                   1004:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn  1005:         } elsif ($action eq 'login') {
1.386     raeburn  1006:             if ($numheaders == 5) {
1.168     raeburn  1007:                 $colspan = ' colspan="2"';
                   1008:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                   1009:             } else {
                   1010:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                   1011:             }
1.230     raeburn  1012:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn  1013:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms      1014:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1015:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn  1016:         }
1.30      raeburn  1017:         $output .= '
1.6       raeburn  1018:            </table>
                   1019:           </td>
                   1020:          </tr>
                   1021:          <tr>
                   1022:            <td>
                   1023:             <table class="LC_nested">
                   1024:              <tr class="LC_info_row">
1.230     raeburn  1025:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz   1026:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn  1027:              </tr>';
                   1028:             $rowtotal ++;
1.230     raeburn  1029:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                   1030:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn  1031:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.409     raeburn  1032:             ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421     raeburn  1033:             ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
                   1034:             ($action eq 'ltitools')) {
1.238     raeburn  1035:             if ($action eq 'coursecategories') {
                   1036:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                   1037:                 $colspan = ' colspan="2"';
1.279     raeburn  1038:             } elsif ($action eq 'trust') {
                   1039:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354     raeburn  1040:             } elsif ($action eq 'passwords') {
                   1041:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434     raeburn  1042:             } elsif ($action eq 'lti') {
                   1043:                 $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
                   1044:                            </table>
                   1045:                           </td>
                   1046:                          </tr>
                   1047:                          <tr>
                   1048:                           <td>
                   1049:                           <table class="LC_nested">
                   1050:                            <tr class="LC_info_row">
                   1051:                             <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1052:                             <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                   1053:                            </tr>'."\n".
                   1054:                            $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238     raeburn  1055:             } else {
                   1056:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                   1057:             }
1.279     raeburn  1058:             if ($action eq 'trust') {
                   1059:                 $output .= '
                   1060:             </table>
                   1061:           </td>
                   1062:          </tr>';
                   1063:                 my @trusthdrs = qw(2 3 4 5 6 7);
                   1064:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                   1065:                 for (my $i=0; $i<@trusthdrs; $i++) {
                   1066:                     $output .= '
                   1067:          <tr>
                   1068:            <td>
                   1069:             <table class="LC_nested">
                   1070:              <tr class="LC_info_row">
                   1071:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                   1072:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                   1073:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                   1074:             </table>
                   1075:           </td>
                   1076:          </tr>';
                   1077:                 }
                   1078:                 $output .= '
                   1079:          <tr>
                   1080:            <td>
                   1081:             <table class="LC_nested">
                   1082:              <tr class="LC_info_row">
                   1083:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                   1084:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                   1085:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1086:             } else {
1.434     raeburn  1087:                 my $hdridx = 2;
                   1088:                 if ($action eq 'lti') {
                   1089:                     $hdridx = 3;
                   1090:                 }
1.279     raeburn  1091:                 $output .= '
1.63      raeburn  1092:            </table>
                   1093:           </td>
                   1094:          </tr>
                   1095:          <tr>
                   1096:            <td>
                   1097:             <table class="LC_nested">
                   1098:              <tr class="LC_info_row">
1.434     raeburn  1099:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
                   1100:               <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238     raeburn  1101:              </tr>'."\n";
1.279     raeburn  1102:                 if ($action eq 'coursecategories') {
                   1103:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405     raeburn  1104:                 } elsif (($action eq 'contacts') || ($action eq 'privacy') || 
                   1105:                          ($action eq 'passwords') || ($action eq 'lti')) {
1.354     raeburn  1106:                     if ($action eq 'passwords') {
                   1107:                         $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                   1108:                     } else {
                   1109:                         $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                   1110:                     }
1.434     raeburn  1111:                     $hdridx ++;
1.354     raeburn  1112:                     $output .= '
1.340     raeburn  1113:              </tr>
                   1114:             </table>
                   1115:            </td>
                   1116:           </tr>
                   1117:           <tr>
                   1118:            <td>
                   1119:             <table class="LC_nested">
                   1120:              <tr class="LC_info_row">
1.434     raeburn  1121:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
                   1122:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354     raeburn  1123:                     if ($action eq 'passwords') {
                   1124:                         $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                   1125:                     } else {
                   1126:                         $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1127:                     }
                   1128:                     $output .= '
1.340     raeburn  1129:             </table>
                   1130:           </td>
                   1131:          </tr>
                   1132:          <tr>';
1.279     raeburn  1133:                 } else {
                   1134:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1135:                 }
1.238     raeburn  1136:             }
1.63      raeburn  1137:             $rowtotal ++;
1.236     raeburn  1138:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409     raeburn  1139:                  ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.429     raeburn  1140:                  ($action eq 'wafproxy') || ($action eq 'authordefaults')) {
1.230     raeburn  1141:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346     raeburn  1142:         } elsif ($action eq 'scantron') {
                   1143:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293     raeburn  1144:         } elsif ($action eq 'ssl') {
                   1145:             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
                   1146:             </table>
                   1147:           </td>
                   1148:          </tr>
                   1149:          <tr>
                   1150:            <td>
                   1151:             <table class="LC_nested">
                   1152:              <tr class="LC_info_row">
                   1153:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1154:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                   1155:                            $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
                   1156:             </table>
                   1157:           </td>
                   1158:          </tr>
                   1159:          <tr>
                   1160:            <td>
                   1161:             <table class="LC_nested">
                   1162:              <tr class="LC_info_row">
                   1163:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1164:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                   1165:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn  1166:         } elsif ($action eq 'login') {
1.386     raeburn  1167:             if ($numheaders == 5) {
1.168     raeburn  1168:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1169:            </table>
                   1170:           </td>
                   1171:          </tr>
                   1172:          <tr>
                   1173:            <td>
                   1174:             <table class="LC_nested">
                   1175:              <tr class="LC_info_row">
                   1176:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn  1177:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn  1178:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1179:                 $rowtotal ++;
                   1180:             } else {
                   1181:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1182:             }
1.256     raeburn  1183:             $output .= '
                   1184:            </table>
                   1185:           </td>
                   1186:          </tr>
                   1187:          <tr>
                   1188:            <td>
                   1189:             <table class="LC_nested">
                   1190:              <tr class="LC_info_row">';
1.386     raeburn  1191:             if ($numheaders == 5) {
1.256     raeburn  1192:                 $output .= '
                   1193:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1194:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1195:              </tr>';
                   1196:             } else {
                   1197:                 $output .= '
                   1198:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1199:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                   1200:              </tr>';
                   1201:             }
                   1202:             $rowtotal ++;
1.386     raeburn  1203:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1204:            </table>
                   1205:           </td>
                   1206:          </tr>
                   1207:          <tr>
                   1208:            <td>
                   1209:             <table class="LC_nested">
                   1210:              <tr class="LC_info_row">';
                   1211:             if ($numheaders == 5) {
                   1212:                 $output .= '
                   1213:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1214:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
                   1215:              </tr>';
                   1216:             } else {
                   1217:                 $output .= '
                   1218:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1219:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1220:              </tr>';
                   1221:             }
                   1222:             $rowtotal ++;
                   1223:             $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn  1224:         } elsif ($action eq 'requestcourses') {
1.247     raeburn  1225:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                   1226:             $rowtotal ++;
                   1227:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn  1228:            </table>
                   1229:           </td>
                   1230:          </tr>
                   1231:          <tr>
                   1232:            <td>
                   1233:             <table class="LC_nested">
                   1234:              <tr class="LC_info_row">
                   1235:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1236:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn  1237:                        &textbookcourses_javascript($settings).
                   1238:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                   1239:             </table>
                   1240:            </td>
                   1241:           </tr>
                   1242:          <tr>
                   1243:            <td>
                   1244:             <table class="LC_nested">
                   1245:              <tr class="LC_info_row">
                   1246:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1247:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                   1248:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn  1249:             </table>
                   1250:            </td>
                   1251:           </tr>
                   1252:           <tr>
                   1253:            <td>
                   1254:             <table class="LC_nested">
                   1255:              <tr class="LC_info_row">
1.306     raeburn  1256:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1257:               <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn  1258:              </tr>'.
                   1259:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn  1260:         } elsif ($action eq 'requestauthor') {
                   1261:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn  1262:             $rowtotal ++;
1.122     jms      1263:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1264:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn  1265:            </table>
                   1266:           </td>
                   1267:          </tr>
                   1268:          <tr>
                   1269:            <td>
                   1270:             <table class="LC_nested">
                   1271:              <tr class="LC_info_row">
1.306     raeburn  1272:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69      raeburn  1273:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306     raeburn  1274:               <td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1275:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1276:              </tr>'.
1.30      raeburn  1277:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1278:            </table>
                   1279:           </td>
                   1280:          </tr>
                   1281:          <tr>
                   1282:            <td>
                   1283:             <table class="LC_nested">
                   1284:              <tr class="LC_info_row">
1.59      bisitz   1285:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1286:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1287:              </tr>'.
1.30      raeburn  1288:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1289:             $rowtotal += 2;
1.6       raeburn  1290:         }
1.3       raeburn  1291:     } else {
1.30      raeburn  1292:         $output .= '
1.3       raeburn  1293:           <tr>
                   1294:            <td>
                   1295:             <table class="LC_nested">
1.30      raeburn  1296:              <tr class="LC_info_row">';
1.277     raeburn  1297:         if ($action eq 'login') {
1.30      raeburn  1298:             $output .= '  
1.59      bisitz   1299:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1300:         } elsif ($action eq 'serverstatuses') {
                   1301:             $output .= '
1.306     raeburn  1302:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69      raeburn  1303:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1304: 
1.6       raeburn  1305:         } else {
1.30      raeburn  1306:             $output .= '
1.306     raeburn  1307:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1308:         }
1.72      raeburn  1309:         if (defined($item->{'header'}->[0]->{'col3'})) {
1.306     raeburn  1310:             $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72      raeburn  1311:                        &mt($item->{'header'}->[0]->{'col2'});
                   1312:             if ($action eq 'serverstatuses') {
                   1313:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1314:             } 
1.69      raeburn  1315:         } else {
1.306     raeburn  1316:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1317:                        &mt($item->{'header'}->[0]->{'col2'});
                   1318:         }
                   1319:         $output .= '</td>';
                   1320:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1321:             if (defined($item->{'header'}->[0]->{'col4'})) {
1.306     raeburn  1322:                 $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150     raeburn  1323:                             &mt($item->{'header'}->[0]->{'col3'});
                   1324:             } else {
1.306     raeburn  1325:                 $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1326:                            &mt($item->{'header'}->[0]->{'col3'});
                   1327:             }
1.69      raeburn  1328:             if ($action eq 'serverstatuses') {
                   1329:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1330:             }
                   1331:             $output .= '</td>';
1.6       raeburn  1332:         }
1.150     raeburn  1333:         if ($item->{'header'}->[0]->{'col4'}) {
1.306     raeburn  1334:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1335:                        &mt($item->{'header'}->[0]->{'col4'});
                   1336:         }
1.69      raeburn  1337:         $output .= '</tr>';
1.48      raeburn  1338:         $rowtotal ++;
1.168     raeburn  1339:         if ($action eq 'quotas') {
1.86      raeburn  1340:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1341:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.286     raeburn  1342:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
1.421     raeburn  1343:                  ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230     raeburn  1344:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1345:         }
1.3       raeburn  1346:     }
1.30      raeburn  1347:     $output .= '
1.3       raeburn  1348:    </table>
                   1349:   </td>
                   1350:  </tr>
1.30      raeburn  1351: </table><br />';
                   1352:     return ($output,$rowtotal);
1.1       raeburn  1353: }
                   1354: 
1.3       raeburn  1355: sub print_login {
1.168     raeburn  1356:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386     raeburn  1357:     my ($css_class,$datatable,$switchserver,%lt);
1.6       raeburn  1358:     my %choices = &login_choices();
1.386     raeburn  1359:     if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
                   1360:         %lt = &login_file_options();
                   1361:         $switchserver = &check_switchserver($dom,$confname);
                   1362:     }
1.168     raeburn  1363:     if ($caller eq 'service') {
1.149     raeburn  1364:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1365:         my $choice = $choices{'disallowlogin'};
                   1366:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1367:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306     raeburn  1368:                       '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1369:                       '<th>'.$choices{'server'}.'</th>'.
                   1370:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1371:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1372:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1373:         my %disallowed;
                   1374:         if (ref($settings) eq 'HASH') {
                   1375:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1376:                %disallowed = %{$settings->{'loginvia'}};
                   1377:             }
                   1378:         }
                   1379:         foreach my $lonhost (sort(keys(%servers))) {
                   1380:             my $direct = 'selected="selected"';
1.128     raeburn  1381:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1382:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1383:                     $direct = '';
                   1384:                 }
1.110     raeburn  1385:             }
1.115     raeburn  1386:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1387:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1388:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1389:                           '</option>';
1.184     raeburn  1390:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1391:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1392:                 my $selected = '';
1.128     raeburn  1393:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1394:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1395:                         $selected = 'selected="selected"';
                   1396:                     }
1.110     raeburn  1397:                 }
                   1398:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1399:                               $servers{$hostid}.'</option>';
                   1400:             }
1.128     raeburn  1401:             $datatable .= '</select></td>'.
                   1402:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1403:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1404:                 my $pathname = $path;
                   1405:                 if ($path eq 'custom') {
                   1406:                     $pathname = &mt('Custom Path').' ->';
                   1407:                 }
                   1408:                 my $selected = '';
                   1409:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1410:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1411:                         $selected = 'selected="selected"';
                   1412:                     }
                   1413:                 } elsif ($path eq '') {
                   1414:                     $selected = 'selected="selected"';
                   1415:                 }
                   1416:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1417:             }
                   1418:             $datatable .= '</select></td>';
                   1419:             my ($custom,$exempt);
                   1420:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1421:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1422:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1423:             }
                   1424:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1425:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1426:                           '</tr>';
1.110     raeburn  1427:         }
                   1428:         $datatable .= '</table></td></tr>';
                   1429:         return $datatable;
1.168     raeburn  1430:     } elsif ($caller eq 'page') {
                   1431:         my %defaultchecked = ( 
                   1432:                                'coursecatalog' => 'on',
1.188     raeburn  1433:                                'helpdesk'      => 'on',
1.168     raeburn  1434:                                'adminmail'     => 'off',
                   1435:                                'newuser'       => 'off',
                   1436:                              );
1.188     raeburn  1437:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1438:         my (%checkedon,%checkedoff);
1.42      raeburn  1439:         foreach my $item (@toggles) {
1.168     raeburn  1440:             if ($defaultchecked{$item} eq 'on') { 
                   1441:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1442:                 $checkedoff{$item} = ' ';
1.168     raeburn  1443:             } elsif ($defaultchecked{$item} eq 'off') {
                   1444:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1445:                 $checkedon{$item} = ' ';
                   1446:             }
1.1       raeburn  1447:         }
1.168     raeburn  1448:         my @images = ('img','logo','domlogo','login');
1.402     raeburn  1449:         my @alttext = ('img','logo','domlogo');
1.168     raeburn  1450:         my @logintext = ('textcol','bgcol');
                   1451:         my @bgs = ('pgbg','mainbg','sidebg');
                   1452:         my @links = ('link','alink','vlink');
                   1453:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1454:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1455:         my (%is_custom,%designs);
                   1456:         my %defaults = (
                   1457:                        font => $defaultdesign{'login.font'},
                   1458:                        );
1.6       raeburn  1459:         foreach my $item (@images) {
1.168     raeburn  1460:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1461:             $defaults{'showlogo'}{$item} = 1;
                   1462:         }
                   1463:         foreach my $item (@bgs) {
                   1464:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1465:         }
1.41      raeburn  1466:         foreach my $item (@logintext) {
1.168     raeburn  1467:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1468:         }
1.168     raeburn  1469:         foreach my $item (@links) {
                   1470:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1471:         }
1.168     raeburn  1472:         if (ref($settings) eq 'HASH') {
                   1473:             foreach my $item (@toggles) {
                   1474:                 if ($settings->{$item} eq '1') {
                   1475:                     $checkedon{$item} =  ' checked="checked" ';
                   1476:                     $checkedoff{$item} = ' ';
                   1477:                 } elsif ($settings->{$item} eq '0') {
                   1478:                     $checkedoff{$item} =  ' checked="checked" ';
                   1479:                     $checkedon{$item} = ' ';
                   1480:                 }
                   1481:             }
                   1482:             foreach my $item (@images) {
                   1483:                 if (defined($settings->{$item})) {
                   1484:                     $designs{$item} = $settings->{$item};
                   1485:                     $is_custom{$item} = 1;
                   1486:                 }
                   1487:                 if (defined($settings->{'showlogo'}{$item})) {
                   1488:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1489:                 }
                   1490:             }
1.402     raeburn  1491:             foreach my $item (@alttext) {
                   1492:                 if (ref($settings->{'alttext'}) eq 'HASH') {
                   1493:                     if ($settings->{'alttext'}->{$item} ne '') {
                   1494:                         $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
                   1495:                     }
                   1496:                 }
                   1497:             }
1.168     raeburn  1498:             foreach my $item (@logintext) {
                   1499:                 if ($settings->{$item} ne '') {
                   1500:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1501:                     $is_custom{$item} = 1;
                   1502:                 }
                   1503:             }
                   1504:             if ($settings->{'font'} ne '') {
                   1505:                 $designs{'font'} = $settings->{'font'};
                   1506:                 $is_custom{'font'} = 1;
                   1507:             }
                   1508:             foreach my $item (@bgs) {
                   1509:                 if ($settings->{$item} ne '') {
                   1510:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1511:                     $is_custom{$item} = 1;
                   1512:                 }
                   1513:             }
                   1514:             foreach my $item (@links) {
                   1515:                 if ($settings->{$item} ne '') {
                   1516:                     $designs{'links'}{$item} = $settings->{$item};
                   1517:                     $is_custom{$item} = 1;
                   1518:                 }
                   1519:             }
                   1520:         } else {
                   1521:             if ($designhash{$dom.'.login.font'} ne '') {
                   1522:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1523:                 $is_custom{'font'} = 1;
                   1524:             }
                   1525:             foreach my $item (@images) {
                   1526:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1527:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1528:                     $is_custom{$item} = 1;
                   1529:                 }
                   1530:             }
                   1531:             foreach my $item (@bgs) {
                   1532:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1533:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1534:                     $is_custom{$item} = 1;
                   1535:                 }
1.6       raeburn  1536:             }
1.168     raeburn  1537:             foreach my $item (@links) {
                   1538:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1539:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1540:                     $is_custom{$item} = 1;
                   1541:                 }
1.6       raeburn  1542:             }
                   1543:         }
1.168     raeburn  1544:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1545:                                                       logo => 'Institution Logo',
                   1546:                                                       domlogo => 'Domain Logo',
                   1547:                                                       login => 'Login box');
                   1548:         my $itemcount = 1;
                   1549:         foreach my $item (@toggles) {
                   1550:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1551:             $datatable .=  
                   1552:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1553:                 '</td><td>'.
                   1554:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1555:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1556:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1557:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1558:                 '</tr>';
                   1559:             $itemcount ++;
1.6       raeburn  1560:         }
1.168     raeburn  1561:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1562:         $datatable .= '</tr></table></td></tr>';
                   1563:     } elsif ($caller eq 'help') {
1.386     raeburn  1564:         my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168     raeburn  1565:         my $itemcount = 1;
                   1566:         $defaulturl = '/adm/loginproblems.html';
                   1567:         $defaulttype = 'default';
                   1568:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1569:         my @currlangs;
                   1570:         if (ref($settings) eq 'HASH') {
                   1571:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1572:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1573:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1574:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1575:                     $type{$key} = 'custom';
                   1576:                     unless ($key eq 'nolang') {
                   1577:                         push(@currlangs,$key);
                   1578:                     }
                   1579:                 }
                   1580:             } elsif ($settings->{'helpurl'} ne '') {
                   1581:                 $type{'nolang'} = 'custom';
                   1582:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1583:             }
                   1584:         }
1.168     raeburn  1585:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1586:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1587:             $datatable .= '<tr'.$css_class.'>';
                   1588:             if ($url{$lang} eq '') {
                   1589:                 $url{$lang} = $defaulturl;
                   1590:             }
                   1591:             if ($type{$lang} eq '') {
                   1592:                 $type{$lang} = $defaulttype;
                   1593:             }
                   1594:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1595:             if ($lang eq 'nolang') {
                   1596:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1597:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1598:             } else {
                   1599:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1600:                                   $langchoices{$lang},
                   1601:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1602:             }
                   1603:             $datatable .= '</span></td>'."\n".
                   1604:                           '<td class="LC_left_item">';
                   1605:             if ($type{$lang} eq 'custom') {
                   1606:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1607:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1608:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1609:             } else {
                   1610:                 $datatable .= $lt{'upl'};
                   1611:             }
                   1612:             $datatable .='<br />';
                   1613:             if ($switchserver) {
                   1614:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1615:             } else {
                   1616:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1617:             }
1.168     raeburn  1618:             $datatable .= '</td></tr>';
                   1619:             $itemcount ++;
1.6       raeburn  1620:         }
1.168     raeburn  1621:         my @addlangs;
                   1622:         foreach my $lang (sort(keys(%langchoices))) {
                   1623:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1624:             push(@addlangs,$lang);
                   1625:         }
                   1626:         if (@addlangs > 0) {
                   1627:             my %toadd;
                   1628:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1629:             $toadd{''} = &mt('Select');
                   1630:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1631:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1632:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1633:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1634:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1635:             if ($switchserver) {
                   1636:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1637:             } else {
                   1638:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1639:             }
1.168     raeburn  1640:             $datatable .= '</td></tr>';
1.169     raeburn  1641:             $itemcount ++;
1.6       raeburn  1642:         }
1.169     raeburn  1643:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1644:     } elsif ($caller eq 'headtag') {
                   1645:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1646:         my $choice = $choices{'headtag'};
                   1647:         $css_class = ' class="LC_odd_row"';
                   1648:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1649:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1650:                       '<th>'.$choices{'current'}.'</th>'.
                   1651:                       '<th>'.$choices{'action'}.'</th>'.
                   1652:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1653:         my (%currurls,%currexempt);
                   1654:         if (ref($settings) eq 'HASH') {
                   1655:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1656:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1657:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1658:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1659:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1660:                     }
                   1661:                 }
                   1662:             }
                   1663:         }
                   1664:         foreach my $lonhost (sort(keys(%domservers))) {
                   1665:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1666:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1667:             if ($currurls{$lonhost}) {
                   1668:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1669:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1670:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1671:                               '">'.$lt{'curr'}.'</a></td>'.
                   1672:                               '<td><span class="LC_nobreak"><label>'.
                   1673:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1674:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1675:             } else {
                   1676:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1677:             }
                   1678:             $datatable .='<br />';
                   1679:             if ($switchserver) {
                   1680:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1681:             } else {
                   1682:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1683:             }
1.330     raeburn  1684:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256     raeburn  1685:         }
                   1686:         $datatable .= '</table></td></tr>';
1.386     raeburn  1687:     } elsif ($caller eq 'saml') {
                   1688:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1689:         $datatable .= '<tr><td colspan="3" style="text-align: left">'.
                   1690:                       '<table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1691:                       '<th>'.$choices{'samllanding'}.'</th>'.
                   1692:                       '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412     raeburn  1693:         my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386     raeburn  1694:         foreach my $lonhost (keys(%domservers)) {
                   1695:             $samlurl{$lonhost} = '/adm/sso';
                   1696:             $styleon{$lonhost} = 'display:none';
                   1697:             $styleoff{$lonhost} = '';
                   1698:         }
1.411     raeburn  1699:         if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386     raeburn  1700:             foreach my $lonhost (keys(%{$settings->{'saml'}})) {
                   1701:                 if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
                   1702:                     $saml{$lonhost} = 1;
                   1703:                     $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
                   1704:                     $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
                   1705:                     $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                   1706:                     $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                   1707:                     $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412     raeburn  1708:                     $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386     raeburn  1709:                     $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                   1710:                     $styleon{$lonhost} = '';
                   1711:                     $styleoff{$lonhost} = 'display:none';
                   1712:                 } else {
                   1713:                     $styleon{$lonhost} = 'display:none';
                   1714:                     $styleoff{$lonhost} = '';
                   1715:                 }
                   1716:             }
                   1717:         }
                   1718:         my $itemcount = 1;
                   1719:         foreach my $lonhost (sort(keys(%domservers))) {
                   1720:             my $samlon = ' ';
                   1721:             my $samloff = ' checked="checked" ';
                   1722:             if ($saml{$lonhost}) {
                   1723:                 $samlon = $samloff;
                   1724:                 $samloff = ' ';
                   1725:             }
1.412     raeburn  1726:             my $samlwinon = '';
                   1727:             my $samlwinoff = ' checked="checked"';
                   1728:             if ($samlwindow{$lonhost}) {
                   1729:                 $samlwinon = $samlwinoff;
                   1730:                 $samlwinoff = '';
                   1731:             }
1.386     raeburn  1732:             my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1733:             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
                   1734:                           '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
                   1735:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
                   1736:                           &mt('No').'</label>'.('&nbsp;'x2).
                   1737:                           '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
                   1738:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
                   1739:                           &mt('Yes').'</label></span></td>'.
                   1740:                           '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412     raeburn  1741:                           '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386     raeburn  1742:                           '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412     raeburn  1743:                           '<th>'.&mt('Alt Text').'</th></tr>'.
                   1744:                           '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386     raeburn  1745:                           $samltext{$lonhost}.'" /></td><td>';
                   1746:             if ($samlimg{$lonhost}) {
                   1747:                 $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
                   1748:                               '<span class="LC_nobreak"><label>'.
                   1749:                               '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
                   1750:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1751:             } else {
                   1752:                 $datatable .= $lt{'upl'};
                   1753:             }
                   1754:             $datatable .='<br />';
                   1755:             if ($switchserver) {
                   1756:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1757:             } else {
                   1758:                 $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
                   1759:             }
                   1760:             $datatable .= '</td>'.
1.412     raeburn  1761:                           '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
                   1762:                           'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
                   1763:                           '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
                   1764:                           '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
                   1765:                           '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
                   1766:                           '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
                   1767:                           '<tr'.$css_class.'>'.
                   1768:                           '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386     raeburn  1769:                           'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412     raeburn  1770:                           '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386     raeburn  1771:                           $samltitle{$lonhost}.'</textarea></td>'.
1.412     raeburn  1772:                           '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
                   1773:                           &mt('No').'</label>'.('&nbsp;'x2).'<label><input type="radio" '.
                   1774:                           'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
                   1775:                           '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386     raeburn  1776:                           'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                   1777:                           '</table></td>'.
                   1778:                           '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%">&nbsp;</td></tr>';
                   1779:            $itemcount ++;
                   1780:         }
                   1781:         $datatable .= '</table></td></tr>';
1.1       raeburn  1782:     }
1.6       raeburn  1783:     return $datatable;
                   1784: }
                   1785: 
                   1786: sub login_choices {
                   1787:     my %choices =
                   1788:         &Apache::lonlocal::texthash (
1.116     bisitz   1789:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1790:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1791:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1792:             disallowlogin => "Login page requests redirected",
                   1793:             hostid        => "Server",
1.128     raeburn  1794:             server        => "Redirect to:",
                   1795:             serverpath    => "Path",
                   1796:             custompath    => "Custom", 
                   1797:             exempt        => "Exempt IP(s)",
1.110     raeburn  1798:             directlogin   => "No redirect",
                   1799:             newuser       => "Link to create a user account",
                   1800:             img           => "Header",
                   1801:             logo          => "Main Logo",
                   1802:             domlogo       => "Domain Logo",
                   1803:             login         => "Log-in Header", 
                   1804:             textcol       => "Text color",
                   1805:             bgcol         => "Box color",
                   1806:             bgs           => "Background colors",
                   1807:             links         => "Link colors",
                   1808:             font          => "Font color",
                   1809:             pgbg          => "Header",
                   1810:             mainbg        => "Page",
                   1811:             sidebg        => "Login box",
                   1812:             link          => "Link",
                   1813:             alink         => "Active link",
                   1814:             vlink         => "Visited link",
1.256     raeburn  1815:             headtag       => "Custom markup",
                   1816:             action        => "Action",
                   1817:             current       => "Current",
1.386     raeburn  1818:             samllanding   => "Dual login?",
                   1819:             samloptions   => "Options",
1.402     raeburn  1820:             alttext       => "Alt text",
1.6       raeburn  1821:         );
                   1822:     return %choices;
                   1823: }
                   1824: 
1.386     raeburn  1825: sub login_file_options {
                   1826:       return &Apache::lonlocal::texthash(
                   1827:                                            del     => 'Delete?',
                   1828:                                            rep     => 'Replace:',
                   1829:                                            upl     => 'Upload:',
                   1830:                                            curr    => 'View contents',
                   1831:                                            default => 'Default',
                   1832:                                            custom  => 'Custom',
                   1833:                                            none    => 'None',
                   1834:       );
                   1835: }
                   1836: 
1.394     raeburn  1837: sub print_ipaccess {
                   1838:     my ($dom,$settings,$rowtotal) = @_;
                   1839:     my $css_class;
                   1840:     my $itemcount = 0;
                   1841:     my $datatable;
                   1842:     my %ordered;
                   1843:     if (ref($settings) eq 'HASH') {
                   1844:         foreach my $item (keys(%{$settings})) {
                   1845:             if (ref($settings->{$item}) eq 'HASH') {
                   1846:                 my $num = $settings->{$item}{'order'};
                   1847:                 if ($num eq '') {
                   1848:                     $num = scalar(keys(%{$settings}));
                   1849:                 }
                   1850:                 $ordered{$num} = $item;
                   1851:             }
                   1852:         }
                   1853:     }
                   1854:     my $maxnum = scalar(keys(%ordered));
                   1855:     if (keys(%ordered)) {
                   1856:         my @items = sort { $a <=> $b } keys(%ordered);
                   1857:         for (my $i=0; $i<@items; $i++) {
                   1858:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1859:             my $item = $ordered{$items[$i]};
                   1860:             my ($name,$ipranges,%commblocks,%courses);
                   1861:             if (ref($settings->{$item}) eq 'HASH') {
                   1862:                 $name = $settings->{$item}->{'name'};
                   1863:                 $ipranges = $settings->{$item}->{'ip'};
                   1864:                 if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
                   1865:                     %commblocks = %{$settings->{$item}->{'commblocks'}};
                   1866:                 }
                   1867:                 if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
                   1868:                     %courses = %{$settings->{$item}->{'courses'}};
                   1869:                 }
                   1870:             }
                   1871:             my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
                   1872:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   1873:                          .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
                   1874:             for (my $k=0; $k<=$maxnum; $k++) {
                   1875:                 my $vpos = $k+1;
                   1876:                 my $selstr;
                   1877:                 if ($k == $i) {
                   1878:                     $selstr = ' selected="selected" ';
                   1879:                 }
                   1880:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1881:             }
                   1882:             $datatable .= '</select>'.('&nbsp;'x2).
                   1883:                 '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
                   1884:                 &mt('Delete?').'</label></span></td>'.
                   1885:                 '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
                   1886:                 &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
                   1887:                 '</td></tr>';
                   1888:             $itemcount ++;
                   1889:         }
                   1890:     }
                   1891:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1892:     my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
                   1893:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   1894:                   '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
                   1895:                   '<select name="ipaccess_pos_add"'.$chgstr.'>';
                   1896:     for (my $k=0; $k<$maxnum+1; $k++) {
                   1897:         my $vpos = $k+1;
                   1898:         my $selstr;
                   1899:         if ($k == $maxnum) {
                   1900:             $selstr = ' selected="selected" ';
                   1901:         }
                   1902:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1903:     }
                   1904:     $datatable .= '</select>&nbsp;'."\n".
                   1905:                   '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   1906:                   '<td colspan="2">'.
                   1907:                   &ipaccess_options('add',$itemcount,$dom).
                   1908:                   '</td>'."\n".
                   1909:                   '</tr>'."\n";
                   1910:     $$rowtotal ++;
                   1911:     return $datatable;
                   1912: }
                   1913: 
                   1914: sub ipaccess_options {
                   1915:     my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
                   1916:     my (%currblocks,%currcourses,$output);
                   1917:     if (ref($blocksref) eq 'HASH') {
                   1918:         %currblocks = %{$blocksref};
                   1919:     }
                   1920:     if (ref($coursesref) eq 'HASH') {
                   1921:         %currcourses = %{$coursesref};
                   1922:     }
                   1923:     $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
                   1924:               '<span class="LC_nobreak">'.&mt('Name').':&nbsp;'.
                   1925:               '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
                   1926:               '</span></fieldset>'.
                   1927:               '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
                   1928:               &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   1929:               &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
                   1930:               '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
                   1931:               $ipranges.'</textarea></fieldset>'.
                   1932:               '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
                   1933:               &blocker_checkboxes($num,$blocksref).'</fieldset>'.
                   1934:               '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
                   1935:               '<table>';
                   1936:     foreach my $cid (sort(keys(%currcourses))) {
                   1937:         my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   1938:         $output .= '<tr><td><span class="LC_nobreak">'.
                   1939:                    '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
                   1940:                    &mt('Delete?').'&nbsp;<span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
                   1941:                    ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
                   1942:     }
                   1943:     $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').':&nbsp;'.
                   1944:                '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
                   1945:                 &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
                   1946:                '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
                   1947:                '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
                   1948:                '</span></td></tr></table>'."\n".
                   1949:                '</fieldset>';
                   1950:     return $output;
                   1951: }
                   1952: 
                   1953: sub blocker_checkboxes {
                   1954:     my ($num,$blocks) = @_;
                   1955:     my ($typeorder,$types) = &commblocktype_text();
                   1956:     my $numinrow = 6;
                   1957:     my $output = '<table>';
                   1958:     for (my $i=0; $i<@{$typeorder}; $i++) {
                   1959:         my $block = $typeorder->[$i];
                   1960:         my $blockstatus;
                   1961:         if (ref($blocks) eq 'HASH') {
                   1962:             if ($blocks->{$block} eq 'on') {
                   1963:                 $blockstatus = 'checked="checked"';
                   1964:             }
                   1965:         }
                   1966:         my $rem = $i%($numinrow);
                   1967:         if ($rem == 0) {
                   1968:             if ($i > 0) {
                   1969:                 $output .= '</tr>';
                   1970:             }
                   1971:             $output .= '<tr>';
                   1972:         }
                   1973:         if ($i == scalar(@{$typeorder})-1) {
                   1974:             my $colsleft = $numinrow-$rem;
                   1975:             if ($colsleft > 1) {
                   1976:                 $output .= '<td colspan="'.$colsleft.'">';
                   1977:             } else {
                   1978:                 $output .= '<td>';
                   1979:             }
                   1980:         } else {
                   1981:             $output .= '<td>';
                   1982:         }
                   1983:         my $item = 'ipaccess_block_'.$num;
                   1984:         if ($blockstatus) {
                   1985:             $blockstatus = ' '.$blockstatus;
                   1986:         }
                   1987:         $output .= '<span class="LC_nobreak"><label>'."\n".
                   1988:                    '<input type="checkbox" name="'.$item.'"'.
                   1989:                    $blockstatus.' value="'.$block.'"'.' />'.
                   1990:                    $types->{$block}.'</label></span>'."\n".
                   1991:                    '<br /></td>';
                   1992:     }
                   1993:     $output .= '</tr></table>';
                   1994:     return $output;
                   1995: }
                   1996: 
                   1997: sub commblocktype_text {
                   1998:     my %types = &Apache::lonlocal::texthash(
                   1999:         'com' => 'Messaging',
                   2000:         'chat' => 'Chat Room',
                   2001:         'boards' => 'Discussion',
                   2002:         'port' => 'Portfolio',
                   2003:         'groups' => 'Groups',
                   2004:         'blogs' => 'Blogs',
                   2005:         'about' => 'User Information',
                   2006:         'printout' => 'Printouts',
                   2007:         'passwd' => 'Change Password',
                   2008:         'grades' => 'Gradebook',
1.397     raeburn  2009:         'search' => 'Course search',
                   2010:         'wishlist' => 'Stored links',
                   2011:         'annotate' => 'Annotations',
1.394     raeburn  2012:     );
1.397     raeburn  2013:     my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394     raeburn  2014:     return ($typeorder,\%types);
                   2015: }
                   2016: 
1.6       raeburn  2017: sub print_rolecolors {
1.30      raeburn  2018:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  2019:     my %choices = &color_font_choices();
                   2020:     my @bgs = ('pgbg','tabbg','sidebg');
                   2021:     my @links = ('link','alink','vlink');
                   2022:     my @images = ('img');
                   2023:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 2024:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  2025:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   2026:     my (%is_custom,%designs);
1.200     raeburn  2027:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  2028:     if (ref($settings) eq 'HASH') {
                   2029:         if (ref($settings->{$role}) eq 'HASH') {
                   2030:             if ($settings->{$role}->{'img'} ne '') {
                   2031:                 $designs{'img'} = $settings->{$role}->{'img'};
                   2032:                 $is_custom{'img'} = 1;
                   2033:             }
                   2034:             if ($settings->{$role}->{'font'} ne '') {
                   2035:                 $designs{'font'} = $settings->{$role}->{'font'};
                   2036:                 $is_custom{'font'} = 1;
                   2037:             }
1.97      tempelho 2038:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   2039:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   2040:                 $is_custom{'fontmenu'} = 1;
                   2041:             }
1.6       raeburn  2042:             foreach my $item (@bgs) {
                   2043:                 if ($settings->{$role}->{$item} ne '') {
                   2044:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   2045:                     $is_custom{$item} = 1;
                   2046:                 }
                   2047:             }
                   2048:             foreach my $item (@links) {
                   2049:                 if ($settings->{$role}->{$item} ne '') {
                   2050:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   2051:                     $is_custom{$item} = 1;
                   2052:                 }
                   2053:             }
                   2054:         }
                   2055:     } else {
                   2056:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   2057:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   2058:             $is_custom{'img'} = 1;
                   2059:         }
1.97      tempelho 2060:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   2061:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   2062:             $is_custom{'fontmenu'} = 1; 
                   2063:         }
1.6       raeburn  2064:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   2065:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   2066:             $is_custom{'font'} = 1;
                   2067:         }
                   2068:         foreach my $item (@bgs) {
                   2069:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   2070:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   2071:                 $is_custom{$item} = 1;
                   2072:             
                   2073:             }
                   2074:         }
                   2075:         foreach my $item (@links) {
                   2076:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   2077:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   2078:                 $is_custom{$item} = 1;
                   2079:             }
                   2080:         }
                   2081:     }
                   2082:     my $itemcount = 1;
1.30      raeburn  2083:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  2084:     $datatable .= '</tr></table></td></tr>';
                   2085:     return $datatable;
                   2086: }
                   2087: 
1.200     raeburn  2088: sub role_defaults {
                   2089:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  2090:     my %defaults;
                   2091:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  2092:         return %defaults;
                   2093:     }
                   2094:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   2095:     if ($role eq 'login') {
                   2096:         %defaults = (
                   2097:                        font => $defaultdesign{$role.'.font'},
                   2098:                     );
                   2099:         if (ref($logintext) eq 'ARRAY') {
                   2100:             foreach my $item (@{$logintext}) {
                   2101:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   2102:             }
                   2103:         }
                   2104:         foreach my $item (@{$images}) {
                   2105:             $defaults{'showlogo'}{$item} = 1;
                   2106:         }
                   2107:     } else {
                   2108:         %defaults = (
                   2109:                        img => $defaultdesign{$role.'.img'},
                   2110:                        font => $defaultdesign{$role.'.font'},
                   2111:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   2112:                     );
                   2113:     }
                   2114:     foreach my $item (@{$bgs}) {
                   2115:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   2116:     }
                   2117:     foreach my $item (@{$links}) {
                   2118:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   2119:     }
                   2120:     foreach my $item (@{$images}) {
                   2121:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   2122:     }
                   2123:     return %defaults;
                   2124: }
                   2125: 
1.6       raeburn  2126: sub display_color_options {
1.9       raeburn  2127:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   2128:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  2129:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  2130:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  2131:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  2132:         '<td>'.$choices->{'font'}.'</td>';
                   2133:     if (!$is_custom->{'font'}) {
1.329     raeburn  2134:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  2135:     } else {
                   2136:         $datatable .= '<td>&nbsp;</td>';
                   2137:     }
1.174     foxr     2138:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   2139: 
1.8       raeburn  2140:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2141:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  2142:                   ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2143:                   '&nbsp;</span></td></tr>';
1.107     raeburn  2144:     unless ($role eq 'login') { 
                   2145:         $datatable .= '<tr'.$css_class.'>'.
                   2146:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   2147:         if (!$is_custom->{'fontmenu'}) {
1.329     raeburn  2148:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  2149:         } else {
                   2150:             $datatable .= '<td>&nbsp;</td>';
                   2151:         }
1.202     raeburn  2152: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     2153: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  2154:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2155:                       '<input class="colorchooser" type="text" size="10" name="'
                   2156: 		      .$role.'_fontmenu"'.
                   2157:                       ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2158:                       '&nbsp;</span></td></tr>';
1.97      tempelho 2159:     }
1.9       raeburn  2160:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  2161:     foreach my $img (@{$images}) {
1.18      albertel 2162: 	$itemcount ++;
1.6       raeburn  2163:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  2164:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  2165:                       '<td>'.$choices->{$img};
1.402     raeburn  2166:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70      raeburn  2167:         if ($role eq 'login') {
                   2168:             if ($img eq 'login') {
                   2169:                 $login_hdr_pick =
1.135     bisitz   2170:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  2171:                 $logincolors =
                   2172:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  2173:                                        $designs,$defaults);
1.402     raeburn  2174:             } else {
                   2175:                 if ($img ne 'domlogo') {
                   2176:                     $datatable.= &logo_display_options($img,$defaults,$designs);
                   2177:                 }
                   2178:                 if (ref($designs->{'alttext'}) eq 'HASH') {
                   2179:                     $alttext = $designs->{'alttext'}{$img};
                   2180:                 }
1.70      raeburn  2181:             }
                   2182:         }
                   2183:         $datatable .= '</td>';
1.6       raeburn  2184:         if ($designs->{$img} ne '') {
                   2185:             $imgfile = $designs->{$img};
1.18      albertel 2186: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  2187:         } else {
                   2188:             $imgfile = $defaults->{$img};
                   2189:         }
                   2190:         if ($imgfile) {
1.9       raeburn  2191:             my ($showfile,$fullsize);
                   2192:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  2193:                 my $urldir = $1;
                   2194:                 my $filename = $2;
                   2195:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   2196:                 if (@info) {
                   2197:                     my $thumbfile = 'tn-'.$filename;
                   2198:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   2199:                     if (@thumb) {
                   2200:                         $showfile = $urldir.'/'.$thumbfile;
                   2201:                     } else {
                   2202:                         $showfile = $imgfile;
                   2203:                     }
                   2204:                 } else {
                   2205:                     $showfile = '';
                   2206:                 }
                   2207:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  2208:                 $showfile = $imgfile;
1.6       raeburn  2209:                 my $imgdir = $1;
                   2210:                 my $filename = $2;
1.159     raeburn  2211:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  2212:                     $showfile = "/$imgdir/tn-".$filename;
                   2213:                 } else {
1.159     raeburn  2214:                     my $input = $londocroot.$imgfile;
                   2215:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  2216:                     if (!-e $output) {
1.9       raeburn  2217:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  2218:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   2219:                         if ($fullwidth ne '' && $fullheight ne '') {
                   2220:                             if ($fullwidth > $width && $fullheight > $height) { 
                   2221:                                 my $size = $width.'x'.$height;
1.316     raeburn  2222:                                 my @args = ('convert','-sample',$size,$input,$output);
                   2223:                                 system({$args[0]} @args);
1.159     raeburn  2224:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  2225:                             }
                   2226:                         }
1.6       raeburn  2227:                     }
                   2228:                 }
1.16      raeburn  2229:             }
1.6       raeburn  2230:             if ($showfile) {
1.40      raeburn  2231:                 if ($showfile =~ m{^/(adm|res)/}) {
                   2232:                     if ($showfile =~ m{^/res/}) {
                   2233:                         my $local_showfile =
                   2234:                             &Apache::lonnet::filelocation('',$showfile);
                   2235:                         &Apache::lonnet::repcopy($local_showfile);
                   2236:                     }
                   2237:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   2238:                 }
                   2239:                 if ($imgfile) {
                   2240:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   2241:                         if ($imgfile =~ m{^/res/}) {
                   2242:                             my $local_imgfile =
                   2243:                                 &Apache::lonnet::filelocation('',$imgfile);
                   2244:                             &Apache::lonnet::repcopy($local_imgfile);
                   2245:                         }
                   2246:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   2247:                     } else {
                   2248:                         $fullsize = $imgfile;
                   2249:                     }
                   2250:                 }
1.41      raeburn  2251:                 $datatable .= '<td>';
                   2252:                 if ($img eq 'login') {
1.135     bisitz   2253:                     $datatable .= $login_hdr_pick;
                   2254:                 } 
1.41      raeburn  2255:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   2256:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  2257:             } else {
1.201     raeburn  2258:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2259:                               &mt('Upload:').'<br />';
1.6       raeburn  2260:             }
                   2261:         } else {
1.201     raeburn  2262:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2263:                           &mt('Upload:').'<br />';
1.6       raeburn  2264:         }
1.9       raeburn  2265:         if ($switchserver) {
                   2266:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2267:         } else {
1.135     bisitz   2268:             if ($img ne 'login') { # suppress file selection for Log-in header
                   2269:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   2270:             }
1.9       raeburn  2271:         }
1.402     raeburn  2272:         if (($role eq 'login') && ($img ne 'login')) {
                   2273:             $datatable .= ('&nbsp;' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
                   2274:                           '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
                   2275:                           '</label></span>';
                   2276:         }
1.9       raeburn  2277:         $datatable .= '</td></tr>';
1.6       raeburn  2278:     }
                   2279:     $itemcount ++;
                   2280:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2281:     $datatable .= '<tr'.$css_class.'>'.
                   2282:                   '<td>'.$choices->{'bgs'}.'</td>';
                   2283:     my $bgs_def;
                   2284:     foreach my $item (@{$bgs}) {
                   2285:         if (!$is_custom->{$item}) {
1.329     raeburn  2286:             $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span>&nbsp;<span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6       raeburn  2287:         }
                   2288:     }
                   2289:     if ($bgs_def) {
1.8       raeburn  2290:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  2291:     } else {
                   2292:         $datatable .= '<td>&nbsp;</td>';
                   2293:     }
                   2294:     $datatable .= '<td class="LC_right_item">'.
                   2295:                   '<table border="0"><tr>';
1.174     foxr     2296: 
1.6       raeburn  2297:     foreach my $item (@{$bgs}) {
1.306     raeburn  2298:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     2299: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  2300:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     2301:             $datatable .= '&nbsp;';
1.6       raeburn  2302:         }
1.174     foxr     2303:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  2304:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  2305:     }
                   2306:     $datatable .= '</tr></table></td></tr>';
                   2307:     $itemcount ++;
                   2308:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2309:     $datatable .= '<tr'.$css_class.'>'.
                   2310:                   '<td>'.$choices->{'links'}.'</td>';
                   2311:     my $links_def;
                   2312:     foreach my $item (@{$links}) {
                   2313:         if (!$is_custom->{$item}) {
1.329     raeburn  2314:             $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6       raeburn  2315:         }
                   2316:     }
                   2317:     if ($links_def) {
1.8       raeburn  2318:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  2319:     } else {
                   2320:         $datatable .= '<td>&nbsp;</td>';
                   2321:     }
                   2322:     $datatable .= '<td class="LC_right_item">'.
                   2323:                   '<table border="0"><tr>';
                   2324:     foreach my $item (@{$links}) {
1.234     raeburn  2325: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  2326:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  2327:         if ($designs->{'links'}{$item}) {
1.174     foxr     2328:             $datatable.='&nbsp;';
1.6       raeburn  2329:         }
1.174     foxr     2330:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  2331:                       '" /></td>';
                   2332:     }
1.30      raeburn  2333:     $$rowtotal += $itemcount;
1.3       raeburn  2334:     return $datatable;
                   2335: }
                   2336: 
1.70      raeburn  2337: sub logo_display_options {
                   2338:     my ($img,$defaults,$designs) = @_;
                   2339:     my $checkedon;
                   2340:     if (ref($defaults) eq 'HASH') {
                   2341:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   2342:             if ($defaults->{'showlogo'}{$img}) {
                   2343:                 $checkedon = 'checked="checked" ';     
                   2344:             }
                   2345:         } 
                   2346:     }
                   2347:     if (ref($designs) eq 'HASH') {
                   2348:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   2349:             if (defined($designs->{'showlogo'}{$img})) {
                   2350:                 if ($designs->{'showlogo'}{$img} == 0) {
                   2351:                     $checkedon = '';
                   2352:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   2353:                     $checkedon = 'checked="checked" ';
                   2354:                 }
                   2355:             }
                   2356:         }
                   2357:     }
                   2358:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   2359:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   2360:            &mt('show').'</label>'."\n";
                   2361: }
                   2362: 
1.41      raeburn  2363: sub login_header_options  {
1.135     bisitz   2364:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   2365:     my $output = '';
1.41      raeburn  2366:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   2367:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  2368:         if (!$is_custom->{'textcol'}) {
                   2369:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   2370:                        '&nbsp;&nbsp;&nbsp;';
                   2371:         }
                   2372:         if (!$is_custom->{'bgcol'}) {
                   2373:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   2374:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   2375:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   2376:         }
                   2377:         $output .= '<br />';
                   2378:     }
                   2379:     $output .='<br />';
                   2380:     return $output;
                   2381: }
                   2382: 
                   2383: sub login_text_colors {
1.201     raeburn  2384:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  2385:     my $color_menu = '<table border="0"><tr>';
                   2386:     foreach my $item (@{$logintext}) {
1.306     raeburn  2387:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  2388:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   2389:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   2390:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  2391:     }
                   2392:     $color_menu .= '</tr></table><br />';
                   2393:     return $color_menu;
                   2394: }
                   2395: 
                   2396: sub image_changes {
                   2397:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   2398:     my $output;
1.135     bisitz   2399:     if ($img eq 'login') {
1.331     raeburn  2400:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   2401:     } elsif (!$is_custom) {
1.70      raeburn  2402:         if ($img ne 'domlogo') {
1.331     raeburn  2403:             $output = &mt('Default image:').'<br />';
1.41      raeburn  2404:         } else {
1.331     raeburn  2405:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  2406:         }
                   2407:     }
1.331     raeburn  2408:     if ($img ne 'login') {
1.135     bisitz   2409:         if ($img_import) {
                   2410:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   2411:         }
                   2412:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   2413:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   2414:         if ($is_custom) {
                   2415:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   2416:                        '<input type="checkbox" name="'.
                   2417:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   2418:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   2419:         } else {
1.306     raeburn  2420:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   2421:         }
1.41      raeburn  2422:     }
                   2423:     return $output;
                   2424: }
                   2425: 
1.3       raeburn  2426: sub print_quotas {
1.86      raeburn  2427:     my ($dom,$settings,$rowtotal,$action) = @_;
                   2428:     my $context;
                   2429:     if ($action eq 'quotas') {
                   2430:         $context = 'tools';
                   2431:     } else {
                   2432:         $context = $action;
                   2433:     }
1.429     raeburn  2434:     my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44      raeburn  2435:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  2436:     my $typecount = 0;
1.101     raeburn  2437:     my ($css_class,%titles);
1.86      raeburn  2438:     if ($context eq 'requestcourses') {
1.325     raeburn  2439:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  2440:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  2441:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   2442:         %titles = &courserequest_titles();
1.163     raeburn  2443:     } elsif ($context eq 'requestauthor') {
                   2444:         @usertools = ('author');
                   2445:         @options = ('norequest','approval','automatic');
1.210     raeburn  2446:         %titles = &authorrequest_titles();
1.86      raeburn  2447:     } else {
1.430     raeburn  2448:         @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101     raeburn  2449:         %titles = &tool_titles();
1.86      raeburn  2450:     }
1.26      raeburn  2451:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  2452:         foreach my $type (@{$types}) {
1.429     raeburn  2453:             my $currdefquota;
1.163     raeburn  2454:             unless (($context eq 'requestcourses') ||
                   2455:                     ($context eq 'requestauthor')) {
1.86      raeburn  2456:                 if (ref($settings) eq 'HASH') {
                   2457:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  2458:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  2459:                     } else {
                   2460:                         $currdefquota = $settings->{$type};
                   2461:                     }
1.78      raeburn  2462:                 }
1.72      raeburn  2463:             }
1.3       raeburn  2464:             if (defined($usertypes->{$type})) {
                   2465:                 $typecount ++;
                   2466:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  2467:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  2468:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  2469:                               '<td class="LC_left_item">';
1.101     raeburn  2470:                 if ($context eq 'requestcourses') {
                   2471:                     $datatable .= '<table><tr>';
                   2472:                 }
                   2473:                 my %cell;  
1.72      raeburn  2474:                 foreach my $item (@usertools) {
1.101     raeburn  2475:                     if ($context eq 'requestcourses') {
                   2476:                         my ($curroption,$currlimit);
                   2477:                         if (ref($settings) eq 'HASH') {
                   2478:                             if (ref($settings->{$item}) eq 'HASH') {
                   2479:                                 $curroption = $settings->{$item}->{$type};
                   2480:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2481:                                     $currlimit = $1; 
                   2482:                                 }
                   2483:                             }
                   2484:                         }
                   2485:                         if (!$curroption) {
                   2486:                             $curroption = 'norequest';
                   2487:                         }
                   2488:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2489:                         foreach my $option (@options) {
                   2490:                             my $val = $option;
                   2491:                             if ($option eq 'norequest') {
                   2492:                                 $val = 0;  
                   2493:                             }
                   2494:                             if ($option eq 'validate') {
                   2495:                                 my $canvalidate = 0;
                   2496:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2497:                                     if ($validations{$item}{$type}) {
                   2498:                                         $canvalidate = 1;
                   2499:                                     }
                   2500:                                 }
                   2501:                                 next if (!$canvalidate);
                   2502:                             }
                   2503:                             my $checked = '';
                   2504:                             if ($option eq $curroption) {
                   2505:                                 $checked = ' checked="checked"';
                   2506:                             } elsif ($option eq 'autolimit') {
                   2507:                                 if ($curroption =~ /^autolimit/) {
                   2508:                                     $checked = ' checked="checked"';
                   2509:                                 }                       
                   2510:                             } 
                   2511:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2512:                                   '<input type="radio" name="crsreq_'.$item.
                   2513:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2514:                                   $titles{$option}.'</label>';
1.101     raeburn  2515:                             if ($option eq 'autolimit') {
1.127     raeburn  2516:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2517:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2518:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2519:                             }
1.127     raeburn  2520:                             $cell{$item} .= '</span> ';
1.103     raeburn  2521:                             if ($option eq 'autolimit') {
1.127     raeburn  2522:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2523:                             }
1.101     raeburn  2524:                         }
1.163     raeburn  2525:                     } elsif ($context eq 'requestauthor') {
                   2526:                         my $curroption;
                   2527:                         if (ref($settings) eq 'HASH') {
                   2528:                             $curroption = $settings->{$type};
                   2529:                         }
                   2530:                         if (!$curroption) {
                   2531:                             $curroption = 'norequest';
                   2532:                         }
                   2533:                         foreach my $option (@options) {
                   2534:                             my $val = $option;
                   2535:                             if ($option eq 'norequest') {
                   2536:                                 $val = 0;
                   2537:                             }
                   2538:                             my $checked = '';
                   2539:                             if ($option eq $curroption) {
                   2540:                                 $checked = ' checked="checked"';
                   2541:                             }
                   2542:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2543:                                   '<input type="radio" name="authorreq_'.$type.
                   2544:                                   '" value="'.$val.'"'.$checked.' />'.
                   2545:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2546:                         }
1.101     raeburn  2547:                     } else {
                   2548:                         my $checked = 'checked="checked" ';
1.413     raeburn  2549:                         if ($item eq 'timezone') {
                   2550:                             $checked = '';
                   2551:                         }
1.101     raeburn  2552:                         if (ref($settings) eq 'HASH') {
                   2553:                             if (ref($settings->{$item}) eq 'HASH') {
1.413     raeburn  2554:                                 if (!$settings->{$item}->{$type}) {
1.101     raeburn  2555:                                     $checked = '';
                   2556:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2557:                                     $checked =  'checked="checked" ';
                   2558:                                 }
1.78      raeburn  2559:                             }
1.72      raeburn  2560:                         }
1.101     raeburn  2561:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2562:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2563:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2564:                                       '</label></span>&nbsp; ';
1.72      raeburn  2565:                     }
1.101     raeburn  2566:                 }
                   2567:                 if ($context eq 'requestcourses') {
                   2568:                     $datatable .= '</tr><tr>';
                   2569:                     foreach my $item (@usertools) {
1.106     raeburn  2570:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2571:                     }
                   2572:                     $datatable .= '</tr></table>';
1.72      raeburn  2573:                 }
1.86      raeburn  2574:                 $datatable .= '</td>';
1.163     raeburn  2575:                 unless (($context eq 'requestcourses') ||
                   2576:                         ($context eq 'requestauthor')) {
1.86      raeburn  2577:                     $datatable .= 
1.197     raeburn  2578:                               '<td class="LC_right_item">'.
1.429     raeburn  2579:                               '<span class="LC_nobreak">'.
1.3       raeburn  2580:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2581:                               '" value="'.$currdefquota.
1.197     raeburn  2582:                               '" size="5" /></span></td>';
1.86      raeburn  2583:                 }
                   2584:                 $datatable .= '</tr>';
1.3       raeburn  2585:             }
                   2586:         }
                   2587:     }
1.163     raeburn  2588:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2589:         $defaultquota = '20';
                   2590:         if (ref($settings) eq 'HASH') {
                   2591:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2592:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2593:             } elsif (defined($settings->{'default'})) {
                   2594:                 $defaultquota = $settings->{'default'};
                   2595:             }
1.3       raeburn  2596:         }
                   2597:     }
                   2598:     $typecount ++;
                   2599:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2600:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2601:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2602:                   '<td class="LC_left_item">';
1.101     raeburn  2603:     if ($context eq 'requestcourses') {
                   2604:         $datatable .= '<table><tr>';
                   2605:     }
                   2606:     my %defcell;
1.72      raeburn  2607:     foreach my $item (@usertools) {
1.101     raeburn  2608:         if ($context eq 'requestcourses') {
                   2609:             my ($curroption,$currlimit);
                   2610:             if (ref($settings) eq 'HASH') {
                   2611:                 if (ref($settings->{$item}) eq 'HASH') {
                   2612:                     $curroption = $settings->{$item}->{'default'};
                   2613:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2614:                         $currlimit = $1;
                   2615:                     }
                   2616:                 }
                   2617:             }
                   2618:             if (!$curroption) {
                   2619:                 $curroption = 'norequest';
                   2620:             }
                   2621:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2622:             foreach my $option (@options) {
                   2623:                 my $val = $option;
                   2624:                 if ($option eq 'norequest') {
                   2625:                     $val = 0;
                   2626:                 }
                   2627:                 if ($option eq 'validate') {
                   2628:                     my $canvalidate = 0;
                   2629:                     if (ref($validations{$item}) eq 'HASH') {
                   2630:                         if ($validations{$item}{'default'}) {
                   2631:                             $canvalidate = 1;
                   2632:                         }
                   2633:                     }
                   2634:                     next if (!$canvalidate);
                   2635:                 }
                   2636:                 my $checked = '';
                   2637:                 if ($option eq $curroption) {
                   2638:                     $checked = ' checked="checked"';
                   2639:                 } elsif ($option eq 'autolimit') {
                   2640:                     if ($curroption =~ /^autolimit/) {
                   2641:                         $checked = ' checked="checked"';
                   2642:                     }
                   2643:                 }
                   2644:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2645:                                   '<input type="radio" name="crsreq_'.$item.
                   2646:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2647:                                   $titles{$option}.'</label>';
                   2648:                 if ($option eq 'autolimit') {
1.127     raeburn  2649:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2650:                                        $item.'_limit_default" size="1" '.
                   2651:                                        'value="'.$currlimit.'" />';
                   2652:                 }
1.127     raeburn  2653:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2654:                 if ($option eq 'autolimit') {
1.127     raeburn  2655:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2656:                 }
1.101     raeburn  2657:             }
1.163     raeburn  2658:         } elsif ($context eq 'requestauthor') {
                   2659:             my $curroption;
                   2660:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2661:                 $curroption = $settings->{'default'};
1.163     raeburn  2662:             }
                   2663:             if (!$curroption) {
                   2664:                 $curroption = 'norequest';
                   2665:             }
                   2666:             foreach my $option (@options) {
                   2667:                 my $val = $option;
                   2668:                 if ($option eq 'norequest') {
                   2669:                     $val = 0;
                   2670:                 }
                   2671:                 my $checked = '';
                   2672:                 if ($option eq $curroption) {
                   2673:                     $checked = ' checked="checked"';
                   2674:                 }
                   2675:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2676:                               '<input type="radio" name="authorreq_default"'.
                   2677:                               ' value="'.$val.'"'.$checked.' />'.
                   2678:                               $titles{$option}.'</label></span>&nbsp; ';
                   2679:             }
1.101     raeburn  2680:         } else {
                   2681:             my $checked = 'checked="checked" ';
                   2682:             if (ref($settings) eq 'HASH') {
                   2683:                 if (ref($settings->{$item}) eq 'HASH') {
                   2684:                     if ($settings->{$item}->{'default'} == 0) {
                   2685:                         $checked = '';
                   2686:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2687:                         $checked = 'checked="checked" ';
                   2688:                     }
1.78      raeburn  2689:                 }
1.72      raeburn  2690:             }
1.101     raeburn  2691:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2692:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2693:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2694:                           '</label></span>&nbsp; ';
                   2695:         }
                   2696:     }
                   2697:     if ($context eq 'requestcourses') {
                   2698:         $datatable .= '</tr><tr>';
                   2699:         foreach my $item (@usertools) {
1.106     raeburn  2700:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2701:         }
1.101     raeburn  2702:         $datatable .= '</tr></table>';
1.72      raeburn  2703:     }
1.86      raeburn  2704:     $datatable .= '</td>';
1.163     raeburn  2705:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2706:         $datatable .= '<td class="LC_right_item">'.
1.429     raeburn  2707:                       '<span class="LC_nobreak">'.
1.86      raeburn  2708:                       '<input type="text" name="defaultquota" value="'.
1.429     raeburn  2709:                       $defaultquota.'" size="5" /></span></td>';
1.86      raeburn  2710:     }
                   2711:     $datatable .= '</tr>';
1.72      raeburn  2712:     $typecount ++;
                   2713:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2714:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2715:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2716:     if ($context eq 'requestcourses') {
1.109     raeburn  2717:         $datatable .= &mt('(overrides affiliation, if set)').
                   2718:                       '</td>'.
                   2719:                       '<td class="LC_left_item">'.
                   2720:                       '<table><tr>';
1.101     raeburn  2721:     } else {
1.109     raeburn  2722:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2723:                       '</td>'.
                   2724:                       '<td class="LC_left_item" colspan="2">'.
                   2725:                       '<br />';
1.101     raeburn  2726:     }
                   2727:     my %advcell;
1.72      raeburn  2728:     foreach my $item (@usertools) {
1.101     raeburn  2729:         if ($context eq 'requestcourses') {
                   2730:             my ($curroption,$currlimit);
                   2731:             if (ref($settings) eq 'HASH') {
                   2732:                 if (ref($settings->{$item}) eq 'HASH') {
                   2733:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2734:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2735:                         $currlimit = $1;
                   2736:                     }
                   2737:                 }
                   2738:             }
                   2739:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2740:             my $checked = '';
                   2741:             if ($curroption eq '') {
                   2742:                 $checked = ' checked="checked"';
                   2743:             }
                   2744:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2745:                                '<input type="radio" name="crsreq_'.$item.
                   2746:                                '__LC_adv" value=""'.$checked.' />'.
                   2747:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2748:             foreach my $option (@options) {
                   2749:                 my $val = $option;
                   2750:                 if ($option eq 'norequest') {
                   2751:                     $val = 0;
                   2752:                 }
                   2753:                 if ($option eq 'validate') {
                   2754:                     my $canvalidate = 0;
                   2755:                     if (ref($validations{$item}) eq 'HASH') {
                   2756:                         if ($validations{$item}{'_LC_adv'}) {
                   2757:                             $canvalidate = 1;
                   2758:                         }
                   2759:                     }
                   2760:                     next if (!$canvalidate);
                   2761:                 }
                   2762:                 my $checked = '';
1.104     raeburn  2763:                 if ($val eq $curroption) {
1.101     raeburn  2764:                     $checked = ' checked="checked"';
                   2765:                 } elsif ($option eq 'autolimit') {
                   2766:                     if ($curroption =~ /^autolimit/) {
                   2767:                         $checked = ' checked="checked"';
                   2768:                     }
                   2769:                 }
                   2770:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2771:                                   '<input type="radio" name="crsreq_'.$item.
                   2772:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2773:                                   $titles{$option}.'</label>';
                   2774:                 if ($option eq 'autolimit') {
1.127     raeburn  2775:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2776:                                        $item.'_limit__LC_adv" size="1" '.
                   2777:                                        'value="'.$currlimit.'" />';
                   2778:                 }
1.127     raeburn  2779:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2780:                 if ($option eq 'autolimit') {
1.127     raeburn  2781:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2782:                 }
1.101     raeburn  2783:             }
1.163     raeburn  2784:         } elsif ($context eq 'requestauthor') {
                   2785:             my $curroption;
                   2786:             if (ref($settings) eq 'HASH') {
                   2787:                 $curroption = $settings->{'_LC_adv'};
                   2788:             }
                   2789:             my $checked = '';
                   2790:             if ($curroption eq '') {
                   2791:                 $checked = ' checked="checked"';
                   2792:             }
                   2793:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2794:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2795:                           ' value=""'.$checked.' />'.
                   2796:                           &mt('No override set').'</label></span>&nbsp; ';
                   2797:             foreach my $option (@options) {
                   2798:                 my $val = $option;
                   2799:                 if ($option eq 'norequest') {
                   2800:                     $val = 0;
                   2801:                 }
                   2802:                 my $checked = '';
                   2803:                 if ($val eq $curroption) {
                   2804:                     $checked = ' checked="checked"';
                   2805:                 }
                   2806:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2807:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2808:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2809:                               $titles{$option}.'</label></span>&nbsp; ';
                   2810:             }
1.101     raeburn  2811:         } else {
                   2812:             my $checked = 'checked="checked" ';
                   2813:             if (ref($settings) eq 'HASH') {
                   2814:                 if (ref($settings->{$item}) eq 'HASH') {
                   2815:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2816:                         $checked = '';
                   2817:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2818:                         $checked = 'checked="checked" ';
                   2819:                     }
1.79      raeburn  2820:                 }
1.72      raeburn  2821:             }
1.101     raeburn  2822:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2823:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2824:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2825:                           '</label></span>&nbsp; ';
                   2826:         }
                   2827:     }
                   2828:     if ($context eq 'requestcourses') {
                   2829:         $datatable .= '</tr><tr>';
                   2830:         foreach my $item (@usertools) {
1.106     raeburn  2831:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2832:         }
1.101     raeburn  2833:         $datatable .= '</tr></table>';
1.72      raeburn  2834:     }
1.98      raeburn  2835:     $datatable .= '</td></tr>';
1.30      raeburn  2836:     $$rowtotal += $typecount;
1.3       raeburn  2837:     return $datatable;
                   2838: }
                   2839: 
1.163     raeburn  2840: sub print_requestmail {
1.305     raeburn  2841:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2842:     my ($now,$datatable,%currapp);
1.102     raeburn  2843:     $now = time;
                   2844:     if (ref($settings) eq 'HASH') {
                   2845:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2846:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2847:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2848:             }
                   2849:         }
                   2850:     }
1.191     raeburn  2851:     my $numinrow = 2;
1.224     raeburn  2852:     my $css_class;
1.305     raeburn  2853:     if ($$rowtotal%2) {
                   2854:         $css_class = 'LC_odd_row';
                   2855:     }
                   2856:     if ($customcss) {
                   2857:         $css_class .= " $customcss";
                   2858:     }
                   2859:     $css_class =~ s/^\s+//;
                   2860:     if ($css_class) {
                   2861:         $css_class = ' class="'.$css_class.'"';
                   2862:     }
                   2863:     if ($rowstyle) {
                   2864:         $css_class .= ' style="'.$rowstyle.'"';
                   2865:     }
1.163     raeburn  2866:     my $text;
                   2867:     if ($action eq 'requestcourses') {
                   2868:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2869:     } elsif ($action eq 'requestauthor') {
                   2870:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2871:     } else {
1.224     raeburn  2872:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2873:     }
1.224     raeburn  2874:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2875:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2876:                  ' <td class="LC_left_item">';
1.191     raeburn  2877:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2878:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2879:     if ($numdc > 0) {
                   2880:         $datatable .= $table;
1.102     raeburn  2881:     } else {
                   2882:         $datatable .= &mt('There are no active Domain Coordinators');
                   2883:     }
                   2884:     $datatable .='</td></tr>';
                   2885:     return $datatable;
                   2886: }
                   2887: 
1.216     raeburn  2888: sub print_studentcode {
                   2889:     my ($settings,$rowtotal) = @_;
                   2890:     my $rownum = 0; 
1.218     raeburn  2891:     my ($output,%current);
1.325     raeburn  2892:     my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248     raeburn  2893:     if (ref($settings) eq 'HASH') {
                   2894:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2895:             foreach my $type (@crstypes) {
                   2896:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2897:             }
1.218     raeburn  2898:         }
                   2899:     }
                   2900:     $output .= '<tr>'.
                   2901:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2902:                '<td class="LC_left_item">';
                   2903:     foreach my $type (@crstypes) {
                   2904:         my $check = ' ';
                   2905:         if ($current{$type}) {
                   2906:             $check = ' checked="checked" ';
                   2907:         }
                   2908:         $output .= '<span class="LC_nobreak"><label>'.
                   2909:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2910:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2911:     }
                   2912:     $output .= '</td></tr>';
                   2913:     $$rowtotal ++;
                   2914:     return $output;
1.216     raeburn  2915: }
                   2916: 
                   2917: sub print_textbookcourses {
1.242     raeburn  2918:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2919:     my $rownum = 0;
                   2920:     my $css_class;
                   2921:     my $itemcount = 1;
                   2922:     my $maxnum = 0;
                   2923:     my $bookshash;
                   2924:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2925:         $bookshash = $settings->{$type};
1.216     raeburn  2926:     }
                   2927:     my %ordered;
                   2928:     if (ref($bookshash) eq 'HASH') {
                   2929:         foreach my $item (keys(%{$bookshash})) {
                   2930:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2931:                 my $num = $bookshash->{$item}{'order'};
                   2932:                 $ordered{$num} = $item;
                   2933:             }
                   2934:         }
                   2935:     }
                   2936:     my $confname = $dom.'-domainconfig';
                   2937:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2938:     my $maxnum = scalar(keys(%ordered));
                   2939:     my $datatable;
1.216     raeburn  2940:     if (keys(%ordered)) {
                   2941:         my @items = sort { $a <=> $b } keys(%ordered);
                   2942:         for (my $i=0; $i<@items; $i++) {
                   2943:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2944:             my $key = $ordered{$items[$i]};
                   2945:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2946:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2947:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2948:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2949:                 $subject = $bookshash->{$key}->{'subject'};
                   2950:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2951:                 if ($type eq 'textbooks') {
1.243     raeburn  2952:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2953:                     $author = $bookshash->{$key}->{'author'};
                   2954:                     $image = $bookshash->{$key}->{'image'};
                   2955:                     if ($image ne '') {
                   2956:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2957:                         my $imagethumb = "$path/tn-".$imagefile;
                   2958:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2959:                     }
1.216     raeburn  2960:                 }
                   2961:             }
1.242     raeburn  2962:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2963:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2964:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2965:             for (my $k=0; $k<=$maxnum; $k++) {
                   2966:                 my $vpos = $k+1;
                   2967:                 my $selstr;
                   2968:                 if ($k == $i) {
                   2969:                     $selstr = ' selected="selected" ';
                   2970:                 }
                   2971:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2972:             }
                   2973:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2974:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2975:                 &mt('Delete?').'</label></span></td>'.
                   2976:                 '<td colspan="2">'.
1.242     raeburn  2977:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2978:                 ('&nbsp;'x2).
1.242     raeburn  2979:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2980:             if ($type eq 'textbooks') {
                   2981:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2982:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2983:                               ('&nbsp;'x2).
1.242     raeburn  2984:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2985:                               ('&nbsp;'x2).
                   2986:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2987:                 if ($image) {
1.267     raeburn  2988:                     $datatable .= $imgsrc.
1.242     raeburn  2989:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2990:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2991:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2992:                 }
                   2993:                 if ($switchserver) {
                   2994:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2995:                 } else {
                   2996:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2997:                 }
1.216     raeburn  2998:             }
1.242     raeburn  2999:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  3000:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   3001:                           $coursetitle.'</span></td></tr>'."\n";
                   3002:             $itemcount ++;
                   3003:         }
                   3004:     }
                   3005:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  3006:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  3007:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  3008:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   3009:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  3010:     for (my $k=0; $k<$maxnum+1; $k++) {
                   3011:         my $vpos = $k+1;
                   3012:         my $selstr;
                   3013:         if ($k == $maxnum) {
                   3014:             $selstr = ' selected="selected" ';
                   3015:         }
                   3016:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3017:     }
                   3018:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  3019:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216     raeburn  3020:                   '<td colspan="2">'.
1.242     raeburn  3021:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  3022:                   ('&nbsp;'x2).
1.242     raeburn  3023:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   3024:                   ('&nbsp;'x2);
                   3025:     if ($type eq 'textbooks') {
1.243     raeburn  3026:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   3027:                       ('&nbsp;'x2).
                   3028:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  3029:                       ('&nbsp;'x2).
                   3030:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   3031:         if ($switchserver) {
                   3032:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3033:         } else {
                   3034:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   3035:         }
1.334     raeburn  3036:         $datatable .= '</span>'."\n";
1.216     raeburn  3037:     }
1.334     raeburn  3038:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  3039:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   3040:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  3041:                   &Apache::loncommon::selectcourse_link
1.334     raeburn  3042:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216     raeburn  3043:                   '</span></td>'."\n".
                   3044:                   '</tr>'."\n";
                   3045:     $itemcount ++;
                   3046:     return $datatable;
                   3047: }
                   3048: 
1.217     raeburn  3049: sub textbookcourses_javascript {
1.242     raeburn  3050:     my ($settings) = @_;
                   3051:     return unless(ref($settings) eq 'HASH');
                   3052:     my (%ordered,%total,%jstext);
                   3053:     foreach my $type ('textbooks','templates') {
                   3054:         $total{$type} = 0;
                   3055:         if (ref($settings->{$type}) eq 'HASH') {
                   3056:             foreach my $item (keys(%{$settings->{$type}})) {
                   3057:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   3058:                     my $num = $settings->{$type}->{$item}{'order'};
                   3059:                     $ordered{$type}{$num} = $item;
                   3060:                 }
                   3061:             }
                   3062:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   3063:         }
                   3064:         my @jsarray = ();
                   3065:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   3066:             push(@jsarray,$ordered{$type}{$item});
                   3067:         }
                   3068:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  3069:     }
                   3070:     return <<"ENDSCRIPT";
                   3071: <script type="text/javascript">
                   3072: // <![CDATA[
1.242     raeburn  3073: function reorderBooks(form,item,caller) {
1.217     raeburn  3074:     var changedVal;
1.242     raeburn  3075: $jstext{'textbooks'};
                   3076: $jstext{'templates'};
                   3077:     var newpos;
                   3078:     var maxh;
                   3079:     if (caller == 'textbooks') {  
                   3080:         newpos = 'textbooks_addbook_pos';
                   3081:         maxh = 1 + $total{'textbooks'};
                   3082:     } else {
                   3083:         newpos = 'templates_addbook_pos';
                   3084:         maxh = 1 + $total{'templates'};
                   3085:     }
1.217     raeburn  3086:     var current = new Array;
                   3087:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3088:     if (item == newpos) {
                   3089:         changedVal = newitemVal;
                   3090:     } else {
                   3091:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3092:         current[newitemVal] = newpos;
                   3093:     }
1.242     raeburn  3094:     if (caller == 'textbooks') {
                   3095:         for (var i=0; i<textbooks.length; i++) {
                   3096:             var elementName = 'textbooks_'+textbooks[i];
                   3097:             if (elementName != item) {
                   3098:                 if (form.elements[elementName]) {
                   3099:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3100:                     current[currVal] = elementName;
                   3101:                 }
                   3102:             }
                   3103:         }
                   3104:     }
                   3105:     if (caller == 'templates') {
                   3106:         for (var i=0; i<templates.length; i++) {
                   3107:             var elementName = 'templates_'+templates[i];
                   3108:             if (elementName != item) {
                   3109:                 if (form.elements[elementName]) {
                   3110:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3111:                     current[currVal] = elementName;
                   3112:                 }
1.217     raeburn  3113:             }
                   3114:         }
                   3115:     }
                   3116:     var oldVal;
                   3117:     for (var j=0; j<maxh; j++) {
                   3118:         if (current[j] == undefined) {
                   3119:             oldVal = j;
                   3120:         }
                   3121:     }
                   3122:     if (oldVal < changedVal) {
                   3123:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3124:            var elementName = current[k];
                   3125:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3126:         }
                   3127:     } else {
                   3128:         for (var k=changedVal; k<oldVal; k++) {
                   3129:             var elementName = current[k];
                   3130:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3131:         }
                   3132:     }
                   3133:     return;
                   3134: }
                   3135: 
                   3136: // ]]>
                   3137: </script>
                   3138: 
                   3139: ENDSCRIPT
                   3140: }
                   3141: 
1.267     raeburn  3142: sub ltitools_javascript {
                   3143:     my ($settings) = @_;
1.319     raeburn  3144:     my $togglejs = &ltitools_toggle_js();
                   3145:     unless (ref($settings) eq 'HASH') {
                   3146:         return $togglejs;
                   3147:     }
1.267     raeburn  3148:     my (%ordered,$total,%jstext);
                   3149:     $total = 0;
                   3150:     foreach my $item (keys(%{$settings})) {
                   3151:         if (ref($settings->{$item}) eq 'HASH') {
                   3152:             my $num = $settings->{$item}{'order'};
                   3153:             $ordered{$num} = $item;
                   3154:         }
                   3155:     }
                   3156:     $total = scalar(keys(%{$settings}));
                   3157:     my @jsarray = ();
                   3158:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3159:         push(@jsarray,$ordered{$item});
                   3160:     }
                   3161:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3162:     return <<"ENDSCRIPT";
                   3163: <script type="text/javascript">
                   3164: // <![CDATA[
1.319     raeburn  3165: function reorderLTITools(form,item) {
1.267     raeburn  3166:     var changedVal;
                   3167: $jstext
                   3168:     var newpos = 'ltitools_add_pos';
                   3169:     var maxh = 1 + $total;
                   3170:     var current = new Array;
                   3171:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3172:     if (item == newpos) {
                   3173:         changedVal = newitemVal;
                   3174:     } else {
                   3175:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3176:         current[newitemVal] = newpos;
                   3177:     }
                   3178:     for (var i=0; i<ltitools.length; i++) {
                   3179:         var elementName = 'ltitools_'+ltitools[i];
                   3180:         if (elementName != item) {
                   3181:             if (form.elements[elementName]) {
                   3182:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3183:                 current[currVal] = elementName;
                   3184:             }
                   3185:         }
                   3186:     }
                   3187:     var oldVal;
                   3188:     for (var j=0; j<maxh; j++) {
                   3189:         if (current[j] == undefined) {
                   3190:             oldVal = j;
                   3191:         }
                   3192:     }
                   3193:     if (oldVal < changedVal) {
                   3194:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3195:            var elementName = current[k];
                   3196:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3197:         }
                   3198:     } else {
                   3199:         for (var k=changedVal; k<oldVal; k++) {
                   3200:             var elementName = current[k];
                   3201:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3202:         }
                   3203:     }
                   3204:     return;
                   3205: }
                   3206: 
                   3207: // ]]>
                   3208: </script>
                   3209: 
1.319     raeburn  3210: $togglejs
                   3211: 
                   3212: ENDSCRIPT
                   3213: }
                   3214: 
                   3215: sub ltitools_toggle_js {
                   3216:     return <<"ENDSCRIPT";
                   3217: <script type="text/javascript">
                   3218: // <![CDATA[
                   3219: 
                   3220: function toggleLTITools(form,setting,item) {
                   3221:     var radioname = '';
                   3222:     var divid = '';
                   3223:     if ((setting == 'passback') || (setting == 'roster')) {
                   3224:         radioname = 'ltitools_'+setting+'_'+item;
                   3225:         divid = 'ltitools_'+setting+'time_'+item;
                   3226:         var num = form.elements[radioname].length;
                   3227:         if (num) {
                   3228:             var setvis = '';
                   3229:             for (var i=0; i<num; i++) {
                   3230:                 if (form.elements[radioname][i].checked) {
                   3231:                     if (form.elements[radioname][i].value == '1') {
                   3232:                         if (document.getElementById(divid)) {
                   3233:                             document.getElementById(divid).style.display = 'inline-block';
                   3234:                         }
                   3235:                         setvis = 1;
                   3236:                     }
                   3237:                     break;
                   3238:                 }
                   3239:             }
                   3240:         }
                   3241:         if (!setvis) {
                   3242:             if (document.getElementById(divid)) {
                   3243:                 document.getElementById(divid).style.display = 'none';
                   3244:             }
                   3245:         }
                   3246:     }
1.324     raeburn  3247:     if (setting == 'user') {
                   3248:         divid = 'ltitools_'+setting+'_div_'+item;
                   3249:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   3250:         if (document.getElementById(divid)) {
                   3251:             if (document.getElementById(checkid)) {
                   3252:                 if (document.getElementById(checkid).checked) {
                   3253:                     document.getElementById(divid).style.display = 'inline-block';
                   3254:                 } else {
                   3255:                     document.getElementById(divid).style.display = 'none';
                   3256:                 }
                   3257:             }
                   3258:         }
                   3259:     }
1.319     raeburn  3260:     return;
                   3261: }
                   3262: // ]]>
                   3263: </script>
                   3264: 
1.267     raeburn  3265: ENDSCRIPT
                   3266: }
                   3267: 
1.381     raeburn  3268: sub wafproxy_javascript {
                   3269:     my ($dom) = @_;
                   3270:     return <<"ENDSCRIPT";
                   3271: <script type="text/javascript">
                   3272: // <![CDATA[
                   3273: function updateWAF() {
                   3274:     if (document.getElementById('wafproxy_remoteip')) {
                   3275:         var wafremote = 0;
                   3276:         if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
                   3277:             wafremote = 1;
                   3278:         }
                   3279:         var fields = new Array('header','trust');
                   3280:         for (var i=0; i<fields.length; i++) {
                   3281:             if (document.getElementById('wafproxy_'+fields[i])) {
                   3282:                 if (wafremote == 1) {
                   3283:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
                   3284:                 }
                   3285:                 else {
                   3286:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
                   3287:                 }
                   3288:             }
                   3289:         }
                   3290:         if (document.getElementById('wafproxyranges_$dom')) {
                   3291:             if (wafremote == 1) {
                   3292:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3293:             } else {
                   3294:                 for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3295:                     if (document.display.wafproxy_vpnaccess[i].checked) {
                   3296:                         if (document.display.wafproxy_vpnaccess[i].value == 0) {
                   3297:                             document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3298:                         }
                   3299:                     }
                   3300:                 }
                   3301:             }
                   3302:         }
                   3303:     }
                   3304:     return;
                   3305: }
                   3306: 
                   3307: function checkWAF() {
                   3308:     if (document.getElementById('wafproxy_remoteip')) {
                   3309:         var wafvpn = 0;
                   3310:         for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3311:             if (document.display.wafproxy_vpnaccess[i].checked) {
                   3312:                 if (document.display.wafproxy_vpnaccess[i].value == 1) {
                   3313:                     wafvpn = 1;
                   3314:                 }
                   3315:                 break;
                   3316:             }
                   3317:         }
                   3318:         var vpn = new Array('vpnint','vpnext');
                   3319:         for (var i=0; i<vpn.length; i++) {
                   3320:             if (document.getElementById('wafproxy_show_'+vpn[i])) {
                   3321:                 if (wafvpn == 1) {
                   3322:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
                   3323:                 }
                   3324:                 else {
                   3325:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
                   3326:                 }
                   3327:             }
                   3328:         }
                   3329:         if (document.getElementById('wafproxyranges_$dom')) {
                   3330:             if (wafvpn == 1) {
                   3331:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3332:             }
                   3333:             else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
                   3334:                 document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3335:             }
                   3336:         }
                   3337:     }
                   3338:     return;
                   3339: }
                   3340: 
                   3341: function toggleWAF() {
                   3342:     if (document.getElementById('wafproxy_table')) {
                   3343:         var wafproxy = 0;
                   3344:         for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
                   3345:              if (document.display.wafproxy_${dom}[i].checked) {
                   3346:                  if (document.display.wafproxy_${dom}[i].value == 1) {
                   3347:                      wafproxy = 1;
                   3348:                      break;
                   3349:                 }
                   3350:             }
                   3351:         }
                   3352:         if (wafproxy == 1) {
                   3353:             document.getElementById('wafproxy_table').style.display='inline';
                   3354:         }
                   3355:         else {
                   3356:            document.getElementById('wafproxy_table').style.display='none';
                   3357:         }
                   3358:         if (document.getElementById('wafproxyrow_${dom}')) {
                   3359:             if (wafproxy == 1) {
                   3360:                 document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
                   3361:             }
                   3362:             else {
                   3363:                 document.getElementById('wafproxyrow_${dom}').style.display = 'none';
                   3364:             }
                   3365:         }
                   3366:         if (document.getElementById('nowafproxyrow_$dom')) {
                   3367:             if (wafproxy == 1) {
                   3368:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
                   3369:             }
                   3370:             else {
                   3371:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
                   3372:             }
                   3373:         }
                   3374:     }
                   3375:     return;
                   3376: }
                   3377: // ]]>
                   3378: </script>
                   3379: 
                   3380: ENDSCRIPT
                   3381: }
                   3382: 
1.372     raeburn  3383: sub proctoring_javascript {
                   3384:     my ($settings) = @_;
                   3385:     my (%ordered,$total,%jstext);
                   3386:     $total = 0;
                   3387:     if (ref($settings) eq 'HASH') {
                   3388:         foreach my $item (keys(%{$settings})) {
                   3389:             if (ref($settings->{$item}) eq 'HASH') {
                   3390:                 my $num = $settings->{$item}{'order'};
                   3391:                 $ordered{$num} = $item;
                   3392:             }
                   3393:         }
                   3394:         $total = scalar(keys(%{$settings}));
                   3395:     } else {
                   3396:         %ordered = (
                   3397:                        0 => 'proctorio',
                   3398:                        1 => 'examity',
                   3399:                    );
                   3400:         $total = 2; 
                   3401:     }
                   3402:     my @jsarray = ();
                   3403:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3404:         push(@jsarray,$ordered{$item});
                   3405:     }
                   3406:     my $jstext = '    var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3407:     return <<"ENDSCRIPT";
                   3408: <script type="text/javascript">
                   3409: // <![CDATA[
                   3410: function reorderProctoring(form,item) {
                   3411:     var changedVal;
                   3412: $jstext
                   3413:     var maxh = $total;
                   3414:     var current = new Array;
                   3415:     var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3416:     for (var i=0; i<proctors.length; i++) {
                   3417:         var elementName = 'proctoring_pos_'+proctors[i];
                   3418:         if (elementName != item) {
                   3419:             if (form.elements[elementName]) {
                   3420:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3421:                 current[currVal] = elementName;
                   3422:             }
                   3423:         }
                   3424:     }
                   3425:     var oldVal;
                   3426:     for (var j=0; j<maxh; j++) {
                   3427:         if (current[j] == undefined) {
                   3428:             oldVal = j;
                   3429:         }
                   3430:     }
                   3431:     if (oldVal < changedVal) {
                   3432:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3433:            var elementName = current[k];
                   3434:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3435:         }
                   3436:     } else {
                   3437:         for (var k=changedVal; k<oldVal; k++) {
                   3438:             var elementName = current[k];
                   3439:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3440:         }
                   3441:     }
                   3442:     return;
                   3443: }
                   3444: 
                   3445: function toggleProctoring(form,item) {
                   3446:     var fieldsets = document.getElementsByClassName('proctoring_'+item);
                   3447:     if (fieldsets.length) {
                   3448:         var radioname = 'proctoring_available_'+item;
                   3449:         var num = form.elements[radioname].length;
                   3450:         if (num) {
                   3451:             var setvis = '';
                   3452:             for (var i=0; i<num; i++) {
                   3453:                 if (form.elements[radioname][i].checked) {
                   3454:                     if (form.elements[radioname][i].value == '1') {
                   3455:                        setvis = 1;
                   3456:                        break;
                   3457:                     }
                   3458:                 }
                   3459:             }
                   3460:             for (var j=0; j<fieldsets.length; j++) {
                   3461:                 if (setvis) {
                   3462:                     fieldsets[j].style.display = 'block';
                   3463:                 } else {
                   3464:                     fieldsets[j].style.display = 'none';
                   3465:                 }
                   3466:             }
                   3467:         }
                   3468:     }
                   3469:     return;
                   3470: }
                   3471: 
                   3472: // ]]>
                   3473: </script>
                   3474: 
                   3475: ENDSCRIPT
                   3476: }
                   3477: 
                   3478: 
1.320     raeburn  3479: sub lti_javascript {
1.405     raeburn  3480:     my ($dom,$settings) = @_;
                   3481:     my $togglejs = &lti_toggle_js($dom);
1.419     raeburn  3482:     my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320     raeburn  3483:     unless (ref($settings) eq 'HASH') {
1.419     raeburn  3484:         return $togglejs.'
                   3485: <script type="text/javascript">
                   3486: // <![CDATA[
                   3487: 
                   3488: '.$linkprot_js.'
                   3489: 
                   3490: // ]]>
                   3491: </script>
                   3492: ';
1.320     raeburn  3493:     }
                   3494:     my (%ordered,$total,%jstext);
1.390     raeburn  3495:     $total = scalar(keys(%{$settings}));
1.320     raeburn  3496:     foreach my $item (keys(%{$settings})) {
                   3497:         if (ref($settings->{$item}) eq 'HASH') {
                   3498:             my $num = $settings->{$item}{'order'};
1.390     raeburn  3499:             if ($num eq '') {
                   3500:                 $num = $total - 1;
                   3501:             }
1.320     raeburn  3502:             $ordered{$num} = $item;
                   3503:         }
                   3504:     }
                   3505:     my @jsarray = ();
                   3506:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3507:         push(@jsarray,$ordered{$item});
                   3508:     }
                   3509:     my $jstext = '    var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3510:     return <<"ENDSCRIPT";
                   3511: <script type="text/javascript">
                   3512: // <![CDATA[
                   3513: function reorderLTI(form,item) {
                   3514:     var changedVal;
                   3515: $jstext
                   3516:     var newpos = 'lti_pos_add';
                   3517:     var maxh = 1 + $total;
                   3518:     var current = new Array;
                   3519:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3520:     if (item == newpos) {
                   3521:         changedVal = newitemVal;
                   3522:     } else {
                   3523:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3524:         current[newitemVal] = newpos;
                   3525:     }
                   3526:     for (var i=0; i<lti.length; i++) {
                   3527:         var elementName = 'lti_pos_'+lti[i];
                   3528:         if (elementName != item) {
                   3529:             if (form.elements[elementName]) {
                   3530:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3531:                 current[currVal] = elementName;
                   3532:             }
                   3533:         }
                   3534:     }
                   3535:     var oldVal;
                   3536:     for (var j=0; j<maxh; j++) {
                   3537:         if (current[j] == undefined) {
                   3538:             oldVal = j;
                   3539:         }
                   3540:     }
                   3541:     if (oldVal < changedVal) {
                   3542:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3543:            var elementName = current[k];
                   3544:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3545:         }
                   3546:     } else {
                   3547:         for (var k=changedVal; k<oldVal; k++) {
                   3548:             var elementName = current[k];
                   3549:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3550:         }
                   3551:     }
                   3552:     return;
                   3553: }
1.406     raeburn  3554: 
                   3555: $linkprot_js
                   3556: 
1.320     raeburn  3557: // ]]>
                   3558: </script>
                   3559: 
                   3560: $togglejs
                   3561: 
                   3562: ENDSCRIPT
                   3563: }
                   3564: 
                   3565: sub lti_toggle_js {
1.405     raeburn  3566:     my ($dom) = @_;
1.325     raeburn  3567:     my %lcauthparmtext = &Apache::lonlocal::texthash (
                   3568:                             localauth => 'Local auth argument',
                   3569:                             krb       => 'Kerberos domain',
                   3570:                          );
1.391     raeburn  3571:     my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
                   3572:     &js_escape(\$crsincalert);
1.405     raeburn  3573:     my %servers = &Apache::lonnet::get_servers($dom,'library');
                   3574:     my $primary = &Apache::lonnet::domain($dom,'primary');
                   3575:     my $course_servers = "'".join("','",keys(%servers))."'";
1.320     raeburn  3576:     return <<"ENDSCRIPT";
                   3577: <script type="text/javascript">
                   3578: // <![CDATA[
                   3579: 
                   3580: function toggleLTI(form,setting,item) {
1.391     raeburn  3581:     if ((setting == 'requser') || (setting == 'crsinc')) {
                   3582:         var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
                   3583:         var setvis = '';
                   3584:         var radioname = 'lti_requser_'+item;
                   3585:         var num = form.elements[radioname].length;
                   3586:         if (num) {
                   3587:             for (var i=0; i<num; i++) {
                   3588:                 if (form.elements[radioname][i].checked) {
                   3589:                     if (form.elements[radioname][i].value == '1') {
                   3590:                         setvis = 1;
                   3591:                         break;
                   3592:                     }
                   3593:                 }
                   3594:             }
                   3595:         }
                   3596:         if (usrfieldsets.length) {
                   3597:             for (var j=0; j<usrfieldsets.length; j++) {
                   3598:                 if (setvis) {
                   3599:                     usrfieldsets[j].style.display = 'block';
                   3600:                 } else {
                   3601:                     usrfieldsets[j].style.display = 'none';
                   3602:                 }
                   3603:             }
                   3604:         }
                   3605:         var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
                   3606:         if (crsfieldsets.length) {
                   3607:             radioname = 'lti_crsinc_'+item;
1.345     raeburn  3608:             var num = form.elements[radioname].length;
                   3609:             if (num) {
1.391     raeburn  3610:                 var crsvis = '';
1.345     raeburn  3611:                 for (var i=0; i<num; i++) {
                   3612:                     if (form.elements[radioname][i].checked) {
                   3613:                         if (form.elements[radioname][i].value == '1') {
1.391     raeburn  3614:                             if (setvis == '') {
                   3615:                                 if (setting == 'crsinc'){
                   3616:                                     alert("$crsincalert");
                   3617:                                     form.elements[radioname][0].checked = true;
                   3618:                                 }
                   3619:                             } else {
                   3620:                                 crsvis = 1;
                   3621:                             }
                   3622:                             break;
1.345     raeburn  3623:                         }
                   3624:                     }
                   3625:                 }
1.391     raeburn  3626:                 setvis = crsvis;
                   3627:             }
                   3628:             for (var j=0; j<crsfieldsets.length; j++) {
                   3629:                 if (setvis) {
                   3630:                     crsfieldsets[j].style.display = 'block';
                   3631:                 } else {
                   3632:                     crsfieldsets[j].style.display = 'none';
1.345     raeburn  3633:                 }
                   3634:             }
                   3635:         }
1.363     raeburn  3636:     } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320     raeburn  3637:         var radioname = '';
                   3638:         var divid = '';
                   3639:         if (setting == 'user') {
                   3640:             radioname = 'lti_mapuser_'+item;
                   3641:             divid = 'lti_userfield_'+item;
1.343     raeburn  3642:         } else if (setting == 'crs') {
1.320     raeburn  3643:             radioname = 'lti_mapcrs_'+item;
                   3644:             divid = 'lti_crsfield_'+item;
1.363     raeburn  3645:         } else if (setting == 'callback') {
                   3646:             radioname = 'lti_callback_'+item;
                   3647:             divid = 'lti_callbackfield_'+item;
1.337     raeburn  3648:         } else {
1.351     raeburn  3649:             radioname = 'lti_passback_'+item;
1.337     raeburn  3650:             divid =  'lti_passback_'+item;
1.320     raeburn  3651:         }
                   3652:         var num = form.elements[radioname].length;
                   3653:         if (num) {
                   3654:             var setvis = '';
                   3655:             for (var i=0; i<num; i++) {
                   3656:                if (form.elements[radioname][i].checked) {
1.363     raeburn  3657:                    if ((setting == 'passback') || (setting == 'callback')) {
1.337     raeburn  3658:                        if (form.elements[radioname][i].value == '1') {
                   3659:                            if (document.getElementById(divid)) {
                   3660:                                document.getElementById(divid).style.display = 'inline-block';
                   3661:                            }
                   3662:                            setvis = 1;
                   3663:                            break;
                   3664:                        }
                   3665:                    } else {
                   3666:                        if (form.elements[radioname][i].value == 'other') {
                   3667:                            if (document.getElementById(divid)) {
                   3668:                                document.getElementById(divid).style.display = 'inline-block';
                   3669:                            }
                   3670:                            setvis = 1;
                   3671:                            break;
1.320     raeburn  3672:                        }
                   3673:                    }
1.425     raeburn  3674:                }
1.320     raeburn  3675:             }
                   3676:             if (!setvis) {
                   3677:                 if (document.getElementById(divid)) {
                   3678:                     document.getElementById(divid).style.display = 'none';
                   3679:                 }
                   3680:             }
                   3681:         }
                   3682:     } else if ((setting == 'sec') || (setting == 'secsrc')) {
                   3683:         var numsec = form.elements['lti_crssec_'+item].length;
                   3684:         if (numsec) {
                   3685:             var setvis = '';
                   3686:             for (var i=0; i<numsec; i++) {
                   3687:                 if (form.elements['lti_crssec_'+item][i].checked) {
                   3688:                     if (form.elements['lti_crssec_'+item][i].value == '1') {
                   3689:                         if (document.getElementById('lti_crssecfield_'+item)) {
                   3690:                             document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
                   3691:                             setvis = 1;
                   3692:                             var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
                   3693:                             if (numsrcsec) {
                   3694:                                 var setsrcvis = '';
                   3695:                                 for (var j=0; j<numsrcsec; j++) {
                   3696:                                     if (form.elements['lti_crssecsrc_'+item][j].checked) {
                   3697:                                         if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
                   3698:                                             if (document.getElementById('lti_secsrcfield_'+item)) {
                   3699:                                                 document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
                   3700:                                                 setsrcvis = 1;
                   3701:                                             }
                   3702:                                         }
                   3703:                                     }
                   3704:                                 }
                   3705:                                 if (!setsrcvis) {
                   3706:                                     if (document.getElementById('lti_secsrcfield_'+item)) {
                   3707:                                         document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3708:                                     }
                   3709:                                 }
                   3710:                             }
                   3711:                         }
                   3712:                     }
                   3713:                 }
                   3714:             }
                   3715:             if (!setvis) {
                   3716:                 if (document.getElementById('lti_crssecfield_'+item)) {
                   3717:                     document.getElementById('lti_crssecfield_'+item).style.display = 'none';
                   3718:                 }
                   3719:                 if (document.getElementById('lti_secsrcfield_'+item)) {
                   3720:                     document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3721:                 }
                   3722:             }
                   3723:         }
1.325     raeburn  3724:     } else if (setting == 'lcauth') {
                   3725:         var numauth = form.elements['lti_lcauth_'+item].length;
                   3726:         if (numauth) {
                   3727:             for (var i=0; i<numauth; i++) {
                   3728:                 if (form.elements['lti_lcauth_'+item][i].checked) {
                   3729:                     if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                   3730:                         if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                   3731:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                   3732:                         } else {
                   3733:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                   3734:                             if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                   3735:                                 if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                   3736:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                   3737:                                 } else {
                   3738:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                   3739:                                 }
                   3740:                             }
                   3741:                         }
                   3742:                     }
                   3743:                 }
                   3744:             }
                   3745:         }
1.326     raeburn  3746:     } else if (setting == 'lcmenu') {
                   3747:         var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
                   3748:         var divid = 'lti_menufield_'+item;
                   3749:         var setvis = '';
                   3750:         for (var i=0; i<menus.length; i++) {
1.425     raeburn  3751:             var radioname = menus[i];
1.326     raeburn  3752:             var num = form.elements[radioname].length;
                   3753:             if (num) {
                   3754:                 for (var j=0; j<num; j++) {
                   3755:                     if (form.elements[radioname][j].checked) {
                   3756:                         if (form.elements[radioname][j].value == '1') {
                   3757:                             if (document.getElementById(divid)) {
                   3758:                                 document.getElementById(divid).style.display = 'inline-block';
                   3759:                             }
                   3760:                             setvis = 1;
                   3761:                             break;
                   3762:                         }
                   3763:                     }
                   3764:                 }
                   3765:             }
                   3766:             if (setvis == 1) {
                   3767:                 break;
                   3768:             }
                   3769:         }
                   3770:         if (!setvis) {
                   3771:             if (document.getElementById(divid)) {
                   3772:                 document.getElementById(divid).style.display = 'none';
                   3773:             }
                   3774:         }
1.320     raeburn  3775:     }
                   3776:     return;
                   3777: }
1.405     raeburn  3778: 
1.320     raeburn  3779: // ]]>
                   3780: </script>
                   3781: 
                   3782: ENDSCRIPT
                   3783: }
                   3784: 
1.385     raeburn  3785: sub autoupdate_javascript {
                   3786:     return <<"ENDSCRIPT";
                   3787: <script type="text/javascript">
                   3788: // <![CDATA[
                   3789: function toggleLastActiveDays(form) {
                   3790:     var radioname = 'lastactive';
                   3791:     var divid = 'lastactive_div';
                   3792:     var num = form.elements[radioname].length;
                   3793:     if (num) {
                   3794:         var setvis = '';
                   3795:         for (var i=0; i<num; i++) {
                   3796:             if (form.elements[radioname][i].checked) {
                   3797:                 if (form.elements[radioname][i].value == '1') {
                   3798:                     if (document.getElementById(divid)) {
                   3799:                         document.getElementById(divid).style.display = 'inline-block';
                   3800:                     }
                   3801:                     setvis = 1;
                   3802:                 }
                   3803:                 break;
                   3804:             }
                   3805:         }
                   3806:         if (!setvis) {
                   3807:             if (document.getElementById(divid)) {
                   3808:                 document.getElementById(divid).style.display = 'none';
                   3809:             }
                   3810:         }
                   3811:     }
                   3812:     return;
                   3813: }
                   3814: // ]]>
                   3815: </script>
                   3816: 
                   3817: ENDSCRIPT
                   3818: }
                   3819: 
1.399     raeburn  3820: sub autoenroll_javascript {
                   3821:     return <<"ENDSCRIPT";
                   3822: <script type="text/javascript">
                   3823: // <![CDATA[
                   3824: function toggleFailsafe(form) {
                   3825:     var radioname = 'autoenroll_failsafe';
                   3826:     var divid = 'autoenroll_failsafe_div';
                   3827:     var num = form.elements[radioname].length;
                   3828:     if (num) {
                   3829:         var setvis = '';
                   3830:         for (var i=0; i<num; i++) {
                   3831:             if (form.elements[radioname][i].checked) {
                   3832:                 if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
                   3833:                     if (document.getElementById(divid)) {
                   3834:                         document.getElementById(divid).style.display = 'inline-block';
                   3835:                     }
                   3836:                     setvis = 1;
                   3837:                 }
                   3838:                 break;
                   3839:             }
                   3840:         }
                   3841:         if (!setvis) {
                   3842:             if (document.getElementById(divid)) {
                   3843:                 document.getElementById(divid).style.display = 'none';
                   3844:             }
                   3845:         }
                   3846:     }
                   3847:     return;
                   3848: }
                   3849: // ]]>
                   3850: </script>
                   3851: 
                   3852: ENDSCRIPT
                   3853: }
                   3854: 
1.386     raeburn  3855: sub saml_javascript {
                   3856:     return <<"ENDSCRIPT";
                   3857: <script type="text/javascript">
                   3858: // <![CDATA[
1.425     raeburn  3859: function toggleSamlOptions(form,hostid) {
1.386     raeburn  3860:     var radioname = 'saml_'+hostid;
                   3861:     var tablecellon = 'samloptionson_'+hostid;
                   3862:     var tablecelloff = 'samloptionsoff_'+hostid;
                   3863:     var num = form.elements[radioname].length;
                   3864:     if (num) {
1.425     raeburn  3865:         var setvis = '';
1.386     raeburn  3866:         for (var i=0; i<num; i++) {
                   3867:             if (form.elements[radioname][i].checked) {
1.425     raeburn  3868:                 if (form.elements[radioname][i].value == '1') {
1.386     raeburn  3869:                     if (document.getElementById(tablecellon)) {
                   3870:                         document.getElementById(tablecellon).style.display='';
                   3871:                     }
                   3872:                     if (document.getElementById(tablecelloff)) {
                   3873:                         document.getElementById(tablecelloff).style.display='none';
                   3874:                     }
                   3875:                     setvis = 1;
                   3876:                 }
                   3877:                 break;
                   3878:             }
                   3879:         }
                   3880:         if (!setvis) {
                   3881:             if (document.getElementById(tablecellon)) {
                   3882:                 document.getElementById(tablecellon).style.display='none';
                   3883:             }
                   3884:             if (document.getElementById(tablecelloff)) {
                   3885:                 document.getElementById(tablecelloff).style.display='';
                   3886:             }
                   3887:         }
                   3888:     }
                   3889:     return;
                   3890: }
                   3891: // ]]>
                   3892: </script>
                   3893: 
                   3894: ENDSCRIPT
                   3895: }
                   3896: 
1.394     raeburn  3897: sub ipaccess_javascript {
                   3898:     my ($settings) = @_;
                   3899:     my (%ordered,$total,%jstext);
                   3900:     $total = 0;
                   3901:     if (ref($settings) eq 'HASH') {
                   3902:         foreach my $item (keys(%{$settings})) {
                   3903:             if (ref($settings->{$item}) eq 'HASH') {
                   3904:                 my $num = $settings->{$item}{'order'};
                   3905:                 $ordered{$num} = $item;
                   3906:             }
                   3907:         }
                   3908:         $total = scalar(keys(%{$settings}));
                   3909:     }
                   3910:     my @jsarray = ();
                   3911:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3912:         push(@jsarray,$ordered{$item});
                   3913:     }
                   3914:     my $jstext = '    var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3915:     return <<"ENDSCRIPT";
                   3916: <script type="text/javascript">
                   3917: // <![CDATA[
                   3918: function reorderIPaccess(form,item) {
                   3919:     var changedVal;
                   3920: $jstext
                   3921:     var newpos = 'ipaccess_pos_add';
                   3922:     var maxh = 1 + $total;
                   3923:     var current = new Array;
                   3924:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3925:     if (item == newpos) {
                   3926:         changedVal = newitemVal;
                   3927:     } else {
                   3928:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3929:         current[newitemVal] = newpos;
                   3930:     }
                   3931:     for (var i=0; i<ipaccess.length; i++) {
                   3932:         var elementName = 'ipaccess_pos_'+ipaccess[i];
                   3933:         if (elementName != item) {
                   3934:             if (form.elements[elementName]) {
                   3935:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3936:                 current[currVal] = elementName;
                   3937:             }
                   3938:         }
                   3939:     }
                   3940:     var oldVal;
                   3941:     for (var j=0; j<maxh; j++) {
                   3942:         if (current[j] == undefined) {
                   3943:             oldVal = j;
                   3944:         }
                   3945:     }
                   3946:     if (oldVal < changedVal) {
                   3947:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3948:            var elementName = current[k];
                   3949:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3950:         }
                   3951:     } else {
                   3952:         for (var k=changedVal; k<oldVal; k++) {
                   3953:             var elementName = current[k];
                   3954:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3955:         }
                   3956:     }
                   3957:     return;
                   3958: }
                   3959: // ]]>
                   3960: </script>
                   3961: 
                   3962: ENDSCRIPT
                   3963: }
                   3964: 
1.429     raeburn  3965: sub authordefaults_javascript {
                   3966:     my %alert = &Apache::lonlocal::texthash (
                   3967:                     reqd => 'Warning: at least one editor needs to be available.',
                   3968:                     rest => 'Unchecking this editor disallowed while others unchecked.',
                   3969:     );
                   3970:     &js_escape(\%alert);
                   3971:     return <<"ENDSCRIPT";
                   3972: <script type="text/javascript">
                   3973: // <![CDATA[
                   3974: 
                   3975: function checkEditors(form,checkbox,current) {
                   3976:     if (form.elements[checkbox].length != undefined) {
                   3977:         var count = 0;
                   3978:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   3979:             if (form.elements[checkbox][i].checked) {
                   3980:                 count ++;
                   3981:             }
                   3982:         }
                   3983:         if (count == 0) {
                   3984:             if (current.type =='radio') {
                   3985:                 current.checked = true;
                   3986:                 alert('$alert{reqd}\\n$alert{rest}');
                   3987:             }
                   3988:         }
                   3989:     }
                   3990:     return;
                   3991: }
                   3992: // ]]>
                   3993: </script>
                   3994: 
                   3995: ENDSCRIPT
                   3996: }
                   3997: 
1.3       raeburn  3998: sub print_autoenroll {
1.30      raeburn  3999:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  4000:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399     raeburn  4001:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
                   4002:         $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
                   4003:     $failsafesty = 'none';
                   4004:     %failsafechecked = (
                   4005:         off => ' checked="checked"',
                   4006:     );
1.3       raeburn  4007:     if (ref($settings) eq 'HASH') {
                   4008:         if (exists($settings->{'run'})) {
                   4009:             if ($settings->{'run'} eq '0') {
                   4010:                 $runoff = ' checked="checked" ';
                   4011:                 $runon = ' ';
                   4012:             } else {
                   4013:                 $runon = ' checked="checked" ';
                   4014:                 $runoff = ' ';
                   4015:             }
                   4016:         } else {
                   4017:             if ($autorun) {
                   4018:                 $runon = ' checked="checked" ';
                   4019:                 $runoff = ' ';
                   4020:             } else {
                   4021:                 $runoff = ' checked="checked" ';
                   4022:                 $runon = ' ';
                   4023:             }
                   4024:         }
1.129     raeburn  4025:         if (exists($settings->{'co-owners'})) {
                   4026:             if ($settings->{'co-owners'} eq '0') {
                   4027:                 $coownersoff = ' checked="checked" ';
                   4028:                 $coownerson = ' ';
                   4029:             } else {
                   4030:                 $coownerson = ' checked="checked" ';
                   4031:                 $coownersoff = ' ';
                   4032:             }
                   4033:         } else {
                   4034:             $coownersoff = ' checked="checked" ';
                   4035:             $coownerson = ' ';
                   4036:         }
1.3       raeburn  4037:         if (exists($settings->{'sender_domain'})) {
                   4038:             $defdom = $settings->{'sender_domain'};
                   4039:         }
1.399     raeburn  4040:         if (exists($settings->{'failsafe'})) {
                   4041:             $failsafe = $settings->{'failsafe'};
                   4042:             if ($failsafe eq 'zero') {
1.400     raeburn  4043:                 $failsafechecked{'zero'} = ' checked="checked"';
1.399     raeburn  4044:                 $failsafechecked{'off'} = '';
                   4045:                 $failsafesty = 'inline-block';
                   4046:             } elsif ($failsafe eq 'any') {
                   4047:                 $failsafechecked{'any'} = ' checked="checked"';
                   4048:                 $failsafechecked{'off'} = '';
                   4049:             }
                   4050:             $autofailsafe = $settings->{'autofailsafe'};
                   4051:         } elsif (exists($settings->{'autofailsafe'})) {
                   4052:             $autofailsafe = $settings->{'autofailsafe'};
                   4053:             if ($autofailsafe ne '') {
                   4054:                 $failsafechecked{'zero'} = ' checked="checked"';
                   4055:                 $failsafe = 'zero';
1.400     raeburn  4056:                 $failsafechecked{'off'} = '';
1.399     raeburn  4057:             }
1.274     raeburn  4058:         }
1.14      raeburn  4059:     } else {
                   4060:         if ($autorun) {
                   4061:             $runon = ' checked="checked" ';
                   4062:             $runoff = ' ';
                   4063:         } else {
                   4064:             $runoff = ' checked="checked" ';
                   4065:             $runon = ' ';
                   4066:         }
1.3       raeburn  4067:     }
                   4068:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  4069:     my $notif_sender;
                   4070:     if (ref($settings) eq 'HASH') {
                   4071:         $notif_sender = $settings->{'sender_uname'};
                   4072:     }
1.3       raeburn  4073:     my $datatable='<tr class="LC_odd_row">'.
                   4074:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  4075:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  4076:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  4077:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4078:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  4079:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  4080:                   '</tr><tr>'.
                   4081:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  4082:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  4083:                   &mt('username').':&nbsp;'.
                   4084:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  4085:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  4086:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   4087:                   '<tr class="LC_odd_row">'.
                   4088:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   4089:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4090:                   '<input type="radio" name="autoassign_coowners"'.
                   4091:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4092:                   '<label><input type="radio" name="autoassign_coowners"'.
                   4093:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  4094:                   '</tr><tr>'.
                   4095:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400     raeburn  4096:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4097:                   '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span>&nbsp;&nbsp;&nbsp; '.
                   4098:                   '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
                   4099:                   '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399     raeburn  4100:                   '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
                   4101:                   '<span class="LC_nobreak">'.
                   4102:                   &mt('Threshold for number of students in section to drop: [_1]',
                   4103:                       '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
                   4104:                   '</span></div></td></tr>';
1.274     raeburn  4105:     $$rowtotal += 4;
1.3       raeburn  4106:     return $datatable;
                   4107: }
                   4108: 
                   4109: sub print_autoupdate {
1.30      raeburn  4110:     my ($position,$dom,$settings,$rowtotal) = @_;
1.385     raeburn  4111:     my ($enable,$datatable);
1.3       raeburn  4112:     if ($position eq 'top') {
1.385     raeburn  4113:         my %choices = &Apache::lonlocal::texthash (
                   4114:                           run        => 'Auto-update active?',
                   4115:                           classlists => 'Update information in classlists?',
                   4116:                           unexpired  => 'Skip updates for users without active or future roles?',
                   4117:                           lastactive => 'Skip updates for inactive users?',
                   4118:         );
                   4119:         my $itemcount = 0;
1.3       raeburn  4120:         my $updateon = ' ';
                   4121:         my $updateoff = ' checked="checked" ';
                   4122:         if (ref($settings) eq 'HASH') {
                   4123:             if ($settings->{'run'} eq '1') {
                   4124:                 $updateon = $updateoff;
                   4125:                 $updateoff = ' ';
                   4126:             }
                   4127:         }
1.385     raeburn  4128:         $enable = '<tr class="LC_odd_row">'.
                   4129:                   '<td>'.$choices{'run'}.'</td>'.
                   4130:                   '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  4131:                   '<input type="radio" name="autoupdate_run"'.
1.397     raeburn  4132:                   $updateoff.'value="0" />'.&mt('No').'</label>&nbsp;'.
1.8       raeburn  4133:                   '<label><input type="radio" name="autoupdate_run"'.
1.385     raeburn  4134:                   $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3       raeburn  4135:                   '</tr>';
1.385     raeburn  4136:         my @toggles = ('classlists','unexpired');
                   4137:         my %defaultchecked = ('classlists' => 'off',
                   4138:                               'unexpired'  => 'off'
                   4139:                               );
                   4140:         $$rowtotal ++;
                   4141:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4142:                                                      \%choices,$itemcount,'','','left','no');
                   4143:         $datatable = $enable.$datatable;
                   4144:         $$rowtotal += $itemcount;
                   4145:         my $lastactiveon = ' ';
                   4146:         my $lastactiveoff = ' checked="checked" ';
                   4147:         my $lastactivestyle = 'none';
                   4148:         my $lastactivedays;
                   4149:         my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
                   4150:         if (ref($settings) eq 'HASH') {
                   4151:             if ($settings->{'lastactive'} =~ /^\d+$/) {
                   4152:                 $lastactiveon = $lastactiveoff;
                   4153:                 $lastactiveoff = ' ';
                   4154:                 $lastactivestyle = 'inline-block';
                   4155:                 $lastactivedays = $settings->{'lastactive'};
                   4156:             }
                   4157:         }
                   4158:         my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4159:         $datatable .= '<tr'.$css_class.'>'.
                   4160:                       '<td>'.$choices{'lastactive'}.'</td>'.
                   4161:                       '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                   4162:                       '<input type="radio" name="lastactive"'.
                   4163:                       $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   4164:                       '&nbsp;<label>'.
                   4165:                       '<input type="radio" name="lastactive"'.
                   4166:                       $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
                   4167:                       '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
                   4168:                       ':&nbsp;'.&mt('inactive = no activity in last [_1] days',
                   4169:                           '<input type="text" size="5" name="lastactivedays" value="'.
                   4170:                           $lastactivedays.'" />').
                   4171:                       '</span></td>'.
                   4172:                       '</tr>';
                   4173:         $$rowtotal ++;
1.131     raeburn  4174:     } elsif ($position eq 'middle') {
                   4175:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4176:         my $numinrow = 3;
                   4177:         my $locknamesettings;
                   4178:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   4179:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  4180:                                     'lockablenames',$rowtotal);
1.131     raeburn  4181:         $$rowtotal ++;
1.3       raeburn  4182:     } else {
1.44      raeburn  4183:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  4184:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  4185:                       'permanentemail','id');
1.33      raeburn  4186:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  4187:         my $numrows = 0;
1.26      raeburn  4188:         if (ref($types) eq 'ARRAY') {
                   4189:             if (@{$types} > 0) {
                   4190:                 $datatable = 
                   4191:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   4192:                                          \@fields,$types,\$numrows);
1.30      raeburn  4193:                     $$rowtotal += @{$types}; 
1.26      raeburn  4194:             }
1.3       raeburn  4195:         }
                   4196:         $datatable .= 
                   4197:             &usertype_update_row($settings,{'default' => $othertitle},
                   4198:                                  \%fieldtitles,\@fields,['default'],
                   4199:                                  \$numrows);
1.30      raeburn  4200:         $$rowtotal ++;     
1.3       raeburn  4201:     }
                   4202:     return $datatable;
                   4203: }
                   4204: 
1.125     raeburn  4205: sub print_autocreate {
                   4206:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  4207:     my (%createon,%createoff,%currhash);
1.125     raeburn  4208:     my @types = ('xml','req');
                   4209:     if (ref($settings) eq 'HASH') {
                   4210:         foreach my $item (@types) {
                   4211:             $createoff{$item} = ' checked="checked" ';
                   4212:             $createon{$item} = ' ';
                   4213:             if (exists($settings->{$item})) {
                   4214:                 if ($settings->{$item}) {
                   4215:                     $createon{$item} = ' checked="checked" ';
                   4216:                     $createoff{$item} = ' ';
                   4217:                 }
                   4218:             }
                   4219:         }
1.210     raeburn  4220:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  4221:             $currhash{$settings->{'xmldc'}} = 1;
                   4222:         }
1.125     raeburn  4223:     } else {
                   4224:         foreach my $item (@types) {
                   4225:             $createoff{$item} = ' checked="checked" ';
                   4226:             $createon{$item} = ' ';
                   4227:         }
                   4228:     }
                   4229:     $$rowtotal += 2;
1.191     raeburn  4230:     my $numinrow = 2;
1.125     raeburn  4231:     my $datatable='<tr class="LC_odd_row">'.
                   4232:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   4233:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4234:                   '<input type="radio" name="autocreate_xml"'.
                   4235:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4236:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  4237:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   4238:                   '</td></tr><tr>'.
                   4239:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   4240:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4241:                   '<input type="radio" name="autocreate_req"'.
                   4242:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4243:                   '<label><input type="radio" name="autocreate_req"'.
                   4244:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  4245:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4246:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  4247:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  4248:     if ($numdc > 1) {
1.247     raeburn  4249:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   4250:                       '</td><td class="LC_left_item">';
1.125     raeburn  4251:     } else {
1.247     raeburn  4252:         $datatable .= &mt('Course creation processed as:').
                   4253:                       '</td><td class="LC_right_item">';
1.125     raeburn  4254:     }
1.247     raeburn  4255:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  4256:     $$rowtotal += $rows;
1.125     raeburn  4257:     return $datatable;
                   4258: }
                   4259: 
1.23      raeburn  4260: sub print_directorysrch {
1.277     raeburn  4261:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4262:     my $datatable;
                   4263:     if ($position eq 'top') {
                   4264:         my $instsrchon = ' ';
                   4265:         my $instsrchoff = ' checked="checked" ';
                   4266:         my ($exacton,$containson,$beginson);
                   4267:         my $instlocalon = ' ';
                   4268:         my $instlocaloff = ' checked="checked" ';
                   4269:         if (ref($settings) eq 'HASH') {
                   4270:             if ($settings->{'available'} eq '1') {
                   4271:                 $instsrchon = $instsrchoff;
                   4272:                 $instsrchoff = ' ';
                   4273:             }
                   4274:             if ($settings->{'localonly'} eq '1') {
                   4275:                 $instlocalon = $instlocaloff;
                   4276:                 $instlocaloff = ' ';
                   4277:             }
                   4278:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   4279:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   4280:                     if ($type eq 'exact') {
                   4281:                         $exacton = ' checked="checked" ';
                   4282:                     } elsif ($type eq 'contains') {
                   4283:                         $containson = ' checked="checked" ';
                   4284:                     } elsif ($type eq 'begins') {
                   4285:                         $beginson = ' checked="checked" ';
                   4286:                     }
                   4287:                 }
                   4288:             } else {
                   4289:                 if ($settings->{'searchtypes'} eq 'exact') {
                   4290:                     $exacton = ' checked="checked" ';
                   4291:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   4292:                     $containson = ' checked="checked" ';
                   4293:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  4294:                     $exacton = ' checked="checked" ';
                   4295:                     $containson = ' checked="checked" ';
                   4296:                 }
                   4297:             }
1.277     raeburn  4298:         }
                   4299:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   4300:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4301: 
                   4302:         my $numinrow = 4;
                   4303:         my $cansrchrow = 0;
                   4304:         $datatable='<tr class="LC_odd_row">'.
                   4305:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   4306:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4307:                    '<input type="radio" name="dirsrch_available"'.
                   4308:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4309:                    '<label><input type="radio" name="dirsrch_available"'.
                   4310:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4311:                    '</tr><tr>'.
                   4312:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   4313:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4314:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   4315:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4316:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   4317:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4318:                    '</tr>';
                   4319:         $$rowtotal += 2;
                   4320:         if (ref($usertypes) eq 'HASH') {
                   4321:             if (keys(%{$usertypes}) > 0) {
                   4322:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  4323:                                              $numinrow,$othertitle,'cansearch',
                   4324:                                              $rowtotal);
1.277     raeburn  4325:                 $cansrchrow = 1;
1.25      raeburn  4326:             }
1.23      raeburn  4327:         }
1.277     raeburn  4328:         if ($cansrchrow) {
                   4329:             $$rowtotal ++;
                   4330:             $datatable .= '<tr>';
                   4331:         } else {
                   4332:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  4333:         }
1.277     raeburn  4334:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   4335:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   4336:         foreach my $title (@{$titleorder}) {
                   4337:             if (defined($searchtitles->{$title})) {
                   4338:                 my $check = ' ';
                   4339:                 if (ref($settings) eq 'HASH') {
                   4340:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   4341:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   4342:                             $check = ' checked="checked" ';
                   4343:                         }
1.39      raeburn  4344:                     }
1.25      raeburn  4345:                 }
1.277     raeburn  4346:                 $datatable .= '<td class="LC_left_item">'.
                   4347:                               '<span class="LC_nobreak"><label>'.
                   4348:                               '<input type="checkbox" name="searchby" '.
                   4349:                               'value="'.$title.'"'.$check.'/>'.
                   4350:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  4351:             }
                   4352:         }
1.277     raeburn  4353:         $datatable .= '</tr></table></td></tr>';
                   4354:         $$rowtotal ++;
                   4355:         if ($cansrchrow) {
                   4356:             $datatable .= '<tr class="LC_odd_row">';
                   4357:         } else {
                   4358:             $datatable .= '<tr>';
                   4359:         }
                   4360:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   4361:                       '<td class="LC_left_item" colspan="2">'.
                   4362:                       '<span class="LC_nobreak"><label>'.
                   4363:                       '<input type="checkbox" name="searchtypes" '.
                   4364:                       $exacton.' value="exact" />'.&mt('Exact match').
                   4365:                       '</label>&nbsp;'.
                   4366:                       '<label><input type="checkbox" name="searchtypes" '.
                   4367:                       $beginson.' value="begins" />'.&mt('Begins with').
                   4368:                       '</label>&nbsp;'.
                   4369:                       '<label><input type="checkbox" name="searchtypes" '.
                   4370:                       $containson.' value="contains" />'.&mt('Contains').
                   4371:                       '</label></span></td></tr>';
                   4372:         $$rowtotal ++;
1.26      raeburn  4373:     } else {
1.277     raeburn  4374:         my $domsrchon = ' checked="checked" ';
                   4375:         my $domsrchoff = ' ';
                   4376:         my $domlocalon = ' ';
                   4377:         my $domlocaloff = ' checked="checked" ';
                   4378:         if (ref($settings) eq 'HASH') {
                   4379:             if ($settings->{'lclocalonly'} eq '1') {
                   4380:                 $domlocalon = $domlocaloff;
                   4381:                 $domlocaloff = ' ';
                   4382:             }
                   4383:             if ($settings->{'lcavailable'} eq '0') {
                   4384:                 $domsrchoff = $domsrchon;
                   4385:                 $domsrchon = ' ';
                   4386:             }
                   4387:         }
                   4388:         $datatable='<tr class="LC_odd_row">'.
                   4389:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   4390:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4391:                       '<input type="radio" name="dirsrch_domavailable"'.
                   4392:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4393:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   4394:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4395:                       '</tr><tr>'.
                   4396:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   4397:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4398:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   4399:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4400:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   4401:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4402:                       '</tr>';
                   4403:         $$rowtotal += 2;
1.26      raeburn  4404:     }
1.25      raeburn  4405:     return $datatable;
                   4406: }
                   4407: 
1.28      raeburn  4408: sub print_contacts {
1.286     raeburn  4409:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  4410:     my $datatable;
                   4411:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  4412:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340     raeburn  4413:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286     raeburn  4414:     if ($position eq 'top') {
                   4415:         if (ref($settings) eq 'HASH') {
                   4416:             foreach my $item (@contacts) {
                   4417:                 if (exists($settings->{$item})) {
                   4418:                     $to{$item} = $settings->{$item};
                   4419:                 }
                   4420:             }
                   4421:         }
                   4422:     } elsif ($position eq 'middle') {
                   4423:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350     raeburn  4424:                      'updatesmail','idconflictsmail','hostipmail');
1.288     raeburn  4425:         foreach my $type (@mailings) {
                   4426:             $otheremails{$type} = '';
                   4427:         }
1.340     raeburn  4428:     } elsif ($position eq 'lower') {
                   4429:         if (ref($settings) eq 'HASH') {
                   4430:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   4431:                 %lonstatus = %{$settings->{'lonstatus'}};
                   4432:             }
                   4433:         }
1.286     raeburn  4434:     } else {
                   4435:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  4436:         foreach my $type (@mailings) {
                   4437:             $otheremails{$type} = '';
                   4438:         }
1.286     raeburn  4439:         $bccemails{'helpdeskmail'} = '';
                   4440:         $bccemails{'otherdomsmail'} = '';
                   4441:         $includestr{'helpdeskmail'} = '';
                   4442:         $includestr{'otherdomsmail'} = '';
                   4443:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   4444:     }
1.28      raeburn  4445:     if (ref($settings) eq 'HASH') {
1.340     raeburn  4446:         unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4447:             foreach my $type (@mailings) {
                   4448:                 if (exists($settings->{$type})) {
                   4449:                     if (ref($settings->{$type}) eq 'HASH') {
                   4450:                         foreach my $item (@contacts) {
                   4451:                             if ($settings->{$type}{$item}) {
                   4452:                                 $checked{$type}{$item} = ' checked="checked" ';
                   4453:                             }
                   4454:                         }
                   4455:                         $otheremails{$type} = $settings->{$type}{'others'};
                   4456:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4457:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   4458:                             if ($settings->{$type}{'include'} ne '') {
                   4459:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4460:                                 $includestr{$type} = &unescape($includestr{$type});
                   4461:                             }
                   4462:                         }
                   4463:                     }
                   4464:                 } elsif ($type eq 'lonstatusmail') {
                   4465:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   4466:                 }
1.28      raeburn  4467:             }
                   4468:         }
1.286     raeburn  4469:         if ($position eq 'bottom') {
                   4470:             foreach my $type (@mailings) {
                   4471:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   4472:                 if ($settings->{$type}{'include'} ne '') {
                   4473:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4474:                     $includestr{$type} = &unescape($includestr{$type});
                   4475:                 }
                   4476:             }
                   4477:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   4478:                 if (ref($fields) eq 'ARRAY') {
                   4479:                     foreach my $field (@{$fields}) {
                   4480:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  4481:                     }
1.286     raeburn  4482:                 }
                   4483:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   4484:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   4485:                 } else {
1.289     raeburn  4486:                     $maxsize = '1.0';
1.286     raeburn  4487:                 }
                   4488:             } else {
                   4489:                 if (ref($fields) eq 'ARRAY') {
                   4490:                     foreach my $field (@{$fields}) {
                   4491:                         $currfield{$field} = 'yes';
1.134     raeburn  4492:                     }
1.28      raeburn  4493:                 }
1.286     raeburn  4494:                 $maxsize = '1.0';
1.28      raeburn  4495:             }
                   4496:         }
                   4497:     } else {
1.286     raeburn  4498:         if ($position eq 'top') {
                   4499:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   4500:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   4501:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   4502:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  4503:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4504:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   4505:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   4506:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350     raeburn  4507:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4508:         } elsif ($position eq 'bottom') {
                   4509:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   4510:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   4511:             if (ref($fields) eq 'ARRAY') {
                   4512:                 foreach my $field (@{$fields}) {
                   4513:                     $currfield{$field} = 'yes';
                   4514:                 }
                   4515:             }
                   4516:             $maxsize = '1.0';
                   4517:         }
1.28      raeburn  4518:     }
                   4519:     my ($titles,$short_titles) = &contact_titles();
                   4520:     my $rownum = 0;
                   4521:     my $css_class;
1.286     raeburn  4522:     if ($position eq 'top') {
                   4523:         foreach my $item (@contacts) {
                   4524:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4525:             $datatable .= '<tr'.$css_class.'>'. 
                   4526:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   4527:                           '</span></td><td class="LC_right_item">'.
                   4528:                           '<input type="text" name="'.$item.'" value="'.
                   4529:                           $to{$item}.'" /></td></tr>';
                   4530:             $rownum ++;
                   4531:         }
1.315     raeburn  4532:     } elsif ($position eq 'bottom') {
                   4533:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4534:         $datatable .= '<tr'.$css_class.'>'.
                   4535:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   4536:                       &mt('(e-mail, subject, and description always shown)').
                   4537:                       '</td><td class="LC_left_item">';
                   4538:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   4539:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   4540:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   4541:             foreach my $field (@{$fields}) {
                   4542:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   4543:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   4544:                     $datatable .= ' '.&mt('(logged-in users)');
                   4545:                 }
                   4546:                 $datatable .='</td><td>';
                   4547:                 my $clickaction;
                   4548:                 if ($field eq 'screenshot') {
                   4549:                     $clickaction = ' onclick="screenshotSize(this);"';
                   4550:                 }
                   4551:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   4552:                     foreach my $option (@{$possoptions->{$field}}) {
                   4553:                         my $checked;
                   4554:                         if ($currfield{$field} eq $option) {
                   4555:                             $checked = ' checked="checked"';
                   4556:                         }
                   4557:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   4558:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   4559:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   4560:                                       '</label></span>'.('&nbsp;'x2);
                   4561:                     }
                   4562:                 }
                   4563:                 if ($field eq 'screenshot') {
                   4564:                     my $display;
                   4565:                     if ($currfield{$field} eq 'no') {
                   4566:                         $display = ' style="display:none"';
                   4567:                     }
1.334     raeburn  4568:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315     raeburn  4569:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   4570:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   4571:                 }
                   4572:                 $datatable .= '</td></tr>';
                   4573:             }
                   4574:             $datatable .= '</table>';
                   4575:         }
                   4576:         $datatable .= '</td></tr>'."\n";
                   4577:         $rownum ++;
                   4578:     }
1.340     raeburn  4579:     unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4580:         foreach my $type (@mailings) {
                   4581:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4582:             $datatable .= '<tr'.$css_class.'>'.
                   4583:                           '<td><span class="LC_nobreak">'.
                   4584:                           $titles->{$type}.': </span></td>'.
                   4585:                           '<td class="LC_left_item">';
                   4586:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4587:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   4588:             }
                   4589:             $datatable .= '<span class="LC_nobreak">';
                   4590:             foreach my $item (@contacts) {
                   4591:                 $datatable .= '<label>'.
                   4592:                               '<input type="checkbox" name="'.$type.'"'.
                   4593:                               $checked{$type}{$item}.
                   4594:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   4595:                               '</label>&nbsp;';
                   4596:             }
                   4597:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4598:                           '<input type="text" name="'.$type.'_others" '.
                   4599:                           'value="'.$otheremails{$type}.'"  />';
                   4600:             my %locchecked;
                   4601:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4602:                 foreach my $loc ('s','b') {
                   4603:                     if ($includeloc{$type} eq $loc) {
                   4604:                         $locchecked{$loc} = ' checked="checked"';
                   4605:                         last;
                   4606:                     }
                   4607:                 }
                   4608:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4609:                               '<input type="text" name="'.$type.'_bcc" '.
                   4610:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   4611:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4612:                               &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4613:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286     raeburn  4614:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4615:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4616:                               ('&nbsp;'x2).
                   4617:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4618:                               '</span></fieldset>';
                   4619:             }
                   4620:             $datatable .= '</td></tr>'."\n";
                   4621:             $rownum ++;
                   4622:         }
1.28      raeburn  4623:     }
1.286     raeburn  4624:     if ($position eq 'middle') {
                   4625:         my %choices;
1.340     raeburn  4626:         my $corelink = &core_link_msu();
                   4627:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286     raeburn  4628:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340     raeburn  4629:                                         $corelink);
                   4630:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   4631:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286     raeburn  4632:         my %defaultchecked = ('reporterrors'  => 'on',
1.340     raeburn  4633:                               'reportupdates' => 'on',
                   4634:                               'reportstatus'  => 'on');
1.286     raeburn  4635:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4636:                                                    \%choices,$rownum);
                   4637:         $datatable .= $reports;
1.340     raeburn  4638:     } elsif ($position eq 'lower') {
1.378     raeburn  4639:         my (%current,%excluded,%weights);
1.340     raeburn  4640:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   4641:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378     raeburn  4642:             $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340     raeburn  4643:         } else {
1.378     raeburn  4644:             $current{'errorthreshold'} = $defaults->{'threshold'};
1.340     raeburn  4645:         }
                   4646:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378     raeburn  4647:             $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340     raeburn  4648:         } else {
1.378     raeburn  4649:             $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340     raeburn  4650:         }
                   4651:         if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341     raeburn  4652:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4653:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   4654:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   4655:                 } else {
                   4656:                     $weights{$type} = $defaults->{$type};
                   4657:                 }
                   4658:             }
                   4659:         } else {
1.341     raeburn  4660:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4661:                 $weights{$type} = $defaults->{$type};
                   4662:             }
                   4663:         }
                   4664:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   4665:             if (@{$lonstatus{'excluded'}} > 0) {
                   4666:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   4667:             }
                   4668:         }
1.425     raeburn  4669:         foreach my $item ('errorthreshold','errorsysmail') {
1.378     raeburn  4670:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4671:             $datatable .= '<tr'.$css_class.'>'.
                   4672:                           '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4673:                           $titles->{$item}.
                   4674:                           '</span></td><td class="LC_left_item">'.
                   4675:                           '<input type="text" name="'.$item.'" value="'.
                   4676:                           $current{$item}.'" size="5" /></td></tr>';
                   4677:             $rownum ++;
                   4678:         }
1.340     raeburn  4679:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4680:         $datatable .= '<tr'.$css_class.'>'.
                   4681:                       '<td class="LC_left_item">'.
                   4682:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   4683:                       '</span></td><td class="LC_left_item"><table><tr>';
1.341     raeburn  4684:         foreach my $type ('E','W','N','U') {
1.340     raeburn  4685:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   4686:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   4687:                           $weights{$type}.'" size="5" /></td>';
                   4688:         }
                   4689:         $datatable .= '</tr></table></tr>';
                   4690:         $rownum ++;
                   4691:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4692:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   4693:                       $titles->{'errorexcluded'}.'</td>'.
                   4694:                       '<td class="LC_left_item"><table>';
                   4695:         my $numinrow = 4;
                   4696:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   4697:         for (my $i=0; $i<@ids; $i++) {
                   4698:             my $rem = $i%($numinrow);
                   4699:             if ($rem == 0) {
                   4700:                 if ($i > 0) {
                   4701:                     $datatable .= '</tr>';
                   4702:                 }
                   4703:                 $datatable .= '<tr>';
                   4704:             }
                   4705:             my $check;
                   4706:             if ($excluded{$ids[$i]}) {
                   4707:                 $check = ' checked="checked" ';
                   4708:             }
                   4709:             $datatable .= '<td class="LC_left_item">'.
                   4710:                           '<span class="LC_nobreak"><label>'.
                   4711:                           '<input type="checkbox" name="errorexcluded" '.
                   4712:                           'value="'.$ids[$i].'"'.$check.' />'.
                   4713:                           $ids[$i].'</label></span></td>';
                   4714:         }
                   4715:         my $colsleft = $numinrow - @ids%($numinrow);
                   4716:         if ($colsleft > 1 ) {
                   4717:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4718:                           '&nbsp;</td>';
                   4719:         } elsif ($colsleft == 1) {
                   4720:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4721:         }
                   4722:         $datatable .= '</tr></table></td></tr>';
                   4723:         $rownum ++;
1.286     raeburn  4724:     } elsif ($position eq 'bottom') {
1.315     raeburn  4725:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4726:         my (@posstypes,%usertypeshash);
                   4727:         if (ref($types) eq 'ARRAY') {
                   4728:             @posstypes = @{$types};
                   4729:         }
                   4730:         if (@posstypes) {
                   4731:             if (ref($usertypes) eq 'HASH') {
                   4732:                 %usertypeshash = %{$usertypes};
                   4733:             }
                   4734:             my @overridden;
                   4735:             my $numinrow = 4;
                   4736:             if (ref($settings) eq 'HASH') {
                   4737:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   4738:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   4739:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   4740:                             push(@overridden,$key);
                   4741:                             foreach my $item (@contacts) {
                   4742:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   4743:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   4744:                                 }
                   4745:                             }
                   4746:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   4747:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   4748:                             $includeloc{'override_'.$key} = '';
                   4749:                             $includestr{'override_'.$key} = '';
                   4750:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425     raeburn  4751:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315     raeburn  4752:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   4753:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   4754:                             }
1.286     raeburn  4755:                         }
                   4756:                     }
                   4757:                 }
1.315     raeburn  4758:             }
                   4759:             my $customclass = 'LC_helpdesk_override';
                   4760:             my $optionsprefix = 'LC_options_helpdesk_';
                   4761: 
                   4762:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   4763:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   4764:                                          $numinrow,$othertitle,'overrides',
                   4765:                                          \$rownum,$onclicktypes,$customclass);
                   4766:             $rownum ++;
                   4767:             $usertypeshash{'default'} = $othertitle;
                   4768:             foreach my $status (@posstypes) {
                   4769:                 my $css_class;
                   4770:                 if ($rownum%2) {
                   4771:                     $css_class = 'LC_odd_row ';
                   4772:                 }
                   4773:                 $css_class .= $customclass;
                   4774:                 my $rowid = $optionsprefix.$status;
                   4775:                 my $hidden = 1;
                   4776:                 my $currstyle = 'display:none';
                   4777:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   4778:                     $currstyle = 'display:table-row';
                   4779:                     $hidden = 0;
                   4780:                 }
                   4781:                 my $key = 'override_'.$status;
                   4782:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   4783:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   4784:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   4785:                                                   \@contacts,$short_titles);
                   4786:                 unless ($hidden) {
                   4787:                     $rownum ++;
1.286     raeburn  4788:                 }
                   4789:             }
1.134     raeburn  4790:         }
1.28      raeburn  4791:     }
1.30      raeburn  4792:     $$rowtotal += $rownum;
1.28      raeburn  4793:     return $datatable;
                   4794: }
                   4795: 
1.340     raeburn  4796: sub core_link_msu {
                   4797:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   4798:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   4799: }
                   4800: 
1.315     raeburn  4801: sub overridden_helpdesk {
                   4802:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   4803:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   4804:     my $class = 'LC_left_item';
                   4805:     if ($css_class) {
                   4806:         $css_class = ' class="'.$css_class.'"';
                   4807:     }
                   4808:     if ($rowid) {
                   4809:         $rowid = ' id="'.$rowid.'"';
                   4810:     }
                   4811:     if ($rowstyle) {
                   4812:         $rowstyle = ' style="'.$rowstyle.'"';
                   4813:     }
                   4814:     my ($output,$description);
                   4815:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   4816:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   4817:               "<td>$description</td>\n".
                   4818:               '<td class="'.$class.'" colspan="2">'.
                   4819:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   4820:               '<span class="LC_nobreak">';
                   4821:     if (ref($contacts) eq 'ARRAY') {
                   4822:         foreach my $item (@{$contacts}) {
                   4823:             my $check;
                   4824:             if (ref($checked) eq 'HASH') {
                   4825:                $check = $checked->{$item};
                   4826:             }
                   4827:             my $title;
                   4828:             if (ref($short_titles) eq 'HASH') {
1.425     raeburn  4829:                 $title = $short_titles->{$item};
1.315     raeburn  4830:             }
                   4831:             $output .= '<label>'.
                   4832:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   4833:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   4834:         }
                   4835:     }
                   4836:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4837:                '<input type="text" name="override_'.$type.'_others" '.
                   4838:                'value="'.$otheremails.'"  />';
                   4839:     my %locchecked;
                   4840:     foreach my $loc ('s','b') {
                   4841:         if ($includeloc eq $loc) {
                   4842:             $locchecked{$loc} = ' checked="checked"';
                   4843:             last;
                   4844:         }
                   4845:     }
                   4846:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4847:                '<input type="text" name="override_'.$type.'_bcc" '.
                   4848:                'value="'.$bccemails.'"  /></fieldset>'.
                   4849:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4850:                &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4851:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315     raeburn  4852:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4853:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4854:                ('&nbsp;'x2).
                   4855:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4856:                '</span></fieldset>'.
                   4857:                '</td></tr>'."\n";
                   4858:     return $output;
                   4859: }
                   4860: 
1.286     raeburn  4861: sub contacts_javascript {
                   4862:     return <<"ENDSCRIPT";
                   4863: 
                   4864: <script type="text/javascript">
                   4865: // <![CDATA[
                   4866: 
                   4867: function screenshotSize(field) {
                   4868:     if (document.getElementById('help_screenshotsize')) {
                   4869:         if (field.value == 'no') {
1.289     raeburn  4870:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  4871:         } else {
                   4872:             document.getElementById('help_screenshotsize').style.display="";
                   4873:         }
                   4874:     }
                   4875:     return;
                   4876: }
                   4877: 
1.315     raeburn  4878: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   4879:     if (form.elements[checkbox].length != undefined) {
                   4880:         var count = 0;
                   4881:         if (docount) {
                   4882:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   4883:                 if (form.elements[checkbox][i].checked) {
                   4884:                     count ++;
                   4885:                 }
                   4886:             }
                   4887:         }
                   4888:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   4889:             var type = form.elements[checkbox][i].value;
                   4890:             if (document.getElementById(prefix+type)) {
                   4891:                 if (form.elements[checkbox][i].checked) {
                   4892:                     document.getElementById(prefix+type).style.display = 'table-row';
                   4893:                     if (count % 2 == 1) {
                   4894:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   4895:                     } else {
                   4896:                         document.getElementById(prefix+type).className = target;
                   4897:                     }
                   4898:                     count ++;
                   4899:                 } else {
                   4900:                     document.getElementById(prefix+type).style.display = 'none';
                   4901:                 }
                   4902:             }
                   4903:         }
                   4904:     }
                   4905:     return;
                   4906: }
                   4907: 
1.286     raeburn  4908: // ]]>
                   4909: </script>
                   4910: 
                   4911: ENDSCRIPT
                   4912: }
                   4913: 
1.118     jms      4914: sub print_helpsettings {
1.282     raeburn  4915:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4916:     my $confname = $dom.'-domainconfig';
1.285     raeburn  4917:     my $formname = 'display';
1.168     raeburn  4918:     my ($datatable,$itemcount);
1.282     raeburn  4919:     if ($position eq 'top') {
                   4920:         $itemcount = 1;
                   4921:         my (%choices,%defaultchecked,@toggles);
                   4922:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   4923:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   4924:                                      &mt('LON-CAPA bug tracker'),600,500));
                   4925:         %defaultchecked = ('submitbugs' => 'on');
                   4926:         @toggles = ('submitbugs');
                   4927:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4928:                                                      \%choices,$itemcount);
                   4929:         $$rowtotal ++;
                   4930:     } else {
                   4931:         my $css_class;
                   4932:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  4933:         my (%customroles,%ordered,%current);
1.301     raeburn  4934:         if (ref($settings) eq 'HASH') {
                   4935:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   4936:                 %current = %{$settings->{'adhoc'}};
                   4937:             }
1.285     raeburn  4938:         }
                   4939:         my $count = 0;
                   4940:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  4941:             if ($key=~/^rolesdef\_(\w+)$/) {
                   4942:                 my $rolename = $1;
1.285     raeburn  4943:                 my (%privs,$order);
1.282     raeburn  4944:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   4945:                 $customroles{$rolename} = \%privs;
1.285     raeburn  4946:                 if (ref($current{$rolename}) eq 'HASH') {
                   4947:                     $order = $current{$rolename}{'order'};
                   4948:                 }
                   4949:                 if ($order eq '') {
                   4950:                     $order = $count;
                   4951:                 }
                   4952:                 $ordered{$order} = $rolename;
                   4953:                 $count++;
                   4954:             }
                   4955:         }
                   4956:         my $maxnum = scalar(keys(%ordered));
                   4957:         my @roles_by_num = ();
                   4958:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   4959:             push(@roles_by_num,$item);
                   4960:         }
                   4961:         my $context = 'domprefs';
                   4962:         my $crstype = 'Course';
                   4963:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  4964:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  4965:         my ($numstatustypes,@jsarray);
                   4966:         if (ref($types) eq 'ARRAY') {
                   4967:             if (@{$types} > 0) {
                   4968:                 $numstatustypes = scalar(@{$types});
                   4969:                 push(@accesstypes,'status');
                   4970:                 @jsarray = ('bystatus');
1.282     raeburn  4971:             }
                   4972:         }
1.290     raeburn  4973:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  4974:         if (keys(%domhelpdesk)) {
                   4975:             push(@accesstypes,('inc','exc'));
                   4976:             push(@jsarray,('notinc','notexc'));
                   4977:         }
                   4978:         my $hiddenstr = join("','",@jsarray);
1.282     raeburn  4979:         my $context = 'domprefs';
                   4980:         my $crstype = 'Course';
1.285     raeburn  4981:         my $prefix = 'helproles_';
                   4982:         my $add_class = 'LC_hidden';
                   4983:         foreach my $num (@roles_by_num) {
                   4984:             my $role = $ordered{$num};
                   4985:             my ($desc,$access,@statuses);
                   4986:             if (ref($current{$role}) eq 'HASH') {
                   4987:                 $desc = $current{$role}{'desc'};
                   4988:                 $access = $current{$role}{'access'};
                   4989:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   4990:                     @statuses = @{$current{$role}{'insttypes'}};
                   4991:                 }
                   4992:             }
                   4993:             if ($desc eq '') {
                   4994:                 $desc = $role;
                   4995:             }
                   4996:             my $identifier = 'custhelp'.$num;
1.282     raeburn  4997:             my %full=();
                   4998:             my %levels= (
                   4999:                          course => {},
                   5000:                          domain => {},
                   5001:                          system => {},
                   5002:                         );
                   5003:             my %levelscurrent=(
                   5004:                                course => {},
                   5005:                                domain => {},
                   5006:                                system => {},
                   5007:                               );
                   5008:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   5009:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   5010:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  5011:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  5012:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  5013:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   5014:             for (my $k=0; $k<=$maxnum; $k++) {
                   5015:                 my $vpos = $k+1;
                   5016:                 my $selstr;
                   5017:                 if ($k == $num) {
                   5018:                     $selstr = ' selected="selected" ';
                   5019:                 }
                   5020:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5021:             }
                   5022:             $datatable .= '</select>'.('&nbsp;'x2).
                   5023:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   5024:                           '</td>'.
                   5025:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   5026:                           &mt('Name shown to users:').
                   5027:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   5028:                           '</fieldset>'.
                   5029:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   5030:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   5031:                           '<fieldset>'.
                   5032:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  5033:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  5034:                                                                    \%levelscurrent,$identifier,
                   5035:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   5036:                           '</fieldset></td>';
1.282     raeburn  5037:             $itemcount ++;
                   5038:         }
                   5039:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5040:         my $newcust = 'custhelp'.$count;
                   5041:         my (%privs,%levelscurrent);
                   5042:         my %full=();
                   5043:         my %levels= (
                   5044:                      course => {},
                   5045:                      domain => {},
                   5046:                      system => {},
                   5047:                     );
                   5048:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   5049:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  5050:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  5051:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  5052:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   5053:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   5054:         for (my $k=0; $k<$maxnum+1; $k++) {
                   5055:             my $vpos = $k+1;
                   5056:             my $selstr;
                   5057:             if ($k == $maxnum) {
                   5058:                 $selstr = ' selected="selected" ';
                   5059:             }
                   5060:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5061:         }
                   5062:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  5063:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   5064:                       '</label></span></td>'.
1.285     raeburn  5065:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   5066:                       '<span class="LC_nobreak">'.
                   5067:                       &mt('Internal name:').
                   5068:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   5069:                       '</span>'.('&nbsp;'x4).
                   5070:                       '<span class="LC_nobreak">'.
                   5071:                       &mt('Name shown to users:').
                   5072:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   5073:                       '</span></fieldset>'.
                   5074:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   5075:                                              $usertypes,$types,\%domhelpdesk).
                   5076:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  5077:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   5078:                                                                 \@templateroles,$newcust).
                   5079:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   5080:                                                                \%levelscurrent,$newcust).
1.334     raeburn  5081:                       '</fieldset>'.
                   5082:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   5083:                       '</td></tr>';
1.282     raeburn  5084:         $count ++;
                   5085:         $$rowtotal += $count;
                   5086:     }
1.166     raeburn  5087:     return $datatable;
1.121     raeburn  5088: }
                   5089: 
1.285     raeburn  5090: sub adhocbutton {
                   5091:     my ($prefix,$num,$field,$visibility) = @_;
                   5092:     my %lt = &Apache::lonlocal::texthash(
                   5093:                                           show => 'Show details',
                   5094:                                           hide => 'Hide details',
                   5095:                                         );
                   5096:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   5097:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   5098:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   5099:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   5100: }
                   5101: 
                   5102: sub helpsettings_javascript {
                   5103:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   5104:     return unless(ref($roles_by_num) eq 'ARRAY');
                   5105:     my %html_js_lt = &Apache::lonlocal::texthash(
                   5106:                                           show => 'Show details',
                   5107:                                           hide => 'Hide details',
                   5108:                                         );
                   5109:     &html_escape(\%html_js_lt);
                   5110:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   5111:     return <<"ENDSCRIPT";
                   5112: <script type="text/javascript">
                   5113: // <![CDATA[
                   5114: 
                   5115: function reorderHelpRoles(form,item) {
                   5116:     var changedVal;
                   5117: $jstext
                   5118:     var newpos = 'helproles_${total}_pos';
                   5119:     var maxh = 1 + $total;
                   5120:     var current = new Array();
                   5121:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   5122:     if (item == newpos) {
                   5123:         changedVal = newitemVal;
                   5124:     } else {
                   5125:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   5126:         current[newitemVal] = newpos;
                   5127:     }
                   5128:     for (var i=0; i<helproles.length; i++) {
                   5129:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   5130:         if (elementName != item) {
                   5131:             if (form.elements[elementName]) {
                   5132:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   5133:                 current[currVal] = elementName;
                   5134:             }
                   5135:         }
                   5136:     }
                   5137:     var oldVal;
                   5138:     for (var j=0; j<maxh; j++) {
                   5139:         if (current[j] == undefined) {
                   5140:             oldVal = j;
                   5141:         }
                   5142:     }
                   5143:     if (oldVal < changedVal) {
                   5144:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   5145:            var elementName = current[k];
                   5146:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   5147:         }
                   5148:     } else {
                   5149:         for (var k=changedVal; k<oldVal; k++) {
                   5150:             var elementName = current[k];
                   5151:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   5152:         }
                   5153:     }
                   5154:     return;
                   5155: }
                   5156: 
                   5157: function helpdeskAccess(num) {
                   5158:     var curraccess = null;
                   5159:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   5160:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   5161:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   5162:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   5163:             }
                   5164:         }
                   5165:     }
                   5166:     var shown = Array();
                   5167:     var hidden = Array();
                   5168:     if (curraccess == 'none') {
                   5169:         hidden = Array('$hiddenstr');
                   5170:     } else {
                   5171:         if (curraccess == 'status') {
                   5172:             shown = Array('bystatus');
                   5173:             hidden = Array('notinc','notexc');
                   5174:         } else {
                   5175:             if (curraccess == 'exc') {
                   5176:                 shown = Array('notexc');
                   5177:                 hidden = Array('notinc','bystatus');
                   5178:             }
                   5179:             if (curraccess == 'inc') {
                   5180:                 shown = Array('notinc');
                   5181:                 hidden = Array('notexc','bystatus');
                   5182:             }
1.293     raeburn  5183:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  5184:                 hidden = Array('notinc','notexc','bystatus');
                   5185:             }
                   5186:         }
                   5187:     }
                   5188:     if (hidden.length > 0) {
                   5189:         for (var i=0; i<hidden.length; i++) {
                   5190:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   5191:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   5192:             }
                   5193:         }
                   5194:     }
                   5195:     if (shown.length > 0) {
                   5196:         for (var i=0; i<shown.length; i++) {
                   5197:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   5198:                 if (shown[i] == 'privs') {
                   5199:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   5200:                 } else {
                   5201:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   5202:                 }
                   5203:             }
                   5204:         }
                   5205:     }
                   5206:     return;
                   5207: }
                   5208: 
                   5209: function toggleHelpdeskItem(num,field) {
                   5210:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   5211:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  5212:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  5213:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   5214:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5215:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   5216:             }
                   5217:         } else {
                   5218:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   5219:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5220:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   5221:             }
                   5222:         }
                   5223:     }
                   5224:     return;
                   5225: }
                   5226: 
                   5227: // ]]>
                   5228: </script>
                   5229: 
                   5230: ENDSCRIPT
                   5231: }
                   5232: 
                   5233: sub helpdeskroles_access {
                   5234:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   5235:         $usertypes,$types,$domhelpdesk) = @_;
                   5236:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   5237:     my %lt = &Apache::lonlocal::texthash(
                   5238:                     'rou'    => 'Role usage',
                   5239:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  5240:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   5241:                     'dh'     => 'All with domain helpdesk role',
                   5242:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  5243:                     'none'   => 'None',
                   5244:                     'status' => 'Determined based on institutional status',
                   5245:                     'inc'    => 'Include all, but exclude specific personnel',
                   5246:                     'exc'    => 'Exclude all, but include specific personnel',
                   5247:                   );
                   5248:     my %usecheck = (
                   5249:                      all => ' checked="checked"',
                   5250:                    );
                   5251:     my %displaydiv = (
                   5252:                       status => 'none',
                   5253:                       inc    => 'none',
                   5254:                       exc    => 'none',
                   5255:                       priv   => 'block',
                   5256:                      );
                   5257:     my $output;
                   5258:     if (ref($current) eq 'HASH') {
                   5259:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   5260:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   5261:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   5262:                 delete($usecheck{'all'});
                   5263:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   5264:                     my $access = $1;
                   5265:                     $displaydiv{$access} = 'inline';
                   5266:                 } elsif ($current->{access} eq 'none') {
                   5267:                     $displaydiv{'priv'} = 'none';
                   5268:                 }
                   5269:             }
                   5270:         }
                   5271:     }
                   5272:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   5273:               '<p>'.$lt{'whi'}.'</p>';
                   5274:     foreach my $access (@{$accesstypes}) {
                   5275:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   5276:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   5277:                    $lt{$access}.'</label>';
                   5278:         if ($access eq 'status') {
                   5279:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   5280:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   5281:                                                                  $othertitle,$usertypes,$types).
                   5282:                        '</div>';
                   5283:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   5284:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   5285:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5286:                        '</div>';
                   5287:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   5288:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   5289:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5290:                        '</div>';
                   5291:         }
                   5292:         $output .= '</p>';
                   5293:     }
                   5294:     $output .= '</fieldset>';
                   5295:     return $output;
                   5296: }
                   5297: 
1.121     raeburn  5298: sub radiobutton_prefs {
1.192     raeburn  5299:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385     raeburn  5300:         $additional,$align,$firstval) = @_;
1.121     raeburn  5301:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   5302:                    (ref($choices) eq 'HASH'));
                   5303: 
1.170     raeburn  5304:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  5305: 
                   5306:     foreach my $item (@{$toggles}) {
                   5307:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      5308:             $checkedon{$item} = ' checked="checked" ';
                   5309:             $checkedoff{$item} = ' ';
1.121     raeburn  5310:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      5311:             $checkedoff{$item} = ' checked="checked" ';
                   5312:             $checkedon{$item} = ' ';
                   5313:         }
                   5314:     }
                   5315:     if (ref($settings) eq 'HASH') {
1.121     raeburn  5316:         foreach my $item (@{$toggles}) {
1.118     jms      5317:             if ($settings->{$item} eq '1') {
                   5318:                 $checkedon{$item} =  ' checked="checked" ';
                   5319:                 $checkedoff{$item} = ' ';
                   5320:             } elsif ($settings->{$item} eq '0') {
                   5321:                 $checkedoff{$item} =  ' checked="checked" ';
                   5322:                 $checkedon{$item} = ' ';
                   5323:             }
                   5324:         }
1.121     raeburn  5325:     }
1.192     raeburn  5326:     if ($onclick) {
                   5327:         $onclick = ' onclick="'.$onclick.'"';
                   5328:     }
1.121     raeburn  5329:     foreach my $item (@{$toggles}) {
1.118     jms      5330:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  5331:         $datatable .=
1.306     raeburn  5332:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  5333:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  5334:             '</span></td>';
                   5335:         if ($align eq 'left') {
                   5336:             $datatable .= '<td class="LC_left_item">';
                   5337:         } else {
                   5338:             $datatable .= '<td class="LC_right_item">';
                   5339:         }
1.385     raeburn  5340:         $datatable .= '<span class="LC_nobreak">';
                   5341:         if ($firstval eq 'no') {
                   5342:             $datatable .=
                   5343:                 '<label><input type="radio" name="'.
                   5344:                 $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
                   5345:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5346:                 $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
                   5347:         } else {
                   5348:             $datatable .=
                   5349:                 '<label><input type="radio" name="'.
                   5350:                 $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
                   5351:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5352:                 $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
                   5353:         }
                   5354:         $datatable .= '</span>'.$additional.'</td></tr>';
1.118     jms      5355:         $itemcount ++;
1.121     raeburn  5356:     }
                   5357:     return ($datatable,$itemcount);
                   5358: }
                   5359: 
1.267     raeburn  5360: sub print_ltitools {
1.421     raeburn  5361:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5362:     my (%rules,%encrypt,%privkeys,%linkprot);
1.267     raeburn  5363:     if (ref($settings) eq 'HASH') {
1.421     raeburn  5364:         if ($position eq 'top') {
                   5365:             if (exists($settings->{'encrypt'})) {
                   5366:                 if (ref($settings->{'encrypt'}) eq 'HASH') {
                   5367:                     foreach my $key (keys(%{$settings->{'encrypt'}})) {
                   5368:                         $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324     raeburn  5369:                     }
                   5370:                 }
1.267     raeburn  5371:             }
1.421     raeburn  5372:             if (exists($settings->{'private'})) {
                   5373:                 if (ref($settings->{'private'}) eq 'HASH') {
                   5374:                     if (ref($settings->{'private'}) eq 'HASH') {
                   5375:                         if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
                   5376:                             map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267     raeburn  5377:                         }
                   5378:                     }
                   5379:                 }
                   5380:             }
1.421     raeburn  5381:         } elsif ($position eq 'middle') {
                   5382:             if (exists($settings->{'rules'})) {
                   5383:                 if (ref($settings->{'rules'}) eq 'HASH') {
                   5384:                     %rules = %{$settings->{'rules'}};
1.273     raeburn  5385:                 }
                   5386:             }
1.421     raeburn  5387:         } else {
                   5388:             foreach my $key ('encrypt','private','rules') {
                   5389:                 if (exists($settings->{$key})) {
                   5390:                     delete($settings->{$key});
1.267     raeburn  5391:                 }
                   5392:             }
                   5393:         }
                   5394:     }
1.421     raeburn  5395:     my $datatable;
                   5396:     my $itemcount = 1;
                   5397:     if ($position eq 'top') {
                   5398:         $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
                   5399:     } elsif ($position eq 'middle') {
                   5400:         $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
                   5401:         $$rowtotal += $itemcount;
                   5402:     } else {
                   5403:         $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267     raeburn  5404:     }
                   5405:     return $datatable;
                   5406: }
                   5407: 
                   5408: sub ltitools_names {
                   5409:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  5410:                                           'title'          => 'Title',
                   5411:                                           'version'        => 'Version',
                   5412:                                           'msgtype'        => 'Message Type',
1.323     raeburn  5413:                                           'sigmethod'      => 'Signature Method',
1.296     raeburn  5414:                                           'url'            => 'URL',
                   5415:                                           'key'            => 'Key',
1.322     raeburn  5416:                                           'lifetime'       => 'Nonce lifetime (s)',
1.296     raeburn  5417:                                           'secret'         => 'Secret',
1.425     raeburn  5418:                                           'icon'           => 'Icon',
1.324     raeburn  5419:                                           'user'           => 'User',
1.296     raeburn  5420:                                           'fullname'       => 'Full Name',
                   5421:                                           'firstname'      => 'First Name',
                   5422:                                           'lastname'       => 'Last Name',
                   5423:                                           'email'          => 'E-mail',
                   5424:                                           'roles'          => 'Role',
1.298     raeburn  5425:                                           'window'         => 'Window',
                   5426:                                           'tab'            => 'Tab',
1.296     raeburn  5427:                                           'iframe'         => 'iFrame',
                   5428:                                           'height'         => 'Height',
                   5429:                                           'width'          => 'Width',
                   5430:                                           'linktext'       => 'Default Link Text',
                   5431:                                           'explanation'    => 'Default Explanation',
                   5432:                                           'passback'       => 'Tool can return grades:',
                   5433:                                           'roster'         => 'Tool can retrieve roster:',
                   5434:                                           'crstarget'      => 'Display target',
                   5435:                                           'crslabel'       => 'Course label',
1.425     raeburn  5436:                                           'crstitle'       => 'Course title',
1.296     raeburn  5437:                                           'crslinktext'    => 'Link Text',
                   5438:                                           'crsexplanation' => 'Explanation',
1.318     raeburn  5439:                                           'crsappend'      => 'Provider URL',
1.267     raeburn  5440:                                         );
                   5441:     return %lt;
                   5442: }
                   5443: 
1.421     raeburn  5444: sub secrets_form {
                   5445:     my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
                   5446:     my @ids=&Apache::lonnet::current_machine_ids();
                   5447:     my %servers = &Apache::lonnet::get_servers($dom,'library');
                   5448:     my $primary = &Apache::lonnet::domain($dom,'primary');
                   5449:     my ($css_class,$extra,$numshown,$itemcount,$output);
                   5450:     $itemcount = 0;
                   5451:     foreach my $hostid (sort(keys(%servers))) {
                   5452:         my ($showextra,$divsty,$switch);
                   5453:         if ($hostid eq $primary) {
                   5454:             if ($context eq 'ltisec') {
                   5455:                 if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
                   5456:                     $showextra = 1;
                   5457:                 }
                   5458:                 if ($encrypt->{'ltisec_crslinkprot'}) {
                   5459:                     $showextra = 1;
                   5460:                 }
                   5461:             } else {
                   5462:                 if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
                   5463:                     $showextra = 1;
                   5464:                 }
                   5465:             }
                   5466:             unless (grep(/^\Q$hostid\E$/,@ids)) {
                   5467:                 $switch = 1;
                   5468:             }
                   5469:             if ($showextra) {
                   5470:                 $numshown ++;
                   5471:                 $divsty = 'display:inline-block';
                   5472:             } else {
                   5473:                 $divsty = 'display:none';
                   5474:             }
                   5475:             $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
                   5476:                       '<legend>'.$hostid.'</legend>';
                   5477:             if ($switch) {
                   5478:                 my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&amp;role='.
                   5479:                                    &HTML::Entities::encode($env{'request.role'},'\'<>"&').
                   5480:                                    '&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
                   5481:                 if (exists($privkeys->{$hostid})) {
                   5482:                     $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
                   5483:                               '<span class="LC_nobreak">'.
                   5484:                               &mt('Encryption Key').': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   5485:                               '<span class="LC_nobreak">'.&mt('Change?').
                   5486:                               '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
                   5487:                               ('&nbsp;'x2).
                   5488:                               '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
                   5489:                               '</label>&nbsp;&nbsp;</span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
                   5490:                               '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
                   5491:                               '</span></div>';
                   5492:                 } else {
                   5493:                     $extra .= '<span class="LC_nobreak">'.
                   5494:                               &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
                   5495:                               '</span>'."\n";
                   5496:                 }
                   5497:             } elsif (exists($privkeys->{$hostid})) {
                   5498:                 $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
                   5499:                           &mt('Encryption Key').': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   5500:                           '<span class="LC_nobreak">'.&mt('Change?').
                   5501:                           '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
                   5502:                           ('&nbsp;'x2).
                   5503:                           '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
                   5504:                           '</label>&nbsp;&nbsp;</span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
                   5505:                           '<span class="LC_nobreak">'.&mt('New Key').':'.
                   5506:                           '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
                   5507:                           '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
                   5508:                           '</span></div>';
                   5509:             } else {
                   5510:                 $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
                   5511:                           '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
                   5512:                           '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
                   5513:             }
                   5514:             $extra .= '</fieldset>';
                   5515:         }
                   5516:     }
                   5517:     my (%choices,@toggles,%defaultchecked);
                   5518:     if ($context eq 'ltisec') {
                   5519:         %choices = &Apache::lonlocal::texthash (
                   5520:                                                   ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
                   5521:                                                   ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
                   5522:                                                   ltisec_consumers   => 'Encrypt stored consumer secrets defined in domain',
                   5523:                                                );
                   5524:         @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
                   5525:         %defaultchecked = (
                   5526:                            'ltisec_crslinkprot' => 'off',
                   5527:                            'ltisec_domlinkprot' => 'off',
                   5528:                            'ltisec_consumers'   => 'off',
                   5529:                           );
                   5530:     } else {
                   5531:         %choices = &Apache::lonlocal::texthash (
                   5532:                                                   toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
                   5533:                                                   toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
                   5534:                                                );
                   5535:         @toggles = qw(toolsec_crs toolsec_dom);
                   5536:         %defaultchecked = (
                   5537:                            'toolsec_crs' => 'off',
                   5538:                            'toolsec_dom' => 'off',
                   5539:                           );
                   5540:     }
                   5541:     my ($onclick,$itemcount);
                   5542:     $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
                   5543:     ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
                   5544:                                               \%choices,$itemcount,$onclick,'','left','no');
                   5545: 
                   5546:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5547:     my $noprivkeysty = 'display:inline-block';
                   5548:     if ($numshown) {
                   5549:         $noprivkeysty = 'display:none';
                   5550:     }
                   5551:     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
                   5552:                '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
                   5553:                '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
                   5554:                $extra.
                   5555:                '</td></tr>';
                   5556:     $itemcount ++;
                   5557:     $$rowtotal += $itemcount;
                   5558:     return $output;
                   5559: }
                   5560: 
1.372     raeburn  5561: sub print_proctoring {
                   5562:     my ($dom,$settings,$rowtotal) = @_;
                   5563:     my $itemcount = 1;
                   5564:     my (%ordered,%providernames,%current,%currentdef);
                   5565:     my $confname = $dom.'-domainconfig';
                   5566:     my $switchserver = &check_switchserver($dom,$confname);
                   5567:     if (ref($settings) eq 'HASH') {
                   5568:         foreach my $item (keys(%{$settings})) {
                   5569:             if (ref($settings->{$item}) eq 'HASH') {
                   5570:                 my $num = $settings->{$item}{'order'};
                   5571:                 $ordered{$num} = $item;
                   5572:             }
                   5573:         }
                   5574:     } else {
                   5575:         %ordered = (
                   5576:                      1 => 'proctorio',
                   5577:                      2 => 'examity',
                   5578:                    );
                   5579:     }
                   5580:     %providernames = &proctoring_providernames();
                   5581:     my $maxnum = scalar(keys(%ordered));
                   5582:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   5583:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   5584:     if (ref($requref) eq 'HASH') {
                   5585:         %requserfields = %{$requref};
                   5586:     }
                   5587:     if (ref($opturef) eq 'HASH') {
                   5588:         %optuserfields = %{$opturef};
                   5589:     }
                   5590:     if (ref($defref) eq 'HASH') {
                   5591:         %defaults = %{$defref};
                   5592:     }
                   5593:     if (ref($extref) eq 'HASH') {
                   5594:         %extended = %{$extref};
                   5595:     }
                   5596:     if (ref($crsref) eq 'HASH') {
                   5597:         %crsconf = %{$crsref};
                   5598:     }
                   5599:     if (ref($rolesref) eq 'ARRAY') {
                   5600:         @courseroles = @{$rolesref};
                   5601:     }
                   5602:     if (ref($ltiref) eq 'ARRAY') {
                   5603:         @ltiroles = @{$ltiref};
                   5604:     }
                   5605:     my $datatable;
                   5606:     my $css_class;
                   5607:     if (keys(%ordered)) {
                   5608:         my @items = sort { $a <=> $b } keys(%ordered);
                   5609:         for (my $i=0; $i<@items; $i++) {
                   5610:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5611:             my $provider = $ordered{$items[$i]};
                   5612:             my $optionsty = 'none';
                   5613:             my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
                   5614:                 %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
                   5615:             if (ref($settings) eq 'HASH') {
                   5616:                 if (ref($settings->{$provider}) eq 'HASH') {
                   5617:                     %current = %{$settings->{$provider}};
                   5618:                     if ($current{'available'}) {
                   5619:                         $optionsty = 'block';
                   5620:                         $available = 1;
                   5621:                     }
                   5622:                     if ($current{'lifetime'} =~ /^\d+$/) {
                   5623:                         $lifetime = $current{'lifetime'};
                   5624:                     }
                   5625:                     if ($current{'version'} =~ /^\d+\.\d+$/) {
                   5626:                         $version = $current{'version'};
                   5627:                     }
                   5628:                     if ($current{'image'} ne '') {
                   5629:                         $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
                   5630:                     }
                   5631:                     if (ref($current{'fields'}) eq 'ARRAY') {
                   5632:                         map { $checkedfields{$_} = 1; } @{$current{'fields'}};
                   5633:                     }
                   5634:                     $userincdom = $current{'incdom'};
                   5635:                     if (ref($current{'roles'}) eq 'HASH') {
                   5636:                         %rolemaps = %{$current{'roles'}};
                   5637:                         $checkedfields{'roles'} = 1;
                   5638:                     }
                   5639:                     if (ref($current{'defaults'}) eq 'ARRAY') {
                   5640:                         foreach my $val (@{$current{'defaults'}}) {
                   5641:                             if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
                   5642:                                 $inuse{$val} = 1;
                   5643:                             } else {
                   5644:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5645:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5646:                                         if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
                   5647:                                             $inuse{$poss} = $val;
                   5648:                                             last;
                   5649:                                         }
                   5650:                                     }
                   5651:                                 }
                   5652:                             }
                   5653:                         }
                   5654:                     } elsif (ref($current{'defaults'}) eq 'HASH') {
                   5655:                         foreach my $key (keys(%{$current{'defaults'}})) {
                   5656:                             my $currval = $current{'defaults'}{$key}; 
                   5657:                             if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
                   5658:                                 $inuse{$key} = 1;
                   5659:                             } else {
                   5660:                                 my $match;
                   5661:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5662:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5663:                                         if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
                   5664:                                             $inuse{$poss} = $key;
                   5665:                                             last;
                   5666:                                         }
                   5667:                                     } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
                   5668:                                         foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
                   5669:                                             if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
                   5670:                                                 if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
                   5671:                                                     $currentdef{$inner} = $currval;
                   5672:                                                     $match = 1;
                   5673:                                                     last;
                   5674:                                                 }
                   5675:                                             } elsif ($inner eq $key) {
                   5676:                                                 $currentdef{$key} = $currval;
                   5677:                                                 $match = 1;
                   5678:                                                 last;
                   5679:                                             }
                   5680:                                         }
                   5681:                                     }
                   5682:                                     last if ($match);
                   5683:                                 }
                   5684:                             }
                   5685:                         }
                   5686:                     }
                   5687:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   5688:                         map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
                   5689:                     }
                   5690:                 }
                   5691:             }
                   5692:             my %lt = &proctoring_titles($provider);
                   5693:             my %fieldtitles = &proctoring_fieldtitles($provider);
                   5694:             my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
                   5695:             my %checkedavailable = (
                   5696:                                    yes => '',
                   5697:                                    no  => ' checked="checked"',
                   5698:                                  );
                   5699:             if ($available) {
                   5700:                 $checkedavailable{'yes'} = $checkedavailable{'no'};
                   5701:                 $checkedavailable{'no'} = '';
                   5702:             }
                   5703:             my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
                   5704:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5705:                          .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
                   5706:             for (my $k=0; $k<$maxnum; $k++) {
                   5707:                 my $vpos = $k+1;
                   5708:                 my $selstr;
                   5709:                 if ($k == $i) {
                   5710:                     $selstr = ' selected="selected" ';
                   5711:                 }
                   5712:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5713:             }
                   5714:             if ($version eq '') {
                   5715:                 if ($provider eq 'proctorio') {
                   5716:                     $version = '1.0';
                   5717:                 } elsif ($provider eq 'examity') {
                   5718:                     $version = '1.1';
                   5719:                 }
                   5720:             }
                   5721:             if ($lifetime eq '') {
                   5722:                 $lifetime = '300';
                   5723:             }
                   5724:             $datatable .=
                   5725:                 '</select>'.('&nbsp;'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
                   5726:                 '<span class="LC_nobreak">'.$lt{'avai'}.'&nbsp;'.
                   5727:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   5728:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
                   5729:                 '</td>'.
                   5730:                 '<td colspan="2">'.
                   5731:                 '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
                   5732:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
                   5733:                 '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
                   5734:                 ('&nbsp;'x2).
                   5735:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
                   5736:                 '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5737:                 '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
                   5738:                 ('&nbsp;'x2).
                   5739:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
                   5740:                 '<br />'.
                   5741:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
                   5742:                 '<br />'.
                   5743:                 '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
                   5744:                 ('&nbsp;'x2).
                   5745:                 '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
                   5746:                 '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
                   5747:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   5748:             if ($imgsrc) {
                   5749:                 $datatable .= $imgsrc.
                   5750:                               '<label><input type="checkbox" name="proctoring_image_del"'.
                   5751:                               ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
                   5752:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:');
                   5753:             }
                   5754:             $datatable .= '&nbsp;';
                   5755:             if ($switchserver) {
                   5756:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5757:             } else {
                   5758:                 $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
                   5759:             }
                   5760:             unless ($imgsrc) {
                   5761:                 $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
                   5762:             }
                   5763:             $datatable .= '</fieldset>'."\n";
                   5764:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   5765:                 if (@{$requserfields{$provider}} > 0) {
                   5766:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
                   5767:                     foreach my $field (@{$requserfields{$provider}}) {
                   5768:                         $datatable .= '<span class="LC_nobreak">'.
                   5769:                                       '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
                   5770:                                       $lt{$field}.'</label>';
                   5771:                         if ($field eq 'user') {
                   5772:                             my $seluserdom = '';
                   5773:                             my $unseluserdom = ' selected="selected"';
                   5774:                             if ($userincdom) {
                   5775:                                 $seluserdom = $unseluserdom;
                   5776:                                 $unseluserdom = '';
                   5777:                             }
                   5778:                             $datatable .= ':&nbsp;'.
                   5779:                                 '<select name="proctoring_userincdom_'.$provider.'">'.
                   5780:                                 '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
                   5781:                                 '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
                   5782:                                 '</select>&nbsp;';
                   5783:                         } else {
                   5784:                             $datatable .= '&nbsp;';
                   5785:                             if ($field eq 'roles') {
                   5786:                                 $showroles = 1; 
                   5787:                             } 
                   5788:                         }
                   5789:                         $datatable .= '</span> ';
                   5790:                     }
                   5791:                 }
                   5792:                 $datatable .= '</fieldset>'."\n";
                   5793:             }
                   5794:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   5795:                 if (@{$optuserfields{$provider}} > 0) {
                   5796:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>'; 
                   5797:                     foreach my $field (@{$optuserfields{$provider}}) {
                   5798:                         my $checked;
                   5799:                         if ($checkedfields{$field}) {
                   5800:                             $checked = ' checked="checked"';
                   5801:                         }
                   5802:                         $datatable .= '<span class="LC_nobreak">'.
                   5803:                                       '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span>&nbsp; ';
                   5804:                     }
                   5805:                     $datatable .= '</fieldset>'."\n";
                   5806:                 }
                   5807:             }
                   5808:             if (ref($defaults{$provider}) eq 'ARRAY') {
                   5809:                 if (@{$defaults{$provider}}) {
                   5810:                     my (%options,@selectboxes);
                   5811:                     if (ref($extended{$provider}) eq 'HASH') {
                   5812:                         %options = %{$extended{$provider}};
                   5813:                     }
                   5814:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
                   5815:                     my ($rem,$numinrow,$dropdowns);
                   5816:                     if ($provider eq 'proctorio') { 
                   5817:                         $datatable .= '<table>';
                   5818:                         $numinrow = 4;
                   5819:                     }
                   5820:                     my $i = 0;
                   5821:                     foreach my $field (@{$defaults{$provider}}) {
                   5822:                         my $checked;
                   5823:                         if ($inuse{$field}) {
                   5824:                             $checked = ' checked="checked"';
                   5825:                         }
                   5826:                         if ($provider eq 'examity') {
                   5827:                             if ($field eq 'display') {
                   5828:                                 $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
                   5829:                                 foreach my $option ('iframe','tab','window') {
                   5830:                                     my $checkdisp;
                   5831:                                     if ($currentdef{'target'} eq $option) {
                   5832:                                         $checkdisp = ' checked="checked"';
                   5833:                                     }
                   5834:                                     $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
                   5835:                                     $fieldtitles{$option}.'</label>'.('&nbsp;'x2);
                   5836:                                 }
                   5837:                                 $datatable .= ('&nbsp;'x4);
                   5838:                                 foreach my $dimen ('width','height') {
                   5839:                                     $datatable .= '<label>'.$fieldtitles{$dimen}.'&nbsp;'.
                   5840:                                                   '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
                   5841:                                                   'value="'.$currentdef{$dimen}.'" /></label>'.
                   5842:                                                   ('&nbsp;'x2);
                   5843:                                 }
                   5844:                                 $datatable .= '</span><br />'.
                   5845:                                               '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
                   5846:                                               '<input type="text" name="proctoring_linktext_'.$provider.'" '.
                   5847:                                               'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
                   5848:                                               '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
                   5849:                                               '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
                   5850:                                               $currentdef{'explanation'}.
                   5851:                                               '</textarea></div><div style=""></div><br />';
                   5852:                             }
                   5853:                         } else {
                   5854:                             if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   5855:                                 my ($output,$selnone);
                   5856:                                 unless ($checked) {
                   5857:                                     $selnone = ' selected="selected"';
                   5858:                                 }
                   5859:                                 $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
                   5860:                                            '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
                   5861:                                            '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>'; 
                   5862:                                 foreach my $option (@{$options{$field}}) {
                   5863:                                     my $sel; 
                   5864:                                     if ($inuse{$field} eq $option) {
                   5865:                                         $sel = ' selected="selected"';
                   5866:                                     }
                   5867:                                     $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
                   5868:                                 }
                   5869:                                 $output .= '</select></span>';
                   5870:                                 push(@selectboxes,$output);
                   5871:                             } else {
                   5872:                                 $rem = $i%($numinrow);
                   5873:                                 if ($rem == 0) {
                   5874:                                     if ($i > 0) {
                   5875:                                         $datatable .= '</tr>';
                   5876:                                     }
                   5877:                                     $datatable .= '<tr>';
                   5878:                                 }
                   5879:                                 $datatable .= '<td class="LC_left_item">'.
                   5880:                                               '<span class="LC_nobreak">'.
                   5881:                                               '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
                   5882:                                               $fieldtitles{$field}.'</label></span></td>';
                   5883:                                 $i++;
                   5884:                             }
                   5885:                         }
                   5886:                     }
                   5887:                     if ($provider eq 'proctorio') {
                   5888:                         if ($numinrow) {
                   5889:                             $rem = $i%$numinrow;
                   5890:                         }
                   5891:                         my $colsleft = $numinrow - $rem;
                   5892:                         if ($colsleft > 1) {
                   5893:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   5894:                         } else {
                   5895:                             $datatable .= '<td class="LC_left_item">';
                   5896:                         }
                   5897:                         $datatable .= '&nbsp;'.
                   5898:                                       '</td></tr></table>';
                   5899:                         if (@selectboxes) {
                   5900:                             $datatable .= '<hr /><table>';
                   5901:                             $numinrow = 2;
                   5902:                             for (my $i=0; $i<@selectboxes; $i++) {
                   5903:                                 $rem = $i%($numinrow);
                   5904:                                 if ($rem == 0) {
                   5905:                                     if ($i > 0) {
                   5906:                                         $datatable .= '</tr>';
                   5907:                                     }
                   5908:                                     $datatable .= '<tr>';
                   5909:                                 }
                   5910:                                 $datatable .= '<td class="LC_left_item">'.
                   5911:                                               $selectboxes[$i].'</td>';
                   5912:                             }
                   5913:                             if ($numinrow) {
                   5914:                                 $rem = $i%$numinrow;
                   5915:                             }
                   5916:                             $colsleft = $numinrow - $rem;
                   5917:                             if ($colsleft > 1) {
                   5918:                                 $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   5919:                             } else {
                   5920:                                 $datatable .= '<td class="LC_left_item">';
                   5921:                             }
                   5922:                             $datatable .= '&nbsp;'.
                   5923:                                           '</td></tr></table>';
                   5924:                         }
                   5925:                     }
                   5926:                     $datatable .= '</fieldset>';
                   5927:                 }
                   5928:                 if (ref($crsconf{$provider}) eq 'ARRAY') {
                   5929:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   5930:                                   '<legend>'.&mt('Configurable in course').'</legend>';
                   5931:                     my ($rem,$numinrow);
                   5932:                     if ($provider eq 'proctorio') {
                   5933:                         $datatable .= '<table>';
                   5934:                         $numinrow = 4;
                   5935:                     }
                   5936:                     my $i = 0;
                   5937:                     foreach my $item (@{$crsconf{$provider}}) {
                   5938:                         my $name;
                   5939:                         if ($provider eq 'examity') {
                   5940:                             $name = $lt{'crs'.$item};
                   5941:                         } elsif ($provider eq 'proctorio') {
                   5942:                             $name = $fieldtitles{$item};
                   5943:                             $rem = $i%($numinrow);
                   5944:                             if ($rem == 0) {
                   5945:                                 if ($i > 0) {
                   5946:                                     $datatable .= '</tr>';
                   5947:                                 }
                   5948:                                 $datatable .= '<tr>';
                   5949:                             }
                   5950:                             $datatable .= '<td class="LC_left_item>';
                   5951:                         }
                   5952:                         my $checked;
                   5953:                         if ($crsconfig{$item}) {
                   5954:                             $checked = ' checked="checked"';
                   5955:                         }
                   5956:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   5957:                                       '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
                   5958:                                       $name.'</label></span>';
                   5959:                         if ($provider eq 'examity') {
                   5960:                             $datatable .= '&nbsp; ';
                   5961:                         }
                   5962:                         $datatable .= "\n";
                   5963:                         $i++;
                   5964:                     }
                   5965:                     if ($provider eq 'proctorio') {
                   5966:                         if ($numinrow) {
                   5967:                             $rem = $i%$numinrow;
                   5968:                         }
                   5969:                         my $colsleft = $numinrow - $rem;
                   5970:                         if ($colsleft > 1) {
                   5971:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   5972:                         } else {
                   5973:                             $datatable .= '<td class="LC_left_item">';
                   5974:                         }
                   5975:                         $datatable .= '&nbsp;'.
                   5976:                                       '</td></tr></table>';
                   5977:                     }
                   5978:                     $datatable .= '</fieldset>';
                   5979:                 }
                   5980:                 if ($showroles) {
                   5981:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   5982:                                   '<legend>'.&mt('Role mapping').'</legend><table><tr>';
                   5983:                     foreach my $role (@courseroles) {
                   5984:                         my ($selected,$selectnone);
                   5985:                         if (!$rolemaps{$role}) {
                   5986:                             $selectnone = ' selected="selected"';
                   5987:                         }
                   5988:                         $datatable .= '<td style="text-align: center">'.
                   5989:                                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5990:                                       '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
                   5991:                                       '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5992:                         foreach my $ltirole (@ltiroles) {
                   5993:                             unless ($selectnone) {
                   5994:                                 if ($rolemaps{$role} eq $ltirole) {
                   5995:                                     $selected = ' selected="selected"';
                   5996:                                 } else {
                   5997:                                     $selected = '';
                   5998:                                 }
                   5999:                             }
                   6000:                             $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   6001:                         }
                   6002:                         $datatable .= '</select></td>';
                   6003:                     }
                   6004:                     $datatable .= '</tr></table></fieldset>'.
                   6005:                                   '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6006:                                   '<legend>'.&mt('Custom items sent on launch').'</legend>'.
                   6007:                                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   6008:                                   '<tr><td></td><td>lms</td>'.
                   6009:                                   '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
                   6010:                                   ' value="Loncapa" disabled="disabled"/></td></tr>';
                   6011:                     if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
                   6012:                         (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
                   6013:                         my %custom = %{$settings->{$provider}->{'custom'}};
                   6014:                         if (keys(%custom) > 0) {
                   6015:                             foreach my $key (sort(keys(%custom))) {
                   6016:                                 next if ($key eq 'lms');
                   6017:                                 $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6018:                                               '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
                   6019:                                               $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   6020:                                               '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
                   6021:                                               ' value="'.$custom{$key}.'" /></td></tr>';
                   6022:                             }
                   6023:                         }
                   6024:                     }
                   6025:                     $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6026:                                   '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
                   6027:                                   &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
                   6028:                                   '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
                   6029:                                   '</table></fieldset></td></tr>'."\n";
                   6030:                 }
                   6031:                 $datatable .= '</td></tr>';
                   6032:             }
                   6033:             $itemcount ++;
                   6034:         }
                   6035:     }
                   6036:     return $datatable;
                   6037: }
                   6038: 
                   6039: sub proctoring_data {
                   6040:     my $requserfields = {
                   6041:                       proctorio => ['user'],
                   6042:                       examity   => ['roles','user'],
                   6043:                      };
                   6044:     my $optuserfields = {
                   6045:                         proctorio => ['fullname'],
                   6046:                         examity   => ['fullname','firstname','lastname','email'],
                   6047:                      };
                   6048:     my $defaults = {
                   6049:                   proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6050:                                 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6051:                                 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6052:                                 'closetabs','onescreen','print','downloads','cache','rightclick',
                   6053:                                 'reentry','calculator','whiteboard'],
                   6054:                   examity   => ['display'],
                   6055:                 };
                   6056:     my $extended = { 
                   6057:                   proctorio => {
                   6058:                                  verifyid => ['verifyidauto','verifyidlive'],
                   6059:                                  fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
                   6060:                                  tabslinks => ['notabs','linksonly'],
                   6061:                                  reentry => ['noreentry','agentreentry'],
                   6062:                                  calculator => ['calculatorbasic','calculatorsci'],
                   6063:                                },
                   6064:                   examity => {
                   6065:                                display => {
                   6066:                                            target      => ['iframe','tab','window'],
                   6067:                                            width       => '',
                   6068:                                            height      => '',
                   6069:                                            linktext    => '',
                   6070:                                            explanation => '',
                   6071:                                           },
                   6072:                              },
                   6073:                 };
                   6074:     my $crsconf = {
                   6075:                  proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6076:                                'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6077:                                'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6078:                                'closetabs','onescreen','print','downloads','cache','rightclick',
                   6079:                                'reentry','calculator','whiteboard'],
                   6080:                  examity => ['label','title','target','linktext','explanation','append'],
                   6081:                };
                   6082:     my $courseroles = ['cc','in','ta','ep','st'];
                   6083:     my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
                   6084:     return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
                   6085: }
                   6086: 
                   6087: sub proctoring_titles {
                   6088:     my ($item) = @_;
                   6089:     my (%common_lt,%custom_lt);
                   6090:     %common_lt = &Apache::lonlocal::texthash (
                   6091:                      'avai'      => 'Available?',
                   6092:                      'base'      => 'Basic Settings',
                   6093:                      'requ'      => 'User data required to be sent on launch',
                   6094:                      'optu'      => 'User data optionally sent on launch',
                   6095:                      'udsl'      => 'User data sent on launch',
                   6096:                      'defa'      => 'Defaults for items configurable in course',
                   6097:                      'sigmethod' => 'Signature Method',
                   6098:                      'key'       => 'Key',
                   6099:                      'lifetime'  => 'Nonce lifetime (s)',
                   6100:                      'secret'    => 'Secret',
                   6101:                      'icon'      => 'Icon',
                   6102:                      'fullname'  => 'Full Name',
                   6103:                      'visible'   => 'Visible input',
                   6104:                      'username'  => 'username',
                   6105:                      'user'      => 'User',
                   6106:                  );
                   6107:     if ($item eq 'proctorio') {
                   6108:         %custom_lt = &Apache::lonlocal::texthash (
                   6109:                          'version'        => 'OAuth version',
                   6110:                          'url'            => 'API URL',
                   6111:                          'uname:dom'      => 'username-domain',
                   6112:         );
                   6113:     } elsif ($item eq 'examity') {
                   6114:         %custom_lt = &Apache::lonlocal::texthash (
                   6115:                          'version'        => 'LTI Version',
                   6116:                          'url'            => 'URL',
                   6117:                          'uname:dom'      => 'username:domain',
                   6118:                          'msgtype'        => 'Message Type',
                   6119:                          'firstname'      => 'First Name',
                   6120:                          'lastname'       => 'Last Name',
                   6121:                          'email'          => 'E-mail',
                   6122:                          'roles'          => 'Role',
                   6123:                          'crstarget'      => 'Display target',
                   6124:                          'crslabel'       => 'Course label',
                   6125:                          'crstitle'       => 'Course title', 
                   6126:                          'crslinktext'    => 'Link Text',
                   6127:                          'crsexplanation' => 'Explanation',
                   6128:                          'crsappend'      => 'Provider URL',
                   6129:         );
                   6130:     }
                   6131:     my %lt = (%common_lt,%custom_lt);
                   6132:     return %lt;
                   6133: }
                   6134: 
                   6135: sub proctoring_fieldtitles {
                   6136:     my ($item) = @_;
                   6137:     if ($item eq 'proctorio') {
                   6138:         return &Apache::lonlocal::texthash (
                   6139:                   'recordvideo' => 'Record video',
                   6140:                   'recordaudio' => 'Record audio',
                   6141:                   'recordscreen' => 'Record screen',
                   6142:                   'recordwebtraffic' => 'Record web traffic',
                   6143:                   'recordroomstart' => 'Record room scan',
                   6144:                   'verifyvideo' => 'Verify webcam',
                   6145:                   'verifyaudio' => 'Verify microphone',
                   6146:                   'verifydesktop' => 'Verify desktop recording',
                   6147:                   'verifyid' => 'Photo ID verification',
                   6148:                   'verifysignature' => 'Require signature',
                   6149:                   'fullscreen' => 'Fullscreen',
                   6150:                   'clipboard' => 'Disable copy/paste',
                   6151:                   'tabslinks' => 'New tabs/windows',
                   6152:                   'closetabs' => 'Close other tabs',
                   6153:                   'onescreen' => 'Limit to single screen',
                   6154:                   'print' => 'Disable Printing',
                   6155:                   'downloads' => 'Disable Downloads',
                   6156:                   'cache' => 'Empty cache after exam',
                   6157:                   'rightclick' => 'Disable right click',
                   6158:                   'reentry' => 'Re-entry to exam',
                   6159:                   'calculator' => 'Onscreen calculator',
                   6160:                   'whiteboard' => 'Onscreen whiteboard',
                   6161:                   'verifyidauto' => 'Automated verification',
                   6162:                   'verifyidlive' => 'Live agent verification',
                   6163:                   'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
                   6164:                   'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
                   6165:                   'fullscreensever' => 'Forced, navigation away ends exam',
                   6166:                   'notabs' => 'Disaallowed',
                   6167:                   'linksonly' => 'Allowed from links in exam',
                   6168:                   'noreentry' => 'Disallowed',
                   6169:                   'agentreentry' => 'Agent required for re-entry',
                   6170:                   'calculatorbasic' => 'Basic',
                   6171:                   'calculatorsci' => 'Scientific',
                   6172:         );
                   6173:     } elsif ($item eq 'examity') {
                   6174:         return &Apache::lonlocal::texthash (
                   6175:                 'target'         => 'Display target',   
                   6176:                 'window'         => 'Window',
                   6177:                 'tab'            => 'Tab',
                   6178:                 'iframe'         => 'iFrame',
                   6179:                 'height'         => 'Height (pixels)',
                   6180:                 'width'          => 'Width (pixels)',
                   6181:                 'linktext'       => 'Default Link Text',
                   6182:                 'explanation'    => 'Default Explanation',
                   6183:                 'append'         => 'Provider URL',
                   6184:         );
                   6185:     }
                   6186: }
                   6187: 
                   6188: sub proctoring_providernames {
                   6189:     return (
                   6190:              proctorio => 'Proctorio',
                   6191:              examity   => 'Examity',
                   6192:            );
                   6193: }
                   6194: 
1.320     raeburn  6195: sub print_lti {
1.405     raeburn  6196:     my ($position,$dom,$settings,$rowtotal) = @_;
1.320     raeburn  6197:     my $itemcount = 1;
1.405     raeburn  6198:     my ($datatable,$css_class);
1.434     raeburn  6199:     my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320     raeburn  6200:     if (ref($settings) eq 'HASH') {
1.405     raeburn  6201:         if ($position eq 'top') {
                   6202:             if (exists($settings->{'encrypt'})) {
                   6203:                 if (ref($settings->{'encrypt'}) eq 'HASH') {
                   6204:                     foreach my $key (keys(%{$settings->{'encrypt'}})) {
                   6205:                         if ($key eq 'consumers') {
                   6206:                             $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
                   6207:                         } else {
                   6208:                             $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
                   6209:                         }
                   6210:                     }
                   6211:                 }
                   6212:             }
                   6213:             if (exists($settings->{'private'})) {
                   6214:                 if (ref($settings->{'private'}) eq 'HASH') {
                   6215:                     if (ref($settings->{'private'}) eq 'HASH') {
                   6216:                         if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
                   6217:                             map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
                   6218:                         }
                   6219:                     }
                   6220:                 }
                   6221:             }
1.434     raeburn  6222:         } elsif ($position eq 'upper') {
1.405     raeburn  6223:             if (exists($settings->{'rules'})) {
                   6224:                 if (ref($settings->{'rules'}) eq 'HASH') {
                   6225:                     %rules = %{$settings->{'rules'}};
                   6226:                 }
                   6227:             }
1.434     raeburn  6228:         } elsif ($position eq 'middle') {
                   6229:             if (exists($settings->{'suggested'})) {
                   6230:                 if (ref($settings->{'suggested'}) eq 'HASH') {
                   6231:                     %suggestions = %{$settings->{'suggested'}};
                   6232:                 }
                   6233:             }
1.405     raeburn  6234:         } elsif ($position eq 'lower') {
                   6235:             if (exists($settings->{'linkprot'})) {
                   6236:                 if (ref($settings->{'linkprot'}) eq 'HASH') {
                   6237:                     %linkprot = %{$settings->{'linkprot'}};
1.406     raeburn  6238:                     if ($linkprot{'lock'}) {
                   6239:                         delete($linkprot{'lock'});
                   6240:                     }
1.405     raeburn  6241:                 }
                   6242:             }
                   6243:         } else {
1.434     raeburn  6244:             foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405     raeburn  6245:                 if (exists($settings->{$key})) {
                   6246:                     delete($settings->{$key});
1.390     raeburn  6247:                 }
1.320     raeburn  6248:             }
                   6249:         }
                   6250:     }
1.405     raeburn  6251:     if ($position eq 'top') {
1.421     raeburn  6252:         $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434     raeburn  6253:     } elsif ($position eq 'upper') {
                   6254:         $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
                   6255:         $$rowtotal += $itemcount;
1.421     raeburn  6256:     } elsif ($position eq 'middle') {
1.434     raeburn  6257:         $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421     raeburn  6258:         $$rowtotal += $itemcount;
                   6259:     } elsif ($position eq 'lower') {
1.434     raeburn  6260:         $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421     raeburn  6261:     } else {
1.424     raeburn  6262:         my ($switchserver,$switchmessage);
                   6263:         $switchserver = &check_switchserver($dom);
                   6264:         $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421     raeburn  6265:         my $maxnum = 0;
                   6266:         my %ordered;
                   6267:         if (ref($settings) eq 'HASH') {
                   6268:             foreach my $item (keys(%{$settings})) {
                   6269:                 if (ref($settings->{$item}) eq 'HASH') {
                   6270:                     my $num = $settings->{$item}{'order'};
                   6271:                     if ($num eq '') {
                   6272:                         $num = scalar(keys(%{$settings}));
                   6273:                     }
                   6274:                     $ordered{$num} = $item;
1.405     raeburn  6275:                 }
1.352     raeburn  6276:             }
1.405     raeburn  6277:         }
                   6278:         $maxnum = scalar(keys(%ordered));
                   6279:         my %lt = &lti_names();
                   6280:         if (keys(%ordered)) {
                   6281:             my @items = sort { $a <=> $b } keys(%ordered);
                   6282:             for (my $i=0; $i<@items; $i++) {
                   6283:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6284:                 my $item = $ordered{$items[$i]};
1.424     raeburn  6285:                 my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405     raeburn  6286:                 if (ref($settings->{$item}) eq 'HASH') {
                   6287:                     $key = $settings->{$item}->{'key'};
1.424     raeburn  6288:                     $usable = $settings->{$item}->{'usable'};
1.405     raeburn  6289:                     $lifetime = $settings->{$item}->{'lifetime'};
                   6290:                     $consumer = $settings->{$item}->{'consumer'};
                   6291:                     $requser = $settings->{$item}->{'requser'};
                   6292:                     $crsinc = $settings->{$item}->{'crsinc'};
                   6293:                     $current = $settings->{$item};
                   6294:                 }
                   6295:                 my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
                   6296:                 my %checkedrequser = (
                   6297:                                        yes => ' checked="checked"',
                   6298:                                        no  => '',
                   6299:                                      );
                   6300:                 if (!$requser) {
                   6301:                     $checkedrequser{'no'} = $checkedrequser{'yes'};
                   6302:                     $checkedrequser{'yes'} = '';
                   6303:                 }
                   6304:                 my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
                   6305:                 my %checkedcrsinc = (
1.391     raeburn  6306:                                       yes => ' checked="checked"',
                   6307:                                       no  => '',
1.405     raeburn  6308:                                     );
                   6309:                 if (!$crsinc) {
                   6310:                     $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
                   6311:                     $checkedcrsinc{'yes'} = '';
                   6312:                 }
                   6313:                 my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
                   6314:                 $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6315:                              .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
                   6316:                 for (my $k=0; $k<=$maxnum; $k++) {
                   6317:                     my $vpos = $k+1;
                   6318:                     my $selstr;
                   6319:                     if ($k == $i) {
                   6320:                         $selstr = ' selected="selected" ';
                   6321:                     }
                   6322:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320     raeburn  6323:                 }
1.405     raeburn  6324:                 $datatable .= '</select>'.('&nbsp;'x2).
                   6325:                     '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
                   6326:                     &mt('Delete?').'</label></span></td>'.
                   6327:                     '<td colspan="2">'.
                   6328:                     '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6329:                     '<span class="LC_nobreak">'.$lt{'consumer'}.
                   6330:                     ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
                   6331:                     ('&nbsp;'x2).
                   6332:                     '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                   6333:                     '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   6334:                     ('&nbsp;'x2).
                   6335:                     '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424     raeburn  6336:                     'value="'.$lifetime.'" size="3" /></span><br /><br />';
                   6337:                 if ($key ne '') {
                   6338:                     $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
                   6339:                     if ($switchserver) {
                   6340:                         $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
                   6341:                     } else {
                   6342:                         $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
                   6343:                     }
                   6344:                     $datatable .= '</span> '.('&nbsp;'x2);
                   6345:                 } elsif (!$switchserver) {
                   6346:                     $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
                   6347:                                   '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
                   6348:                                   '</span> '.('&nbsp;'x2);
                   6349:                 }
                   6350:                 if ($switchserver) {
                   6351:                     if ($usable ne '') {
                   6352:                         $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
                   6353:                                       $lt{'secret'}.': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   6354:                                       '<span class="LC_nobreak">'.&mt('Change secret?').
                   6355:                                       '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
                   6356:                                       ('&nbsp;'x2).
                   6357:                                      '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.('&nbsp;'x2).
                   6358:                                       '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
                   6359:                                       '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
                   6360:                                       '</div>';
                   6361:                     } elsif ($key eq '') {
                   6362:                         $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
                   6363:                     } else {
                   6364:                         $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
                   6365:                     }
                   6366:                 } else {
                   6367:                     if ($usable ne '') {
                   6368:                         $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
                   6369:                                       $lt{'secret'}.': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   6370:                                       '<span class="LC_nobreak">'.&mt('Change?').
                   6371:                                       '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
                   6372:                                       ('&nbsp;'x2).
                   6373:                                       '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
                   6374:                                       '</label>&nbsp;&nbsp;</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
                   6375:                                       '<span class="LC_nobreak">'.&mt('New Secret').':'.
                   6376:                                       '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
                   6377:                                       '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
                   6378:                     } else {
                   6379:                         $datatable .=
                   6380:                             '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   6381:                             '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
                   6382:                             '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
                   6383:                     }
                   6384:                 }
1.425     raeburn  6385:                 $datatable .= '<br /><br />'.
1.405     raeburn  6386:                     '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6387:                     '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6388:                     '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
                   6389:                     '<br /><br />'.
                   6390:                     '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6391:                     '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6392:                     '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
                   6393:                     ('&nbsp;'x4).
                   6394:                     '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
                   6395:                     '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
                   6396:                 $itemcount ++;
1.320     raeburn  6397:             }
                   6398:         }
1.405     raeburn  6399:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6400:         my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
                   6401:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   6402:                       '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
                   6403:                       '<select name="lti_pos_add"'.$chgstr.'>';
                   6404:         for (my $k=0; $k<$maxnum+1; $k++) {
                   6405:             my $vpos = $k+1;
                   6406:             my $selstr;
                   6407:             if ($k == $maxnum) {
                   6408:                 $selstr = ' selected="selected" ';
                   6409:             }
                   6410:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320     raeburn  6411:         }
1.405     raeburn  6412:         $datatable .= '</select>&nbsp;'."\n".
                   6413:                       '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   6414:                       '<td colspan="2">'.
                   6415:                       '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6416:                       '<span class="LC_nobreak">'.$lt{'consumer'}.
                   6417:                       ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
                   6418:                       ('&nbsp;'x2).
                   6419:                       '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   6420:                       '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   6421:                       ('&nbsp;'x2).
1.424     raeburn  6422:                       '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
                   6423:         if ($switchserver) {
                   6424:             $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
                   6425:         } else {
                   6426:             $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
                   6427:                           ('&nbsp;'x2).
                   6428:                           '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
                   6429:                           '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
                   6430:         }
                   6431:         $datatable .= '<br /><br />'.
1.405     raeburn  6432:                       '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6433:                       '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6434:                       '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
                   6435:                       '<br /><br />'.
                   6436:                       '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6437:                       '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6438:                       '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
                   6439:                       '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
                   6440:                       '</td>'."\n".
                   6441:                       '</tr>'."\n";
                   6442:         $itemcount ++;
1.320     raeburn  6443:     }
1.405     raeburn  6444:     $$rowtotal += $itemcount;
                   6445:     return $datatable;
1.320     raeburn  6446: }
                   6447: 
                   6448: sub lti_names {
                   6449:     my %lt = &Apache::lonlocal::texthash(
                   6450:                                           'version'   => 'LTI Version',
                   6451:                                           'url'       => 'URL',
                   6452:                                           'key'       => 'Key',
1.322     raeburn  6453:                                           'lifetime'  => 'Nonce lifetime (s)',
1.345     raeburn  6454:                                           'consumer'  => 'Consumer',
1.320     raeburn  6455:                                           'secret'    => 'Secret',
1.345     raeburn  6456:                                           'requser'   => "User's identity sent",
1.391     raeburn  6457:                                           'crsinc'    => "Course's identity sent",
1.320     raeburn  6458:                                           'email'     => 'Email address',
                   6459:                                           'sourcedid' => 'User ID',
                   6460:                                           'other'     => 'Other',
                   6461:                                           'passback'  => 'Can return grades to Consumer:',
                   6462:                                           'roster'    => 'Can retrieve roster from Consumer:',
1.326     raeburn  6463:                                           'topmenu'   => 'Display LON-CAPA page header',
1.345     raeburn  6464:                                           'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320     raeburn  6465:                                         );
                   6466:     return %lt;
                   6467: }
                   6468: 
                   6469: sub lti_options {
1.325     raeburn  6470:     my ($num,$current,$itemcount,%lt) = @_;
1.363     raeburn  6471:     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320     raeburn  6472:     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
                   6473:     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392     raeburn  6474:     $checked{'storecrs'}{'Y'} = ' checked="checked"';
                   6475:     $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320     raeburn  6476:     $checked{'mapcrstype'} = {};
                   6477:     $checked{'makeuser'} = {};
                   6478:     $checked{'selfenroll'} = {};
                   6479:     $checked{'crssec'} = {};
                   6480:     $checked{'crssecsrc'} = {};
1.325     raeburn  6481:     $checked{'lcauth'} = {};
1.326     raeburn  6482:     $checked{'menuitem'} = {};
1.325     raeburn  6483:     if ($num eq 'add') {
                   6484:         $checked{'lcauth'}{'lti'} = ' checked="checked"';
                   6485:     }
1.320     raeburn  6486:     my $userfieldsty = 'none';
                   6487:     my $crsfieldsty = 'none';
                   6488:     my $crssecfieldsty = 'none';
                   6489:     my $secsrcfieldsty = 'none';
1.363     raeburn  6490:     my $callbacksty = 'none';
1.337     raeburn  6491:     my $passbacksty = 'none';
1.345     raeburn  6492:     my $optionsty = 'block';
1.391     raeburn  6493:     my $crssty = 'block';
1.325     raeburn  6494:     my $lcauthparm;
                   6495:     my $lcauthparmstyle = 'display:none';
                   6496:     my $lcauthparmtext;
1.326     raeburn  6497:     my $menusty;
1.325     raeburn  6498:     my $numinrow = 4;
1.326     raeburn  6499:     my %menutitles = &ltimenu_titles();
1.320     raeburn  6500: 
                   6501:     if (ref($current) eq 'HASH') {
1.345     raeburn  6502:         if (!$current->{'requser'}) {
                   6503:             $optionsty = 'none';
1.391     raeburn  6504:             $crssty = 'none';
                   6505:         } elsif (!$current->{'crsinc'}) {
                   6506:             $crssty = 'none';
1.345     raeburn  6507:         }
1.320     raeburn  6508:         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
                   6509:             $checked{'mapuser'}{'sourcedid'} = '';
                   6510:             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425     raeburn  6511:                 $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320     raeburn  6512:             } else {
                   6513:                 $checked{'mapuser'}{'other'} = ' checked="checked"';
                   6514:                 $userfield = $current->{'mapuser'};
                   6515:                 $userfieldsty = 'inline-block';
                   6516:             }
                   6517:         }
                   6518:         if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
                   6519:             $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
                   6520:             if ($current->{'mapcrs'} eq 'context_id') {
1.425     raeburn  6521:                 $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320     raeburn  6522:             } else {
                   6523:                 $checked{'mapcrs'}{'other'} = ' checked="checked"';
                   6524:                 $cidfield = $current->{'mapcrs'};
                   6525:                 $crsfieldsty = 'inline-block';
                   6526:             }
                   6527:         }
                   6528:         if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
                   6529:             foreach my $type (@{$current->{'mapcrstype'}}) {
                   6530:                 $checked{'mapcrstype'}{$type} = ' checked="checked"';
                   6531:             }
                   6532:         }
1.392     raeburn  6533:         if (!$current->{'storecrs'}) {
                   6534:             $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
                   6535:             $checked{'storecrs'}{'Y'} = '';
                   6536:         }
1.345     raeburn  6537:         if ($current->{'makecrs'}) {
1.320     raeburn  6538:             $checked{'makecrs'}{'Y'} = '  checked="checked"';
1.326     raeburn  6539:         }
1.320     raeburn  6540:         if (ref($current->{'makeuser'}) eq 'ARRAY') {
                   6541:             foreach my $role (@{$current->{'makeuser'}}) {
                   6542:                 $checked{'makeuser'}{$role} = ' checked="checked"';
                   6543:             }
                   6544:         }
1.325     raeburn  6545:         if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
                   6546:             $checked{'lcauth'}{$1} = ' checked="checked"';
                   6547:             unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   6548:                 $lcauthparm = $current->{'lcauthparm'};
1.425     raeburn  6549:                 $lcauthparmstyle = 'display:table-row';
1.325     raeburn  6550:                 if ($current->{'lcauth'} eq 'localauth') {
                   6551:                     $lcauthparmtext = &mt('Local auth argument');
                   6552:                 } else {
                   6553:                     $lcauthparmtext = &mt('Kerberos domain');
                   6554:                 }
                   6555:             }
                   6556:         }
1.320     raeburn  6557:         if (ref($current->{'selfenroll'}) eq 'ARRAY') {
                   6558:             foreach my $role (@{$current->{'selfenroll'}}) {
                   6559:                 $checked{'selfenroll'}{$role} = ' checked="checked"';
                   6560:             }
                   6561:         }
                   6562:         if (ref($current->{'maproles'}) eq 'HASH') {
                   6563:             %rolemaps = %{$current->{'maproles'}};
                   6564:         }
                   6565:         if ($current->{'section'} ne '') {
1.425     raeburn  6566:             $checked{'crssec'}{'Y'} = '  checked="checked"';
1.320     raeburn  6567:             $crssecfieldsty = 'inline-block';
                   6568:             if ($current->{'section'} eq 'course_section_sourcedid') {
                   6569:                 $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
                   6570:             } else {
                   6571:                 $checked{'crssecsrc'}{'other'} = ' checked="checked"';
                   6572:                 $crssecsrc = $current->{'section'};
                   6573:                 $secsrcfieldsty = 'inline-block';
                   6574:             }
                   6575:         } else {
                   6576:             $checked{'crssec'}{'N'} = ' checked="checked"';
                   6577:         }
1.363     raeburn  6578:         if ($current->{'callback'} ne '') {
                   6579:             $callback = $current->{'callback'};
                   6580:             $checked{'callback'}{'Y'} = ' checked="checked"';
                   6581:             $callbacksty = 'inline-block';
                   6582:         } else {
                   6583:             $checked{'callback'}{'N'} = ' checked="checked"';
                   6584:         }
1.326     raeburn  6585:         if ($current->{'topmenu'}) {
                   6586:             $checked{'topmenu'}{'Y'} = ' checked="checked"';
                   6587:         } else {
                   6588:             $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6589:         }
                   6590:         if ($current->{'inlinemenu'}) {
                   6591:             $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
                   6592:         } else {
                   6593:             $checked{'inlinemenu'}{'N'} = ' checked="checked"';
                   6594:         }
                   6595:         if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
                   6596:             $menusty = 'inline-block';
                   6597:             if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   6598:                 foreach my $item (@{$current->{'lcmenu'}}) {
                   6599:                     if (exists($menutitles{$item})) {
                   6600:                         $checked{'menuitem'}{$item} = ' checked="checked"';
                   6601:                     }
                   6602:                 }
                   6603:             }
                   6604:         } else {
                   6605:             $menusty = 'none';
                   6606:         }
1.320     raeburn  6607:     } else {
                   6608:         $checked{'makecrs'}{'N'} = ' checked="checked"';
                   6609:         $checked{'crssec'}{'N'} = ' checked="checked"';
1.363     raeburn  6610:         $checked{'callback'}{'N'} = ' checked="checked"';
1.326     raeburn  6611:         $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425     raeburn  6612:         $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326     raeburn  6613:         $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425     raeburn  6614:         $menusty = 'inline-block';
1.320     raeburn  6615:     }
1.325     raeburn  6616:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  6617:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   6618:                                official   => 'Official',
                   6619:                                unofficial => 'Unofficial',
                   6620:                                community  => 'Community',
                   6621:                                textbook   => 'Textbook',
                   6622:                                placement  => 'Placement Test',
1.325     raeburn  6623:                                lti        => 'LTI Provider',
1.320     raeburn  6624:     );
1.325     raeburn  6625:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6626:     my %shortauth = (
                   6627:                      internal => 'int',
                   6628:                      krb4 => 'krb4',
                   6629:                      krb5 => 'krb5',
                   6630:                      localauth  => 'loc'
                   6631:                     );
                   6632:     my %authnames = &authtype_names();
1.320     raeburn  6633:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   6634:     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
                   6635:     my @courseroles = ('cc','in','ta','ep','st');
                   6636:     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
                   6637:     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
                   6638:     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363     raeburn  6639:     my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320     raeburn  6640:     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325     raeburn  6641:     my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326     raeburn  6642:     my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391     raeburn  6643:     my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392     raeburn  6644:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').':&nbsp;'.
1.391     raeburn  6645:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
                   6646:                  $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6647:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
                   6648:                  $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
                   6649:                  '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
                   6650:                  '<span class="LC_nobreak">'.&mt('Parameter').': '.
                   6651:                  '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
                   6652:                  '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
                   6653:                  '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320     raeburn  6654:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
                   6655:     foreach my $option ('sourcedid','email','other') {
                   6656:         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
                   6657:                    $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
                   6658:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6659:     }
                   6660:     $output .= '</span></div>'.
                   6661:                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                   6662:                '<input type="text" name="lti_customuser_'.$num.'" '.
1.372     raeburn  6663:                'value="'.$userfield.'" /></div></fieldset>'.
1.391     raeburn  6664:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320     raeburn  6665:     foreach my $ltirole (@ltiroles) {
                   6666:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425     raeburn  6667:                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';
1.320     raeburn  6668:     }
                   6669:     $output .= '</fieldset>'.
1.391     raeburn  6670:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325     raeburn  6671:                '<table>'.
                   6672:                &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                   6673:                '</table>'.
                   6674:                '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                   6675:                '<td class="LC_left_item">';
                   6676:     foreach my $auth ('lti',@authtypes) {
                   6677:         my $authtext;
                   6678:         if ($auth eq 'lti') {
                   6679:             $authtext = &mt('None');
                   6680:         } else {
                   6681:             $authtext = $authnames{$shortauth{$auth}};
                   6682:         }
                   6683:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                   6684:                    '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                   6685:                    $authtext.'</label></span> &nbsp;';
                   6686:     }
                   6687:     $output .= '</td></tr>'.
                   6688:                '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                   6689:                '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                   6690:                '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                   6691:                '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                   6692:                '</table></fieldset>'.
1.391     raeburn  6693:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
                   6694:                &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
                   6695:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                   6696:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                   6697:                $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6698:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
                   6699:                $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
                   6700:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6701:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                   6702:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                   6703:                $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6704:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
                   6705:                $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
                   6706:      $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6707:                '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                   6708:                '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
                   6709:     foreach my $type ('fullname','coursetitle','role','logout','grades') {
                   6710:         $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                   6711:                    $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                   6712:                    ('&nbsp;'x2);
                   6713:     }
                   6714:     $output .= '</span></div></fieldset>'.
                   6715:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320     raeburn  6716:                '<div class="LC_floatleft"><span class="LC_nobreak">'.
                   6717:                &mt('Unique course identifier').':&nbsp;';
                   6718:     foreach my $option ('course_offering_sourcedid','context_id','other') {
                   6719:         $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
                   6720:                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                   6721:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6722:     }
1.334     raeburn  6723:     $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320     raeburn  6724:                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                   6725:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6726:                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
                   6727:     foreach my $type (@coursetypes) {
                   6728:         $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
                   6729:                    $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
                   6730:                    ('&nbsp;'x2);
                   6731:     }
1.392     raeburn  6732:     $output .= '</span><br /><br />'.
                   6733:                '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').':&nbsp;'.
                   6734:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
                   6735:                $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6736:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
                   6737:                $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6738:                '</fieldset>'.
1.391     raeburn  6739:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
                   6740:     foreach my $ltirole (@lticourseroles) {
                   6741:         my ($selected,$selectnone);
                   6742:         if ($rolemaps{$ltirole} eq '') {
                   6743:             $selectnone = ' selected="selected"';
                   6744:         }
                   6745:         $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
                   6746:                    '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
                   6747:                    '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6748:         foreach my $role (@courseroles) {
                   6749:             unless ($selectnone) {
                   6750:                 if ($rolemaps{$ltirole} eq $role) {
                   6751:                     $selected = ' selected="selected"';
                   6752:                 } else {
                   6753:                     $selected = '';
                   6754:                 }
                   6755:             }
                   6756:             $output .= '<option value="'.$role.'"'.$selected.'>'.
                   6757:                        &Apache::lonnet::plaintext($role,'Course').
                   6758:                        '</option>';
                   6759:         }
                   6760:         $output .= '</select></td>';
                   6761:     }
                   6762:     $output .= '</tr></table></fieldset>'.
                   6763:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320     raeburn  6764:                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                   6765:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                   6766:                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6767:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                   6768:                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6769:                '</fieldset>'.
1.391     raeburn  6770:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320     raeburn  6771:     foreach my $lticrsrole (@lticourseroles) {
                   6772:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                   6773:                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
                   6774:     }
                   6775:     $output .= '</fieldset>'.
1.391     raeburn  6776:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320     raeburn  6777:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                   6778:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                   6779:                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6780:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334     raeburn  6781:                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320     raeburn  6782:                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                   6783:                '<span class="LC_nobreak">'.&mt('From').':<label>'.
                   6784:                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
                   6785:                $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
                   6786:                &mt('Standard field').'</label>'.('&nbsp;'x2).
                   6787:                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                   6788:                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334     raeburn  6789:                '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320     raeburn  6790:                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337     raeburn  6791:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
                   6792:     my ($pb1p1chk,$pb1p0chk,$onclickpb);
                   6793:     foreach my $extra ('roster','passback') {
1.320     raeburn  6794:         my $checkedon = '';
                   6795:         my $checkedoff = ' checked="checked"';
1.337     raeburn  6796:         if ($extra eq 'passback') {
                   6797:             $pb1p1chk = ' checked="checked"';
                   6798:             $pb1p0chk = '';
1.425     raeburn  6799:             $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337     raeburn  6800:         } else {
1.425     raeburn  6801:             $onclickpb = '';
1.337     raeburn  6802:         }
1.320     raeburn  6803:         if (ref($current) eq 'HASH') {
                   6804:             if (($current->{$extra})) {
                   6805:                 $checkedon = $checkedoff;
                   6806:                 $checkedoff = '';
1.337     raeburn  6807:                 if ($extra eq 'passback') {
                   6808:                     $passbacksty = 'inline-block';
                   6809:                 }
                   6810:                 if ($current->{'passbackformat'} eq '1.0') {
                   6811:                     $pb1p0chk =  ' checked="checked"';
                   6812:                     $pb1p1chk = '';
                   6813:                 }
1.320     raeburn  6814:             }
                   6815:         }
                   6816:         $output .= $lt{$extra}.'&nbsp;'.
1.337     raeburn  6817:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320     raeburn  6818:                    &mt('No').'</label>'.('&nbsp;'x2).
1.339     raeburn  6819:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320     raeburn  6820:                    &mt('Yes').'</label><br />';
                   6821:     }
1.337     raeburn  6822:     $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                   6823:                '<span class="LC_nobreak">'.&mt('Grade format').
                   6824:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                   6825:                &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                   6826:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363     raeburn  6827:                &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391     raeburn  6828:                '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334     raeburn  6829:     $output .= '</span></div></fieldset>';
1.320     raeburn  6830: #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
                   6831: #
                   6832: #    $output .= '</fieldset>'.
                   6833: #        '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
                   6834:     return $output;
                   6835: }
                   6836: 
1.326     raeburn  6837: sub ltimenu_titles {
                   6838:     return &Apache::lonlocal::texthash(
                   6839:                                         fullname    => 'Full name',
                   6840:                                         coursetitle => 'Course title',
                   6841:                                         role        => 'Role',
                   6842:                                         logout      => 'Logout',
                   6843:                                         grades      => 'Grades',
                   6844:     );
                   6845: }
                   6846: 
1.434     raeburn  6847: sub linkprot_suggestions {
                   6848:     my ($suggested,$itemcount) = @_;
                   6849:     my $count = 0;
                   6850:     my $next = 1;
                   6851:     my %lt = &Apache::lonlocal::texthash(
                   6852:                                           'name' => 'Suggested Launcher',
                   6853:                                           'info' => 'Recommendations',
                   6854:                                         );
                   6855:     my ($datatable,$css_class,$dest);
                   6856:     if (ref($suggested) eq 'HASH') {
                   6857:         my @current = sort { $a <=> $b } keys(%{$suggested});
                   6858:         $next += $current[-1];
                   6859:         for (my $i=0; $i<@current; $i++) {
                   6860:             my $num = $current[$i];
                   6861:             my %values;
                   6862:             if (ref($suggested->{$num}) eq 'HASH') {
                   6863:                 %values = %{$suggested->{$num}};
                   6864:             } else {
                   6865:                 next;
                   6866:             }
                   6867:             $css_class = $$itemcount%2?' class="LC_odd_row"':'';
                   6868:             $datatable .=
                   6869:                 '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   6870:                 '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
                   6871:                 &mt('Delete?').'</label></span></td><td>'."\n".
                   6872:                 '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
                   6873:                 '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
                   6874:                 '</fieldset></div>'.
                   6875:                 '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
                   6876:                 '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
                   6877:                 '</fieldset></div>'.
                   6878:                 '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
                   6879:                 '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
                   6880:             $$itemcount ++;
                   6881:         }
                   6882:     }
                   6883:     $css_class = $$itemcount%2?' class="LC_odd_row"':'';
                   6884:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   6885:                   '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
                   6886:                   '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   6887:                   '<td>'."\n".
                   6888:                   '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
                   6889:                   '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
                   6890:                   '</fieldset></div>'.
                   6891:                   '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
                   6892:                   '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
                   6893:                   '</fieldset></div>'.
                   6894:                   '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
                   6895:                   '</td></tr>'."\n";
                   6896:     return $datatable;
                   6897: }
                   6898: 
1.121     raeburn  6899: sub print_coursedefaults {
1.139     raeburn  6900:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  6901:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  6902:     my $itemcount = 1;
1.192     raeburn  6903:     my %choices =  &Apache::lonlocal::texthash (
                   6904:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  6905:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432     raeburn  6906:         coursequota          => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192     raeburn  6907:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   6908:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  6909:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   6910:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398     raeburn  6911:         inline_chem          => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314     raeburn  6912:         texengine            => 'Default method to display mathematics',
1.257     raeburn  6913:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  6914:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   6915:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405     raeburn  6916:         ltiauth              => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422     raeburn  6917:         domexttool           => 'External Tools defined in the domain may be used in courses/communities (by type)',
                   6918:         exttool              => 'External Tools can be defined and configured in courses/communities (by type)',
1.432     raeburn  6919:         crsauthor            => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438   ! raeburn  6920:         crseditors           => 'Available editors for web pages and/or problems created in a course/community',
1.192     raeburn  6921:     );
1.198     raeburn  6922:     my %staticdefaults = (
                   6923:                            anonsurvey_threshold => 10,
                   6924:                            uploadquota          => 500,
1.428     raeburn  6925:                            coursequota          => 20,
1.257     raeburn  6926:                            postsubmit           => 60,
1.276     raeburn  6927:                            mysqltables          => 172800,
1.422     raeburn  6928:                            domexttool           => 1,
                   6929:                            exttool              => 0,
1.432     raeburn  6930:                            crsauthor            => 1,
1.438   ! raeburn  6931:                            crseditors           => ['edit','xml'],  
1.198     raeburn  6932:                          );
1.139     raeburn  6933:     if ($position eq 'top') {
1.257     raeburn  6934:         %defaultchecked = (
                   6935:                             'canuse_pdfforms' => 'off',
                   6936:                             'uselcmath'       => 'on',
                   6937:                             'usejsme'         => 'on',
1.398     raeburn  6938:                             'inline_chem'     => 'on',
1.289     raeburn  6939:                             'canclone'        => 'none',
1.257     raeburn  6940:                           );
1.398     raeburn  6941:         @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349     raeburn  6942:         my $deftex = $Apache::lonnet::deftex;
1.314     raeburn  6943:         if (ref($settings) eq 'HASH') {
                   6944:             if ($settings->{'texengine'}) {
                   6945:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   6946:                     $deftex = $settings->{'texengine'};
                   6947:                 }
                   6948:             }
                   6949:         }
                   6950:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6951:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   6952:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   6953:                        '</span></td><td class="LC_right_item">'.
                   6954:                        '<select name="texengine">'."\n";
                   6955:         my %texoptions = (
                   6956:                             MathJax  => 'MathJax',
                   6957:                             mimetex  => &mt('Convert to Images'),
                   6958:                             tth      => &mt('TeX to HTML'),
                   6959:                          );
                   6960:         foreach my $renderer ('MathJax','mimetex','tth') {
                   6961:             my $selected = '';
                   6962:             if ($renderer eq $deftex) {
                   6963:                 $selected = ' selected="selected"';
                   6964:             }
                   6965:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   6966:         }
                   6967:         $mathdisp .= '</select></td></tr>'."\n";
                   6968:         $itemcount ++;
1.139     raeburn  6969:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  6970:                                                      \%choices,$itemcount);
1.314     raeburn  6971:         $datatable = $mathdisp.$datatable;
1.264     raeburn  6972:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6973:         $datatable .=
1.306     raeburn  6974:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  6975:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   6976:             '</span></td><td class="LC_left_item">';
                   6977:         my $currcanclone = 'none';
                   6978:         my $onclick;
                   6979:         my @cloneoptions = ('none','domain');
1.380     raeburn  6980:         my %clonetitles = &Apache::lonlocal::texthash (
1.264     raeburn  6981:                              none     => 'No additional course requesters',
                   6982:                              domain   => "Any course requester in course's domain",
                   6983:                              instcode => 'Course requests for official courses ...',
                   6984:                           );
                   6985:         my (%codedefaults,@code_order,@posscodes);
                   6986:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   6987:                                                     \@code_order) eq 'ok') {
                   6988:             if (@code_order > 0) {
                   6989:                 push(@cloneoptions,'instcode');
                   6990:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   6991:             }
                   6992:         }
                   6993:         if (ref($settings) eq 'HASH') {
                   6994:             if ($settings->{'canclone'}) {
                   6995:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   6996:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   6997:                         if (@code_order > 0) {
                   6998:                             $currcanclone = 'instcode';
                   6999:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   7000:                         }
                   7001:                     }
                   7002:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   7003:                     $currcanclone = $settings->{'canclone'};
                   7004:                 }
                   7005:             }
1.289     raeburn  7006:         }
1.264     raeburn  7007:         foreach my $option (@cloneoptions) {
                   7008:             my ($checked,$additional);
                   7009:             if ($currcanclone eq $option) {
                   7010:                 $checked = ' checked="checked"';
                   7011:             }
                   7012:             if ($option eq 'instcode') {
                   7013:                 if (@code_order) {
                   7014:                     my $show = 'none';
                   7015:                     if ($checked) {
                   7016:                         $show = 'block';
                   7017:                     }
1.317     raeburn  7018:                     $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264     raeburn  7019:                                   &mt('Institutional codes for new and cloned course have identical:').
                   7020:                                   '<br />';
                   7021:                     foreach my $item (@code_order) {
                   7022:                         my $codechk;
                   7023:                         if ($checked) {
                   7024:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   7025:                                 $codechk = ' checked="checked"';
                   7026:                             }
                   7027:                         }
                   7028:                         $additional .= '<label>'.
                   7029:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   7030:                                        $item.'</label>';
                   7031:                     }
                   7032:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   7033:                 }
                   7034:             }
                   7035:             $datatable .=
                   7036:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   7037:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   7038:                 '</label>&nbsp;'.$additional.'</span><br />';
                   7039:         }
                   7040:         $datatable .= '</td>'.
                   7041:                       '</tr>';
                   7042:         $itemcount ++;
1.139     raeburn  7043:     } else {
                   7044:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428     raeburn  7045:         my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
                   7046:             %deftimeout,%currmysql);
1.192     raeburn  7047:         my $currusecredits = 0;
1.257     raeburn  7048:         my $postsubmitclient = 1;
1.405     raeburn  7049:         my $ltiauth = 0;
1.422     raeburn  7050:         my %domexttool;
                   7051:         my %exttool;
1.432     raeburn  7052:         my %crsauthor;
1.438   ! raeburn  7053:         my %crseditors;
1.271     raeburn  7054:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  7055:         if (ref($settings) eq 'HASH') {
1.404     raeburn  7056:             if ($settings->{'ltiauth'}) {
                   7057:                 $ltiauth = 1;
1.405     raeburn  7058:             }
1.422     raeburn  7059:             if (ref($settings->{'domexttool'}) eq 'HASH') {
                   7060:                 foreach my $type (@types) {
                   7061:                     if ($settings->{'domexttool'}->{$type}) {
                   7062:                         $domexttool{$type} = ' checked="checked"';
                   7063:                     }
                   7064:                 }
                   7065:             } else {
                   7066:                 foreach my $type (@types) {
                   7067:                     if ($staticdefaults{'domexttool'}) {
                   7068:                         $domexttool{$type} = ' checked="checked"';
                   7069:                     }
                   7070:                 }
                   7071:             }
                   7072:             if (ref($settings->{'exttool'}) eq 'HASH') {
                   7073:                 foreach my $type (@types) {
                   7074:                     if ($settings->{'exttool'}->{$type}) {
                   7075:                         $exttool{$type} = ' checked="checked"';
                   7076:                     }
                   7077:                 }
                   7078:             }
1.432     raeburn  7079:             if (ref($settings->{'crsauthor'}) eq 'HASH') {
                   7080:                 foreach my $type (@types) {
                   7081:                     if ($settings->{'crsauthor'}->{$type}) {
                   7082:                         $crsauthor{$type} = ' checked="checked"';
                   7083:                     }
                   7084:                 }
                   7085:             } else {
                   7086:                 foreach my $type (@types) {
                   7087:                     if ($staticdefaults{'crsauthor'}) {
                   7088:                         $crsauthor{$type} = ' checked="checked"';
                   7089:                     }
                   7090:                 }
                   7091:             }
1.438   ! raeburn  7092:             if (ref($settings->{'crseditors'}) eq 'ARRAY') {
        !          7093:                 foreach my $editor (@{$settings->{'crseditors'}}) {
        !          7094:                     $crseditors{$editor} = ' checked="checked"';
        !          7095:                 }
        !          7096:             } else {
        !          7097:                 foreach my $editor (@{$staticdefaults{'crseditors'}}) {
        !          7098:                     $crseditors{$editor} = ' checked="checked"';
        !          7099:                 }
        !          7100:             }
1.139     raeburn  7101:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  7102:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   7103:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   7104:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   7105:                 }
                   7106:             }
1.428     raeburn  7107:             if (ref($settings->{'coursequota'}) eq 'HASH') {
                   7108:                 foreach my $type (keys(%{$settings->{'coursequota'}})) {
                   7109:                     $currcoursequota{$type} = $settings->{'coursequota'}{$type};
                   7110:                 }
                   7111:             }
1.192     raeburn  7112:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  7113:                 foreach my $type (@types) {
                   7114:                     next if ($type eq 'community');
                   7115:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   7116:                     if ($defcredits{$type} ne '') {
                   7117:                         $currusecredits = 1;
                   7118:                     }
                   7119:                 }
                   7120:             }
                   7121:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   7122:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   7123:                     $postsubmitclient = 0;
                   7124:                     foreach my $type (@types) {
                   7125:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7126:                     }
                   7127:                 } else {
                   7128:                     foreach my $type (@types) {
                   7129:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   7130:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  7131:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  7132:                             } else {
                   7133:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7134:                             }
                   7135:                         } else {
                   7136:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7137:                         }
                   7138:                     }
                   7139:                 }
                   7140:             } else {
                   7141:                 foreach my $type (@types) {
                   7142:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  7143:                 }
                   7144:             }
1.276     raeburn  7145:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   7146:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   7147:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   7148:                 }
                   7149:             } else {
                   7150:                 foreach my $type (@types) {
                   7151:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   7152:                 }
                   7153:             }
1.258     raeburn  7154:         } else {
                   7155:             foreach my $type (@types) {
                   7156:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422     raeburn  7157:                 if ($staticdefaults{'domexttool'}) {
                   7158:                     $domexttool{$type} = ' checked="checked"';
                   7159:                 }
1.432     raeburn  7160:                 if ($staticdefaults{'crsauthor'}) {
                   7161:                     $crsauthor{$type} = ' checked="checked"';
                   7162:                 }
1.258     raeburn  7163:             }
1.438   ! raeburn  7164:             foreach my $editor (@{$staticdefaults{'crseditors'}}) {
        !          7165:                 $crseditors{$editor} = ' checked="checked"';
        !          7166:             }
1.139     raeburn  7167:         }
                   7168:         if (!$currdefresponder) {
1.198     raeburn  7169:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  7170:         } elsif ($currdefresponder < 1) {
                   7171:             $currdefresponder = 1;
                   7172:         }
1.198     raeburn  7173:         foreach my $type (@types) {
                   7174:             if ($curruploadquota{$type} eq '') {
                   7175:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   7176:             }
1.428     raeburn  7177:             if ($currcoursequota{$type} eq '') {
                   7178:                 $currcoursequota{$type} = $staticdefaults{'coursequota'};
                   7179:             }
1.198     raeburn  7180:         }
1.139     raeburn  7181:         $datatable .=
1.192     raeburn  7182:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7183:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  7184:                 '</span></td>'.
                   7185:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7186:                 '<input type="text" name="anonsurvey_threshold"'.
                   7187:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  7188:                 '</td></tr>'."\n";
                   7189:         $itemcount ++;
                   7190:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7191:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7192:                       $choices{'uploadquota'}.
                   7193:                       '</span></td>'.
1.306     raeburn  7194:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  7195:                       '<table><tr>';
1.198     raeburn  7196:         foreach my $type (@types) {
1.306     raeburn  7197:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  7198:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   7199:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   7200:         }
                   7201:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  7202:         $itemcount ++;
1.428     raeburn  7203:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7204:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7205:                       $choices{'coursequota'}.
                   7206:                       '</span></td>'.
                   7207:                       '<td style="text-align: right" class="LC_right_item">'.
                   7208:                       '<table><tr>';
                   7209:         foreach my $type (@types) {
                   7210:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
                   7211:                            '<input type="text" name="coursequota_'.$type.'"'.
                   7212:                            ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
                   7213:         }
                   7214:         $datatable .= '</tr></table></td></tr>'."\n";
                   7215:         $itemcount ++;
1.236     raeburn  7216:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  7217:         my $display = 'none';
1.192     raeburn  7218:         if ($currusecredits) {
                   7219:             $display = 'block';
                   7220:         }
                   7221:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  7222:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   7223:         foreach my $type (@types) {
                   7224:             next if ($type eq 'community');
1.306     raeburn  7225:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7226:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  7227:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  7228:         }
                   7229:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  7230:         %defaultchecked = ('coursecredits' => 'off');
                   7231:         @toggles = ('coursecredits');
                   7232:         my $current = {
                   7233:                         'coursecredits' => $currusecredits,
                   7234:                       };
                   7235:         (my $table,$itemcount) =
                   7236:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  7237:                                \%choices,$itemcount,$onclick,$additional,'left');
                   7238:         $datatable .= $table;
                   7239:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   7240:         my $display = 'none';
                   7241:         if ($postsubmitclient) {
                   7242:             $display = 'block';
                   7243:         }
                   7244:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  7245:                       &mt('Number of seconds submit is disabled').'<br />'.
                   7246:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   7247:                       '<table><tr>';
1.257     raeburn  7248:         foreach my $type (@types) {
1.306     raeburn  7249:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7250:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   7251:                            $deftimeout{$type}.'" size="5" /></td>';
                   7252:         }
                   7253:         $additional .= '</tr></table></div>'."\n";
                   7254:         %defaultchecked = ('postsubmit' => 'on');
                   7255:         @toggles = ('postsubmit');
1.280     raeburn  7256:         $current = {
                   7257:                        'postsubmit' => $postsubmitclient,
                   7258:                    };
1.257     raeburn  7259:         ($table,$itemcount) =
                   7260:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   7261:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  7262:         $datatable .= $table;
1.276     raeburn  7263:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7264:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7265:                       $choices{'mysqltables'}.
                   7266:                       '</span></td>'.
1.306     raeburn  7267:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  7268:                       '<table><tr>';
                   7269:         foreach my $type (@types) {
1.306     raeburn  7270:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  7271:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  7272:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  7273:         }
                   7274:         $datatable .= '</tr></table></td></tr>'."\n";
                   7275:         $itemcount ++;
1.404     raeburn  7276:         %defaultchecked = ('ltiauth' => 'off');
                   7277:         @toggles = ('ltiauth');
                   7278:         $current = {
                   7279:                        'ltiauth' => $ltiauth,
                   7280:                    };
                   7281:         ($table,$itemcount) =
                   7282:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   7283:                                \%choices,$itemcount,undef,undef,'left');
                   7284:         $datatable .= $table;
1.422     raeburn  7285:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7286:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7287:                       $choices{'domexttool'}.
                   7288:                       '</span></td>'.
                   7289:                       '<td style="text-align: right" class="LC_right_item">'.
                   7290:                       '<table><tr>';
                   7291:         foreach my $type (@types) {
                   7292:             $datatable .= '<td style="text-align: left">'.
                   7293:                           '<span class="LC_nobreak">'.
1.438   ! raeburn  7294:                           '<label><input type="checkbox" name="domexttool"'.
1.422     raeburn  7295:                           ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438   ! raeburn  7296:                           &mt($type).'</label></span></td>'."\n";
1.422     raeburn  7297:         }
                   7298:         $datatable .= '</tr></table></td></tr>'."\n";
1.404     raeburn  7299:         $itemcount ++;
1.422     raeburn  7300:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7301:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7302:                       $choices{'exttool'}.
                   7303:                       '</span></td>'.
                   7304:                       '<td style="text-align: right" class="LC_right_item">'.
                   7305:                       '<table><tr>';
                   7306:         foreach my $type (@types) {
                   7307:             $datatable .= '<td style="text-align: left">'.
                   7308:                           '<span class="LC_nobreak">'.
1.438   ! raeburn  7309:                           '<label><input type="checkbox" name="exttool"'.
1.422     raeburn  7310:                           ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438   ! raeburn  7311:                           &mt($type).'</label></span></td>'."\n";
1.422     raeburn  7312:         }
                   7313:         $datatable .= '</tr></table></td></tr>'."\n";
1.432     raeburn  7314:         $itemcount ++;
                   7315:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7316:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7317:                       $choices{'crsauthor'}.
                   7318:                       '</span></td>'.
                   7319:                       '<td style="text-align: right" class="LC_right_item">'.
                   7320:                       '<table><tr>';
                   7321:         foreach my $type (@types) {
                   7322:             $datatable .= '<td style="text-align: left">'.
                   7323:                           '<span class="LC_nobreak">'.
1.438   ! raeburn  7324:                           '<label><input type="checkbox" name="crsauthor"'.
1.432     raeburn  7325:                           ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438   ! raeburn  7326:                           &mt($type).'</label></span></td>'."\n";
        !          7327:         }
        !          7328:         $datatable .= '</tr></table></td></tr>'."\n";
        !          7329:         $itemcount ++;
        !          7330:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
        !          7331:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
        !          7332:                       $choices{'crseditors'}.
        !          7333:                       '</span></td>'.
        !          7334:                       '<td style="text-align: right" class="LC_right_item">'.
        !          7335:                       '<table><tr>';
        !          7336:         my @editors = ('edit','xml','daxe');
        !          7337:         my %editornames = &crseditor_titles();
        !          7338:         foreach my $editor (@editors) {
        !          7339:             $datatable .= '<td style="text-align: left">'.
        !          7340:                           '<span class="LC_nobreak">'.
        !          7341:                           '<label><input type="checkbox" name="crseditors"'.
        !          7342:                           ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
        !          7343:                           $editornames{$editor}.'</label></span></td>'."\n";
1.432     raeburn  7344:         }
                   7345:         $datatable .= '</tr></table></td></tr>'."\n";
1.139     raeburn  7346:     }
1.192     raeburn  7347:     $$rowtotal += $itemcount;
1.121     raeburn  7348:     return $datatable;
1.118     jms      7349: }
                   7350: 
1.438   ! raeburn  7351: sub crseditor_titles {
        !          7352:     return &Apache::lonlocal::texthash(
        !          7353:                edit  => 'Standard editor (Edit)',
        !          7354:                xml   => 'Text editor (EditXML)',
        !          7355:                daxe  => 'Daxe editor (Daxe)',
        !          7356:            );
        !          7357: }
        !          7358: 
1.429     raeburn  7359: sub print_authordefaults {
                   7360:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7361:     my ($css_class,$datatable,%checkedon,%checkedoff);
                   7362:     my $itemcount = 1;
                   7363:     my %titles = &authordefaults_titles();
                   7364:     if ($position eq 'top') {
                   7365:         my %defaultchecked = (
                   7366:                             'nocodemirror' => 'off',
1.437     raeburn  7367:                             'daxecollapse' => 'off',
1.429     raeburn  7368:                             'domcoordacc'  => 'on',
                   7369:                           );
1.437     raeburn  7370:         my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429     raeburn  7371:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   7372:                                                      \%titles,$itemcount);
                   7373:         my %staticdefaults = (
                   7374:                                 'copyright'    => 'default',
                   7375:                                 'sourceavail'  => 'closed',
                   7376:                              );
                   7377:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7378:         my %currrights;
                   7379:         foreach my $item ('copyright','sourceavail') {
                   7380:             $currrights{$item} = $staticdefaults{$item};
                   7381:             if (ref($settings) eq 'HASH') {
                   7382:                 if (exists($settings->{$item})) {
                   7383:                     $currrights{$item} = $settings->{$item};
                   7384:                 }
                   7385:             }
                   7386:         }
                   7387:         $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
                   7388:                       '<span class="LC_nobreak">'.$titles{'copyright'}.
                   7389:                       '</span></td><td class="LC_right_item">'.
                   7390:                       &selectbox('copyright',$currrights{'copyright'},'',
                   7391:                                  \&Apache::loncommon::copyrightdescription,
                   7392:                                  (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
                   7393:                       '</td></tr>'."\n";
                   7394:         $itemcount ++;
                   7395:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7396:         $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
                   7397:                       '<span class="LC_nobreak">'.$titles{'sourceavail'}.
                   7398:                       '</span></td><td class="LC_right_item">'.
                   7399:                       &selectbox('sourceavail',$currrights{'sourceavail'},'',
                   7400:                                  \&Apache::loncommon::source_copyrightdescription,
                   7401:                                  (&Apache::loncommon::source_copyrightids)).
                   7402:                       '</td></tr>'."\n";        
                   7403:     } else {
                   7404:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7405:         my $curreditors;
                   7406:         my %staticdefaults = (
                   7407:                                 editors => ['edit','xml'],
                   7408:                                 authorquota => 500,
                   7409:                                 webdav => 0,
                   7410:                              );
                   7411:         my $curreditors = $staticdefaults{'editors'};
                   7412:         if ((ref($settings) eq 'HASH') &&
                   7413:             (ref($settings->{'editors'}) eq 'ARRAY')) {
                   7414:             $curreditors = $settings->{'editors'};
                   7415:         } else {
                   7416:             $curreditors = $staticdefaults{'editors'};
                   7417:         }
                   7418:         my @editors = ('edit','xml','daxe');
                   7419:         $datatable = '<tr'.$css_class.'>'."\n".
                   7420:                      '<td>'.$titles{'editors'}.'</td>'."\n".
                   7421:                      '<td class="LC_left_item">'."\n".
                   7422:                      '<span class="LC_nobreak">';
                   7423:         foreach my $editor (@editors) {
                   7424:             my $checked;
                   7425:             if (grep(/^\Q$editor\E$/,@{$curreditors})) {
                   7426:                 $checked = ' checked="checked"';
                   7427:             }
                   7428:             $datatable .= '<label>'.
                   7429:                           '<input type="checkbox" name="author_editors" '.
                   7430:                           $checked.' value="'.$editor.'" '.
                   7431:                           'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
                   7432:                           $titles{$editor}.'</label>&nbsp;';
                   7433:         }
                   7434:         $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
                   7435:         $itemcount ++;
                   7436:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7437:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7438:         my @insttypes;
                   7439:         if (ref($types) eq 'ARRAY') {
                   7440:             @insttypes = @{$types};
                   7441:         }
                   7442:         my $typecount = 0;
                   7443:         my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
                   7444:         my @items = ('webdav','authorquota');
                   7445:         my %quotas;
                   7446:         if (ref($domconf{'quotas'}) eq 'HASH') {
                   7447:             %quotas = %{$domconf{'quotas'}};
                   7448:             foreach my $item (@items) {
                   7449:                 if (ref($quotas{$item}) eq 'HASH') {
                   7450:                     foreach my $type (@insttypes,'default') {
                   7451:                         if ($item eq 'authorquota') {
                   7452:                             if ($quotas{$item}{$type} !~ /^\d+$/) {
                   7453:                                 $quotas{$item}{$type} = $staticdefaults{$item};
                   7454:                             }
                   7455:                         } elsif ($item eq 'webdav') {
                   7456:                             if ($quotas{$item}{$type} !~ /^(0|1)$/) {
                   7457:                                 $quotas{$item}{$type} = $staticdefaults{$item};
                   7458:                             }
                   7459:                         }
                   7460:                     }
                   7461:                 } else {
                   7462:                     foreach my $type (@insttypes,'default') {
                   7463:                         $quotas{$item}{$type} = $staticdefaults{$item};
                   7464:                     }
                   7465:                 }
                   7466:             }
                   7467:         } else {
                   7468:             foreach my $item (@items) {
                   7469:                 foreach my $type (@insttypes,'default') {
                   7470:                     $quotas{$item}{$type} = $staticdefaults{$item};
                   7471:                 }
                   7472:             }
                   7473:         }
                   7474:         if (ref($usertypes) eq 'HASH') {
                   7475:             my $numinrow = 4;
                   7476:             my $onclick = '';
                   7477:             $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
                   7478:                                          $numinrow,$othertitle,'authorquota',
                   7479:                                          \$itemcount,$onclick);
                   7480:             $itemcount ++;
                   7481:             $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
                   7482:                                          $numinrow,$othertitle,'webdav',
                   7483:                                          \$itemcount);
                   7484:             $itemcount ++;
                   7485:         }
                   7486:         my $checkedno = ' checked="checked"';
                   7487:         my ($checkedon,$checkedoff);
                   7488:         if (ref($quotas{'webdav'}) eq 'HASH') {
1.436     raeburn  7489:             if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429     raeburn  7490:                 if ($quotas{'webdav'}{'_LC_adv'}) {
                   7491:                     $checkedon = $checkedno;
                   7492:                 } else {
                   7493:                     $checkedoff = $checkedno;
                   7494:                 }
                   7495:                 undef($checkedno);
                   7496:             }
                   7497:         }
                   7498:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7499:         $datatable .= '<tr'.$css_class.'>'.
                   7500:                       '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
                   7501:                              $titles{'webdav_LC_adv_over'}.
                   7502:                       '</td>'.
                   7503:                       '<td class="LC_left_item">';
                   7504:         foreach my $option ('none','off','on') {
                   7505:             my ($text,$val,$checked);
                   7506:             if ($option eq 'none') {
                   7507:                 $text = $titles{'none'};
                   7508:                 $val = '';
                   7509:                 $checked = $checkedno;
                   7510:             } elsif ($option eq 'off') {
                   7511:                 $text = $titles{'overoff'};
                   7512:                 $val = 0;
                   7513:                 $checked = $checkedoff;
                   7514:             } elsif ($option eq 'on') {
                   7515:                 $text = $titles{'overon'};
                   7516:                 $val = 1;
                   7517:                 $checked = $checkedon;
1.436     raeburn  7518:             }
1.429     raeburn  7519:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7520:                           '<input type="radio" name="webdav_LC_adv"'.
                   7521:                           ' value="'.$val.'"'.$checked.' />'.
                   7522:                           $text.'</label></span>&nbsp; ';
                   7523:         }
                   7524:         $datatable .= '</td></tr>';
                   7525:         $itemcount ++;
                   7526:     }
                   7527:     $$rowtotal += $itemcount;
                   7528:     return $datatable;
                   7529: }
                   7530: 
                   7531: sub authordefaults_titles {
                   7532:     return &Apache::lonlocal::texthash(
                   7533:                copyright => 'Copyright/Distribution',
                   7534:                sourceavail => ' Source Available',
                   7535:                editors => 'Available Editors',
                   7536:                webdav => 'WebDAV',
                   7537:                authorquota => 'Authoring Space quotas (MB)',
                   7538:                nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437     raeburn  7539:                daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429     raeburn  7540:                domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
                   7541:                edit  => 'Standard editor (Edit)',
                   7542:                xml   => 'Text editor (EditXML)',
                   7543:                daxe  => 'Daxe editor (Daxe)',
                   7544:                webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
                   7545:                webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
                   7546:                none => 'No override set',
                   7547:                overon => 'Override -- webDAV on',
1.436     raeburn  7548:                overoff => 'Override -- webDAV off',
1.429     raeburn  7549:     );
                   7550: }
                   7551: 
                   7552: sub selectbox {
                   7553:     my ($name,$value,$readonly,$functionref,@idlist)=@_;
                   7554:     my $selout = '<select name="'.$name.'">';
                   7555:     foreach my $id (@idlist) {
                   7556:         $selout.='<option value="'.$id.'"';
                   7557:         if ($id eq $value) {
                   7558:             $selout.=' selected="selected"';
                   7559:         }
                   7560:         if ($readonly) {
                   7561:             $selout .= ' disabled="disabled"';
                   7562:         }
                   7563:         $selout.='>'.&{$functionref}($id).'</option>';
                   7564:     }
                   7565:     $selout.='</select>';
                   7566:     return $selout;
                   7567: }
                   7568: 
1.231     raeburn  7569: sub print_selfenrollment {
                   7570:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7571:     my ($css_class,$datatable);
                   7572:     my $itemcount = 1;
1.271     raeburn  7573:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  7574:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  7575:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   7576:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  7577:         my @rows;
                   7578:         my $key;
                   7579:         if ($position eq 'top') {
                   7580:             $key = 'admin'; 
                   7581:             if (ref($rowsref) eq 'ARRAY') {
                   7582:                 @rows = @{$rowsref};
                   7583:             }
                   7584:         } elsif ($position eq 'middle') {
                   7585:             $key = 'default';
                   7586:             @rows = ('types','registered','approval','limit');
                   7587:         }
                   7588:         foreach my $row (@rows) {
                   7589:             if (defined($titlesref->{$row})) {
                   7590:                 $itemcount ++;
                   7591:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7592:                 $datatable .= '<tr'.$css_class.'>'.
                   7593:                               '<td>'.$titlesref->{$row}.'</td>'.
                   7594:                               '<td class="LC_left_item">'.
                   7595:                               '<table><tr>';
                   7596:                 my (%current,%currentcap);
                   7597:                 if (ref($settings) eq 'HASH') {
                   7598:                     if (ref($settings->{$key}) eq 'HASH') {
                   7599:                         foreach my $type (@types) {
                   7600:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7601:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   7602:                             }
                   7603:                             if (($row eq 'limit') && ($key eq 'default')) {
                   7604:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7605:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   7606:                                 }
                   7607:                             }
                   7608:                         }
                   7609:                     }
                   7610:                 }
                   7611:                 my %roles = (
                   7612:                              '0' => &Apache::lonnet::plaintext('dc'),
                   7613:                             ); 
                   7614:             
                   7615:                 foreach my $type (@types) {
                   7616:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   7617:                         $datatable .= '<th>'.&mt($type).'</th>';
                   7618:                     }
                   7619:                 }
                   7620:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   7621:                     $datatable .= '</tr><tr>';
                   7622:                 }
                   7623:                 foreach my $type (@types) {
                   7624:                     if ($type eq 'community') {
                   7625:                         $roles{'1'} = &mt('Community personnel');
                   7626:                     } else {
                   7627:                         $roles{'1'} = &mt('Course personnel');
                   7628:                     }
                   7629:                     $datatable .= '<td style="vertical-align: top">';
                   7630:                     if ($position eq 'top') {
                   7631:                         my %checked;
                   7632:                         if ($current{$type} eq '0') {
                   7633:                             $checked{'0'} = ' checked="checked"';
                   7634:                         } else {
                   7635:                             $checked{'1'} = ' checked="checked"';
                   7636:                         }
                   7637:                         foreach my $role ('1','0') {
                   7638:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7639:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   7640:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   7641:                                           $roles{$role}.'</label></span> ';
                   7642:                         }
                   7643:                     } else {
                   7644:                         if ($row eq 'types') {
                   7645:                             my %checked;
                   7646:                             if ($current{$type} =~ /^(all|dom)$/) {
                   7647:                                 $checked{$1} = ' checked="checked"';
                   7648:                             } else {
                   7649:                                 $checked{''} = ' checked="checked"';
                   7650:                             }
                   7651:                             foreach my $val ('','dom','all') {
                   7652:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7653:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7654:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7655:                             }
                   7656:                         } elsif ($row eq 'registered') {
                   7657:                             my %checked;
                   7658:                             if ($current{$type} eq '1') {
                   7659:                                 $checked{'1'} = ' checked="checked"';
                   7660:                             } else {
                   7661:                                 $checked{'0'} = ' checked="checked"';
                   7662:                             }
                   7663:                             foreach my $val ('0','1') {
                   7664:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7665:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7666:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7667:                             }
                   7668:                         } elsif ($row eq 'approval') {
                   7669:                             my %checked;
                   7670:                             if ($current{$type} =~ /^([12])$/) {
                   7671:                                 $checked{$1} = ' checked="checked"';
                   7672:                             } else {
                   7673:                                 $checked{'0'} = ' checked="checked"';
                   7674:                             }
                   7675:                             for my $val (0..2) {
                   7676:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7677:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7678:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7679:                             }
                   7680:                         } elsif ($row eq 'limit') {
                   7681:                             my %checked;
                   7682:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   7683:                                 $checked{$1} = ' checked="checked"';
                   7684:                             } else {
                   7685:                                 $checked{'none'} = ' checked="checked"';
                   7686:                             }
                   7687:                             my $cap;
                   7688:                             if ($currentcap{$type} =~ /^\d+$/) {
                   7689:                                 $cap = $currentcap{$type};
                   7690:                             }
                   7691:                             foreach my $val ('none','allstudents','selfenrolled') {
                   7692:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7693:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7694:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7695:                             }
                   7696:                             $datatable .= '<br />'.
                   7697:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   7698:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   7699:                                           '</span>'; 
                   7700:                         }
                   7701:                     }
                   7702:                     $datatable .= '</td>';
                   7703:                 }
                   7704:                 $datatable .= '</tr>';
                   7705:             }
                   7706:             $datatable .= '</table></td></tr>';
                   7707:         }
                   7708:     } elsif ($position eq 'bottom') {
1.235     raeburn  7709:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   7710:     }
                   7711:     $$rowtotal += $itemcount;
                   7712:     return $datatable;
                   7713: }
                   7714: 
                   7715: sub print_validation_rows {
                   7716:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   7717:     my ($itemsref,$namesref,$fieldsref);
                   7718:     if ($caller eq 'selfenroll') { 
                   7719:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   7720:     } elsif ($caller eq 'requestcourses') {
                   7721:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   7722:     }
                   7723:     my %currvalidation;
                   7724:     if (ref($settings) eq 'HASH') {
                   7725:         if (ref($settings->{'validation'}) eq 'HASH') {
                   7726:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  7727:         }
1.235     raeburn  7728:     }
                   7729:     my $datatable;
                   7730:     my $itemcount = 0;
                   7731:     foreach my $item (@{$itemsref}) {
                   7732:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7733:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7734:                       $namesref->{$item}.
                   7735:                       '</span></td>'.
                   7736:                       '<td class="LC_left_item">';
                   7737:         if (($item eq 'url') || ($item eq 'button')) {
                   7738:             $datatable .= '<span class="LC_nobreak">'.
                   7739:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   7740:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   7741:         } elsif ($item eq 'fields') {
                   7742:             my @currfields;
                   7743:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   7744:                 @currfields = @{$currvalidation{$item}};
                   7745:             }
                   7746:             foreach my $field (@{$fieldsref}) {
                   7747:                 my $check = '';
                   7748:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   7749:                     $check = ' checked="checked"';
                   7750:                 }
                   7751:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7752:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   7753:                               ' value="'.$field.'"'.$check.' />'.$field.
                   7754:                               '</label></span> ';
                   7755:             }
                   7756:         } elsif ($item eq 'markup') {
1.334     raeburn  7757:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235     raeburn  7758:                            $currvalidation{$item}.
1.231     raeburn  7759:                               '</textarea>';
1.235     raeburn  7760:         }
                   7761:         $datatable .= '</td></tr>'."\n";
                   7762:         if (ref($rowtotal)) {
1.231     raeburn  7763:             $itemcount ++;
                   7764:         }
                   7765:     }
1.235     raeburn  7766:     if ($caller eq 'requestcourses') {
                   7767:         my %currhash;
1.248     raeburn  7768:         if (ref($settings) eq 'HASH') {
                   7769:             if (ref($settings->{'validation'}) eq 'HASH') {
                   7770:                 if ($settings->{'validation'}{'dc'} ne '') {
                   7771:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   7772:                 }
1.235     raeburn  7773:             }
                   7774:         }
                   7775:         my $numinrow = 2;
                   7776:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   7777:                                                        'validationdc',%currhash);
1.247     raeburn  7778:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334     raeburn  7779:         $datatable .= '<tr'.$css_class.'><td>';
1.235     raeburn  7780:         if ($numdc > 1) {
1.247     raeburn  7781:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  7782:         } else {
1.247     raeburn  7783:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  7784:         }
1.247     raeburn  7785:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  7786:         $itemcount ++;
                   7787:     }
                   7788:     if (ref($rowtotal)) {
                   7789:         $$rowtotal += $itemcount;
                   7790:     }
1.231     raeburn  7791:     return $datatable;
                   7792: }
                   7793: 
1.357     raeburn  7794: sub print_privacy {
                   7795:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7796:     my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
                   7797:     my $itemcount = 0;
1.417     raeburn  7798:     if ($position eq 'top') {
                   7799:         $numinrow = 2;
                   7800:     } else {
1.357     raeburn  7801:         @items = ('domain','author','course','community');
                   7802:         %names = &Apache::lonlocal::texthash (
                   7803:                      domain => 'Assigned domain role(s)',
                   7804:                      author => 'Assigned co-author role(s)',
                   7805:                      course => 'Assigned course role(s)',
1.416     raeburn  7806:                      community => 'Assigned community role(s)',
1.357     raeburn  7807:                  );
                   7808:         $numinrow = 4;
                   7809:         ($othertitle,$usertypes,$types) =
                   7810:             &Apache::loncommon::sorted_inst_types($dom);
                   7811:     }
                   7812:     if (($position eq 'top') || ($position eq 'middle')) {
                   7813:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   7814:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   7815:         if ($position eq 'top') {
                   7816:             my %curr;
                   7817:             my @options = ('none','user','domain','auto');
                   7818:             my %titles = &Apache::lonlocal::texthash (
                   7819:                 none   => 'Not allowed',
                   7820:                 user   => 'User authorizes',
                   7821:                 domain => 'DC authorizes',
                   7822:                 auto   => 'Unrestricted',
                   7823:                 instdom => 'Other domain shares institution/provider',
                   7824:                 extdom => 'Other domain has different institution/provider',
1.418     raeburn  7825:                 notify => 'Notify when role needs authorization',
1.357     raeburn  7826:             );
                   7827:             my %names = &Apache::lonlocal::texthash (
                   7828:                 domain => 'Domain role',
                   7829:                 author => 'Co-author role',
                   7830:                 course => 'Course role',
                   7831:                 community => 'Community role',
                   7832:             );
                   7833:             my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7834:             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7835:             foreach my $domtype ('instdom','extdom') {
                   7836:                 my (%checked,$skip);
                   7837:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7838:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                   7839:                               '<td class="LC_left_item">';
                   7840:                 if ($domtype eq 'instdom') {
                   7841:                     unless (@instdoms > 1) {
                   7842:                         $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                   7843:                         $skip = 1;
                   7844:                     }
                   7845:                 } elsif ($domtype eq 'extdom') {
                   7846:                     if (keys(%by_location) == 0) {
                   7847:                         $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                   7848:                         $skip = 1;
                   7849:                     }
                   7850:                 }
                   7851:                 unless ($skip) {
                   7852:                     foreach my $roletype ('domain','author','course','community') {
                   7853:                         $checked{'auto'} = ' checked="checked"';
                   7854:                         if (ref($settings) eq 'HASH') {
                   7855:                             if (ref($settings->{approval}) eq 'HASH') {
                   7856:                                 if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                   7857:                                     if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                   7858:                                         $checked{$1} = ' checked="checked"';
                   7859:                                         $checked{'auto'} = '';
                   7860:                                     }
                   7861:                                 }
                   7862:                             }
                   7863:                         }
                   7864:                         $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                   7865:                         foreach my $option (@options) {
                   7866:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7867:                                           '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                   7868:                                           'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   7869:                                           '</label></span>&nbsp; ';
                   7870:                         }
                   7871:                         $datatable .= '</fieldset>';
                   7872:                     }
                   7873:                 }
                   7874:                 $datatable .= '</td></tr>';
                   7875:                 $itemcount ++;
                   7876:             }
1.417     raeburn  7877:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7878:             $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
                   7879:                           '<td class="LC_left_item">';
                   7880:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   7881:                 my %curr;
                   7882:                 if (ref($settings) eq 'HASH') {
                   7883:                     if ($settings->{'notify'} ne '') {
                   7884:                         map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
                   7885:                     }
                   7886:                 }
                   7887:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7888:                 my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
                   7889:                                                              'privacy_notify',%curr);
                   7890:                 if ($numdc > 0) {
                   7891:                     $datatable .= $table;
                   7892:                 } else {
                   7893:                     $datatable .= &mt('There are no active Domain Coordinators');
                   7894:                 }
                   7895:             } else {
                   7896:                 $datatable .= &mt('Nothing to set here, as there are no other domains');
                   7897:             }
                   7898:             $datatable .='</td></tr>';
1.357     raeburn  7899:         } elsif ($position eq 'middle') {
                   7900:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   7901:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7902:                     foreach my $item (@{$types}) {
                   7903:                         $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                   7904:                                                                $numinrow,$itemcount,'','','','','',
                   7905:                                                                '',$usertypes->{$item});
                   7906:                         $itemcount ++;
                   7907:                     }
                   7908:                 }
                   7909:                 $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                   7910:                                                        $numinrow,$itemcount,'','','','','',
                   7911:                                                        '',$othertitle);
                   7912:                 $itemcount ++;
                   7913:             } else {
1.360     raeburn  7914:                 my (@insttypes,%insttitles);
                   7915:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7916:                     @insttypes = @{$types};
                   7917:                     %insttitles = %{$usertypes};
                   7918:                 }
                   7919:                 foreach my $item (@insttypes,'default') {
                   7920:                     my $title;
                   7921:                     if ($item eq 'default') {
                   7922:                         $title = $othertitle;
                   7923:                     } else {
                   7924:                         $title = $insttitles{$item};
                   7925:                     }
                   7926:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7927:                     $datatable .= '<tr'.$css_class.'>'.
                   7928:                                   '<td class="LC_left_item">'.$title.'</td>'.
                   7929:                                   '<td class="LC_left_item">'.
                   7930:                                   &mt('Nothing to set here, as there are no other domains').
                   7931:                                   '</td></tr>';
                   7932:                     $itemcount ++;
                   7933:                 }
1.357     raeburn  7934:             }
                   7935:         }
                   7936:     } else {
                   7937:         my $prefix;
                   7938:         if ($position eq 'lower') {
                   7939:             $prefix = 'priv';
                   7940:         } else {
                   7941:             $prefix = 'unpriv';
                   7942:         }
                   7943:         foreach my $item (@items) {
                   7944:             $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                   7945:                                                    $numinrow,$itemcount,'','','','','',
                   7946:                                                    '',$names{$item});
                   7947:             $itemcount ++;
                   7948:         }
                   7949:     }
                   7950:     if (ref($rowtotal)) {
                   7951:         $$rowtotal += $itemcount;
                   7952:     }
                   7953:     return $datatable;
                   7954: }
                   7955: 
1.354     raeburn  7956: sub print_passwords {
                   7957:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   7958:     my ($datatable,$css_class);
                   7959:     my $itemcount = 0;
                   7960:     my %titles = &Apache::lonlocal::texthash (
                   7961:         captcha        => '"Forgot Password" CAPTCHA validation',
                   7962:         link           => 'Reset link expiration (hours)',
                   7963:         case           => 'Case-sensitive usernames/e-mail',
                   7964:         prelink        => 'Information required (form 1)',
                   7965:         postlink       => 'Information required (form 2)',
                   7966:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   7967:         customtext     => 'Domain specific text (HTML)',
                   7968:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   7969:         intauth_check  => 'Check bcrypt cost if authenticated',
                   7970:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   7971:         permanent      => 'Permanent e-mail address',
                   7972:         critical       => 'Critical notification address',
                   7973:         notify         => 'Notification address',
                   7974:         min            => 'Minimum password length',
                   7975:         max            => 'Maximum password length',
                   7976:         chars          => 'Required characters',
                   7977:         expire         => 'Password expiration (days)',
1.356     raeburn  7978:         numsaved       => 'Number of previous passwords to save and disallow reuse',
1.354     raeburn  7979:     );
                   7980:     if ($position eq 'top') {
                   7981:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7982:         my $shownlinklife = 2;
                   7983:         my $prelink = 'both';
                   7984:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   7985:         if (ref($settings) eq 'HASH') {
                   7986:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   7987:                 $shownlinklife = $settings->{resetlink};
                   7988:             }
                   7989:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   7990:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   7991:             }
                   7992:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   7993:                 $prelink = $settings->{resetprelink};
                   7994:             }
                   7995:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   7996:                 %postlink = %{$settings->{resetpostlink}};
                   7997:             }
                   7998:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   7999:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   8000:             }
                   8001:             if ($settings->{resetremove}) {
                   8002:                 $nostdtext = 1;
                   8003:             }
                   8004:             if ($settings->{resetcustom}) {
                   8005:                 $customurl = $settings->{resetcustom};
                   8006:             }
                   8007:         } else {
                   8008:             if (ref($types) eq 'ARRAY') {
                   8009:                 foreach my $item (@{$types}) {
                   8010:                     $casesens{$item} = 1;
                   8011:                     $postlink{$item} = ['username','email'];
                   8012:                 }
                   8013:             }
                   8014:             $casesens{'default'} = 1;
                   8015:             $postlink{'default'} = ['username','email'];
                   8016:             $prelink = 'both';
                   8017:             %emailsrc = (
                   8018:                           permanent => 1,
                   8019:                           critical  => 1,
                   8020:                           notify    => 1,
                   8021:             );
                   8022:         }
                   8023:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   8024:         $itemcount ++;
                   8025:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8026:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   8027:                       '<td class="LC_left_item">'.
                   8028:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   8029:                       'name="passwords_link" size="3" /></td></tr>';
                   8030:         $itemcount ++;
                   8031:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8032:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   8033:                       '<td class="LC_left_item">';
                   8034:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   8035:             foreach my $item (@{$types}) {
                   8036:                 my $checkedcase;
                   8037:                 if ($casesens{$item}) {
                   8038:                     $checkedcase = ' checked="checked"';
                   8039:                 }
                   8040:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   8041:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   8042:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369     raeburn  8043:                               '</span>&nbsp;&nbsp; ';
1.354     raeburn  8044:             }
                   8045:         }
                   8046:         my $checkedcase;
                   8047:         if ($casesens{'default'}) {
                   8048:             $checkedcase = ' checked="checked"';
                   8049:         }
                   8050:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   8051:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   8052:                       $othertitle.'</label></span></td>';
                   8053:         $itemcount ++;
                   8054:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8055:         my %checkedpre = (
                   8056:                              both => ' checked="checked"',
                   8057:                              either => '',
                   8058:                          );
                   8059:         if ($prelink eq 'either') {
                   8060:             $checkedpre{either} = ' checked="checked"';
                   8061:             $checkedpre{both} = '';
                   8062:         }
                   8063:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   8064:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8065:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   8066:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   8067:                       '<span class="LC_nobreak"><label>'.
                   8068:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   8069:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   8070:         $itemcount ++;
                   8071:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8072:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   8073:                       '<td class="LC_left_item">';
                   8074:         my %postlinked;
                   8075:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   8076:             foreach my $item (@{$types}) {
                   8077:                 undef(%postlinked);
                   8078:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   8079:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   8080:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   8081:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   8082:                 }
                   8083:                 foreach my $field ('email','username') {
                   8084:                     my $checked;
                   8085:                     if ($postlinked{$field}) {
                   8086:                         $checked = ' checked="checked"';
                   8087:                     }
                   8088:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   8089:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   8090:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   8091:                                   '<span>&nbsp;&nbsp; ';
                   8092:                 }
                   8093:                 $datatable .= '</fieldset>';
                   8094:             }
                   8095:         }
                   8096:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   8097:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   8098:         }
                   8099:         $datatable .= '<fieldset style="display: inline-block;">'.
                   8100:                       '<legend>'.$othertitle.'</legend>';
                   8101:         foreach my $field ('email','username') {
                   8102:             my $checked;
                   8103:             if ($postlinked{$field}) {
                   8104:                 $checked = ' checked="checked"';
                   8105:             }
                   8106:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8107:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   8108:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   8109:                           '<span>&nbsp;&nbsp; ';
                   8110:         }
                   8111:         $datatable .= '</fieldset></td></tr>';
                   8112:         $itemcount ++;
                   8113:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8114:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   8115:                       '<td class="LC_left_item">';
                   8116:         foreach my $type ('permanent','critical','notify') {
                   8117:             my $checkedemail;
                   8118:             if ($emailsrc{$type}) {
                   8119:                 $checkedemail = ' checked="checked"';
                   8120:             }
                   8121:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8122:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   8123:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   8124:                           '<span>&nbsp;&nbsp; ';
                   8125:         }
                   8126:         $datatable .= '</td></tr>';
                   8127:         $itemcount ++;
                   8128:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8129:         my $switchserver = &check_switchserver($dom,$confname);
                   8130:         my ($showstd,$noshowstd);
                   8131:         if ($nostdtext) {
                   8132:             $noshowstd = ' checked="checked"';
                   8133:         } else {
                   8134:             $showstd = ' checked="checked"';
                   8135:         }
                   8136:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   8137:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8138:                       &mt('Retain standard text:').
                   8139:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   8140:                       &mt('Yes').'</label>'.'&nbsp;'.
                   8141:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   8142:                       &mt('No').'</label></span><br />'.
                   8143:                       '<span class="LC_fontsize_small">'.
                   8144:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   8145:                       &mt('Include custom text:');
                   8146:         if ($customurl) {
1.369     raeburn  8147:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354     raeburn  8148:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   8149:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   8150:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   8151:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   8152:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   8153:         }
                   8154:         if ($switchserver) {
                   8155:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   8156:         } else {
                   8157:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   8158:                          '<input type="file" name="passwords_customfile" /></span>';
                   8159:         }
                   8160:         $datatable .= '</td></tr>';
                   8161:     } elsif ($position eq 'middle') {
                   8162:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   8163:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   8164:         my %defaults;
                   8165:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   8166:             %defaults = %{$domconf{'defaults'}};
                   8167:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   8168:                 $defaults{'intauth_cost'} = 10;
                   8169:             }
                   8170:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   8171:                 $defaults{'intauth_check'} = 0;
                   8172:             }
                   8173:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   8174:                 $defaults{'intauth_switch'} = 0;
                   8175:             }
                   8176:         } else {
                   8177:             %defaults = (
                   8178:                           'intauth_cost'   => 10,
                   8179:                           'intauth_check'  => 0,
                   8180:                           'intauth_switch' => 0,
                   8181:                         );
                   8182:         }
                   8183:         foreach my $item (@items) {
                   8184:             if ($itemcount%2) {
                   8185:                 $css_class = '';
                   8186:             } else {
                   8187:                 $css_class = ' class="LC_odd_row" ';
                   8188:             }
                   8189:             $datatable .= '<tr'.$css_class.'>'.
                   8190:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   8191:                           '</span></td><td class="LC_left_item" colspan="3">';
                   8192:             if ($item eq 'intauth_switch') {
                   8193:                 my @options = (0,1,2);
                   8194:                 my %optiondesc = &Apache::lonlocal::texthash (
                   8195:                                    0 => 'No',
                   8196:                                    1 => 'Yes',
                   8197:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   8198:                                  );
                   8199:                 $datatable .= '<table width="100%">';
                   8200:                 foreach my $option (@options) {
                   8201:                     my $checked = ' ';
                   8202:                     if ($defaults{$item} eq $option) {
                   8203:                         $checked = ' checked="checked"';
                   8204:                     }
                   8205:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   8206:                                   '<label><input type="radio" name="'.$item.
                   8207:                                   '" value="'.$option.'"'.$checked.' />'.
                   8208:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   8209:                 }
                   8210:                 $datatable .= '</table>';
                   8211:             } elsif ($item eq 'intauth_check') {
                   8212:                 my @options = (0,1,2);
                   8213:                 my %optiondesc = &Apache::lonlocal::texthash (
                   8214:                                    0 => 'No',
                   8215:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   8216:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   8217:                                  );
                   8218:                 $datatable .= '<table width="100%">';
                   8219:                 foreach my $option (@options) {
                   8220:                     my $checked = ' ';
                   8221:                     my $onclick;
                   8222:                     if ($defaults{$item} eq $option) {
                   8223:                         $checked = ' checked="checked"';
                   8224:                     }
                   8225:                     if ($option == 2) {
                   8226:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   8227:                     }
                   8228:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   8229:                                   '<label><input type="radio" name="'.$item.
                   8230:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   8231:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   8232:                 }
                   8233:                 $datatable .= '</table>';
                   8234:             } else {
                   8235:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   8236:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   8237:             }
                   8238:             $datatable .= '</td></tr>';
                   8239:             $itemcount ++;
                   8240:         }
                   8241:     } elsif ($position eq 'lower') {
1.405     raeburn  8242:         $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354     raeburn  8243:     } else {
1.359     raeburn  8244:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   8245:         my %ownerchg = (
                   8246:                           by  => {},
                   8247:                           for => {},
                   8248:                        );
                   8249:         my %ownertitles = &Apache::lonlocal::texthash (
                   8250:                             by  => 'Course owner status(es) allowed',
                   8251:                             for => 'Student status(es) allowed',
                   8252:                           );
1.354     raeburn  8253:         if (ref($settings) eq 'HASH') {
1.359     raeburn  8254:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   8255:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   8256:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   8257:                 }
                   8258:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   8259:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   8260:                 }
1.354     raeburn  8261:             }
                   8262:         }
                   8263:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8264:         $datatable .= '<tr '.$css_class.'>'.
                   8265:                       '<td>'.
                   8266:                       &mt('Requirements').'<ul>'.
1.359     raeburn  8267:                       '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354     raeburn  8268:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   8269:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359     raeburn  8270:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354     raeburn  8271:                       '</ul>'.
                   8272:                       '</td>'.
1.359     raeburn  8273:                       '<td class="LC_left_item">';
                   8274:         foreach my $item ('by','for') {
                   8275:             $datatable .= '<fieldset style="display: inline-block;">'.
                   8276:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   8277:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   8278:                 foreach my $type (@{$types}) {
                   8279:                     my $checked;
                   8280:                     if ($ownerchg{$item}{$type}) {
                   8281:                         $checked = ' checked="checked"';
                   8282:                     }
                   8283:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   8284:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   8285:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369     raeburn  8286:                                   '</span>&nbsp;&nbsp; ';
1.359     raeburn  8287:                 }
                   8288:             }
                   8289:             my $checked;
                   8290:             if ($ownerchg{$item}{'default'}) {
                   8291:                 $checked = ' checked="checked"';
                   8292:             }
                   8293:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   8294:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   8295:                           $othertitle.'</label></span></fieldset>';
                   8296:         }
                   8297:         $datatable .= '</td></tr>';
1.354     raeburn  8298:     }
                   8299:     return $datatable;
                   8300: }
                   8301: 
1.405     raeburn  8302: sub password_rules {
                   8303:     my ($prefix,$itemcountref,$settings) = @_;
                   8304:     my ($min,$max,%chars,$expire,$numsaved,$numinrow);
                   8305:     my %titles;
                   8306:     if ($prefix eq 'passwords') {
                   8307:         %titles = &Apache::lonlocal::texthash (
                   8308:             min            => 'Minimum password length',
                   8309:             max            => 'Maximum password length',
                   8310:             chars          => 'Required characters',
                   8311:         );
1.421     raeburn  8312:     } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405     raeburn  8313:         %titles = &Apache::lonlocal::texthash (
                   8314:             min            => 'Minimum secret length',
                   8315:             max            => 'Maximum secret length',
                   8316:             chars          => 'Required characters',
                   8317:         );
                   8318:     }
                   8319:     $min = $Apache::lonnet::passwdmin;
                   8320:     my $datatable;
                   8321:     my $itemcount;
                   8322:     if (ref($itemcountref)) {
                   8323:         $itemcount = $$itemcountref;
                   8324:     }
                   8325:     if (ref($settings) eq 'HASH') {
                   8326:         if ($settings->{min}) {
                   8327:             $min = $settings->{min};
                   8328:         }
                   8329:         if ($settings->{max}) {
                   8330:             $max = $settings->{max};
                   8331:         }
                   8332:         if (ref($settings->{chars}) eq 'ARRAY') {
                   8333:             map { $chars{$_} = 1; } (@{$settings->{chars}});
                   8334:         }
1.425     raeburn  8335:         if ($prefix eq 'passwords') {
1.405     raeburn  8336:             if ($settings->{expire}) {
                   8337:                 $expire = $settings->{expire};
                   8338:             }
                   8339:             if ($settings->{numsaved}) {
                   8340:                 $numsaved = $settings->{numsaved};
                   8341:             }
                   8342:         }
                   8343:     }
                   8344:     my %rulenames = &Apache::lonlocal::texthash(
                   8345:                                                  uc => 'At least one upper case letter',
                   8346:                                                  lc => 'At least one lower case letter',
                   8347:                                                  num => 'At least one number',
                   8348:                                                  spec => 'At least one non-alphanumeric',
                   8349:                                                );
                   8350:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8351:     $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   8352:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8353:                   '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
                   8354:                   'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8355:                   '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
                   8356:                   '</span></td></tr>';
                   8357:     $itemcount ++;
                   8358:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8359:     $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   8360:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8361:                   '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
                   8362:                   'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8363:                   '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   8364:                   '</span></td></tr>';
                   8365:     $itemcount ++;
                   8366:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8367:     $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   8368:                   '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   8369:                   '</span></td>';
                   8370:     my $numinrow = 2;
                   8371:     my @possrules = ('uc','lc','num','spec');
                   8372:     $datatable .= '<td class="LC_left_item"><table>';
                   8373:     for (my $i=0; $i<@possrules; $i++) {
                   8374:         my ($rem,$checked);
                   8375:         if ($chars{$possrules[$i]}) {
                   8376:             $checked = ' checked="checked"';
                   8377:         }
                   8378:         $rem = $i%($numinrow);
                   8379:         if ($rem == 0) {
                   8380:             if ($i > 0) {
                   8381:                 $datatable .= '</tr>';
                   8382:             }
                   8383:             $datatable .= '<tr>';
                   8384:         }
                   8385:         $datatable .= '<td><span class="LC_nobreak"><label>'.
                   8386:                       '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   8387:                       $rulenames{$possrules[$i]}.'</label></span></td>';
                   8388:     }
                   8389:     my $rem = @possrules%($numinrow);
                   8390:     my $colsleft = $numinrow - $rem;
                   8391:     if ($colsleft > 1 ) {
                   8392:         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8393:                       '&nbsp;</td>';
                   8394:     } elsif ($colsleft == 1) {
                   8395:         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   8396:     }
                   8397:     $datatable .='</table></td></tr>';
                   8398:     $itemcount ++;
                   8399:     if ($prefix eq 'passwords') {
                   8400:         $titles{'expire'} = &mt('Password expiration (days)');
                   8401:         $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
                   8402:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8403:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                   8404:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8405:                       '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
                   8406:                       'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8407:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                   8408:                       '</span></td></tr>';
                   8409:         $itemcount ++;
                   8410:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8411:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   8412:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8413:                       '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
                   8414:                       'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8415:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   8416:                       '</span></td></tr>';
                   8417:         $itemcount ++;
                   8418:     }
                   8419:     if (ref($itemcountref)) {
                   8420:         $$itemcountref += $itemcount;
                   8421:     }
                   8422:     return $datatable;
                   8423: }
                   8424: 
1.373     raeburn  8425: sub print_wafproxy {
                   8426:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8427:     my $css_class;
                   8428:     my $itemcount = 0;
                   8429:     my $datatable;
                   8430:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  8431:     my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374     raeburn  8432:     my %lt = &wafproxy_titles();
1.373     raeburn  8433:     foreach my $server (sort(keys(%servers))) {
                   8434:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381     raeburn  8435:         next if ($serverhome eq '');
1.373     raeburn  8436:         my $serverdom;
                   8437:         if ($serverhome ne $server) {
                   8438:             $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381     raeburn  8439:             if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
                   8440:                 $othercontrol{$server} = $serverdom;
                   8441:             }
1.373     raeburn  8442:         } else {
                   8443:             $serverdom = &Apache::lonnet::host_domain($server);
1.381     raeburn  8444:             next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373     raeburn  8445:             if ($serverdom ne $dom) {
                   8446:                 $othercontrol{$server} = $serverdom;
                   8447:             } else {
                   8448:                 $setdom = 1;
                   8449:                 if (ref($settings) eq 'HASH') {
                   8450:                     if (ref($settings->{'alias'}) eq 'HASH') {
                   8451:                         $aliases{$dom} = $settings->{'alias'};
1.381     raeburn  8452:                         if ($aliases{$dom} ne '') {
                   8453:                             $showdom = 1;
                   8454:                         }
1.373     raeburn  8455:                     }
1.388     raeburn  8456:                     if (ref($settings->{'saml'}) eq 'HASH') {
                   8457:                         $saml{$dom} = $settings->{'saml'};
                   8458:                     }
1.373     raeburn  8459:                 }
                   8460:             }
                   8461:         }
                   8462:     }
1.381     raeburn  8463:     if ($setdom) {
                   8464:         %{$values{$dom}} = ();
                   8465:         if (ref($settings) eq 'HASH') {
                   8466:             foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   8467:                 $values{$dom}{$item} = $settings->{$item};
                   8468:             }
                   8469:         }
                   8470:     }
1.373     raeburn  8471:     if (keys(%othercontrol)) {
                   8472:         %otherdoms = reverse(%othercontrol);
                   8473:         foreach my $domain (keys(%otherdoms)) {
                   8474:             %{$values{$domain}} = ();
                   8475:             my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383     raeburn  8476:             if (ref($config{'wafproxy'}) eq 'HASH') {
                   8477:                 $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425     raeburn  8478:                 if (exists($config{'wafproxy'}{'saml'})) {
1.388     raeburn  8479:                     $saml{$domain} = $config{'wafproxy'}{'saml'};
                   8480:                 }
1.383     raeburn  8481:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   8482:                     $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373     raeburn  8483:                 }
                   8484:             }
                   8485:         }
                   8486:     }
                   8487:     if ($position eq 'top') {
                   8488:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381     raeburn  8489:         my %aliasinfo;
1.373     raeburn  8490:         foreach my $server (sort(keys(%servers))) {
1.381     raeburn  8491:             $itemcount ++;
                   8492:             my $dom_in_effect;
                   8493:             my $aliasrows = '<tr>'.
1.383     raeburn  8494:                             '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433     raeburn  8495:                             &mt('Hostname').': '.
                   8496:                             '<span class="LC_nobreak LC_cusr_emph">'.
                   8497:                             &Apache::lonnet::hostname($server).
                   8498:                             '</span></td><td>&nbsp;</td>';
1.373     raeburn  8499:             if ($othercontrol{$server}) {
1.381     raeburn  8500:                 $dom_in_effect = $othercontrol{$server};
1.388     raeburn  8501:                 my ($current,$forsaml);
1.383     raeburn  8502:                 if (ref($aliases{$dom_in_effect}) eq 'HASH') {
                   8503:                     $current = $aliases{$dom_in_effect}{$server};
1.373     raeburn  8504:                 }
1.388     raeburn  8505:                 if (ref($saml{$dom_in_effect}) eq 'HASH') {
                   8506:                     if ($saml{$dom_in_effect}{$server}) {
                   8507:                         $forsaml = 1;
                   8508:                     }
                   8509:                 }
1.383     raeburn  8510:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8511:                               &mt('Alias').':&nbsp';
1.373     raeburn  8512:                 if ($current) {
1.381     raeburn  8513:                     $aliasrows .= $current;
1.388     raeburn  8514:                     if ($forsaml) {
1.396     raeburn  8515:                          $aliasrows .= '&nbsp;('.&mt('also for SSO Auth').')';
1.388     raeburn  8516:                     }
1.373     raeburn  8517:                 } else {
1.383     raeburn  8518:                     $aliasrows .= &mt('None');
1.373     raeburn  8519:                 }
1.383     raeburn  8520:                 $aliasrows .= '&nbsp;<span class="LC_small">('.
                   8521:                               &mt('controlled by domain: [_1]',
                   8522:                                   '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373     raeburn  8523:             } else {
1.381     raeburn  8524:                 $dom_in_effect = $dom;
1.388     raeburn  8525:                 my ($current,$samlon,$samloff);
                   8526:                 $samloff = ' checked="checked"';
1.373     raeburn  8527:                 if (ref($aliases{$dom}) eq 'HASH') {
                   8528:                     if ($aliases{$dom}{$server}) {
                   8529:                         $current = $aliases{$dom}{$server};
                   8530:                     }
                   8531:                 }
1.388     raeburn  8532:                 if (ref($saml{$dom}) eq 'HASH') {
                   8533:                     if ($saml{$dom}{$server}) {
                   8534:                         $samlon = $samloff;
                   8535:                         undef($samloff);
                   8536:                     }
                   8537:                 }
1.383     raeburn  8538:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8539:                               &mt('Alias').':&nbsp;'.
1.381     raeburn  8540:                               '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388     raeburn  8541:                               'value="'.$current.'" size="30" />'.
                   8542:                               ('&nbsp;'x2).'<span class="LC_nobreak">'.
1.396     raeburn  8543:                               &mt('Alias used for SSO Auth').':&nbsp;<label>'.
1.388     raeburn  8544:                               '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425     raeburn  8545:                               &mt('No').'</label>&nbsp;<label>'.
1.388     raeburn  8546:                               '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
                   8547:                               &mt('Yes').'</label></span>'.
1.425     raeburn  8548:                               '</td>';
1.381     raeburn  8549:             }
                   8550:             $aliasrows .= '</tr>';
                   8551:             $aliasinfo{$dom_in_effect} .= $aliasrows;
                   8552:         }
                   8553:         if ($aliasinfo{$dom}) {
                   8554:             my ($onclick,$wafon,$wafoff,$showtable);
                   8555:             $onclick = ' onclick="javascript:toggleWAF();"';
                   8556:             $wafoff = ' checked="checked"';
                   8557:             $showtable = ' style="display:none";';
                   8558:             if ($showdom) {
                   8559:                 $wafon = $wafoff;
                   8560:                 $wafoff = '';
                   8561:                 $showtable = ' style="display:inline;"';
                   8562:             }
                   8563:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8564:             $datatable = '<tr'.$css_class.'>'.
                   8565:                          '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
                   8566:                          '<span class="LC_nobreak">'.&mt('WAF in use?').'&nbsp;<label>'.
                   8567:                          '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
                   8568:                          &mt('Yes').'</label>'.('&nbsp;'x2).'<label>'.
                   8569:                          '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
                   8570:                          &mt('No').'</label></span></td>'.
                   8571:                          '<td class="LC_left_item">'.
                   8572:                          '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
                   8573:                          '</table></td></tr>';
                   8574:             $itemcount++;
                   8575:         }
1.383     raeburn  8576:         if (keys(%otherdoms)) {
                   8577:             foreach my $key (sort(keys(%otherdoms))) {
1.381     raeburn  8578:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383     raeburn  8579:                 $datatable .= '<tr'.$css_class.'>'.
                   8580:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
                   8581:                               '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
                   8582:                               '</table></td></tr>';
1.381     raeburn  8583:                 $itemcount++;
1.373     raeburn  8584:             }
                   8585:         }
                   8586:     } else {
1.383     raeburn  8587:         my %ip_methods = &remoteip_methods();
1.373     raeburn  8588:         if ($setdom) {
                   8589:             $itemcount ++;
                   8590:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381     raeburn  8591:             my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382     raeburn  8592:                 $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381     raeburn  8593:             $wafstyle = ' style="display:none;"';
                   8594:             $nowafstyle = ' style="display:table-row;"';
                   8595:             $currwafdisplay = ' style="display: none"';
                   8596:             $wafrangestyle = ' style="display: none"';
                   8597:             $curr_remotip = 'n';
1.382     raeburn  8598:             $ssltossl = ' checked="checked"';
1.381     raeburn  8599:             if ($showdom) {
                   8600:                 $wafstyle = ' style="display:table-row;"';
                   8601:                 $nowafstyle =  ' style="display:none;"';
                   8602:                 if (keys(%{$values{$dom}})) {
                   8603:                     if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
                   8604:                         $curr_remotip = $values{$dom}{remoteip};
                   8605:                     }
                   8606:                     if ($curr_remotip eq 'h') {
                   8607:                         $currwafdisplay = ' style="display:table-row"';
                   8608:                         $wafrangestyle = ' style="display:inline-block;"';
                   8609:                     }
1.382     raeburn  8610:                     if ($values{$dom}{'sslopt'}) {
                   8611:                         $alltossl = ' checked="checked"';
                   8612:                         $ssltossl = '';
                   8613:                     }
1.381     raeburn  8614:                 }
                   8615:                 if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
                   8616:                     $vpndircheck = ' checked="checked"';
                   8617:                     $currwafvpn = ' style="display:table-row;"';
                   8618:                     $wafrangestyle = ' style="display:inline-block;"';
                   8619:                 } else {
                   8620:                     $vpnaliascheck = ' checked="checked"';
                   8621:                     $currwafvpn = ' style="display:none;"';
                   8622:                 }
                   8623:             }
                   8624:             $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                   8625:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
                   8626:                           '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
                   8627:                           '</tr>'.
                   8628:                           '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374     raeburn  8629:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381     raeburn  8630:                           '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393     raeburn  8631:                           &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   8632:                           &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381     raeburn  8633:                           '<td class="LC_left_item"><table>'.
                   8634:                           '<tr>'.
                   8635:                           '<td valign="top">'.$lt{'remoteip'}.':&nbsp;'.
                   8636:                           '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
                   8637:             foreach my $option ('m','h','n') {
                   8638:                 my $sel;
                   8639:                 if ($option eq $curr_remotip) {
                   8640:                    $sel = ' selected="selected"';
                   8641:                 }
                   8642:                 $datatable .= '<option value="'.$option.'"'.$sel.'>'.
                   8643:                               $ip_methods{$option}.'</option>';
                   8644:             }
                   8645:             $datatable .= '</select></td></tr>'."\n".
                   8646:                           '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
                   8647:                           $lt{'ipheader'}.':&nbsp;'.
                   8648:                           '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
                   8649:                           'name="wafproxy_ipheader" />'.
                   8650:                           '</td></tr>'."\n".
                   8651:                           '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382     raeburn  8652:                           $lt{'trusted'}.':<br />'.
1.381     raeburn  8653:                           '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
                   8654:                           $values{$dom}{'trusted'}.'</textarea>'.
                   8655:                           '</td></tr>'."\n".
                   8656:                           '<tr><td><hr /></td></tr>'."\n".
                   8657:                           '<tr>'.
                   8658:                           '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
                   8659:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
                   8660:                           $lt{'vpndirect'}.'</label>'.('&nbsp;'x2).
                   8661:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
                   8662:                           $lt{'vpnaliased'}.'</label></span></td></tr>';
                   8663:             foreach my $item ('vpnint','vpnext') {
                   8664:                 $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382     raeburn  8665:                               '<td valign="top">'.$lt{$item}.':<br />'.
1.381     raeburn  8666:                               '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
                   8667:                               $values{$dom}{$item}.'</textarea>'.
                   8668:                               '</td></tr>'."\n";
1.373     raeburn  8669:             }
1.382     raeburn  8670:             $datatable .= '<tr><td><hr /></td></tr>'."\n".
                   8671:                           '<tr>'.
                   8672:                           '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
                   8673:                           '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
                   8674:                           $lt{'alltossl'}.'</label>'.('&nbsp;'x2).
                   8675:                           '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
                   8676:                           $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
                   8677:                           '</table></td></tr>';
1.373     raeburn  8678:         }
                   8679:         if (keys(%otherdoms)) {
                   8680:             foreach my $domain (sort(keys(%otherdoms))) {
                   8681:                 $itemcount ++;
                   8682:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8683:                 $datatable .= '<tr'.$css_class.'>'.
1.383     raeburn  8684:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374     raeburn  8685:                               '<td class="LC_left_item"><table>';
1.382     raeburn  8686:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  8687:                     my $showval = &mt('None');
1.382     raeburn  8688:                     if ($item eq 'ssl') {
                   8689:                         $showval = $lt{'ssltossl'};
                   8690:                     }
1.373     raeburn  8691:                     if ($values{$domain}{$item}) {
1.381     raeburn  8692:                         $showval = $values{$domain}{$item};
1.382     raeburn  8693:                         if ($item eq 'ssl') {
                   8694:                             $showval = $lt{'alltossl'};
1.383     raeburn  8695:                         } elsif ($item eq 'remoteip') {
                   8696:                             $showval = $ip_methods{$values{$domain}{$item}};
1.382     raeburn  8697:                         }
1.373     raeburn  8698:                     }
                   8699:                     $datatable .= '<tr>'.
                   8700:                                   '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';
                   8701:                 }
1.381     raeburn  8702:                 $datatable .= '</table></td></tr>';
1.373     raeburn  8703:             }
                   8704:         }
                   8705:     }
                   8706:     $$rowtotal += $itemcount;
                   8707:     return $datatable;
                   8708: }
                   8709: 
                   8710: sub wafproxy_titles {
                   8711:     return &Apache::lonlocal::texthash(
1.381     raeburn  8712:                remoteip   => "Method for determining user's IP",
                   8713:                ipheader   => 'Request header containing remote IP',
                   8714:                trusted    => 'Trusted IP range(s)',
                   8715:                vpnaccess  => 'Access from institutional VPN',
                   8716:                vpndirect  => 'via regular hostname (no WAF)',
                   8717:                vpnaliased => 'via aliased hostname (WAF)',
                   8718:                vpnint     => 'Internal IP Range(s) for VPN sessions',
                   8719:                vpnext     => 'IP Range(s) for backend WAF connections',
1.382     raeburn  8720:                sslopt     => 'Forwarding http/https',
1.381     raeburn  8721:                alltossl   => 'WAF forwards both http and https requests to https',
                   8722:                ssltossl   => 'WAF forwards http requests to http and https to https',
                   8723:            );
                   8724: }
                   8725: 
                   8726: sub remoteip_methods {
                   8727:     return &Apache::lonlocal::texthash(
                   8728:               m => 'Use Apache mod_remoteip',
                   8729:               h => 'Use headers parsed by LON-CAPA',
                   8730:               n => 'Not in use',
1.373     raeburn  8731:            );
                   8732: }
                   8733: 
1.137     raeburn  8734: sub print_usersessions {
                   8735:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  8736:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  8737:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8738:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  8739: 
                   8740:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  8741:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  8742:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  8743:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  8744:     if ($position eq 'top') {
1.152     raeburn  8745:         if (keys(%serverhomes) > 1) {
1.145     raeburn  8746:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.371     raeburn  8747:             my ($curroffloadnow,$curroffloadoth);
1.261     raeburn  8748:             if (ref($settings) eq 'HASH') {
                   8749:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   8750:                     $curroffloadnow = $settings->{'offloadnow'};
                   8751:                 }
1.371     raeburn  8752:                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   8753:                     $curroffloadoth = $settings->{'offloadoth'};
                   8754:                 }
1.261     raeburn  8755:             }
1.371     raeburn  8756:             my $other_insts = scalar(keys(%by_location));
                   8757:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   8758:                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  8759:         } else {
1.140     raeburn  8760:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  8761:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   8762:                           '</td></tr>';
1.140     raeburn  8763:         }
1.137     raeburn  8764:     } else {
1.279     raeburn  8765:         my %titles = &usersession_titles();
                   8766:         my ($prefix,@types);
                   8767:         if ($position eq 'bottom') {
                   8768:             $prefix = 'remote';
                   8769:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  8770:         } else {
1.279     raeburn  8771:             $prefix = 'hosted';
                   8772:             @types = ('excludedomain','includedomain');
                   8773:         }
                   8774:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8775:     }
                   8776:     $$rowtotal += $itemcount;
                   8777:     return $datatable;
                   8778: }
                   8779: 
                   8780: sub rules_by_location {
                   8781:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   8782:     my ($datatable,$itemcount,$css_class);
                   8783:     if (keys(%{$by_location}) == 0) {
                   8784:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8785:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   8786:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   8787:                      '</td></tr>';
                   8788:         $itemcount = 1;
                   8789:     } else {
                   8790:         $itemcount = 0;
                   8791:         my $numinrow = 5;
                   8792:         my (%current,%checkedon,%checkedoff);
                   8793:         my @locations = sort(keys(%{$by_location}));
                   8794:         foreach my $type (@{$types}) {
                   8795:             $checkedon{$type} = '';
                   8796:             $checkedoff{$type} = ' checked="checked"';
                   8797:         }
                   8798:         if (ref($settings) eq 'HASH') {
                   8799:             if (ref($settings->{$prefix}) eq 'HASH') {
                   8800:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   8801:                     $current{$key} = $settings->{$prefix}{$key};
                   8802:                     if ($key eq 'version') {
                   8803:                         if ($current{$key} ne '') {
1.145     raeburn  8804:                             $checkedon{$key} = ' checked="checked"';
                   8805:                             $checkedoff{$key} = '';
                   8806:                         }
1.279     raeburn  8807:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   8808:                         $checkedon{$key} = ' checked="checked"';
                   8809:                         $checkedoff{$key} = '';
1.137     raeburn  8810:                     }
                   8811:                 }
                   8812:             }
1.279     raeburn  8813:         }
                   8814:         foreach my $type (@{$types}) {
                   8815:             next if ($type ne 'version' && !@locations);
                   8816:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8817:             $datatable .= '<tr'.$css_class.'>
                   8818:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   8819:                            <span class="LC_nobreak">&nbsp;
                   8820:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   8821:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   8822:             if ($type eq 'version') {
                   8823:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   8824:                 my $selector = '<select name="'.$prefix.'_version">';
                   8825:                 foreach my $version (@lcversions) {
                   8826:                     my $selected = '';
                   8827:                     if ($current{'version'} eq $version) {
                   8828:                         $selected = ' selected="selected"';
1.145     raeburn  8829:                     }
1.279     raeburn  8830:                     $selector .= ' <option value="'.$version.'"'.
                   8831:                                  $selected.'>'.$version.'</option>';
                   8832:                 }
                   8833:                 $selector .= '</select> ';
                   8834:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   8835:             } else {
                   8836:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   8837:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   8838:                              ' />'.('&nbsp;'x2).
                   8839:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   8840:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   8841:                              "\n".
                   8842:                              '</div><div><table>';
                   8843:                 my $rem;
                   8844:                 for (my $i=0; $i<@locations; $i++) {
                   8845:                     my ($showloc,$value,$checkedtype);
                   8846:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   8847:                         my $ip = $by_location->{$locations[$i]}->[0];
                   8848:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8849:                             $value = join(':',@{$by_ip->{$ip}});
                   8850:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   8851:                             if (ref($current{$type}) eq 'ARRAY') {
                   8852:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   8853:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   8854:                                         $checkedtype = ' checked="checked"';
                   8855:                                         last;
1.145     raeburn  8856:                                     }
1.138     raeburn  8857:                                 }
                   8858:                             }
                   8859:                         }
1.137     raeburn  8860:                     }
1.279     raeburn  8861:                     $rem = $i%($numinrow);
                   8862:                     if ($rem == 0) {
                   8863:                         if ($i > 0) {
                   8864:                             $datatable .= '</tr>';
                   8865:                         }
                   8866:                         $datatable .= '<tr>';
                   8867:                     }
                   8868:                     $datatable .= '<td class="LC_left_item">'.
                   8869:                                   '<span class="LC_nobreak"><label>'.
                   8870:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   8871:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   8872:                                   '</label></span></td>';
                   8873:                 }
                   8874:                 $rem = @locations%($numinrow);
                   8875:                 my $colsleft = $numinrow - $rem;
                   8876:                 if ($colsleft > 1 ) {
                   8877:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8878:                                   '&nbsp;</td>';
                   8879:                 } elsif ($colsleft == 1) {
                   8880:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  8881:                 }
1.279     raeburn  8882:                 $datatable .= '</tr></table>';
1.137     raeburn  8883:             }
1.279     raeburn  8884:             $datatable .= '</td></tr>';
                   8885:             $itemcount ++;
1.137     raeburn  8886:         }
                   8887:     }
1.279     raeburn  8888:     return ($datatable,$itemcount);
1.137     raeburn  8889: }
                   8890: 
1.275     raeburn  8891: sub print_ssl {
                   8892:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8893:     my ($css_class,$datatable);
                   8894:     my $itemcount = 1;
                   8895:     if ($position eq 'top') {
1.281     raeburn  8896:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8897:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8898:         my $same_institution;
                   8899:         if ($intdom ne '') {
                   8900:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   8901:             if (ref($internet_names) eq 'ARRAY') {
                   8902:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   8903:                     $same_institution = 1;
                   8904:                 }
                   8905:             }
                   8906:         }
1.275     raeburn  8907:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  8908:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   8909:         if ($same_institution) {
                   8910:             my %domservers = &Apache::lonnet::get_servers($dom);
                   8911:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   8912:         } else {
                   8913:             $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
                   8914:         }
                   8915:         $datatable .= '</td></tr>';
1.275     raeburn  8916:         $itemcount ++;
                   8917:     } else {
                   8918:         my %titles = &ssl_titles();
                   8919:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   8920:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8921:         my @alldoms = &Apache::lonnet::all_domains();
                   8922:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   8923:         my @domservers = &Apache::lonnet::get_servers($dom);
                   8924:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8925:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  8926:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   8927:             my $legacy;
                   8928:             unless (ref($settings) eq 'HASH') {
                   8929:                 my $name;
                   8930:                 if ($position eq 'connto') {
                   8931:                     $name = 'loncAllowInsecure';
                   8932:                 } else {
                   8933:                     $name = 'londAllowInsecure';
                   8934:                 }
                   8935:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   8936:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8937:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   8938:                     my %what = (
                   8939:                                    $name => 1,
                   8940:                                );
                   8941:                     my ($result,$returnhash) =
                   8942:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   8943:                     if ($result eq 'ok') {
                   8944:                         if (ref($returnhash) eq 'HASH') {
                   8945:                             $legacy = $returnhash->{$name};
                   8946:                         }
                   8947:                     }
                   8948:                 } else {
                   8949:                     $legacy = $Apache::lonnet::perlvar{$name};
                   8950:                 }
                   8951:             }
1.275     raeburn  8952:             foreach my $type ('dom','intdom','other') {
                   8953:                 my %checked;
                   8954:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8955:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   8956:                               '<td class="LC_right_item">';
                   8957:                 my $skip; 
                   8958:                 if ($type eq 'dom') {
                   8959:                     unless (keys(%servers) > 1) {
                   8960:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   8961:                         $skip = 1;
                   8962:                     }
                   8963:                 }
                   8964:                 if ($type eq 'intdom') {
                   8965:                     unless (@instdoms > 1) {
                   8966:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   8967:                         $skip = 1;
                   8968:                     } 
                   8969:                 } elsif ($type eq 'other') {
                   8970:                     if (keys(%by_location) == 0) {
                   8971:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   8972:                         $skip = 1;
                   8973:                     }
                   8974:                 }
                   8975:                 unless ($skip) {
                   8976:                     $checked{'yes'} = ' checked="checked"'; 
                   8977:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  8978:                         if (ref($settings->{$position}) eq 'HASH') {
                   8979:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  8980:                                 $checked{$1} = $checked{'yes'};
                   8981:                                 delete($checked{'yes'}); 
                   8982:                             }
                   8983:                         }
1.293     raeburn  8984:                     } else {
                   8985:                         if ($legacy == 0) {
                   8986:                             $checked{'req'} = $checked{'yes'};
                   8987:                             delete($checked{'yes'});    
                   8988:                         }
1.275     raeburn  8989:                     }
                   8990:                     foreach my $option ('no','yes','req') {
                   8991:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  8992:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  8993:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   8994:                                       '</label></span>'.('&nbsp;'x2);
                   8995:                     }
                   8996:                 }
                   8997:                 $datatable .= '</td></tr>';
                   8998:                 $itemcount ++; 
                   8999:             }
                   9000:         } else {
                   9001:             my $prefix = 'replication';
                   9002:             my @types = ('certreq','nocertreq');
1.279     raeburn  9003:             if (keys(%by_location) == 0) {
                   9004:                 $datatable .= '<tr'.$css_class.'><td>'.
                   9005:                               &mt('Nothing to set here, as there are no other institutions').
                   9006:                               '</td></tr>';
                   9007:                 $itemcount ++;
1.275     raeburn  9008:             } else {
1.279     raeburn  9009:                 ($datatable,$itemcount) = 
                   9010:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  9011:             }
                   9012:         }
                   9013:     }
                   9014:     $$rowtotal += $itemcount;
                   9015:     return $datatable;
                   9016: }
                   9017: 
                   9018: sub ssl_titles {
                   9019:     return &Apache::lonlocal::texthash (
                   9020:                dom           => 'LON-CAPA servers/VMs from same domain',
                   9021:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   9022:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  9023:                connto        => 'Connections to other servers',
                   9024:                connfrom      => 'Connections from other servers',
1.275     raeburn  9025:                replication   => 'Replicating content to other institutions',
                   9026:                certreq       => 'Client certificate required, but specific domains exempt',
                   9027:                nocertreq     => 'No client certificate required, except for specific domains',
                   9028:                no            => 'SSL not used',
                   9029:                yes           => 'SSL Optional (used if available)',
                   9030:                req           => 'SSL Required',
                   9031:     );
1.279     raeburn  9032: }
                   9033: 
                   9034: sub print_trust {
                   9035:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   9036:     my ($css_class,$datatable,%checked,%choices);
                   9037:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   9038:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   9039:     my $itemcount = 1;
                   9040:     my %titles = &trust_titles();
                   9041:     my @types = ('exc','inc');
                   9042:     if ($prefix eq 'top') {
                   9043:         $prefix = 'content';
                   9044:     } elsif ($prefix eq 'bottom') {
                   9045:         $prefix = 'msg';
                   9046:     }
                   9047:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   9048:     $$rowtotal += $itemcount;
                   9049:     return $datatable;
                   9050: }
                   9051: 
                   9052: sub trust_titles {
                   9053:     return &Apache::lonlocal::texthash(
                   9054:                content  => "Access to this domain's content by others",
                   9055:                shared   => "Access to other domain's content by this domain",
                   9056:                enroll   => "Enrollment in this domain's courses by others", 
                   9057:                othcoau  => "Co-author roles in this domain for others",
                   9058:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   9059:                domroles => "Domain roles in this domain assignable to others",
                   9060:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   9061:                reqcrs   => "Requests for creation of courses in this domain by others",
                   9062:                msg      => "Users in other domains can send messages to this domain",
                   9063:                exc      => "Allow all, but exclude specific domains",
                   9064:                inc      => "Deny all, but include specific domains",
                   9065:            );
1.275     raeburn  9066: } 
                   9067: 
1.138     raeburn  9068: sub build_location_hashes {
1.275     raeburn  9069:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  9070:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  9071:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  9072:     my %iphost = &Apache::lonnet::get_iphost();
                   9073:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   9074:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   9075:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   9076:         foreach my $id (@{$iphost{$primary_ip}}) {
                   9077:             my $intdom = &Apache::lonnet::internet_dom($id);
                   9078:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   9079:                 push(@{$intdoms},$intdom);
                   9080:             }
                   9081:         }
                   9082:     }
                   9083:     foreach my $ip (keys(%iphost)) {
                   9084:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   9085:             foreach my $id (@{$iphost{$ip}}) {
                   9086:                 my $location = &Apache::lonnet::internet_dom($id);
                   9087:                 if ($location) {
1.275     raeburn  9088:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   9089:                         my $dom = &Apache::lonnet::host_domain($id);
                   9090:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   9091:                             push(@{$instdoms},$dom);
                   9092:                         }
                   9093:                         next;
                   9094:                     }
1.138     raeburn  9095:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   9096:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   9097:                             push(@{$by_ip->{$ip}},$location);
                   9098:                         }
                   9099:                     } else {
                   9100:                         $by_ip->{$ip} = [$location];
                   9101:                     }
                   9102:                 }
                   9103:             }
                   9104:         }
                   9105:     }
                   9106:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   9107:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   9108:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   9109:             my $first = $by_ip->{$ip}->[0];
                   9110:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   9111:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   9112:                     push(@{$by_location->{$first}},$ip);
                   9113:                 }
                   9114:             } else {
                   9115:                 $by_location->{$first} = [$ip];
                   9116:             }
                   9117:         }
                   9118:     }
                   9119:     return;
                   9120: }
                   9121: 
1.145     raeburn  9122: sub current_offloads_to {
                   9123:     my ($dom,$settings,$servers) = @_;
                   9124:     my (%spareid,%otherdomconfigs);
1.152     raeburn  9125:     if (ref($servers) eq 'HASH') {
1.145     raeburn  9126:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   9127:             my $gotspares;
1.152     raeburn  9128:             if (ref($settings) eq 'HASH') {
                   9129:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   9130:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   9131:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   9132:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   9133:                         $gotspares = 1;
                   9134:                     }
1.145     raeburn  9135:                 }
                   9136:             }
                   9137:             unless ($gotspares) {
                   9138:                 my $gotspares;
                   9139:                 my $serverhomeID =
                   9140:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   9141:                 my $serverhomedom =
                   9142:                     &Apache::lonnet::host_domain($serverhomeID);
                   9143:                 if ($serverhomedom ne $dom) {
                   9144:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   9145:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   9146:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   9147:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   9148:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   9149:                                 $gotspares = 1;
                   9150:                             }
                   9151:                         }
                   9152:                     } else {
                   9153:                         $otherdomconfigs{$serverhomedom} =
                   9154:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   9155:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   9156:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   9157:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   9158:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   9159:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   9160:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   9161:                                         $gotspares = 1;
                   9162:                                     }
                   9163:                                 }
                   9164:                             }
                   9165:                         }
                   9166:                     }
                   9167:                 }
                   9168:             }
                   9169:             unless ($gotspares) {
                   9170:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   9171:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   9172:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   9173:                } else {
                   9174:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   9175:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   9176:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   9177:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   9178:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   9179:                     } else {
1.150     raeburn  9180:                         my %what = (
                   9181:                              spareid => 1,
                   9182:                         );
                   9183:                         my ($result,$returnhash) = 
                   9184:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   9185:                         if ($result eq 'ok') { 
                   9186:                             if (ref($returnhash) eq 'HASH') {
                   9187:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   9188:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   9189:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   9190:                                 }
                   9191:                             }
1.145     raeburn  9192:                         }
                   9193:                     }
                   9194:                 }
                   9195:             }
                   9196:         }
                   9197:     }
                   9198:     return %spareid;
                   9199: }
                   9200: 
                   9201: sub spares_row {
1.371     raeburn  9202:     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   9203:         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  9204:     my $css_class;
                   9205:     my $numinrow = 4;
                   9206:     my $itemcount = 1;
                   9207:     my $datatable;
1.152     raeburn  9208:     my %typetitles = &sparestype_titles();
                   9209:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  9210:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  9211:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   9212:             my ($othercontrol,$serverdom);
                   9213:             if ($serverhome ne $server) {
                   9214:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   9215:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   9216:             } else {
                   9217:                 $serverdom = &Apache::lonnet::host_domain($server);
                   9218:                 if ($serverdom ne $dom) {
                   9219:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   9220:                 }
                   9221:             }
                   9222:             next unless (ref($spareid->{$server}) eq 'HASH');
1.371     raeburn  9223:             my ($checkednow,$checkedoth);
1.261     raeburn  9224:             if (ref($curroffloadnow) eq 'HASH') {
                   9225:                 if ($curroffloadnow->{$server}) {
                   9226:                     $checkednow = ' checked="checked"';
                   9227:                 }
                   9228:             }
1.371     raeburn  9229:             if (ref($curroffloadoth) eq 'HASH') {
                   9230:                 if ($curroffloadoth->{$server}) {
                   9231:                     $checkedoth = ' checked="checked"';
                   9232:                 }
                   9233:             }
1.145     raeburn  9234:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   9235:             $datatable .= '<tr'.$css_class.'>
                   9236:                            <td rowspan="2">
1.183     bisitz   9237:                             <span class="LC_nobreak">'.
                   9238:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  9239:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  9240:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  9241:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371     raeburn  9242:                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.183     bisitz   9243:                           "\n";
1.371     raeburn  9244:             if ($other_insts) {
                   9245:                 $datatable .= '<br />'.
                   9246:                               '<span class="LC_nobreak">'."\n".
                   9247:                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   9248:                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   9249:                           "\n";
                   9250:             }
1.145     raeburn  9251:             my (%current,%canselect);
1.152     raeburn  9252:             my @choices = 
                   9253:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   9254:             foreach my $type ('primary','default') {
                   9255:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  9256:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   9257:                         my @spares = @{$spareid->{$server}{$type}};
                   9258:                         if (@spares > 0) {
1.152     raeburn  9259:                             if ($othercontrol) {
                   9260:                                 $current{$type} = join(', ',@spares);
                   9261:                             } else {
                   9262:                                 $current{$type} .= '<table>';
                   9263:                                 my $numspares = scalar(@spares);
                   9264:                                 for (my $i=0;  $i<@spares; $i++) {
                   9265:                                     my $rem = $i%($numinrow);
                   9266:                                     if ($rem == 0) {
                   9267:                                         if ($i > 0) {
                   9268:                                             $current{$type} .= '</tr>';
                   9269:                                         }
                   9270:                                         $current{$type} .= '<tr>';
1.145     raeburn  9271:                                     }
1.152     raeburn  9272:                                     $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;'.
                   9273:                                                        $spareid->{$server}{$type}[$i].
                   9274:                                                        '</label></td>'."\n";
                   9275:                                 }
                   9276:                                 my $rem = @spares%($numinrow);
                   9277:                                 my $colsleft = $numinrow - $rem;
                   9278:                                 if ($colsleft > 1 ) {
                   9279:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   9280:                                                        '" class="LC_left_item">'.
                   9281:                                                        '&nbsp;</td>';
                   9282:                                 } elsif ($colsleft == 1) {
                   9283:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  9284:                                 }
1.152     raeburn  9285:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  9286:                             }
1.145     raeburn  9287:                         }
                   9288:                     }
                   9289:                     if ($current{$type} eq '') {
                   9290:                         $current{$type} = &mt('None specified');
                   9291:                     }
1.152     raeburn  9292:                     if ($othercontrol) {
                   9293:                         if ($type eq 'primary') {
                   9294:                             $canselect{$type} = $othercontrol;
                   9295:                         }
                   9296:                     } else {
                   9297:                         $canselect{$type} = 
                   9298:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   9299:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   9300:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   9301:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   9302:                         if (@choices > 0) {
                   9303:                             foreach my $lonhost (@choices) {
                   9304:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   9305:                             }
                   9306:                         }
                   9307:                         $canselect{$type} .= '</select>'."\n";
                   9308:                     }
                   9309:                 } else {
                   9310:                     $current{$type} = &mt('Could not be determined');
                   9311:                     if ($type eq 'primary') {
                   9312:                         $canselect{$type} =  $othercontrol;
                   9313:                     }
1.145     raeburn  9314:                 }
1.152     raeburn  9315:                 if ($type eq 'default') {
                   9316:                     $datatable .= '<tr'.$css_class.'>';
                   9317:                 }
                   9318:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   9319:                               '<td>'.$current{$type}.'</td>'."\n".
                   9320:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  9321:             }
                   9322:             $itemcount ++;
                   9323:         }
                   9324:     }
                   9325:     $$rowtotal += $itemcount;
                   9326:     return $datatable;
                   9327: }
                   9328: 
1.152     raeburn  9329: sub possible_newspares {
                   9330:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   9331:     my $serverhostname = &Apache::lonnet::hostname($server);
                   9332:     my %excluded;
                   9333:     if ($serverhostname ne '') {
                   9334:         %excluded = (
                   9335:                        $serverhostname => 1,
                   9336:                     );
                   9337:     }
                   9338:     if (ref($currspares) eq 'HASH') {
                   9339:         foreach my $type (keys(%{$currspares})) {
                   9340:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   9341:                 if (@{$currspares->{$type}} > 0) {
                   9342:                     foreach my $curr (@{$currspares->{$type}}) {
                   9343:                         my $hostname = &Apache::lonnet::hostname($curr);
                   9344:                         $excluded{$hostname} = 1;
                   9345:                     }
                   9346:                 }
                   9347:             }
                   9348:         }
                   9349:     }
                   9350:     my @choices;
                   9351:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   9352:         if (keys(%{$serverhomes}) > 1) {
                   9353:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   9354:                 unless ($excluded{$name}) {
                   9355:                     if (exists($altids->{$serverhomes->{$name}})) {
                   9356:                         push(@choices,$altids->{$serverhomes->{$name}});
                   9357:                     } else {
                   9358:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  9359:                     }
                   9360:                 }
                   9361:             }
                   9362:         }
                   9363:     }
1.152     raeburn  9364:     return sort(@choices);
1.145     raeburn  9365: }
                   9366: 
1.150     raeburn  9367: sub print_loadbalancing {
                   9368:     my ($dom,$settings,$rowtotal) = @_;
                   9369:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9370:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9371:     my $numinrow = 1;
                   9372:     my $datatable;
                   9373:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342     raeburn  9374:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  9375:     if (ref($settings) eq 'HASH') {
                   9376:         %existing = %{$settings};
                   9377:     }
                   9378:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   9379:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  9380:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  9381:     } else {
                   9382:         return;
                   9383:     }
                   9384:     my ($othertitle,$usertypes,$types) =
                   9385:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  9386:     my $rownum = 8;
1.150     raeburn  9387:     if (ref($types) eq 'ARRAY') {
                   9388:         $rownum += scalar(@{$types});
                   9389:     }
1.171     raeburn  9390:     my @css_class = ('LC_odd_row','LC_even_row');
                   9391:     my $balnum = 0;
                   9392:     my $islast;
                   9393:     my (@toshow,$disabledtext);
                   9394:     if (keys(%currbalancer) > 0) {
                   9395:         @toshow = sort(keys(%currbalancer));
                   9396:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   9397:             push(@toshow,'');
                   9398:         }
                   9399:     } else {
                   9400:         @toshow = ('');
                   9401:         $disabledtext = &mt('No existing load balancer');
                   9402:     }
                   9403:     foreach my $lonhost (@toshow) {
                   9404:         if ($balnum == scalar(@toshow)-1) {
                   9405:             $islast = 1;
                   9406:         } else {
                   9407:             $islast = 0;
                   9408:         }
                   9409:         my $cssidx = $balnum%2;
                   9410:         my $targets_div_style = 'display: none';
                   9411:         my $disabled_div_style = 'display: block';
                   9412:         my $homedom_div_style = 'display: none';
                   9413:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  9414:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  9415:                       '<p>';
                   9416:         if ($lonhost eq '') {
1.210     raeburn  9417:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  9418:             if (keys(%currbalancer) > 0) {
                   9419:                 $datatable .= &mt('Add balancer:');
                   9420:             } else {
                   9421:                 $datatable .= &mt('Enable balancer:');
                   9422:             }
                   9423:             $datatable .= '&nbsp;'.
                   9424:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   9425:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   9426:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   9427:                           '<option value="" selected="selected">'.&mt('None').
                   9428:                           '</option>'."\n";
                   9429:             foreach my $server (sort(keys(%servers))) {
                   9430:                 next if ($currbalancer{$server});
                   9431:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   9432:             }
1.210     raeburn  9433:             $datatable .=
1.171     raeburn  9434:                 '</select>'."\n".
                   9435:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   9436:         } else {
                   9437:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   9438:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   9439:                            &mt('Stop balancing').'</label>'.
                   9440:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   9441:             $targets_div_style = 'display: block';
                   9442:             $disabled_div_style = 'display: none';
                   9443:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   9444:                 $homedom_div_style = 'display: block';
                   9445:             }
                   9446:         }
1.306     raeburn  9447:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  9448:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   9449:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   9450:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   9451:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   9452:         my @sparestypes = ('primary','default');
                   9453:         my %typetitles = &sparestype_titles();
1.284     raeburn  9454:         my %hostherechecked = (
                   9455:                                   no => ' checked="checked"',
                   9456:                               );
1.342     raeburn  9457:         my %balcookiechecked = (
1.425     raeburn  9458:                                   no => ' checked="checked"',
1.342     raeburn  9459:                                );
1.171     raeburn  9460:         foreach my $sparetype (@sparestypes) {
                   9461:             my $targettable;
                   9462:             for (my $i=0; $i<$numspares; $i++) {
                   9463:                 my $checked;
                   9464:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   9465:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   9466:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   9467:                             $checked = ' checked="checked"';
                   9468:                         }
                   9469:                     }
                   9470:                 }
                   9471:                 my ($chkboxval,$disabled);
                   9472:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   9473:                     $chkboxval = $spares[$i];
                   9474:                 }
                   9475:                 if (exists($currbalancer{$spares[$i]})) {
                   9476:                     $disabled = ' disabled="disabled"';
                   9477:                 }
1.210     raeburn  9478:                 $targettable .=
1.253     raeburn  9479:                     '<td><span class="LC_nobreak"><label>'.
                   9480:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  9481:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
1.253     raeburn  9482:                     '</span></label></span></td>';
1.171     raeburn  9483:                 my $rem = $i%($numinrow);
                   9484:                 if ($rem == 0) {
                   9485:                     if (($i > 0) && ($i < $numspares-1)) {
                   9486:                         $targettable .= '</tr>';
                   9487:                     }
                   9488:                     if ($i < $numspares-1) {
                   9489:                         $targettable .= '<tr>';
1.150     raeburn  9490:                     }
                   9491:                 }
                   9492:             }
1.171     raeburn  9493:             if ($targettable ne '') {
                   9494:                 my $rem = $numspares%($numinrow);
                   9495:                 my $colsleft = $numinrow - $rem;
                   9496:                 if ($colsleft > 1 ) {
                   9497:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9498:                                     '&nbsp;</td>';
                   9499:                 } elsif ($colsleft == 1) {
                   9500:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   9501:                 }
                   9502:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   9503:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   9504:             }
1.284     raeburn  9505:             $hostherechecked{$sparetype} = '';
                   9506:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   9507:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   9508:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   9509:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   9510:                         $hostherechecked{'no'} = '';
                   9511:                     }
                   9512:                 }
                   9513:             }
                   9514:         }
1.342     raeburn  9515:         if ($currcookies{$lonhost}) {
                   9516:             %balcookiechecked = (
                   9517:                                     yes => ' checked="checked"',
                   9518:                                 );
                   9519:         }
1.284     raeburn  9520:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   9521:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   9522:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   9523:         foreach my $sparetype (@sparestypes) {
                   9524:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   9525:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   9526:                           '</i></label><br />';
1.171     raeburn  9527:         }
1.342     raeburn  9528:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   9529:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   9530:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   9531:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   9532:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   9533:                       '</div></td></tr>'.
1.171     raeburn  9534:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   9535:                                            $othertitle,$usertypes,$types,\%servers,
                   9536:                                            \%currbalancer,$lonhost,
                   9537:                                            $targets_div_style,$homedom_div_style,
                   9538:                                            $css_class[$cssidx],$balnum,$islast);
                   9539:         $$rowtotal += $rownum;
                   9540:         $balnum ++;
                   9541:     }
                   9542:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   9543:     return $datatable;
                   9544: }
                   9545: 
                   9546: sub get_loadbalancers_config {
1.342     raeburn  9547:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171     raeburn  9548:     return unless ((ref($servers) eq 'HASH') &&
                   9549:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342     raeburn  9550:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   9551:                    (ref($currcookies) eq 'HASH'));
1.171     raeburn  9552:     if (keys(%{$existing}) > 0) {
                   9553:         my $oldlonhost;
                   9554:         foreach my $key (sort(keys(%{$existing}))) {
                   9555:             if ($key eq 'lonhost') {
                   9556:                 $oldlonhost = $existing->{'lonhost'};
                   9557:                 $currbalancer->{$oldlonhost} = 1;
                   9558:             } elsif ($key eq 'targets') {
                   9559:                 if ($oldlonhost) {
                   9560:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   9561:                 }
                   9562:             } elsif ($key eq 'rules') {
                   9563:                 if ($oldlonhost) {
                   9564:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   9565:                 }
                   9566:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   9567:                 $currbalancer->{$key} = 1;
                   9568:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   9569:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.342     raeburn  9570:                 if ($existing->{$key}{'cookie'}) {
                   9571:                     $currcookies->{$key} = 1;
                   9572:                 }
1.150     raeburn  9573:             }
                   9574:         }
1.171     raeburn  9575:     } else {
                   9576:         my ($balancerref,$targetsref) =
                   9577:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   9578:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   9579:             foreach my $server (sort(keys(%{$balancerref}))) {
                   9580:                 $currbalancer->{$server} = 1;
                   9581:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  9582:             }
                   9583:         }
                   9584:     }
1.171     raeburn  9585:     return;
1.150     raeburn  9586: }
                   9587: 
                   9588: sub loadbalancing_rules {
                   9589:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  9590:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   9591:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  9592:     my $output;
1.171     raeburn  9593:     my $num = 0;
1.210     raeburn  9594:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  9595:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   9596:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   9597:         foreach my $type (@{$alltypes}) {
1.171     raeburn  9598:             $num ++;
1.150     raeburn  9599:             my $current;
                   9600:             if (ref($currrules) eq 'HASH') {
                   9601:                 $current = $currrules->{$type};
                   9602:             }
1.253     raeburn  9603:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  9604:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  9605:                     $current = '';
                   9606:                 }
                   9607:             }
                   9608:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  9609:                                              $servers,$currbalancer,$lonhost,$dom,
                   9610:                                              $targets_div_style,$homedom_div_style,
                   9611:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  9612:         }
                   9613:     }
                   9614:     return $output;
                   9615: }
                   9616: 
                   9617: sub loadbalancing_titles {
                   9618:     my ($dom,$intdom,$usertypes,$types) = @_;
                   9619:     my %othertypes = (
                   9620:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   9621:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   9622:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   9623:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  9624:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   9625:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  9626:                      );
1.209     raeburn  9627:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  9628:     my @available;
1.150     raeburn  9629:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  9630:         @available = @{$types};
1.150     raeburn  9631:     }
1.302     raeburn  9632:     unless (grep(/^default$/,@available)) {
                   9633:         push(@available,'default');
                   9634:     }
                   9635:     unshift(@alltypes,@available);
1.150     raeburn  9636:     my %titles;
                   9637:     foreach my $type (@alltypes) {
                   9638:         if ($type =~ /^_LC_/) {
                   9639:             $titles{$type} = $othertypes{$type};
                   9640:         } elsif ($type eq 'default') {
                   9641:             $titles{$type} = &mt('All users from [_1]',$dom);
                   9642:             if (ref($types) eq 'ARRAY') {
                   9643:                 if (@{$types} > 0) {
                   9644:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   9645:                 }
                   9646:             }
                   9647:         } elsif (ref($usertypes) eq 'HASH') {
                   9648:             $titles{$type} = $usertypes->{$type};
                   9649:         }
                   9650:     }
                   9651:     return (\@alltypes,\%othertypes,\%titles);
                   9652: }
                   9653: 
                   9654: sub loadbalance_rule_row {
1.171     raeburn  9655:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   9656:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  9657:     my @rulenames;
1.150     raeburn  9658:     my %ruletitles = &offloadtype_text();
1.209     raeburn  9659:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  9660:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  9661:     } else {
1.209     raeburn  9662:         @rulenames = ('default','homeserver');
                   9663:         if ($type eq '_LC_external') {
                   9664:             push(@rulenames,'externalbalancer');
                   9665:         } else {
                   9666:             push(@rulenames,'specific');
                   9667:         }
                   9668:         push(@rulenames,'none');
1.150     raeburn  9669:     }
                   9670:     my $style = $targets_div_style;
1.253     raeburn  9671:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  9672:         $style = $homedom_div_style;
                   9673:     }
1.171     raeburn  9674:     my $space;
                   9675:     if ($islast && $num == 1) {
1.317     raeburn  9676:         $space = '<div style="display:inline-block;">&nbsp;</div>';
1.171     raeburn  9677:     }
1.210     raeburn  9678:     my $output =
1.306     raeburn  9679:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  9680:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   9681:         '<td valaign="top">'.$space.
                   9682:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  9683:     for (my $i=0; $i<@rulenames; $i++) {
                   9684:         my $rule = $rulenames[$i];
                   9685:         my ($checked,$extra);
                   9686:         if ($rulenames[$i] eq 'default') {
                   9687:             $rule = '';
                   9688:         }
                   9689:         if ($rulenames[$i] eq 'specific') {
                   9690:             if (ref($servers) eq 'HASH') {
                   9691:                 my $default;
                   9692:                 if (($current ne '') && (exists($servers->{$current}))) {
                   9693:                     $checked = ' checked="checked"';
                   9694:                 }
                   9695:                 unless ($checked) {
                   9696:                     $default = ' selected="selected"';
                   9697:                 }
1.210     raeburn  9698:                 $extra =
1.171     raeburn  9699:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9700:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9701:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   9702:                     '<option value=""'.$default.'></option>'."\n";
                   9703:                 foreach my $server (sort(keys(%{$servers}))) {
                   9704:                     if (ref($currbalancer) eq 'HASH') {
                   9705:                         next if (exists($currbalancer->{$server}));
                   9706:                     }
1.150     raeburn  9707:                     my $selected;
1.171     raeburn  9708:                     if ($server eq $current) {
1.150     raeburn  9709:                         $selected = ' selected="selected"';
                   9710:                     }
1.171     raeburn  9711:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  9712:                 }
                   9713:                 $extra .= '</select>';
                   9714:             }
                   9715:         } elsif ($rule eq $current) {
                   9716:             $checked = ' checked="checked"';
                   9717:         }
                   9718:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  9719:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   9720:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   9721:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  9722:                    ')"'.$checked.' />&nbsp;';
                   9723:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   9724:             $output .= $ruletitles{'particular'};
                   9725:         } else {
                   9726:             $output .= $ruletitles{$rulenames[$i]};
                   9727:         }
                   9728:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  9729:     }
                   9730:     $output .= '</div></td></tr>'."\n";
                   9731:     return $output;
                   9732: }
                   9733: 
                   9734: sub offloadtype_text {
                   9735:     my %ruletitles = &Apache::lonlocal::texthash (
                   9736:            'default'          => 'Offloads to default destinations',
                   9737:            'homeserver'       => "Offloads to user's home server",
                   9738:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   9739:            'specific'         => 'Offloads to specific server',
1.161     raeburn  9740:            'none'             => 'No offload',
1.209     raeburn  9741:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   9742:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  9743:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  9744:     );
                   9745:     return %ruletitles;
                   9746: }
                   9747: 
                   9748: sub sparestype_titles {
                   9749:     my %typestitles = &Apache::lonlocal::texthash (
                   9750:                           'primary' => 'primary',
                   9751:                           'default' => 'default',
                   9752:                       );
                   9753:     return %typestitles;
                   9754: }
                   9755: 
1.28      raeburn  9756: sub contact_titles {
                   9757:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  9758:                    'supportemail'    => 'Support E-mail address',
                   9759:                    'adminemail'      => 'Default Server Admin E-mail address',
                   9760:                    'errormail'       => 'Error reports to be e-mailed to',
                   9761:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  9762:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   9763:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  9764:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   9765:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   9766:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  9767:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350     raeburn  9768:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.378     raeburn  9769:                    'errorthreshold'  => 'Error count threshold for status e-mail to admin(s)',
                   9770:                    'errorsysmail'    => 'Error count threshold for e-mail to developer group',
1.340     raeburn  9771:                    'errorweights'    => 'Weights used to compute error count',
                   9772:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  9773:                  );
                   9774:     my %short_titles = &Apache::lonlocal::texthash (
                   9775:                            adminemail   => 'Admin E-mail address',
                   9776:                            supportemail => 'Support E-mail',
                   9777:                        );   
                   9778:     return (\%titles,\%short_titles);
                   9779: }
                   9780: 
1.286     raeburn  9781: sub helpform_fields {
                   9782:     my %titles =  &Apache::lonlocal::texthash (
                   9783:                        'username'   => 'Name',
                   9784:                        'user'       => 'Username/domain',
                   9785:                        'phone'      => 'Phone',
                   9786:                        'cc'         => 'Cc e-mail',
                   9787:                        'course'     => 'Course Details',
                   9788:                        'section'    => 'Sections',
1.289     raeburn  9789:                        'screenshot' => 'File upload',
1.286     raeburn  9790:     );
                   9791:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   9792:     my %possoptions = (
                   9793:                         username     => ['yes','no','req'],
1.289     raeburn  9794:                         phone        => ['yes','no','req'],
1.286     raeburn  9795:                         user         => ['yes','no'],
1.289     raeburn  9796:                         cc           => ['yes','no'],
1.286     raeburn  9797:                         course       => ['yes','no'],
                   9798:                         section      => ['yes','no'],
                   9799:                         screenshot   => ['yes','no'],
                   9800:                       );
                   9801:     my %fieldoptions = &Apache::lonlocal::texthash (
                   9802:                          'yes'  => 'Optional',
                   9803:                          'req'  => 'Required',
                   9804:                          'no'   => "Not shown",
                   9805:     );
                   9806:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   9807: }
                   9808: 
1.72      raeburn  9809: sub tool_titles {
                   9810:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  9811:                      aboutme    => 'Personal web page',
1.86      raeburn  9812:                      blog       => 'Blog',
                   9813:                      portfolio  => 'Portfolio',
1.430     raeburn  9814:                      portaccess => 'Share portfolio files',
1.413     raeburn  9815:                      timezone   => 'Can set time zone',
1.88      bisitz   9816:                      official   => 'Official courses (with institutional codes)',
                   9817:                      unofficial => 'Unofficial courses',
1.98      raeburn  9818:                      community  => 'Communities',
1.216     raeburn  9819:                      textbook   => 'Textbook courses',
1.271     raeburn  9820:                      placement  => 'Placement tests',
1.86      raeburn  9821:                  );
1.72      raeburn  9822:     return %titles;
                   9823: }
                   9824: 
1.101     raeburn  9825: sub courserequest_titles {
                   9826:     my %titles = &Apache::lonlocal::texthash (
                   9827:                                    official   => 'Official',
                   9828:                                    unofficial => 'Unofficial',
                   9829:                                    community  => 'Communities',
1.216     raeburn  9830:                                    textbook   => 'Textbook',
1.271     raeburn  9831:                                    placement  => 'Placement tests',
1.325     raeburn  9832:                                    lti        => 'LTI Provider',
1.101     raeburn  9833:                                    norequest  => 'Not allowed',
1.325     raeburn  9834:                                    approval   => 'Approval by DC',
1.101     raeburn  9835:                                    validate   => 'With validation',
                   9836:                                    autolimit  => 'Numerical limit',
1.103     raeburn  9837:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  9838:                  );
                   9839:     return %titles;
                   9840: }
                   9841: 
1.163     raeburn  9842: sub authorrequest_titles {
                   9843:     my %titles = &Apache::lonlocal::texthash (
                   9844:                                    norequest  => 'Not allowed',
                   9845:                                    approval   => 'Approval by Dom. Coord.',
                   9846:                                    automatic  => 'Automatic approval',
                   9847:                  );
                   9848:     return %titles;
1.210     raeburn  9849: }
1.163     raeburn  9850: 
1.101     raeburn  9851: sub courserequest_conditions {
                   9852:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  9853:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   9854:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  9855:                  );
                   9856:     return %conditions;
                   9857: }
                   9858: 
                   9859: 
1.27      raeburn  9860: sub print_usercreation {
1.30      raeburn  9861:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  9862:     my $numinrow = 4;
1.28      raeburn  9863:     my $datatable;
                   9864:     if ($position eq 'top') {
1.30      raeburn  9865:         $$rowtotal ++;
1.34      raeburn  9866:         my $rowcount = 0;
1.32      raeburn  9867:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  9868:         if (ref($rules) eq 'HASH') {
                   9869:             if (keys(%{$rules}) > 0) {
1.32      raeburn  9870:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   9871:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  9872:                 $$rowtotal ++;
1.32      raeburn  9873:                 $rowcount ++;
                   9874:             }
                   9875:         }
                   9876:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   9877:         if (ref($idrules) eq 'HASH') {
                   9878:             if (keys(%{$idrules}) > 0) {
                   9879:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   9880:                                                 $idruleorder,$numinrow,$rowcount);
                   9881:                 $$rowtotal ++;
                   9882:                 $rowcount ++;
1.28      raeburn  9883:             }
                   9884:         }
1.39      raeburn  9885:         if ($rowcount == 0) {
                   9886:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   9887:             $$rowtotal ++;
                   9888:             $rowcount ++;
                   9889:         }
1.34      raeburn  9890:     } elsif ($position eq 'middle') {
1.224     raeburn  9891:         my @creators = ('author','course','requestcrs');
1.37      raeburn  9892:         my ($rules,$ruleorder) =
                   9893:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  9894:         my %lt = &usercreation_types();
                   9895:         my %checked;
                   9896:         if (ref($settings) eq 'HASH') {
                   9897:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9898:                 foreach my $item (@creators) {
                   9899:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   9900:                 }
                   9901:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   9902:                 foreach my $item (@creators) {
                   9903:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   9904:                         $checked{$item} = 'none';
                   9905:                     }
                   9906:                 }
                   9907:             }
                   9908:         }
                   9909:         my $rownum = 0;
                   9910:         foreach my $item (@creators) {
                   9911:             $rownum ++;
1.224     raeburn  9912:             if ($checked{$item} eq '') {
                   9913:                 $checked{$item} = 'any';
1.34      raeburn  9914:             }
                   9915:             my $css_class;
                   9916:             if ($rownum%2) {
                   9917:                 $css_class = '';
                   9918:             } else {
                   9919:                 $css_class = ' class="LC_odd_row" ';
                   9920:             }
                   9921:             $datatable .= '<tr'.$css_class.'>'.
                   9922:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  9923:                          '</span></td><td style="text-align: right">';
1.224     raeburn  9924:             my @options = ('any');
                   9925:             if (ref($rules) eq 'HASH') {
                   9926:                 if (keys(%{$rules}) > 0) {
                   9927:                     push(@options,('official','unofficial'));
1.37      raeburn  9928:                 }
                   9929:             }
1.224     raeburn  9930:             push(@options,'none');
1.37      raeburn  9931:             foreach my $option (@options) {
1.50      raeburn  9932:                 my $type = 'radio';
1.34      raeburn  9933:                 my $check = ' ';
1.224     raeburn  9934:                 if ($checked{$item} eq $option) {
                   9935:                     $check = ' checked="checked" ';
1.34      raeburn  9936:                 } 
                   9937:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  9938:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  9939:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   9940:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   9941:             }
                   9942:             $datatable .= '</td></tr>';
                   9943:         }
1.28      raeburn  9944:     } else {
                   9945:         my @contexts = ('author','course','domain');
1.325     raeburn  9946:         my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  9947:         my %checked;
                   9948:         if (ref($settings) eq 'HASH') {
                   9949:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   9950:                 foreach my $item (@contexts) {
                   9951:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   9952:                         foreach my $auth (@authtypes) {
                   9953:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   9954:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   9955:                             }
                   9956:                         }
                   9957:                     }
                   9958:                 }
1.27      raeburn  9959:             }
1.35      raeburn  9960:         } else {
                   9961:             foreach my $item (@contexts) {
1.36      raeburn  9962:                 foreach my $auth (@authtypes) {
1.35      raeburn  9963:                     $checked{$item}{$auth} = ' checked="checked" ';
                   9964:                 }
                   9965:             }
1.27      raeburn  9966:         }
1.28      raeburn  9967:         my %title = &context_names();
                   9968:         my %authname = &authtype_names();
                   9969:         my $rownum = 0;
                   9970:         my $css_class; 
                   9971:         foreach my $item (@contexts) {
                   9972:             if ($rownum%2) {
                   9973:                 $css_class = '';
                   9974:             } else {
                   9975:                 $css_class = ' class="LC_odd_row" ';
                   9976:             }
1.30      raeburn  9977:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  9978:                             '<td>'.$title{$item}.
                   9979:                             '</td><td class="LC_left_item">'.
                   9980:                             '<span class="LC_nobreak">';
                   9981:             foreach my $auth (@authtypes) {
                   9982:                 $datatable .= '<label>'. 
                   9983:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   9984:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   9985:                               $authname{$auth}.'</label>&nbsp;';
                   9986:             }
                   9987:             $datatable .= '</span></td></tr>';
                   9988:             $rownum ++;
1.27      raeburn  9989:         }
1.30      raeburn  9990:         $$rowtotal += $rownum;
1.27      raeburn  9991:     }
                   9992:     return $datatable;
                   9993: }
                   9994: 
1.224     raeburn  9995: sub print_selfcreation {
                   9996:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  9997:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   9998:         $emaildomain,$datatable);
1.224     raeburn  9999:     if (ref($settings) eq 'HASH') {
                   10000:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   10001:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  10002:             if (ref($createsettings) eq 'HASH') {
                   10003:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   10004:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   10005:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   10006:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   10007:                         @selfcreate = ('email','login','sso');
                   10008:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   10009:                         @selfcreate = ($createsettings->{'selfcreate'});
                   10010:                     }
                   10011:                 }
                   10012:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   10013:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  10014:                 }
1.305     raeburn  10015:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   10016:                     $emailoptions = $createsettings->{'emailoptions'};
                   10017:                 }
1.303     raeburn  10018:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   10019:                     $emailverified = $createsettings->{'emailverified'};
                   10020:                 }
                   10021:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   10022:                     $emaildomain = $createsettings->{'emaildomain'};
                   10023:                 }
1.224     raeburn  10024:             }
                   10025:         }
                   10026:     }
                   10027:     my %radiohash;
                   10028:     my $numinrow = 4;
                   10029:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  10030:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  10031:     if ($position eq 'top') {
                   10032:         my %choices = &Apache::lonlocal::texthash (
                   10033:                                                       cancreate_login      => 'Institutional Login',
                   10034:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   10035:                                                   );
                   10036:         my @toggles = sort(keys(%choices));
                   10037:         my %defaultchecked = (
                   10038:                                'cancreate_login' => 'off',
                   10039:                                'cancreate_sso'   => 'off',
                   10040:                              );
1.228     raeburn  10041:         my ($onclick,$itemcount);
1.224     raeburn  10042:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   10043:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  10044:         $$rowtotal += $itemcount;
1.425     raeburn  10045: 
1.224     raeburn  10046:         if (ref($usertypes) eq 'HASH') {
                   10047:             if (keys(%{$usertypes}) > 0) {
                   10048:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   10049:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  10050:                                              'statustocreate',$rowtotal);
1.224     raeburn  10051:                 $$rowtotal ++;
                   10052:             }
                   10053:         }
1.240     raeburn  10054:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   10055:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10056:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   10057:         my $rem;
                   10058:         my $numperrow = 2;
                   10059:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   10060:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  10061:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  10062:                      '<td class="LC_left_item">'."\n".
1.334     raeburn  10063:                      '<table>'."\n";
1.240     raeburn  10064:         for (my $i=0; $i<@fields; $i++) {
                   10065:             $rem = $i%($numperrow);
                   10066:             if ($rem == 0) {
                   10067:                 if ($i > 0) {
                   10068:                     $datatable .= '</tr>';
                   10069:                 }
                   10070:                 $datatable .= '<tr>';
                   10071:             }
                   10072:             my $currval;
1.248     raeburn  10073:             if (ref($createsettings) eq 'HASH') {
                   10074:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   10075:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   10076:                 }
1.240     raeburn  10077:             }
                   10078:             $datatable .= '<td class="LC_left_item">'.
                   10079:                           '<span class="LC_nobreak">'.
                   10080:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   10081:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   10082:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   10083:         }
                   10084:         my $colsleft = $numperrow - $rem;
                   10085:         if ($colsleft > 1 ) {
                   10086:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   10087:                          '&nbsp;</td>';
                   10088:         } elsif ($colsleft == 1) {
                   10089:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   10090:         }
                   10091:         $datatable .= '</tr></table></td></tr>';
                   10092:         $$rowtotal ++;
1.224     raeburn  10093:     } elsif ($position eq 'middle') {
                   10094:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  10095:         my @posstypes;
1.224     raeburn  10096:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  10097:             @posstypes = @{$types};
                   10098:         }
                   10099:         unless (grep(/^default$/,@posstypes)) {
                   10100:             push(@posstypes,'default');
                   10101:         }
                   10102:         my %usertypeshash;
                   10103:         if (ref($usertypes) eq 'HASH') {
                   10104:             %usertypeshash = %{$usertypes};
                   10105:         }
                   10106:         $usertypeshash{'default'} = $othertitle;
                   10107:         foreach my $status (@posstypes) {
                   10108:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   10109:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   10110:             $$rowtotal ++;
1.224     raeburn  10111:         }
                   10112:     } else {
1.236     raeburn  10113:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  10114:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  10115:                                                   );
                   10116:         my @toggles = sort(keys(%choices));
                   10117:         my %defaultchecked = (
                   10118:                                'cancreate_email' => 'off',
                   10119:                              );
1.305     raeburn  10120:         my $customclass = 'LC_selfcreate_email';
                   10121:         my $classprefix = 'LC_canmodify_emailusername_';
                   10122:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  10123:         my $display = 'none';
1.305     raeburn  10124:         my $rowstyle = 'display:none';
1.236     raeburn  10125:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   10126:             $display = 'block';
1.305     raeburn  10127:             $rowstyle = 'display:table-row';
1.236     raeburn  10128:         }
1.305     raeburn  10129:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   10130:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   10131:                                                      \%choices,$$rowtotal,$onclick);
                   10132:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   10133:                                          $rowstyle);
                   10134:         $$rowtotal ++;
                   10135:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   10136:                                       $rowstyle);
                   10137:         $$rowtotal ++;
                   10138:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  10139:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  10140:         my ($emailrules,$emailruleorder) =
                   10141:             &Apache::lonnet::inst_userrules($dom,'email');
                   10142:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   10143:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   10144:         if (ref($types) eq 'ARRAY') {
                   10145:             @posstypes = @{$types};
                   10146:         }
                   10147:         if (@posstypes) {
                   10148:             unless (grep(/^default$/,@posstypes)) {
                   10149:                 push(@posstypes,'default');
1.302     raeburn  10150:             }
                   10151:             if (ref($usertypes) eq 'HASH') {
                   10152:                 %usertypeshash = %{$usertypes};
                   10153:             }
1.305     raeburn  10154:             my $currassign;
                   10155:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   10156:                 $currassign = {
                   10157:                                   selfassign => $domdefaults{'inststatusguest'},
                   10158:                               };
                   10159:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   10160:             } else {
                   10161:                 $currassign = { selfassign => [] };
                   10162:             }
                   10163:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   10164:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   10165:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   10166:                                          $numinrow,$othertitle,'selfassign',
                   10167:                                          $rowtotal,$onclicktypes,$customclass,
                   10168:                                          $rowstyle);
                   10169:             $$rowtotal ++;
1.302     raeburn  10170:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  10171:             foreach my $status (@posstypes) {
                   10172:                 my $css_class;
                   10173:                 if ($$rowtotal%2) {
                   10174:                     $css_class = 'LC_odd_row ';
                   10175:                 }
                   10176:                 $css_class .= $customclass;
                   10177:                 my $rowid = $optionsprefix.$status;
                   10178:                 my $hidden = 1;
                   10179:                 my $currstyle = 'display:none';
                   10180:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   10181:                     $currstyle = $rowstyle;
1.425     raeburn  10182:                     $hidden = 0;
1.305     raeburn  10183:                 }
                   10184:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   10185:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   10186:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   10187:                 unless ($hidden) {
                   10188:                     $$rowtotal ++;
                   10189:                 }
1.224     raeburn  10190:             }
1.302     raeburn  10191:         } else {
1.305     raeburn  10192:             my $css_class;
                   10193:             if ($$rowtotal%2) {
                   10194:                 $css_class = 'LC_odd_row ';
                   10195:             }
                   10196:             $css_class .= $customclass;
1.302     raeburn  10197:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  10198:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   10199:                                          $emailrules,$emailruleorder,$settings,'default','',
                   10200:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   10201:             $$rowtotal ++;
1.224     raeburn  10202:         }
                   10203:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  10204:         $numinrow = 1;
1.305     raeburn  10205:         if (@posstypes) {
                   10206:             foreach my $status (@posstypes) {
                   10207:                 my $rowid = $classprefix.$status;
                   10208:                 my $datarowstyle = 'display:none';
1.425     raeburn  10209:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   10210:                     $datarowstyle = $rowstyle;
1.305     raeburn  10211:                 }
                   10212:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   10213:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   10214:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   10215:                 unless ($datarowstyle eq 'display:none') {
                   10216:                     $$rowtotal ++;
                   10217:                 }
1.224     raeburn  10218:             }
1.305     raeburn  10219:         } else {
                   10220:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   10221:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   10222:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  10223:         }
                   10224:     }
                   10225:     return $datatable;
                   10226: }
                   10227: 
1.305     raeburn  10228: sub selfcreate_javascript {
                   10229:     return <<"ENDSCRIPT";
                   10230: 
                   10231: <script type="text/javascript">
                   10232: // <![CDATA[
                   10233: 
                   10234: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   10235:     var x = document.getElementsByClassName(target);
                   10236:     var insttypes = 0;
                   10237:     var insttypeRegExp = new RegExp(prefix);
                   10238:     if ((x.length != undefined) && (x.length > 0)) {
                   10239:         if (form.elements[radio].length != undefined) {
                   10240:             for (var i=0; i<form.elements[radio].length; i++) {
                   10241:                 if (form.elements[radio][i].checked) {
                   10242:                     if (form.elements[radio][i].value == 1) {
                   10243:                         for (var j=0; j<x.length; j++) {
                   10244:                             if (x[j].id == 'undefined') {
                   10245:                                 x[j].style.display = 'table-row';
                   10246:                             } else if (insttypeRegExp.test(x[j].id)) {
                   10247:                                 insttypes ++;
                   10248:                             } else {
                   10249:                                 x[j].style.display = 'table-row';
                   10250:                             }
                   10251:                         }
                   10252:                     } else {
                   10253:                         for (var j=0; j<x.length; j++) {
                   10254:                             x[j].style.display = 'none';
                   10255:                         }
1.236     raeburn  10256:                     }
1.305     raeburn  10257:                     break;
                   10258:                 }
                   10259:             }
                   10260:             if (insttypes > 0) {
                   10261:                 toggleDataRow(form,checkbox,target,altprefix);
                   10262:                 toggleDataRow(form,checkbox,target,prefix,1);
                   10263:             }
                   10264:         }
                   10265:     }
                   10266:     return;
                   10267: }
                   10268: 
                   10269: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   10270:     if (form.elements[checkbox].length != undefined) {
                   10271:         var count = 0;
                   10272:         if (docount) {
                   10273:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   10274:                 if (form.elements[checkbox][i].checked) {
                   10275:                     count ++;
1.236     raeburn  10276:                 }
1.305     raeburn  10277:             }
                   10278:         }
                   10279:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   10280:             var type = form.elements[checkbox][i].value;
                   10281:             if (document.getElementById(prefix+type)) {
                   10282:                 if (form.elements[checkbox][i].checked) {
                   10283:                     document.getElementById(prefix+type).style.display = 'table-row';
                   10284:                     if (count % 2 == 1) {
                   10285:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   10286:                     } else {
                   10287:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  10288:                     }
1.305     raeburn  10289:                     count ++;
1.236     raeburn  10290:                 } else {
1.305     raeburn  10291:                     document.getElementById(prefix+type).style.display = 'none';
                   10292:                 }
                   10293:             }
                   10294:         }
                   10295:     }
                   10296:     return;
                   10297: }
                   10298: 
                   10299: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   10300:     var caller = radio+'_'+status;
                   10301:     if (form.elements[caller].length != undefined) {
                   10302:         for (var i=0; i<form.elements[caller].length; i++) {
                   10303:             if (form.elements[caller][i].checked) {
                   10304:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   10305:                     var curr = form.elements[caller][i].value;
                   10306:                     if (prefix) {
                   10307:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   10308:                     }
                   10309:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   10310:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   10311:                     if (curr == 'custom') {
1.425     raeburn  10312:                         if (prefix) {
1.305     raeburn  10313:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   10314:                         }
                   10315:                     } else if (curr == 'inst') {
                   10316:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   10317:                     } else if (curr == 'noninst') {
                   10318:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  10319:                     }
1.305     raeburn  10320:                     break;
1.236     raeburn  10321:                 }
                   10322:             }
                   10323:         }
                   10324:     }
                   10325: }
                   10326: 
1.305     raeburn  10327: // ]]>
                   10328: </script>
                   10329: 
                   10330: ENDSCRIPT
                   10331: }
                   10332: 
                   10333: sub noninst_users {
                   10334:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425     raeburn  10335:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305     raeburn  10336:     my $class = 'LC_left_item';
                   10337:     if ($css_class) {
1.425     raeburn  10338:         $css_class = ' class="'.$css_class.'"';
1.305     raeburn  10339:     }
                   10340:     if ($rowid) {
                   10341:         $rowid = ' id="'.$rowid.'"';
                   10342:     }
                   10343:     if ($rowstyle) {
                   10344:         $rowstyle = ' style="'.$rowstyle.'"';
                   10345:     }
                   10346:     my ($output,$description);
                   10347:     if ($type eq 'default') {
                   10348:         $description = &mt('Requests for: [_1]',$typetitle);
                   10349:     } else {
                   10350:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   10351:     }
                   10352:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425     raeburn  10353:               "<td>$description</td>\n".
1.305     raeburn  10354:               '<td class="'.$class.'" colspan="2">'.
                   10355:               '<table><tr>';
1.425     raeburn  10356:     my %headers = &Apache::lonlocal::texthash(
1.305     raeburn  10357:               approve  => 'Processing',
                   10358:               email    => 'E-mail',
                   10359:               username => 'Username',
                   10360:     );
                   10361:     foreach my $item ('approve','email','username') {
                   10362:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  10363:     }
1.305     raeburn  10364:     $output .= '</tr><tr>';
                   10365:     foreach my $item ('approve','email','username') {
1.306     raeburn  10366:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  10367:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   10368:         if ($item eq 'approve') {
                   10369:             %choices = &Apache::lonlocal::texthash (
                   10370:                                                      automatic => 'Automatically approved',
                   10371:                                                      approval  => 'Queued for approval',
                   10372:                                                    );
                   10373:             @options = ('automatic','approval');
                   10374:             $hashref = $processing;
                   10375:             $defoption = 'automatic';
                   10376:             $name = 'cancreate_emailprocess_'.$type;
                   10377:         } elsif ($item eq 'email') {
                   10378:             %choices = &Apache::lonlocal::texthash (
                   10379:                                                      any     => 'Any e-mail',
                   10380:                                                      inst    => 'Institutional only',
                   10381:                                                      noninst => 'Non-institutional only',
                   10382:                                                      custom  => 'Custom restrictions',
                   10383:                                                    );
                   10384:             @options = ('any','inst','noninst');
                   10385:             my $showcustom;
                   10386:             if (ref($emailrules) eq 'HASH') {
                   10387:                 if (keys(%{$emailrules}) > 0) {
                   10388:                     push(@options,'custom');
                   10389:                     $showcustom = 'cancreate_emailrule';
                   10390:                     if (ref($settings) eq 'HASH') {
                   10391:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   10392:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   10393:                                 if (exists($emailrules->{$rule})) {
                   10394:                                     $hascustom ++;
                   10395:                                 }
                   10396:                             }
                   10397:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   10398:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   10399:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   10400:                                     if (exists($emailrules->{$rule})) {
                   10401:                                         $hascustom ++;
                   10402:                                     }
                   10403:                                 }
                   10404:                             }
                   10405:                         }
                   10406:                     }
                   10407:                 }
                   10408:             }
                   10409:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   10410:                                                      "'cancreate_emaildomain','$type'".');"';
                   10411:             $hashref = $emailoptions;
                   10412:             $defoption = 'any';
                   10413:             $name = 'cancreate_emailoptions_'.$type;
                   10414:         } elsif ($item eq 'username') {
                   10415:             %choices = &Apache::lonlocal::texthash (
                   10416:                                                      all    => 'Same as e-mail',
                   10417:                                                      first  => 'Omit @domain',
                   10418:                                                      free   => 'Free to choose',
                   10419:                                                    );
                   10420:             @options = ('all','first','free');
                   10421:             $hashref = $emailverified;
                   10422:             $defoption = 'all';
                   10423:             $name = 'cancreate_usernameoptions_'.$type;
                   10424:         }
                   10425:         foreach my $option (@options) {
                   10426:             my $checked;
                   10427:             if (ref($hashref) eq 'HASH') {
                   10428:                 if ($type eq '') {
                   10429:                     if (!exists($hashref->{'default'})) {
                   10430:                         if ($option eq $defoption) {
                   10431:                             $checked = ' checked="checked"';
                   10432:                         }
                   10433:                     } else {
                   10434:                         if ($hashref->{'default'} eq $option) {
                   10435:                             $checked = ' checked="checked"';
                   10436:                         }
1.303     raeburn  10437:                     }
                   10438:                 } else {
1.305     raeburn  10439:                     if (!exists($hashref->{$type})) {
                   10440:                         if ($option eq $defoption) {
                   10441:                             $checked = ' checked="checked"';
                   10442:                         }
                   10443:                     } else {
                   10444:                         if ($hashref->{$type} eq $option) {
                   10445:                             $checked = ' checked="checked"';
                   10446:                         }
1.303     raeburn  10447:                     }
                   10448:                 }
1.305     raeburn  10449:             } elsif (($item eq 'email') && ($hascustom)) {
                   10450:                 if ($option eq 'custom') {
                   10451:                     $checked = ' checked="checked"';
                   10452:                 }
                   10453:             } elsif ($option eq $defoption) {
                   10454:                 $checked = ' checked="checked"';
                   10455:             }
                   10456:             $output .= '<span class="LC_nobreak"><label>'.
                   10457:                        '<input type="radio" name="'.$name.'"'.
                   10458:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   10459:                        $choices{$option}.'</label></span><br />';
                   10460:             if ($item eq 'email') {
                   10461:                 if ($option eq 'custom') {
                   10462:                     my $id = 'cancreate_emailrule_'.$type;
                   10463:                     my $display = 'none';
                   10464:                     if ($checked) {
                   10465:                         $display = 'inline';
1.303     raeburn  10466:                     }
1.305     raeburn  10467:                     my $numinrow = 2;
                   10468:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   10469:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   10470:                                &user_formats_row('email',$settings,$emailrules,
                   10471:                                                  $emailruleorder,$numinrow,'',$type);
                   10472:                               '</table></fieldset>';
                   10473:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   10474:                     my %text = &Apache::lonlocal::texthash (
                   10475:                                                              inst    => 'must end:',
                   10476:                                                              noninst => 'cannot end:',
                   10477:                                                            );
                   10478:                     my $value;
                   10479:                     if (ref($emaildomain) eq 'HASH') {
                   10480:                         if (ref($emaildomain->{$type}) eq 'HASH') {
1.425     raeburn  10481:                             $value = $emaildomain->{$type}->{$option};
1.303     raeburn  10482:                         }
                   10483:                     }
1.305     raeburn  10484:                     if ($value eq '') {
                   10485:                         $value = '@'.$intdom;
                   10486:                     }
                   10487:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   10488:                     my $display = 'none';
                   10489:                     if ($checked) {
                   10490:                         $display = 'inline';
                   10491:                     }
                   10492:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   10493:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   10494:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   10495:                                '</div>';
1.303     raeburn  10496:                 }
                   10497:             }
                   10498:         }
1.305     raeburn  10499:         $output .= '</td>'."\n";
1.303     raeburn  10500:     }
1.305     raeburn  10501:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  10502:     return $output;
                   10503: }
                   10504: 
1.165     raeburn  10505: sub captcha_choice {
1.305     raeburn  10506:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  10507:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   10508:         $vertext,$currver);
1.165     raeburn  10509:     my %lt = &captcha_phrases();
                   10510:     $keyentry = 'hidden';
1.354     raeburn  10511:     my $colspan=2;
1.165     raeburn  10512:     if ($context eq 'cancreate') {
1.224     raeburn  10513:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  10514:     } elsif ($context eq 'login') {
                   10515:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.354     raeburn  10516:     } elsif ($context eq 'passwords') {
                   10517:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   10518:         $colspan=1;
1.165     raeburn  10519:     }
                   10520:     if (ref($settings) eq 'HASH') {
                   10521:         if ($settings->{'captcha'}) {
                   10522:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   10523:         } else {
                   10524:             $checked{'original'} = ' checked="checked"';
                   10525:         }
                   10526:         if ($settings->{'captcha'} eq 'recaptcha') {
                   10527:             $pubtext = $lt{'pub'};
                   10528:             $privtext = $lt{'priv'};
                   10529:             $keyentry = 'text';
1.269     raeburn  10530:             $vertext = $lt{'ver'};
                   10531:             $currver = $settings->{'recaptchaversion'};
                   10532:             if ($currver ne '2') {
                   10533:                 $currver = 1;
                   10534:             }
1.165     raeburn  10535:         }
                   10536:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   10537:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   10538:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   10539:         }
                   10540:     } else {
                   10541:         $checked{'original'} = ' checked="checked"';
                   10542:     }
1.305     raeburn  10543:     my $css_class;
                   10544:     if ($itemcount%2) {
                   10545:         $css_class = 'LC_odd_row';
                   10546:     }
                   10547:     if ($customcss) {
                   10548:         $css_class .= " $customcss";
                   10549:     }
                   10550:     $css_class =~ s/^\s+//;
                   10551:     if ($css_class) {
                   10552:         $css_class = ' class="'.$css_class.'"';
                   10553:     }
                   10554:     if ($rowstyle) {
                   10555:         $css_class .= ' style="'.$rowstyle.'"';
                   10556:     }
1.169     raeburn  10557:     my $output = '<tr'.$css_class.'>'.
1.354     raeburn  10558:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165     raeburn  10559:                  '<table><tr><td>'."\n";
                   10560:     foreach my $option ('original','recaptcha','notused') {
                   10561:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   10562:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   10563:                    $lt{$option}.'</label></span>';
                   10564:         unless ($option eq 'notused') {
                   10565:             $output .= ('&nbsp;'x2)."\n";
                   10566:         }
                   10567:     }
                   10568: #
                   10569: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   10570: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  10571: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  10572: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  10573: #
1.165     raeburn  10574:     $output .= '</td></tr>'."\n".
1.305     raeburn  10575:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  10576:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   10577:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   10578:                $currpub.'" size="40" /></span><br />'."\n".
                   10579:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   10580:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  10581:                $currpriv.'" size="40" /></span><br />'.
                   10582:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   10583:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   10584:                $currver.'" size="3" /></span><br />'.
                   10585:                '</td></tr></table>'."\n".
1.165     raeburn  10586:                '</td></tr>';
                   10587:     return $output;
                   10588: }
                   10589: 
1.32      raeburn  10590: sub user_formats_row {
1.305     raeburn  10591:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  10592:     my $output;
                   10593:     my %text = (
                   10594:                    'username' => 'new usernames',
                   10595:                    'id'       => 'IDs',
                   10596:                );
1.409     raeburn  10597:     unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305     raeburn  10598:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   10599:         $output = '<tr '.$css_class.'>'.
                   10600:                   '<td><span class="LC_nobreak">'.
                   10601:                   &mt("Format rules to check for $text{$type}: ").
                   10602:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  10603:     }
1.27      raeburn  10604:     my $rem;
                   10605:     if (ref($ruleorder) eq 'ARRAY') {
                   10606:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   10607:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   10608:                 my $rem = $i%($numinrow);
                   10609:                 if ($rem == 0) {
                   10610:                     if ($i > 0) {
                   10611:                         $output .= '</tr>';
                   10612:                     }
                   10613:                     $output .= '<tr>';
                   10614:                 }
                   10615:                 my $check = ' ';
1.39      raeburn  10616:                 if (ref($settings) eq 'HASH') {
                   10617:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   10618:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   10619:                             $check = ' checked="checked" ';
                   10620:                         }
1.305     raeburn  10621:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   10622:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   10623:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   10624:                                 $check = ' checked="checked" ';
                   10625:                             }
                   10626:                         }
1.27      raeburn  10627:                     }
                   10628:                 }
1.305     raeburn  10629:                 my $name = $type.'_rule';
                   10630:                 if ($type eq 'email') {
                   10631:                     $name .= '_'.$status;
                   10632:                 }
1.27      raeburn  10633:                 $output .= '<td class="LC_left_item">'.
                   10634:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  10635:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  10636:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   10637:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   10638:             }
                   10639:         }
                   10640:         $rem = @{$ruleorder}%($numinrow);
                   10641:     }
1.305     raeburn  10642:     my $colsleft;
                   10643:     if ($rem) {
                   10644:         $colsleft = $numinrow - $rem;
                   10645:     }
1.27      raeburn  10646:     if ($colsleft > 1 ) {
                   10647:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   10648:                    '&nbsp;</td>';
                   10649:     } elsif ($colsleft == 1) {
                   10650:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   10651:     }
1.409     raeburn  10652:     $output .= '</tr>';
                   10653:     unless (($type eq 'email') || ($type eq 'unamemap')) {
                   10654:         $output .= '</table></td></tr>';
1.305     raeburn  10655:     }
1.27      raeburn  10656:     return $output;
                   10657: }
                   10658: 
1.34      raeburn  10659: sub usercreation_types {
                   10660:     my %lt = &Apache::lonlocal::texthash (
                   10661:                     author     => 'When adding a co-author',
                   10662:                     course     => 'When adding a user to a course',
1.100     raeburn  10663:                     requestcrs => 'When requesting a course',
1.34      raeburn  10664:                     any        => 'Any',
                   10665:                     official   => 'Institutional only ',
                   10666:                     unofficial => 'Non-institutional only',
                   10667:                     none       => 'None',
                   10668:     );
                   10669:     return %lt;
1.48      raeburn  10670: }
1.34      raeburn  10671: 
1.224     raeburn  10672: sub selfcreation_types {
                   10673:     my %lt = &Apache::lonlocal::texthash (
                   10674:                     selfcreate => 'User creates own account',
                   10675:                     any        => 'Any',
                   10676:                     official   => 'Institutional only ',
                   10677:                     unofficial => 'Non-institutional only',
                   10678:                     email      => 'E-mail address',
                   10679:                     login      => 'Institutional Login',
                   10680:                     sso        => 'SSO',
                   10681:              );
                   10682: }
                   10683: 
1.28      raeburn  10684: sub authtype_names {
                   10685:     my %lt = &Apache::lonlocal::texthash(
                   10686:                       int    => 'Internal',
                   10687:                       krb4   => 'Kerberos 4',
                   10688:                       krb5   => 'Kerberos 5',
                   10689:                       loc    => 'Local',
1.325     raeburn  10690:                       lti    => 'LTI',
1.28      raeburn  10691:                   );
                   10692:     return %lt;
                   10693: }
                   10694: 
                   10695: sub context_names {
                   10696:     my %context_title = &Apache::lonlocal::texthash(
                   10697:        author => 'Creating users when an Author',
                   10698:        course => 'Creating users when in a course',
                   10699:        domain => 'Creating users when a Domain Coordinator',
                   10700:     );
                   10701:     return %context_title;
                   10702: }
                   10703: 
1.33      raeburn  10704: sub print_usermodification {
                   10705:     my ($position,$dom,$settings,$rowtotal) = @_;
                   10706:     my $numinrow = 4;
                   10707:     my ($context,$datatable,$rowcount);
                   10708:     if ($position eq 'top') {
                   10709:         $rowcount = 0;
                   10710:         $context = 'author'; 
                   10711:         foreach my $role ('ca','aa') {
                   10712:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10713:                                                    $numinrow,$rowcount);
                   10714:             $$rowtotal ++;
                   10715:             $rowcount ++;
                   10716:         }
1.230     raeburn  10717:     } elsif ($position eq 'bottom') {
1.33      raeburn  10718:         $context = 'course';
                   10719:         $rowcount = 0;
                   10720:         foreach my $role ('st','ep','ta','in','cr') {
                   10721:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10722:                                                    $numinrow,$rowcount);
                   10723:             $$rowtotal ++;
                   10724:             $rowcount ++;
                   10725:         }
                   10726:     }
                   10727:     return $datatable;
                   10728: }
                   10729: 
1.43      raeburn  10730: sub print_defaults {
1.236     raeburn  10731:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  10732:     my $rownum = 0;
1.294     raeburn  10733:     my ($datatable,$css_class,$titles);
                   10734:     unless ($position eq 'bottom') {
                   10735:         $titles = &defaults_titles($dom);
                   10736:     }
1.236     raeburn  10737:     if ($position eq 'top') {
                   10738:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   10739:                      'datelocale_def','portal_def');
                   10740:         my %defaults;
                   10741:         if (ref($settings) eq 'HASH') {
                   10742:             %defaults = %{$settings};
1.43      raeburn  10743:         } else {
1.236     raeburn  10744:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10745:             foreach my $item (@items) {
                   10746:                 $defaults{$item} = $domdefaults{$item};
                   10747:             }
1.43      raeburn  10748:         }
1.236     raeburn  10749:         foreach my $item (@items) {
                   10750:             if ($rownum%2) {
                   10751:                 $css_class = '';
                   10752:             } else {
                   10753:                 $css_class = ' class="LC_odd_row" ';
                   10754:             }
                   10755:             $datatable .= '<tr'.$css_class.'>'.
                   10756:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   10757:                           '</span></td><td class="LC_right_item" colspan="3">';
                   10758:             if ($item eq 'auth_def') {
1.325     raeburn  10759:                 my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236     raeburn  10760:                 my %shortauth = (
                   10761:                                  internal => 'int',
                   10762:                                  krb4 => 'krb4',
                   10763:                                  krb5 => 'krb5',
1.325     raeburn  10764:                                  localauth  => 'loc',
                   10765:                                  lti => 'lti',
1.236     raeburn  10766:                                 );
                   10767:                 my %authnames = &authtype_names();
                   10768:                 foreach my $auth (@authtypes) {
                   10769:                     my $checked = ' ';
                   10770:                     if ($defaults{$item} eq $auth) {
                   10771:                         $checked = ' checked="checked" ';
                   10772:                     }
                   10773:                     $datatable .= '<label><input type="radio" name="'.$item.
                   10774:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   10775:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   10776:                 }
                   10777:             } elsif ($item eq 'timezone_def') {
                   10778:                 my $includeempty = 1;
                   10779:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   10780:             } elsif ($item eq 'datelocale_def') {
                   10781:                 my $includeempty = 1;
                   10782:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   10783:             } elsif ($item eq 'lang_def') {
1.263     raeburn  10784:                 my $includeempty = 1;
                   10785:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414     raeburn  10786:             } elsif ($item eq 'portal_def') {
                   10787:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   10788:                               $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
                   10789:                 my $portalsty = 'none';
                   10790:                 if ($defaults{$item}) {
                   10791:                     $portalsty = 'block';
                   10792:                 }
                   10793:                 foreach my $field ('email','web') {
                   10794:                     my $checkedoff = ' checked="checked"';
                   10795:                     my $checkedon;
                   10796:                     if ($defaults{$item.'_'.$field}) {
                   10797:                         $checkedon = $checkedoff;
                   10798:                         $checkedoff = '';
1.425     raeburn  10799:                     }
1.414     raeburn  10800:                     $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
                   10801:                               '<span class="LC_nobreak">'.$titles->{$field}.'&nbsp;'.
                   10802:                               '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
                   10803:                               ('&nbsp;'x2).
                   10804:                               '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
                   10805:                               '</div>';
                   10806:                 }
1.236     raeburn  10807:             } else {
1.414     raeburn  10808:                 $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43      raeburn  10809:             }
1.236     raeburn  10810:             $datatable .= '</td></tr>';
                   10811:             $rownum ++;
                   10812:         }
1.409     raeburn  10813:     } elsif ($position eq 'middle') {
1.294     raeburn  10814:         my %defaults;
                   10815:         if (ref($settings) eq 'HASH') {
1.354     raeburn  10816:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   10817:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   10818:                 for (my $i=0; $i<$maxnum; $i++) {
                   10819:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10820:                     my $item = $settings->{'inststatusorder'}->[$i];
                   10821:                     my $title = $settings->{'inststatustypes'}->{$item};
                   10822:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   10823:                     $datatable .= '<tr'.$css_class.'>'.
                   10824:                                   '<td><span class="LC_nobreak">'.
                   10825:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   10826:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10827:                         my $vpos = $k+1;
                   10828:                         my $selstr;
                   10829:                         if ($k == $i) {
                   10830:                             $selstr = ' selected="selected" ';
                   10831:                         }
                   10832:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10833:                     }
                   10834:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   10835:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   10836:                                   &mt('delete').'</span></td>'.
1.380     raeburn  10837:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354     raeburn  10838:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   10839:                                   '</span></td></tr>';
                   10840:                 }
                   10841:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10842:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   10843:                 $datatable .= '<tr '.$css_class.'>'.
                   10844:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   10845:                 for (my $k=0; $k<=$maxnum; $k++) {
                   10846:                     my $vpos = $k+1;
                   10847:                     my $selstr;
                   10848:                     if ($k == $maxnum) {
                   10849:                         $selstr = ' selected="selected" ';
                   10850:                     }
                   10851:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10852:                 }
                   10853:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                   10854:                               '<input type="text" size="10" name="addinststatus" value="" />'.
                   10855:                               '&nbsp;'.&mt('(new)').
                   10856:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380     raeburn  10857:                               &mt('Name displayed').':'.
1.354     raeburn  10858:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   10859:                               '</tr>'."\n";
                   10860:                 $rownum ++;
1.294     raeburn  10861:             }
1.354     raeburn  10862:         }
1.409     raeburn  10863:     } else {
                   10864:         my ($unamemaprules,$ruleorder) =
                   10865:             &Apache::lonnet::inst_userrules($dom,'unamemap');
                   10866:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10867:         if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   10868:             my $numinrow = 2;
                   10869:             $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
                   10870:                           &user_formats_row('unamemap',$settings,$unamemaprules,
                   10871:                                             $ruleorder,$numinrow).
                   10872:                           '</table></td></tr>';
                   10873:         }
                   10874:         if ($datatable eq '') {
                   10875:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
                   10876:                           &mt('No rules set for domain in customized localenroll.pm').
                   10877:                           '</td></tr>';
                   10878:         }
1.354     raeburn  10879:     }
                   10880:     $$rowtotal += $rownum;
1.43      raeburn  10881:     return $datatable;
                   10882: }
                   10883: 
1.168     raeburn  10884: sub get_languages_hash {
                   10885:     my %langchoices;
                   10886:     foreach my $id (&Apache::loncommon::languageids()) {
                   10887:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   10888:         if ($code ne '') {
                   10889:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   10890:         }
                   10891:     }
                   10892:     return %langchoices;
                   10893: }
                   10894: 
1.43      raeburn  10895: sub defaults_titles {
1.141     raeburn  10896:     my ($dom) = @_;
1.43      raeburn  10897:     my %titles = &Apache::lonlocal::texthash (
                   10898:                    'auth_def'      => 'Default authentication type',
                   10899:                    'auth_arg_def'  => 'Default authentication argument',
                   10900:                    'lang_def'      => 'Default language',
1.54      raeburn  10901:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  10902:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  10903:                    'portal_def'     => 'Portal/Default URL',
1.414     raeburn  10904:                    'email'          => 'Email links use portal URL',
                   10905:                    'web'            => 'Public web links use portal URL',
1.294     raeburn  10906:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   10907:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   10908:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  10909:                  );
1.141     raeburn  10910:     if ($dom) {
                   10911:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   10912:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   10913:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   10914:         $protocol = 'http' if ($protocol ne 'https');
                   10915:         if ($uint_dom) {
                   10916:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   10917:                                          $uint_dom);
                   10918:         }
                   10919:     }
1.43      raeburn  10920:     return (\%titles);
                   10921: }
                   10922: 
1.346     raeburn  10923: sub print_scantron {
                   10924:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   10925:     if ($position eq 'top') {
                   10926:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   10927:     } else {
                   10928:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   10929:     }
                   10930: }
                   10931: 
                   10932: sub scantron_javascript {
                   10933:     return <<"ENDSCRIPT";
                   10934: 
                   10935: <script type="text/javascript">
                   10936: // <![CDATA[
                   10937: 
                   10938: function toggleScantron(form) {
1.347     raeburn  10939:     var csvfieldset = new Array();
1.346     raeburn  10940:     if (document.getElementById('scantroncsv_cols')) {
1.347     raeburn  10941:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   10942:     }
                   10943:     if (document.getElementById('scantroncsv_options')) {
                   10944:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   10945:     }
                   10946:     if (csvfieldset.length) {
1.346     raeburn  10947:         if (document.getElementById('scantronconfcsv')) {
1.347     raeburn  10948:             var scantroncsv = document.getElementById('scantronconfcsv');
1.346     raeburn  10949:             if (scantroncsv.checked) {
1.347     raeburn  10950:                 for (var i=0; i<csvfieldset.length; i++) {
                   10951:                     csvfieldset[i].style.display = 'block';
                   10952:                 }
1.346     raeburn  10953:             } else {
1.347     raeburn  10954:                 for (var i=0; i<csvfieldset.length; i++) {
                   10955:                     csvfieldset[i].style.display = 'none';
                   10956:                 }
1.346     raeburn  10957:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   10958:                 if (csvselects.length) {
                   10959:                     for (var j=0; j<csvselects.length; j++) {
                   10960:                         csvselects[j].selectedIndex = 0;
                   10961:                     }
                   10962:                 }
                   10963:             }
                   10964:         }
                   10965:     }
                   10966:     return;
                   10967: }
                   10968: // ]]>
                   10969: </script>
                   10970: 
                   10971: ENDSCRIPT
                   10972: 
                   10973: }
                   10974: 
1.46      raeburn  10975: sub print_scantronformat {
                   10976:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   10977:     my $itemcount = 1;
1.60      raeburn  10978:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   10979:         %confhash);
1.46      raeburn  10980:     my $switchserver = &check_switchserver($dom,$confname);
                   10981:     my %lt = &Apache::lonlocal::texthash (
1.95      www      10982:                 default => 'Default bubblesheet format file error',
                   10983:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  10984:              );
                   10985:     my %scantronfiles = (
                   10986:         default => 'default.tab',
                   10987:         custom => 'custom.tab',
                   10988:     );
                   10989:     foreach my $key (keys(%scantronfiles)) {
                   10990:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   10991:                               .$scantronfiles{$key};
                   10992:     }
                   10993:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   10994:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   10995:         if (!$switchserver) {
                   10996:             my $servadm = $r->dir_config('lonAdmEMail');
                   10997:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   10998:             if ($configuserok eq 'ok') {
                   10999:                 if ($author_ok eq 'ok') {
                   11000:                     my %legacyfile = (
1.346     raeburn  11001:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   11002:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  11003:                     );
                   11004:                     my %md5chk;
                   11005:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  11006:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   11007:                         chomp($md5chk{$type});
1.46      raeburn  11008:                     }
                   11009:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   11010:                         foreach my $type (keys(%legacyfile)) {
1.346     raeburn  11011:                             ($scantronurls{$type},my $error) =
1.46      raeburn  11012:                                 &legacy_scantronformat($r,$dom,$confname,
                   11013:                                                  $type,$legacyfile{$type},
                   11014:                                                  $scantronurls{$type},
                   11015:                                                  $scantronfiles{$type});
1.60      raeburn  11016:                             if ($error ne '') {
                   11017:                                 $error{$type} = $error;
                   11018:                             }
                   11019:                         }
                   11020:                         if (keys(%error) == 0) {
                   11021:                             $is_custom = 1;
1.346     raeburn  11022:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  11023:                                 $scantronurls{'custom'};
1.346     raeburn  11024:                             my $putresult =
1.60      raeburn  11025:                                 &Apache::lonnet::put_dom('configuration',
                   11026:                                                          \%confhash,$dom);
                   11027:                             if ($putresult ne 'ok') {
1.346     raeburn  11028:                                 $error{'custom'} =
1.60      raeburn  11029:                                     '<span class="LC_error">'.
                   11030:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   11031:                             }
1.46      raeburn  11032:                         }
                   11033:                     } else {
1.60      raeburn  11034:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  11035:                             &legacy_scantronformat($r,$dom,$confname,
                   11036:                                           'default',$legacyfile{'default'},
                   11037:                                           $scantronurls{'default'},
                   11038:                                           $scantronfiles{'default'});
1.60      raeburn  11039:                         if ($error eq '') {
                   11040:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   11041:                             my $putresult =
                   11042:                                 &Apache::lonnet::put_dom('configuration',
                   11043:                                                          \%confhash,$dom);
                   11044:                             if ($putresult ne 'ok') {
                   11045:                                 $error{'default'} =
                   11046:                                     '<span class="LC_error">'.
                   11047:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   11048:                             }
                   11049:                         } else {
                   11050:                             $error{'default'} = $error;
                   11051:                         }
1.46      raeburn  11052:                     }
                   11053:                 }
                   11054:             }
                   11055:         } else {
1.95      www      11056:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  11057:         }
                   11058:     }
                   11059:     if (ref($settings) eq 'HASH') {
                   11060:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   11061:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   11062:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   11063:                 $scantronurl = '';
                   11064:             } else {
                   11065:                 $scantronurl = $settings->{'scantronformat'};
                   11066:             }
                   11067:             $is_custom = 1;
                   11068:         } else {
                   11069:             $scantronurl = $scantronurls{'default'};
                   11070:         }
                   11071:     } else {
1.60      raeburn  11072:         if ($is_custom) {
                   11073:             $scantronurl = $scantronurls{'custom'};
                   11074:         } else {
                   11075:             $scantronurl = $scantronurls{'default'};
                   11076:         }
1.46      raeburn  11077:     }
                   11078:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11079:     $datatable .= '<tr'.$css_class.'>';
                   11080:     if (!$is_custom) {
1.65      raeburn  11081:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   11082:                       '<span class="LC_nobreak">';
1.46      raeburn  11083:         if ($scantronurl) {
1.199     raeburn  11084:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   11085:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  11086:         } else {
                   11087:             $datatable = &mt('File unavailable for display');
                   11088:         }
1.65      raeburn  11089:         $datatable .= '</span></td>';
1.60      raeburn  11090:         if (keys(%error) == 0) { 
1.306     raeburn  11091:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  11092:             if (!$switchserver) {
                   11093:                 $datatable .= &mt('Upload:').'<br />';
                   11094:             }
                   11095:         } else {
                   11096:             my $errorstr;
                   11097:             foreach my $key (sort(keys(%error))) {
                   11098:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   11099:             }
                   11100:             $datatable .= '<td>'.$errorstr;
                   11101:         }
1.46      raeburn  11102:     } else {
                   11103:         if (keys(%error) > 0) {
                   11104:             my $errorstr;
                   11105:             foreach my $key (sort(keys(%error))) {
                   11106:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   11107:             } 
1.60      raeburn  11108:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  11109:         } elsif ($scantronurl) {
1.199     raeburn  11110:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   11111:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  11112:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  11113:                           $link.
                   11114:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   11115:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  11116:                           '<td><span class="LC_nobreak">&nbsp;'.
                   11117:                           &mt('Replace:').'</span><br />';
1.46      raeburn  11118:         }
                   11119:     }
                   11120:     if (keys(%error) == 0) {
                   11121:         if ($switchserver) {
                   11122:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   11123:         } else {
1.65      raeburn  11124:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   11125:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  11126:         }
                   11127:     }
                   11128:     $datatable .= '</td></tr>';
                   11129:     $$rowtotal ++;
                   11130:     return $datatable;
                   11131: }
                   11132: 
                   11133: sub legacy_scantronformat {
                   11134:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   11135:     my ($url,$error);
                   11136:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   11137:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421     raeburn  11138:         my $modified = [];
1.46      raeburn  11139:         (my $result,$url) =
1.421     raeburn  11140:             &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
                   11141:                                                     'scantron','','',$newfile,$modified);
                   11142:         if ($result eq 'ok') {
                   11143:             &update_modify_urls($r,$modified);
                   11144:         } else {
1.130     raeburn  11145:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  11146:         }
                   11147:     }
                   11148:     return ($url,$error);
                   11149: }
1.43      raeburn  11150: 
1.346     raeburn  11151: sub print_scantronconfig {
                   11152:     my ($dom,$settings,$rowtotal) = @_;
                   11153:     my $itemcount = 2;
                   11154:     my $is_checked = ' checked="checked"';
1.347     raeburn  11155:     my %optionson = (
                   11156:                      hdr => ' checked="checked"',
                   11157:                      pad => ' checked="checked"',
                   11158:                      rem => ' checked="checked"',
                   11159:                     );
                   11160:     my %optionsoff = (
                   11161:                       hdr => '',
                   11162:                       pad => '',
                   11163:                       rem => '',
                   11164:                      );
1.346     raeburn  11165:     my $currcsvsty = 'none';
1.347     raeburn  11166:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346     raeburn  11167:     my @fields = &scantroncsv_fields();
                   11168:     my %titles = &scantronconfig_titles();
                   11169:     if (ref($settings) eq 'HASH') {
                   11170:         if (ref($settings->{config}) eq 'HASH') {
                   11171:             if ($settings->{config}->{dat}) {
                   11172:                 $checked{'dat'} = $is_checked;
                   11173:             }
                   11174:             if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347     raeburn  11175:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   11176:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   11177:                     if (keys(%csvfields) > 0) {
                   11178:                         $checked{'csv'} = $is_checked;
                   11179:                         $currcsvsty = 'block';
                   11180:                     }
                   11181:                 }
                   11182:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   11183:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   11184:                     foreach my $option (keys(%optionson)) {
                   11185:                         unless ($csvoptions{$option}) {
                   11186:                             $optionsoff{$option} = $optionson{$option};
                   11187:                             $optionson{$option} = '';
                   11188:                         }
                   11189:                     }
1.346     raeburn  11190:                 }
                   11191:             }
                   11192:         } else {
                   11193:             $checked{'dat'} = $is_checked;
                   11194:         }
                   11195:     } else {
                   11196:         $checked{'dat'} = $is_checked;
                   11197:     }
                   11198:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   11199:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   11200:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   11201:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   11202:     foreach my $item ('dat','csv') {
                   11203:         my $id;
                   11204:         if ($item eq 'csv') {
                   11205:             $id = 'id="scantronconfcsv" ';
1.347     raeburn  11206:         }
1.346     raeburn  11207:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   11208:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   11209:         if ($item eq 'csv') {
                   11210:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   11211:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   11212:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   11213:             foreach my $col (@fields) {
                   11214:                 my $selnone;
                   11215:                 if ($csvfields{$col} eq '') {
                   11216:                     $selnone = ' selected="selected"';
                   11217:                 }
                   11218:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   11219:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   11220:                               '<option value=""'.$selnone.'></option>';
                   11221:                 for (my $i=0; $i<20; $i++) {
                   11222:                     my $shown = $i+1;
                   11223:                     my $sel;
                   11224:                     unless ($selnone) {
                   11225:                         if (exists($csvfields{$col})) {
                   11226:                             if ($csvfields{$col} == $i) {
                   11227:                                 $sel = ' selected="selected"';
                   11228:                             }
                   11229:                         }
                   11230:                     }
                   11231:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   11232:                 }
                   11233:                 $datatable .= '</select></td></tr>';
                   11234:            }
1.347     raeburn  11235:            $datatable .= '</table></fieldset>'.
                   11236:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   11237:                          '<legend>'.&mt('CSV Options').'</legend>';
                   11238:            foreach my $option ('hdr','pad','rem') {
                   11239:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   11240:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   11241:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   11242:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   11243:            }
                   11244:            $datatable .= '</fieldset>';
1.346     raeburn  11245:            $itemcount ++;
                   11246:         }
                   11247:     }
                   11248:     $datatable .= '</td></tr>';
                   11249:     $$rowtotal ++;
                   11250:     return $datatable;
                   11251: }
                   11252: 
                   11253: sub scantronconfig_titles {
                   11254:     return &Apache::lonlocal::texthash(
                   11255:                                           dat => 'Standard format (.dat)',
                   11256:                                           csv => 'Comma separated values (.csv)',
1.347     raeburn  11257:                                           hdr => 'Remove first line in file (contains column titles)',
                   11258:                                           pad => 'Prepend 0s to PaperID',
1.348     raeburn  11259:                                           rem => 'Remove leading spaces (except Question Response columns)',
1.346     raeburn  11260:                                           CODE => 'CODE',
                   11261:                                           ID   => 'Student ID',
                   11262:                                           PaperID => 'Paper ID',
                   11263:                                           FirstName => 'First Name',
                   11264:                                           LastName => 'Last Name',
                   11265:                                           FirstQuestion => 'First Question Response',
                   11266:                                           Section => 'Section',
                   11267:     );
                   11268: }
                   11269: 
                   11270: sub scantroncsv_fields {
                   11271:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   11272: }
                   11273: 
1.49      raeburn  11274: sub print_coursecategories {
1.57      raeburn  11275:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   11276:     my $datatable;
                   11277:     if ($position eq 'top') {
1.238     raeburn  11278:         my (%checked);
                   11279:         my @catitems = ('unauth','auth');
                   11280:         my @cattypes = ('std','domonly','codesrch','none');
                   11281:         $checked{'unauth'} = 'std';
                   11282:         $checked{'auth'} = 'std';
                   11283:         if (ref($settings) eq 'HASH') {
                   11284:             foreach my $type (@cattypes) {
                   11285:                 if ($type eq $settings->{'unauth'}) {
                   11286:                     $checked{'unauth'} = $type;
                   11287:                 }
                   11288:                 if ($type eq $settings->{'auth'}) {
                   11289:                     $checked{'auth'} = $type;
                   11290:                 }
                   11291:             }
                   11292:         }
                   11293:         my %lt = &Apache::lonlocal::texthash (
                   11294:                                                unauth   => 'Catalog type for unauthenticated users',
                   11295:                                                auth     => 'Catalog type for authenticated users',
                   11296:                                                none     => 'No catalog',
                   11297:                                                std      => 'Standard catalog',
                   11298:                                                domonly  => 'Domain-only catalog',
                   11299:                                                codesrch => "Code search form",
                   11300:                                              );
                   11301:        my $itemcount = 0;
                   11302:        foreach my $item (@catitems) {
                   11303:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   11304:            $datatable .= '<tr '.$css_class.'>'.
                   11305:                          '<td>'.$lt{$item}.'</td>'.
                   11306:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   11307:            foreach my $type (@cattypes) {
                   11308:                my $ischecked;
                   11309:                if ($checked{$item} eq $type) {
                   11310:                    $ischecked=' checked="checked"';
                   11311:                }
                   11312:                $datatable .= '<label>'.
                   11313:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   11314:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   11315:            }
1.327     raeburn  11316:            $datatable .= '</span></td></tr>';
1.238     raeburn  11317:            $itemcount ++;
                   11318:         }
                   11319:         $$rowtotal += $itemcount;
                   11320:     } elsif ($position eq 'middle') {
1.57      raeburn  11321:         my $toggle_cats_crs = ' ';
                   11322:         my $toggle_cats_dom = ' checked="checked" ';
                   11323:         my $can_cat_crs = ' ';
                   11324:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  11325:         my $toggle_catscomm_comm = ' ';
                   11326:         my $toggle_catscomm_dom = ' checked="checked" ';
                   11327:         my $can_catcomm_comm = ' ';
                   11328:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  11329:         my $toggle_catsplace_place = ' ';
                   11330:         my $toggle_catsplace_dom = ' checked="checked" ';
                   11331:         my $can_catplace_place = ' ';
                   11332:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  11333: 
1.57      raeburn  11334:         if (ref($settings) eq 'HASH') {
                   11335:             if ($settings->{'togglecats'} eq 'crs') {
                   11336:                 $toggle_cats_crs = $toggle_cats_dom;
                   11337:                 $toggle_cats_dom = ' ';
                   11338:             }
                   11339:             if ($settings->{'categorize'} eq 'crs') {
                   11340:                 $can_cat_crs = $can_cat_dom;
                   11341:                 $can_cat_dom = ' ';
                   11342:             }
1.120     raeburn  11343:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   11344:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   11345:                 $toggle_catscomm_dom = ' ';
                   11346:             }
                   11347:             if ($settings->{'categorizecomm'} eq 'comm') {
                   11348:                 $can_catcomm_comm = $can_catcomm_dom;
                   11349:                 $can_catcomm_dom = ' ';
                   11350:             }
1.272     raeburn  11351:             if ($settings->{'togglecatsplace'} eq 'place') {
                   11352:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   11353:                 $toggle_catsplace_dom = ' ';
                   11354:             }
                   11355:             if ($settings->{'categorizeplace'} eq 'place') {
                   11356:                 $can_catplace_place = $can_catplace_dom;
                   11357:                 $can_catplace_dom = ' ';
                   11358:             }
1.57      raeburn  11359:         }
                   11360:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  11361:                      togglecats      => 'Show/Hide a course in catalog',
                   11362:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   11363:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   11364:                      categorize      => 'Assign a category to a course',
                   11365:                      categorizecomm  => 'Assign a category to a community',
                   11366:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  11367:                     );
                   11368:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  11369:                      dom   => 'Set in Domain',
                   11370:                      crs   => 'Set in Course',
                   11371:                      comm  => 'Set in Community',
                   11372:                      place => 'Set in Placement Test',
1.57      raeburn  11373:                     );
                   11374:         $datatable = '<tr class="LC_odd_row">'.
                   11375:                   '<td>'.$title{'togglecats'}.'</td>'.
                   11376:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   11377:                   '<input type="radio" name="togglecats"'.
                   11378:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11379:                   '<label><input type="radio" name="togglecats"'.
                   11380:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   11381:                   '</tr><tr>'.
                   11382:                   '<td>'.$title{'categorize'}.'</td>'.
                   11383:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   11384:                   '<label><input type="radio" name="categorize"'.
                   11385:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11386:                   '<label><input type="radio" name="categorize"'.
                   11387:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  11388:                   '</tr><tr class="LC_odd_row">'.
                   11389:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   11390:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   11391:                   '<input type="radio" name="togglecatscomm"'.
                   11392:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11393:                   '<label><input type="radio" name="togglecatscomm"'.
                   11394:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   11395:                   '</tr><tr>'.
                   11396:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   11397:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   11398:                   '<label><input type="radio" name="categorizecomm"'.
                   11399:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11400:                   '<label><input type="radio" name="categorizecomm"'.
                   11401:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327     raeburn  11402:                   '</tr><tr class="LC_odd_row">'.
1.272     raeburn  11403:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   11404:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   11405:                   '<input type="radio" name="togglecatsplace"'.
                   11406:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11407:                   '<label><input type="radio" name="togglecatscomm"'.
                   11408:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   11409:                   '</tr><tr>'.
                   11410:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   11411:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   11412:                   '<label><input type="radio" name="categorizeplace"'.
                   11413:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11414:                   '<label><input type="radio" name="categorizeplace"'.
                   11415:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  11416:                   '</tr>';
1.272     raeburn  11417:         $$rowtotal += 6;
1.57      raeburn  11418:     } else {
                   11419:         my $css_class;
                   11420:         my $itemcount = 1;
                   11421:         my $cathash; 
                   11422:         if (ref($settings) eq 'HASH') {
                   11423:             $cathash = $settings->{'cats'};
                   11424:         }
                   11425:         if (ref($cathash) eq 'HASH') {
                   11426:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   11427:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   11428:                                                    \%allitems,\%idx,\@jsarray);
                   11429:             my $maxdepth = scalar(@cats);
                   11430:             my $colattrib = '';
                   11431:             if ($maxdepth > 2) {
                   11432:                 $colattrib = ' colspan="2" ';
                   11433:             }
                   11434:             my @path;
                   11435:             if (@cats > 0) {
                   11436:                 if (ref($cats[0]) eq 'ARRAY') {
                   11437:                     my $numtop = @{$cats[0]};
                   11438:                     my $maxnum = $numtop;
1.120     raeburn  11439:                     my %default_names = (
                   11440:                           instcode    => &mt('Official courses'),
                   11441:                           communities => &mt('Communities'),
1.272     raeburn  11442:                           placement   => &mt('Placement Tests'),
1.120     raeburn  11443:                     );
                   11444: 
                   11445:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   11446:                         ($cathash->{'instcode::0'} eq '') ||
                   11447:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  11448:                         ($cathash->{'communities::0'} eq '') ||
                   11449:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   11450:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  11451:                         $maxnum ++;
                   11452:                     }
                   11453:                     my $lastidx;
                   11454:                     for (my $i=0; $i<$numtop; $i++) {
                   11455:                         my $parent = $cats[0][$i];
                   11456:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11457:                         my $item = &escape($parent).'::0';
                   11458:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   11459:                         $lastidx = $idx{$item};
                   11460:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   11461:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   11462:                         for (my $k=0; $k<=$maxnum; $k++) {
                   11463:                             my $vpos = $k+1;
                   11464:                             my $selstr;
                   11465:                             if ($k == $i) {
                   11466:                                 $selstr = ' selected="selected" ';
                   11467:                             }
                   11468:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   11469:                         }
1.214     raeburn  11470:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  11471:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  11472:                             $datatable .=  '<span class="LC_nobreak">'
                   11473:                                            .$default_names{$parent}.'</span>';
                   11474:                             if ($parent eq 'instcode') {
                   11475:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   11476:                                               .&mt('with institutional codes')
                   11477:                                               .')</span></td><td'.$colattrib.'>';
                   11478:                             } else {
                   11479:                                 $datatable .= '<table><tr><td>';
                   11480:                             }
                   11481:                             $datatable .= '<span class="LC_nobreak">'
                   11482:                                           .'<label><input type="radio" name="'
                   11483:                                           .$parent.'" value="1" checked="checked" />'
                   11484:                                           .&mt('Display').'</label>';
                   11485:                             if ($parent eq 'instcode') {
                   11486:                                 $datatable .= '&nbsp;';
                   11487:                             } else {
                   11488:                                 $datatable .= '</span></td></tr><tr><td>'
                   11489:                                               .'<span class="LC_nobreak">';
                   11490:                             }
                   11491:                             $datatable .= '<label><input type="radio" name="'
                   11492:                                           .$parent.'" value="0" />'
                   11493:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  11494:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  11495:                                 $datatable .= '</td></tr></table>';
                   11496:                             }
                   11497:                             $datatable .= '</td>';
1.57      raeburn  11498:                         } else {
                   11499:                             $datatable .= $parent
1.214     raeburn  11500:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   11501:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  11502:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   11503:                         }
                   11504:                         my $depth = 1;
                   11505:                         push(@path,$parent);
                   11506:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   11507:                         pop(@path);
                   11508:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   11509:                         $itemcount ++;
                   11510:                     }
1.48      raeburn  11511:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  11512:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   11513:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  11514:                     for (my $k=0; $k<=$maxnum; $k++) {
                   11515:                         my $vpos = $k+1;
                   11516:                         my $selstr;
1.57      raeburn  11517:                         if ($k == $numtop) {
1.48      raeburn  11518:                             $selstr = ' selected="selected" ';
                   11519:                         }
                   11520:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   11521:                     }
1.59      bisitz   11522:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  11523:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   11524:                                   .'</tr>'."\n";
1.48      raeburn  11525:                     $itemcount ++;
1.272     raeburn  11526:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  11527:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   11528:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11529:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   11530:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   11531:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   11532:                             for (my $k=0; $k<=$maxnum; $k++) {
                   11533:                                 my $vpos = $k+1;
                   11534:                                 my $selstr;
                   11535:                                 if ($k == $maxnum) {
                   11536:                                     $selstr = ' selected="selected" ';
                   11537:                                 }
                   11538:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  11539:                             }
1.120     raeburn  11540:                             $datatable .= '</select></span></td>'.
                   11541:                                           '<td><span class="LC_nobreak">'.
                   11542:                                           $default_names{$default}.'</span>';
                   11543:                             if ($default eq 'instcode') {
                   11544:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   11545:                                               .&mt('with institutional codes').')</span>';
                   11546:                             }
                   11547:                             $datatable .= '</td>'
                   11548:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   11549:                                           .&mt('Display').'</label>&nbsp;'
                   11550:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   11551:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  11552:                         }
                   11553:                     }
                   11554:                 }
1.57      raeburn  11555:             } else {
                   11556:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  11557:             }
                   11558:         } else {
1.327     raeburn  11559:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  11560:                           .&initialize_categories($itemcount);
1.48      raeburn  11561:         }
1.57      raeburn  11562:         $$rowtotal += $itemcount;
1.48      raeburn  11563:     }
                   11564:     return $datatable;
                   11565: }
                   11566: 
1.69      raeburn  11567: sub print_serverstatuses {
                   11568:     my ($dom,$settings,$rowtotal) = @_;
                   11569:     my $datatable;
                   11570:     my @pages = &serverstatus_pages();
                   11571:     my (%namedaccess,%machineaccess);
                   11572:     foreach my $type (@pages) {
                   11573:         $namedaccess{$type} = '';
                   11574:         $machineaccess{$type}= '';
                   11575:     }
                   11576:     if (ref($settings) eq 'HASH') {
                   11577:         foreach my $type (@pages) {
                   11578:             if (exists($settings->{$type})) {
                   11579:                 if (ref($settings->{$type}) eq 'HASH') {
                   11580:                     foreach my $key (keys(%{$settings->{$type}})) {
                   11581:                         if ($key eq 'namedusers') {
                   11582:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   11583:                         } elsif ($key eq 'machines') {
                   11584:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   11585:                         }
                   11586:                     }
                   11587:                 }
                   11588:             }
                   11589:         }
                   11590:     }
1.81      raeburn  11591:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  11592:     my $rownum = 0;
                   11593:     my $css_class;
                   11594:     foreach my $type (@pages) {
                   11595:         $rownum ++;
                   11596:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   11597:         $datatable .= '<tr'.$css_class.'>'.
                   11598:                       '<td><span class="LC_nobreak">'.
                   11599:                       $titles->{$type}.'</span></td>'.
                   11600:                       '<td class="LC_left_item">'.
                   11601:                       '<input type="text" name="'.$type.'_namedusers" '.
                   11602:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   11603:                       '<td class="LC_right_item">'.
                   11604:                       '<span class="LC_nobreak">'.
                   11605:                       '<input type="text" name="'.$type.'_machines" '.
                   11606:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.334     raeburn  11607:                       '</span></td></tr>'."\n";
1.69      raeburn  11608:     }
                   11609:     $$rowtotal += $rownum;
                   11610:     return $datatable;
                   11611: }
                   11612: 
                   11613: sub serverstatus_pages {
                   11614:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  11615:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   11616:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   11617:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  11618: }
                   11619: 
1.236     raeburn  11620: sub defaults_javascript {
                   11621:     my ($settings) = @_;
1.354     raeburn  11622:     return unless (ref($settings) eq 'HASH');
1.414     raeburn  11623:     my $portal_js = <<"ENDPORTAL";
                   11624: 
                   11625: function portalExtras(caller) {
                   11626:     var x = caller.value;
                   11627:     var y = new Array('email','web');
1.425     raeburn  11628:     for (var i=0; i<y.length; i++) {
1.414     raeburn  11629:         if (document.getElementById('portal_def_'+y[i]+'_div')) {
                   11630:             var z = document.getElementById('portal_def_'+y[i]+'_div');
                   11631:             if (x.length > 0) {
                   11632:                 z.style.display = 'block';
                   11633:             } else {
                   11634:                 z.style.display = 'none';
                   11635:             }
                   11636:         }
                   11637:     }
                   11638: }
                   11639: ENDPORTAL
1.236     raeburn  11640:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   11641:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   11642:         if ($maxnum eq '') {
                   11643:             $maxnum = 0;
                   11644:         }
                   11645:         $maxnum ++;
1.249     raeburn  11646:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  11647:         return <<"ENDSCRIPT";
                   11648: <script type="text/javascript">
                   11649: // <![CDATA[
                   11650: function reorderTypes(form,caller) {
                   11651:     var changedVal;
                   11652: $jstext 
                   11653:     var newpos = 'addinststatus_pos';
                   11654:     var current = new Array;
                   11655:     var maxh = $maxnum;
                   11656:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11657:     var oldVal;
                   11658:     if (caller == newpos) {
                   11659:         changedVal = newitemVal;
                   11660:     } else {
                   11661:         var curritem = 'inststatus_pos_'+caller;
                   11662:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   11663:         current[newitemVal] = newpos;
                   11664:     }
                   11665:     for (var i=0; i<inststatuses.length; i++) {
                   11666:         if (inststatuses[i] != caller) {
                   11667:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   11668:             if (form.elements[elementName]) {
                   11669:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11670:                 current[currVal] = elementName;
                   11671:             }
                   11672:         }
                   11673:     }
                   11674:     for (var j=0; j<maxh; j++) {
                   11675:         if (current[j] == undefined) {
                   11676:             oldVal = j;
                   11677:         }
                   11678:     }
                   11679:     if (oldVal < changedVal) {
                   11680:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11681:            var elementName = current[k];
                   11682:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11683:         }
                   11684:     } else {
                   11685:         for (var k=changedVal; k<oldVal; k++) {
                   11686:             var elementName = current[k];
                   11687:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11688:         }
                   11689:     }
                   11690:     return;
                   11691: }
                   11692: 
1.414     raeburn  11693: $portal_js
                   11694: 
                   11695: // ]]>
                   11696: </script>
                   11697: 
                   11698: ENDSCRIPT
                   11699:     } else {
                   11700: return <<"ENDSCRIPT";
                   11701: <script type="text/javascript">
                   11702: // <![CDATA[
                   11703: $portal_js
1.236     raeburn  11704: // ]]>
                   11705: </script>
                   11706: 
                   11707: ENDSCRIPT
                   11708:     }
1.354     raeburn  11709:     return;
                   11710: }
                   11711: 
                   11712: sub passwords_javascript {
1.405     raeburn  11713:     my ($prefix) = @_;
                   11714:     my %intalert;
                   11715:     if ($prefix eq 'passwords') {
                   11716:         %intalert = &Apache::lonlocal::texthash (
                   11717:             authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
                   11718:             authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   11719:             passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   11720:             passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   11721:             passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   11722:             passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   11723:         );
1.421     raeburn  11724:     } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405     raeburn  11725:         %intalert = &Apache::lonlocal::texthash (
                   11726:             passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
                   11727:             passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
                   11728:         );
                   11729:     }
1.365     raeburn  11730:     &js_escape(\%intalert);
                   11731:     my $defmin = $Apache::lonnet::passwdmin;
1.425     raeburn  11732:     my $intauthjs;
1.405     raeburn  11733:     if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354     raeburn  11734: 
                   11735: function warnIntAuth(field) {
                   11736:     if (field.name == 'intauth_check') {
                   11737:         if (field.value == '2') {
1.365     raeburn  11738:             alert('$intalert{authcheck}');
1.354     raeburn  11739:         }
                   11740:     }
                   11741:     if (field.name == 'intauth_cost') {
                   11742:         field.value.replace(/\s/g,'');
                   11743:         if (field.value != '') {
                   11744:             var regexdigit=/^\\d+\$/;
                   11745:             if (!regexdigit.test(field.value)) {
1.365     raeburn  11746:                 alert('$intalert{authcost}');
                   11747:             }
                   11748:         }
                   11749:     }
                   11750:     return;
                   11751: }
                   11752: 
1.405     raeburn  11753: ENDSCRIPT
                   11754: 
                   11755:      }
                   11756: 
                   11757:      $intauthjs .= <<"ENDSCRIPT";
                   11758: 
                   11759: function warnInt$prefix(field) {
1.365     raeburn  11760:     field.value.replace(/^\s+/,'');
                   11761:     field.value.replace(/\s+\$/,'');
                   11762:     var regexdigit=/^\\d+\$/;
1.408     raeburn  11763:     if (field.name == '${prefix}_min') {
1.365     raeburn  11764:         if (field.value == '') {
                   11765:             alert('$intalert{passmin}');
                   11766:             field.value = '$defmin';
                   11767:         } else {
                   11768:             if (!regexdigit.test(field.value)) {
                   11769:                 alert('$intalert{passmin}');
                   11770:                 field.value = '$defmin';
                   11771:             }
1.366     raeburn  11772:             var minval = parseInt(field.value,10);
1.365     raeburn  11773:             if (minval < $defmin) {
                   11774:                 alert('$intalert{passmin}');
                   11775:                 field.value = '$defmin';
                   11776:             }
                   11777:         }
                   11778:     } else {
                   11779:         if (field.value == '0') {
                   11780:             field.value = '';
                   11781:         }
                   11782:         if (field.value != '') {
1.408     raeburn  11783:             if (field.name == '${prefix}_expire') {
1.365     raeburn  11784:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/; 
                   11785:                 if (!regexpposnum.test(field.value)) {
                   11786:                     alert('$intalert{passexp}');
                   11787:                     field.value = '';
                   11788:                 } else {
                   11789:                     var expval = parseFloat(field.value);
                   11790:                     if (expval == 0) {
                   11791:                         alert('$intalert{passexp}');
                   11792:                         field.value = '';
                   11793:                     }
                   11794:                 }
                   11795:             } else {
                   11796:                 if (!regexdigit.test(field.value)) {
1.408     raeburn  11797:                     if (field.name == '${prefix}_max') {
1.365     raeburn  11798:                         alert('$intalert{passmax}');
                   11799:                     } else {
1.408     raeburn  11800:                         if (field.name == '${prefix}_numsaved') {
1.365     raeburn  11801:                             alert('$intalert{passnum}');
                   11802:                         }
                   11803:                     }
1.370     raeburn  11804:                     field.value = '';
1.365     raeburn  11805:                 }
1.354     raeburn  11806:             }
                   11807:         }
                   11808:     }
                   11809:     return;
                   11810: }
                   11811: 
                   11812: ENDSCRIPT
                   11813:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  11814: }
                   11815: 
1.49      raeburn  11816: sub coursecategories_javascript {
                   11817:     my ($settings) = @_;
1.57      raeburn  11818:     my ($output,$jstext,$cathash);
1.49      raeburn  11819:     if (ref($settings) eq 'HASH') {
1.57      raeburn  11820:         $cathash = $settings->{'cats'};
                   11821:     }
                   11822:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  11823:         my (@cats,@jsarray,%idx);
1.57      raeburn  11824:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  11825:         if (@jsarray > 0) {
                   11826:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   11827:             for (my $i=0; $i<@jsarray; $i++) {
                   11828:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   11829:                     my $catstr = join('","',@{$jsarray[$i]});
                   11830:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   11831:                 }
                   11832:             }
                   11833:         }
                   11834:     } else {
                   11835:         $jstext  = '    var categories = Array(1);'."\n".
                   11836:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   11837:     }
1.237     bisitz   11838:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   11839:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  11840:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  11841:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   11842:     &js_escape(\$instcode_reserved);
                   11843:     &js_escape(\$communities_reserved);
1.272     raeburn  11844:     &js_escape(\$placement_reserved);
1.265     damieng  11845:     &js_escape(\$choose_again);
1.49      raeburn  11846:     $output = <<"ENDSCRIPT";
                   11847: <script type="text/javascript">
1.109     raeburn  11848: // <![CDATA[
1.49      raeburn  11849: function reorderCats(form,parent,item,idx) {
                   11850:     var changedVal;
                   11851: $jstext
                   11852:     var newpos = 'addcategory_pos';
                   11853:     if (parent == '') {
                   11854:         var has_instcode = 0;
                   11855:         var maxtop = categories[idx].length;
                   11856:         for (var j=0; j<maxtop; j++) {
                   11857:             if (categories[idx][j] == 'instcode::0') {
                   11858:                 has_instcode == 1;
                   11859:             }
                   11860:         }
                   11861:         if (has_instcode == 0) {
                   11862:             categories[idx][maxtop] = 'instcode_pos';
                   11863:         }
                   11864:     } else {
                   11865:         newpos += '_'+parent;
                   11866:     }
                   11867:     var maxh = 1 + categories[idx].length;
                   11868:     var current = new Array;
                   11869:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11870:     if (item == newpos) {
                   11871:         changedVal = newitemVal;
                   11872:     } else {
                   11873:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   11874:         current[newitemVal] = newpos;
                   11875:     }
                   11876:     for (var i=0; i<categories[idx].length; i++) {
                   11877:         var elementName = categories[idx][i];
                   11878:         if (elementName != item) {
                   11879:             if (form.elements[elementName]) {
                   11880:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11881:                 current[currVal] = elementName;
                   11882:             }
                   11883:         }
                   11884:     }
                   11885:     var oldVal;
                   11886:     for (var j=0; j<maxh; j++) {
                   11887:         if (current[j] == undefined) {
                   11888:             oldVal = j;
                   11889:         }
                   11890:     }
                   11891:     if (oldVal < changedVal) {
                   11892:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11893:            var elementName = current[k];
                   11894:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11895:         }
                   11896:     } else {
                   11897:         for (var k=changedVal; k<oldVal; k++) {
                   11898:             var elementName = current[k];
                   11899:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11900:         }
                   11901:     }
                   11902:     return;
                   11903: }
1.120     raeburn  11904: 
                   11905: function categoryCheck(form) {
                   11906:     if (form.elements['addcategory_name'].value == 'instcode') {
                   11907:         alert('$instcode_reserved\\n$choose_again');
                   11908:         return false;
                   11909:     }
                   11910:     if (form.elements['addcategory_name'].value == 'communities') {
                   11911:         alert('$communities_reserved\\n$choose_again');
                   11912:         return false;
                   11913:     }
1.272     raeburn  11914:     if (form.elements['addcategory_name'].value == 'placement') {
                   11915:         alert('$placement_reserved\\n$choose_again');
                   11916:         return false;
                   11917:     }
1.120     raeburn  11918:     return true;
                   11919: }
                   11920: 
1.109     raeburn  11921: // ]]>
1.49      raeburn  11922: </script>
                   11923: 
                   11924: ENDSCRIPT
                   11925:     return $output;
                   11926: }
                   11927: 
1.48      raeburn  11928: sub initialize_categories {
                   11929:     my ($itemcount) = @_;
1.120     raeburn  11930:     my ($datatable,$css_class,$chgstr);
1.380     raeburn  11931:     my %default_names = &Apache::lonlocal::texthash (
1.120     raeburn  11932:                       instcode    => 'Official courses (with institutional codes)',
                   11933:                       communities => 'Communities',
1.272     raeburn  11934:                       placement   => 'Placement Tests',
1.120     raeburn  11935:                         );
1.328     raeburn  11936:     my %selnum = (
                   11937:                    instcode    => '0',
                   11938:                    communities => '1',
                   11939:                    placement   => '2',
                   11940:                  );
                   11941:     my %selected;
1.272     raeburn  11942:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  11943:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327     raeburn  11944:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328     raeburn  11945:         map { $selected{$selnum{$_}} = '' } keys(%selnum);
                   11946:         $selected{$selnum{$default}} = ' selected="selected"';
1.120     raeburn  11947:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328     raeburn  11948:                      .'<select name="'.$default.'_pos"'.$chgstr.'>'
                   11949:                      .'<option value="0"'.$selected{'0'}.'>1</option>'
                   11950:                      .'<option value="1"'.$selected{'1'}.'>2</option>'
                   11951:                      .'<option value="2"'.$selected{'2'}.'>3</option>'
                   11952:                      .'<option value="3">4</option></select>&nbsp;'
1.120     raeburn  11953:                      .$default_names{$default}
                   11954:                      .'</span></td><td><span class="LC_nobreak">'
                   11955:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   11956:                      .&mt('Display').'</label>&nbsp;<label>'
                   11957:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  11958:                  .'</label></span></td></tr>';
1.120     raeburn  11959:         $itemcount ++;
                   11960:     }
1.48      raeburn  11961:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  11962:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  11963:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  11964:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   11965:                   .'<option value="0">1</option>'
                   11966:                   .'<option value="1">2</option>'
1.328     raeburn  11967:                   .'<option value="2">3</option>'
                   11968:                   .'<option value="3" selected="selected">4</option></select>&nbsp;'
1.327     raeburn  11969:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                   11970:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   11971:                   .'</td></tr>';
1.48      raeburn  11972:     return $datatable;
                   11973: }
                   11974: 
                   11975: sub build_category_rows {
1.49      raeburn  11976:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   11977:     my ($text,$name,$item,$chgstr);
1.48      raeburn  11978:     if (ref($cats) eq 'ARRAY') {
                   11979:         my $maxdepth = scalar(@{$cats});
                   11980:         if (ref($cats->[$depth]) eq 'HASH') {
                   11981:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   11982:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   11983:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  11984:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  11985:                 my ($idxnum,$parent_name,$parent_item);
                   11986:                 my $higher = $depth - 1;
                   11987:                 if ($higher == 0) {
                   11988:                     $parent_name = &escape($parent).'::'.$higher;
                   11989:                 } else {
                   11990:                     if (ref($path) eq 'ARRAY') {
                   11991:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11992:                     }
                   11993:                 }
                   11994:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  11995:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  11996:                     if ($j < $numchildren) {
1.48      raeburn  11997:                         $name = $cats->[$depth]{$parent}[$j];
                   11998:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  11999:                         $idxnum = $idx->{$item};
                   12000:                     } else {
                   12001:                         $name = $parent_name;
                   12002:                         $item = $parent_item;
1.48      raeburn  12003:                     }
1.49      raeburn  12004:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   12005:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  12006:                     for (my $i=0; $i<=$numchildren; $i++) {
                   12007:                         my $vpos = $i+1;
                   12008:                         my $selstr;
                   12009:                         if ($j == $i) {
                   12010:                             $selstr = ' selected="selected" ';
                   12011:                         }
                   12012:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   12013:                     }
                   12014:                     $text .= '</select>&nbsp;';
                   12015:                     if ($j < $numchildren) {
                   12016:                         my $deeper = $depth+1;
                   12017:                         $text .= $name.'&nbsp;'
                   12018:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   12019:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   12020:                         if(ref($path) eq 'ARRAY') {
                   12021:                             push(@{$path},$name);
1.49      raeburn  12022:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  12023:                             pop(@{$path});
                   12024:                         }
                   12025:                     } else {
1.330     raeburn  12026:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  12027:                         if ($j == $numchildren) {
                   12028:                             $text .= $name;
                   12029:                         } else {
                   12030:                             $text .= $item;
                   12031:                         }
                   12032:                         $text .= '" value="" />';
                   12033:                     }
                   12034:                     $text .= '</td></tr>';
                   12035:                 }
                   12036:                 $text .= '</table></td>';
                   12037:             } else {
                   12038:                 my $higher = $depth-1;
                   12039:                 if ($higher == 0) {
                   12040:                     $name = &escape($parent).'::'.$higher;
                   12041:                 } else {
                   12042:                     if (ref($path) eq 'ARRAY') {
                   12043:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   12044:                     }
                   12045:                 }
                   12046:                 my $colspan;
                   12047:                 if ($parent ne 'instcode') {
                   12048:                     $colspan = $maxdepth - $depth - 1;
1.330     raeburn  12049:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  12050:                 }
                   12051:             }
                   12052:         }
                   12053:     }
                   12054:     return $text;
                   12055: }
                   12056: 
1.33      raeburn  12057: sub modifiable_userdata_row {
1.305     raeburn  12058:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357     raeburn  12059:         $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228     raeburn  12060:     my ($role,$rolename,$statustype);
                   12061:     $role = $item;
1.224     raeburn  12062:     if ($context eq 'cancreate') {
1.305     raeburn  12063:         if ($item =~ /^(emailusername)_(.+)$/) {
                   12064:             $role = $1;
                   12065:             $statustype = $2;
1.228     raeburn  12066:             if (ref($usertypes) eq 'HASH') {
                   12067:                 if ($usertypes->{$statustype}) {
                   12068:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   12069:                 } else {
                   12070:                     $rolename = &mt('Data provided by user');
                   12071:                 }
                   12072:             }
1.224     raeburn  12073:         }
                   12074:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  12075:         if (ref($usertypes) eq 'HASH') {
                   12076:             $rolename = $usertypes->{$role};
                   12077:         } else {
                   12078:             $rolename = $role;
                   12079:         }
1.325     raeburn  12080:     } elsif ($context eq 'lti') {
                   12081:         $rolename = &mt('Institutional data used (if available)');
1.357     raeburn  12082:     } elsif ($context eq 'privacy') {
                   12083:         $rolename = $itemdesc;
1.33      raeburn  12084:     } else {
1.63      raeburn  12085:         if ($role eq 'cr') {
                   12086:             $rolename = &mt('Custom role');
                   12087:         } else {
                   12088:             $rolename = &Apache::lonnet::plaintext($role);
                   12089:         }
1.33      raeburn  12090:     }
1.224     raeburn  12091:     my (@fields,%fieldtitles);
                   12092:     if (ref($fieldsref) eq 'ARRAY') {
                   12093:         @fields = @{$fieldsref};
                   12094:     } else {
                   12095:         @fields = ('lastname','firstname','middlename','generation',
                   12096:                    'permanentemail','id');
                   12097:     }
                   12098:     if ((ref($titlesref) eq 'HASH')) {
                   12099:         %fieldtitles = %{$titlesref};
                   12100:     } else {
                   12101:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12102:     }
1.33      raeburn  12103:     my $output;
1.305     raeburn  12104:     my $css_class;
                   12105:     if ($rowcount%2) {
                   12106:         $css_class = 'LC_odd_row';
                   12107:     }
                   12108:     if ($customcss) {
                   12109:         $css_class .= " $customcss";
                   12110:     }
                   12111:     $css_class =~ s/^\s+//;
                   12112:     if ($css_class) {
                   12113:         $css_class = ' class="'.$css_class.'"';
                   12114:     }
                   12115:     if ($rowstyle) {
                   12116:         $css_class .= ' style="'.$rowstyle.'"';
                   12117:     }
                   12118:     if ($rowid) {
                   12119:         $rowid = ' id="'.$rowid.'"';
                   12120:     }
                   12121:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  12122:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   12123:               '<td class="LC_left_item" colspan="2"><table>';
                   12124:     my $rem;
                   12125:     my %checks;
                   12126:     if (ref($settings) eq 'HASH') {
1.325     raeburn  12127:         my $hashref;
                   12128:         if ($context eq 'lti') {
                   12129:             if (ref($settings) eq 'HASH') {
                   12130:                 $hashref = $settings->{'instdata'};
                   12131:             }
1.357     raeburn  12132:         } elsif ($context eq 'privacy') {
                   12133:             my ($key,$inner) = split(/_/,$role);
                   12134:             if (ref($settings) eq 'HASH') {
                   12135:                 if (ref($settings->{$key}) eq 'HASH') {
                   12136:                     $hashref = $settings->{$key}->{$inner};
                   12137:                 }
                   12138:             }
1.325     raeburn  12139:         } elsif (ref($settings->{$context}) eq 'HASH') {
1.33      raeburn  12140:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325     raeburn  12141:                 $hashref = $settings->{'lti_instdata'};
                   12142:             }
                   12143:             if ($role eq 'emailusername') {
                   12144:                 if ($statustype) {
                   12145:                     if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   12146:                         $hashref = $settings->{$context}->{$role}->{$statustype};
1.228     raeburn  12147:                     }
1.325     raeburn  12148:                 }
                   12149:             }
                   12150:         }
1.425     raeburn  12151:         if (ref($hashref) eq 'HASH') {
1.325     raeburn  12152:             foreach my $field (@fields) {
                   12153:                 if ($hashref->{$field}) {
                   12154:                     if ($role eq 'emailusername') {
                   12155:                         $checks{$field} = $hashref->{$field};
                   12156:                     } else {
                   12157:                         $checks{$field} = ' checked="checked" ';
1.33      raeburn  12158:                     }
                   12159:                 }
                   12160:             }
                   12161:         }
                   12162:     }
1.305     raeburn  12163:     my $total = scalar(@fields);
                   12164:     for (my $i=0; $i<$total; $i++) {
                   12165:         $rem = $i%($numinrow);
1.33      raeburn  12166:         if ($rem == 0) {
                   12167:             if ($i > 0) {
                   12168:                 $output .= '</tr>';
                   12169:             }
                   12170:             $output .= '<tr>';
                   12171:         }
                   12172:         my $check = ' ';
1.228     raeburn  12173:         unless ($role eq 'emailusername') {
                   12174:             if (exists($checks{$fields[$i]})) {
1.354     raeburn  12175:                 $check = $checks{$fields[$i]};
1.357     raeburn  12176:             } elsif ($context eq 'privacy') {
                   12177:                 if ($role =~ /^priv_(domain|course)$/) {
                   12178:                     if (ref($settings) ne 'HASH') {
                   12179:                         $check = ' checked="checked" ';
                   12180:                     }
                   12181:                 } elsif ($role =~ /^priv_(author|community)$/) {
                   12182:                     if (ref($settings) ne 'HASH') {
                   12183:                         unless ($fields[$i] eq 'id') {
                   12184:                             $check = ' checked="checked" ';
                   12185:                         }
                   12186:                     }
                   12187:                 } elsif ($role =~ /^(unpriv|othdom)_/) {
                   12188:                     if (ref($settings) ne 'HASH') {
                   12189:                         if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                   12190:                             $check = ' checked="checked" ';
                   12191:                         }
                   12192:                     }
                   12193:                 }
1.325     raeburn  12194:             } elsif ($context ne 'lti') {
1.228     raeburn  12195:                 if ($role eq 'st') {
                   12196:                     if (ref($settings) ne 'HASH') {
                   12197:                         $check = ' checked="checked" '; 
                   12198:                     }
1.33      raeburn  12199:                 }
                   12200:             }
                   12201:         }
                   12202:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  12203:                    '<span class="LC_nobreak">';
1.325     raeburn  12204:         my $prefix = 'canmodify';
1.228     raeburn  12205:         if ($role eq 'emailusername') {
                   12206:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   12207:                 $checks{$fields[$i]} = 'omit';
                   12208:             }
                   12209:             foreach my $option ('required','optional','omit') {
                   12210:                 my $checked='';
                   12211:                 if ($checks{$fields[$i]} eq $option) {
                   12212:                     $checked='checked="checked" ';
                   12213:                 }
                   12214:                 $output .= '<label>'.
1.325     raeburn  12215:                            '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228     raeburn  12216:                            &mt($option).'</label>'.('&nbsp;' x2);
                   12217:             }
                   12218:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   12219:         } else {
1.325     raeburn  12220:             if ($context eq 'lti') {
                   12221:                 $prefix = 'lti';
1.357     raeburn  12222:             } elsif ($context eq 'privacy') {
                   12223:                 $prefix = 'privacy';
1.325     raeburn  12224:             }
1.228     raeburn  12225:             $output .= '<label>'.
1.325     raeburn  12226:                        '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228     raeburn  12227:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   12228:                        '</label>';
                   12229:         }
                   12230:         $output .= '</span></td>';
1.33      raeburn  12231:     }
1.305     raeburn  12232:     $rem = $total%$numinrow;
                   12233:     my $colsleft;
                   12234:     if ($rem) {
                   12235:         $colsleft = $numinrow - $rem;
                   12236:     }
                   12237:     if ($colsleft > 1) {
1.33      raeburn  12238:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   12239:                    '&nbsp;</td>';
                   12240:     } elsif ($colsleft == 1) {
                   12241:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   12242:     }
                   12243:     $output .= '</tr></table></td></tr>';
                   12244:     return $output;
                   12245: }
1.28      raeburn  12246: 
1.93      raeburn  12247: sub insttypes_row {
1.305     raeburn  12248:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   12249:         $customcss,$rowstyle) = @_;
1.93      raeburn  12250:     my %lt = &Apache::lonlocal::texthash (
1.429     raeburn  12251:                       cansearch      => 'Users allowed to search',
1.93      raeburn  12252:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429     raeburn  12253:                       lockablenames  => 'User preference to lock name',
                   12254:                       selfassign     => 'Self-reportable affiliations',
                   12255:                       overrides      => "Override domain's helpdesk settings based on requester's affiliation",
                   12256:                       webdav         => 'WebDAV access available',
                   12257:                       authorquota    => 'Authoring Space quota (MB)',
1.93      raeburn  12258:              );
1.429     raeburn  12259:     my ($showdom,$defaultquota);
1.93      raeburn  12260:     if ($context eq 'cansearch') {
                   12261:         $showdom = ' ('.$dom.')';
1.429     raeburn  12262:     } elsif ($context eq 'authorquota') {
                   12263:         $defaultquota = 500;
1.93      raeburn  12264:     }
1.165     raeburn  12265:     my $class = 'LC_left_item';
                   12266:     if ($context eq 'statustocreate') {
                   12267:         $class = 'LC_right_item';
                   12268:     }
1.305     raeburn  12269:     my $css_class;
                   12270:     if ($$rowtotal%2) {
                   12271:         $css_class = 'LC_odd_row';
                   12272:     }
                   12273:     if ($customcss) {
                   12274:         $css_class .= ' '.$customcss;
                   12275:     }
                   12276:     $css_class =~ s/^\s+//;
                   12277:     if ($css_class) {
                   12278:         $css_class = ' class="'.$css_class.'"';
                   12279:     }
                   12280:     if ($rowstyle) {
                   12281:         $css_class .= ' style="'.$rowstyle.'"';
                   12282:     }
                   12283:     if ($onclick) {
                   12284:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  12285:     }
                   12286:     my $output = '<tr'.$css_class.'>'.
                   12287:                  '<td>'.$lt{$context}.$showdom.
                   12288:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  12289:     my $rem;
                   12290:     if (ref($types) eq 'ARRAY') {
                   12291:         for (my $i=0; $i<@{$types}; $i++) {
                   12292:             if (defined($usertypes->{$types->[$i]})) {
                   12293:                 my $rem = $i%($numinrow);
                   12294:                 if ($rem == 0) {
                   12295:                     if ($i > 0) {
                   12296:                         $output .= '</tr>';
                   12297:                     }
                   12298:                     $output .= '<tr>';
1.23      raeburn  12299:                 }
1.429     raeburn  12300:                 if ($context eq 'authorquota') {
                   12301:                     my $currquota;
                   12302:                     if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
                   12303:                         $currquota = $settings->{$context}->{$types->[$i]};
                   12304:                     } else {
                   12305:                         $currquota = $defaultquota;
                   12306:                     }
                   12307:                     $output .= '<td class="LC_left_item">'."\n".
                   12308:                                '<label><span class="LC_nobreak">'."\n".
                   12309:                                $usertypes->{$types->[$i]}.'</span><br />'."\n".
                   12310:                                '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
                   12311:                                'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
                   12312:                                '</label></td>';
                   12313:                 } else {
                   12314:                     my $check = ' ';
                   12315:                     if (ref($settings) eq 'HASH') {
                   12316:                         if (ref($settings->{$context}) eq 'ARRAY') {
                   12317:                             if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   12318:                                 $check = ' checked="checked" ';
                   12319:                             }
                   12320:                         } elsif (ref($settings->{$context}) eq 'HASH') {
                   12321:                             if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   12322:                                 $check = ' checked="checked" ';
                   12323:                             } elsif ($context eq 'webdav') {
                   12324:                                 if ($settings->{$context}->{$types->[$i]}) {
                   12325:                                     $check = ' checked="checked" ';
                   12326:                                 }
                   12327:                             }
                   12328:                         } elsif ($context eq 'statustocreate') {
1.315     raeburn  12329:                             $check = ' checked="checked" ';
                   12330:                         }
1.26      raeburn  12331:                     }
1.429     raeburn  12332:                     $output .= '<td class="LC_left_item">'.
                   12333:                                '<span class="LC_nobreak"><label>'.
                   12334:                                '<input type="checkbox" name="'.$context.'" '.
                   12335:                                'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
                   12336:                                $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  12337:                 }
                   12338:             }
                   12339:         }
1.26      raeburn  12340:         $rem = @{$types}%($numinrow);
1.23      raeburn  12341:     }
                   12342:     my $colsleft = $numinrow - $rem;
1.315     raeburn  12343:     if ($context eq 'overrides') {
                   12344:         if ($colsleft > 1) {
                   12345:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   12346:         } else {
                   12347:             $output .= '<td class="LC_left_item">';
                   12348:         }
1.425     raeburn  12349:         $output .= '&nbsp;';
1.23      raeburn  12350:     } else {
1.334     raeburn  12351:         if ($rem == 0) {
1.315     raeburn  12352:             $output .= '<tr>';
                   12353:         }
                   12354:         if ($colsleft > 1) {
                   12355:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   12356:         } else {
                   12357:             $output .= '<td class="LC_left_item">';
                   12358:         }
1.429     raeburn  12359:         if ($context eq 'authorquota') {
                   12360:             my $currquota = 500;
                   12361:             if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
                   12362:                 if ($settings->{$context}{'default'} =~ /^\d+$/) {
                   12363:                     $currquota = $settings->{$context}{'default'};
                   12364:                 }
                   12365:             }
                   12366:             $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
                   12367:                        '<input type="text" name="'.$context.'_default" '.
                   12368:                        'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
                   12369:                        '</label>';
                   12370:         } else {
                   12371:             my $defcheck = ' ';
                   12372:             if (ref($settings) eq 'HASH') {
                   12373:                 if (ref($settings->{$context}) eq 'ARRAY') {
                   12374:                     if (grep(/^default$/,@{$settings->{$context}})) {
                   12375:                         $defcheck = ' checked="checked" ';
                   12376:                     }
                   12377:                 } elsif (ref($settings->{$context}) eq 'HASH') {
                   12378:                     if (ref($settings->{$context}->{'default'}) eq 'HASH') {
                   12379:                         $defcheck = ' checked="checked" ';
                   12380:                     } elsif ($context eq 'webdav') {
                   12381:                         if ($settings->{$context}->{'default'}) {
                   12382:                             $defcheck = ' checked="checked" ';
                   12383:                         }
                   12384:                     }
                   12385:                 } elsif ($context eq 'statustocreate') {
1.315     raeburn  12386:                     $defcheck = ' checked="checked" ';
                   12387:                 }
1.99      raeburn  12388:             }
1.429     raeburn  12389:             $output .= '<span class="LC_nobreak"><label>'.
                   12390:                        '<input type="checkbox" name="'.$context.'" '.
                   12391:                        'value="default"'.$defcheck.$onclick.'/>'.
                   12392:                        $othertitle.'</label></span>';
1.26      raeburn  12393:         }
1.23      raeburn  12394:     }
1.315     raeburn  12395:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  12396:     return $output;
1.23      raeburn  12397: }
                   12398: 
                   12399: sub sorted_searchtitles {
                   12400:     my %searchtitles = &Apache::lonlocal::texthash(
                   12401:                          'uname' => 'username',
                   12402:                          'lastname' => 'last name',
                   12403:                          'lastfirst' => 'last name, first name',
                   12404:                      );
                   12405:     my @titleorder = ('uname','lastname','lastfirst');
                   12406:     return (\%searchtitles,\@titleorder);
                   12407: }
                   12408: 
1.25      raeburn  12409: sub sorted_searchtypes {
                   12410:     my %srchtypes_desc = (
                   12411:                            exact    => 'is exact match',
                   12412:                            contains => 'contains ..',
                   12413:                            begins   => 'begins with ..',
                   12414:                          );
                   12415:     my @srchtypeorder = ('exact','begins','contains');
                   12416:     return (\%srchtypes_desc,\@srchtypeorder);
                   12417: }
                   12418: 
1.3       raeburn  12419: sub usertype_update_row {
                   12420:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   12421:     my $datatable;
                   12422:     my $numinrow = 4;
                   12423:     foreach my $type (@{$types}) {
                   12424:         if (defined($usertypes->{$type})) {
                   12425:             $$rownums ++;
                   12426:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   12427:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   12428:                           '</td><td class="LC_left_item"><table>';
                   12429:             for (my $i=0; $i<@{$fields}; $i++) {
                   12430:                 my $rem = $i%($numinrow);
                   12431:                 if ($rem == 0) {
                   12432:                     if ($i > 0) {
                   12433:                         $datatable .= '</tr>';
                   12434:                     }
                   12435:                     $datatable .= '<tr>';
                   12436:                 }
                   12437:                 my $check = ' ';
1.39      raeburn  12438:                 if (ref($settings) eq 'HASH') {
                   12439:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   12440:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   12441:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   12442:                                 $check = ' checked="checked" ';
                   12443:                             }
1.3       raeburn  12444:                         }
                   12445:                     }
                   12446:                 }
                   12447: 
                   12448:                 if ($i == @{$fields}-1) {
                   12449:                     my $colsleft = $numinrow - $rem;
                   12450:                     if ($colsleft > 1) {
                   12451:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   12452:                     } else {
                   12453:                         $datatable .= '<td>';
                   12454:                     }
                   12455:                 } else {
                   12456:                     $datatable .= '<td>';
                   12457:                 }
1.8       raeburn  12458:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   12459:                               '<input type="checkbox" name="updateable_'.$type.
                   12460:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   12461:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  12462:             }
                   12463:             $datatable .= '</tr></table></td></tr>';
                   12464:         }
                   12465:     }
                   12466:     return $datatable;
1.1       raeburn  12467: }
                   12468: 
                   12469: sub modify_login {
1.205     raeburn  12470:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  12471:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386     raeburn  12472:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412     raeburn  12473:         %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168     raeburn  12474:     %title = ( coursecatalog => 'Display course catalog',
                   12475:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  12476:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  12477:                newuser => 'Link for visitors to create a user account',
1.386     raeburn  12478:                loginheader => 'Log-in box header',
                   12479:                saml => 'Dual SSO and non-SSO login');
1.168     raeburn  12480:     @offon = ('off','on');
1.112     raeburn  12481:     if (ref($domconfig{login}) eq 'HASH') {
                   12482:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   12483:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   12484:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   12485:             }
                   12486:         }
1.386     raeburn  12487:         if (ref($domconfig{login}{'saml'}) eq 'HASH') {
                   12488:             foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
                   12489:                 if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
                   12490:                     $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
                   12491:                     $saml{$lonhost} = 1;
                   12492:                     $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
                   12493:                     $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
                   12494:                     $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                   12495:                     $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                   12496:                     $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412     raeburn  12497:                     $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386     raeburn  12498:                     $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                   12499:                 }
                   12500:             }
                   12501:         }
1.112     raeburn  12502:     }
1.9       raeburn  12503:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   12504:                                            \%domconfig,\%loginhash);
1.188     raeburn  12505:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  12506:     foreach my $item (@toggles) {
                   12507:         $loginhash{login}{$item} = $env{'form.'.$item};
                   12508:     }
1.41      raeburn  12509:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  12510:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   12511:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   12512:                                          \%loginhash);
                   12513:     }
1.110     raeburn  12514: 
1.149     raeburn  12515:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  12516:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  12517:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  12518:     if (keys(%servers) > 1) {
                   12519:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  12520:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   12521:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   12522:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   12523:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   12524:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   12525:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   12526:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   12527:                         $changes{'loginvia'}{$lonhost} = 1;
                   12528:                     } else {
                   12529:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   12530:                         $changes{'loginvia'}{$lonhost} = 1;
                   12531:                     }
                   12532:                 } else {
                   12533:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   12534:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   12535:                         $changes{'loginvia'}{$lonhost} = 1;
                   12536:                     }
                   12537:                 }
                   12538:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   12539:                     foreach my $item (@loginvia_attribs) {
                   12540:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   12541:                     }
                   12542:                 } else {
                   12543:                     foreach my $item (@loginvia_attribs) {
                   12544:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   12545:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   12546:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   12547:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   12548:                                 $new = '/';
                   12549:                             }
                   12550:                         }
                   12551:                         if (($item eq 'custompath') && 
                   12552:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   12553:                             $new = '';
                   12554:                         }
                   12555:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   12556:                             $changes{'loginvia'}{$lonhost} = 1;
                   12557:                         }
                   12558:                         if ($item eq 'exempt') {
1.256     raeburn  12559:                             $new = &check_exempt_addresses($new);
1.128     raeburn  12560:                         }
                   12561:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   12562:                     }
                   12563:                 }
1.112     raeburn  12564:             } else {
1.128     raeburn  12565:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   12566:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  12567:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  12568:                     foreach my $item (@loginvia_attribs) {
                   12569:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   12570:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   12571:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   12572:                                 $new = '/';
                   12573:                             }
                   12574:                         }
                   12575:                         if (($item eq 'custompath') && 
                   12576:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   12577:                             $new = '';
                   12578:                         }
                   12579:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   12580:                     }
1.110     raeburn  12581:                 }
                   12582:             }
                   12583:         }
                   12584:     }
1.119     raeburn  12585: 
1.168     raeburn  12586:     my $servadm = $r->dir_config('lonAdmEMail');
                   12587:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   12588:     if (ref($domconfig{'login'}) eq 'HASH') {
                   12589:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   12590:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   12591:                 if ($lang eq 'nolang') {
                   12592:                     push(@currlangs,$lang);
                   12593:                 } elsif (defined($langchoices{$lang})) {
                   12594:                     push(@currlangs,$lang);
                   12595:                 } else {
                   12596:                     next;
                   12597:                 }
                   12598:             }
                   12599:         }
                   12600:     }
                   12601:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   12602:     if (@currlangs > 0) {
                   12603:         foreach my $lang (@currlangs) {
                   12604:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   12605:                 $changes{'helpurl'}{$lang} = 1;
                   12606:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   12607:                 $changes{'helpurl'}{$lang} = 1;
                   12608:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   12609:                 push(@newlangs,$lang);
                   12610:             } else {
                   12611:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   12612:             }
                   12613:         }
                   12614:     }
                   12615:     unless (grep(/^nolang$/,@currlangs)) {
                   12616:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   12617:             $changes{'helpurl'}{'nolang'} = 1;
                   12618:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   12619:             push(@newlangs,'nolang');
                   12620:         }
                   12621:     }
                   12622:     if ($env{'form.loginhelpurl_add_lang'}) {
                   12623:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   12624:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   12625:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   12626:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   12627:         }
                   12628:     }
                   12629:     if ((@newlangs > 0) || ($addedfile)) {
                   12630:         my $error;
                   12631:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12632:         if ($configuserok eq 'ok') {
                   12633:             if ($switchserver) {
                   12634:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   12635:             } elsif ($author_ok eq 'ok') {
                   12636:                 my @allnew = @newlangs;
                   12637:                 if ($addedfile ne '') {
                   12638:                     push(@allnew,$addedfile);
                   12639:                 }
1.421     raeburn  12640:                 my $modified = [];
1.168     raeburn  12641:                 foreach my $lang (@allnew) {
                   12642:                     my $formelem = 'loginhelpurl_'.$lang;
                   12643:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   12644:                         $formelem = 'loginhelpurl_add_file';
                   12645:                     }
1.425     raeburn  12646:                     (my $result,$newurl{$lang}) =
1.421     raeburn  12647:                         &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
                   12648:                                                                 "help/$lang",'','',$newfile{$lang},
                   12649:                                                                 $modified);
1.168     raeburn  12650:                     if ($result eq 'ok') {
                   12651:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   12652:                         $changes{'helpurl'}{$lang} = 1;
                   12653:                     } else {
                   12654:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   12655:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  12656:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  12657:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   12658:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   12659:                         }
                   12660:                     }
                   12661:                 }
1.421     raeburn  12662:                 &update_modify_urls($r,$modified);
1.168     raeburn  12663:             } else {
                   12664:                 $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);
                   12665:             }
                   12666:         } else {
                   12667:             $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);
                   12668:         }
                   12669:         if ($error) {
                   12670:             &Apache::lonnet::logthis($error);
                   12671:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12672:         }
                   12673:     }
1.256     raeburn  12674: 
                   12675:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   12676:     if (ref($domconfig{'login'}) eq 'HASH') {
                   12677:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   12678:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   12679:                 if ($domservers{$lonhost}) {
                   12680:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12681:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  12682:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  12683:                     }
                   12684:                 }
                   12685:             }
                   12686:         }
                   12687:     }
                   12688:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   12689:     foreach my $lonhost (sort(keys(%domservers))) {
                   12690:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12691:             $changes{'headtag'}{$lonhost} = 1;
                   12692:         } else {
                   12693:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   12694:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   12695:             }
                   12696:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   12697:                 push(@newhosts,$lonhost);
                   12698:             } elsif ($currheadtagurls{$lonhost}) {
                   12699:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   12700:                 if ($currexempt{$lonhost}) {
1.289     raeburn  12701:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  12702:                         $changes{'headtag'}{$lonhost} = 1;
                   12703:                     }
                   12704:                 } elsif ($possexempt{$lonhost}) {
                   12705:                     $changes{'headtag'}{$lonhost} = 1;
                   12706:                 }
                   12707:                 if ($possexempt{$lonhost}) {
                   12708:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12709:                 }
                   12710:             }
                   12711:         }
                   12712:     }
                   12713:     if (@newhosts) {
                   12714:         my $error;
                   12715:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12716:         if ($configuserok eq 'ok') {
                   12717:             if ($switchserver) {
                   12718:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   12719:             } elsif ($author_ok eq 'ok') {
1.421     raeburn  12720:                 my $modified = [];
1.256     raeburn  12721:                 foreach my $lonhost (@newhosts) {
                   12722:                     my $formelem = 'loginheadtag_'.$lonhost;
1.425     raeburn  12723:                     (my $result,$newheadtagurls{$lonhost}) =
1.421     raeburn  12724:                         &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
                   12725:                                                                 "login/headtag/$lonhost",'','',
                   12726:                                                                 $env{'form.loginheadtag_'.$lonhost.'.filename'},
                   12727:                                                                 $modified);
1.256     raeburn  12728:                     if ($result eq 'ok') {
                   12729:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   12730:                         $changes{'headtag'}{$lonhost} = 1;
                   12731:                         if ($possexempt{$lonhost}) {
                   12732:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12733:                         }
                   12734:                     } else {
                   12735:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   12736:                                            $newheadtagurls{$lonhost},$result);
                   12737:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12738:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   12739:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   12740:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   12741:                         }
                   12742:                     }
                   12743:                 }
1.421     raeburn  12744:                 &update_modify_urls($r,$modified);
1.256     raeburn  12745:             } else {
                   12746:                 $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
                   12747:             }
                   12748:         } else {
                   12749:             $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
                   12750:         }
                   12751:         if ($error) {
                   12752:             &Apache::lonnet::logthis($error);
                   12753:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12754:         }
                   12755:     }
1.386     raeburn  12756:     my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
                   12757:     my @newsamlimgs;
                   12758:     foreach my $lonhost (keys(%domservers)) {
                   12759:         if ($env{'form.saml_'.$lonhost}) {
                   12760:             if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                   12761:                 push(@newsamlimgs,$lonhost);
                   12762:             }
1.412     raeburn  12763:             foreach my $item ('text','alt','url','title','window','notsso') {
1.386     raeburn  12764:                 $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
                   12765:             }
                   12766:             if ($saml{$lonhost}) {
1.412     raeburn  12767:                 if ($env{'form.saml_window_'.$lonhost} ne '1') {
                   12768:                     $env{'form.saml_window_'.$lonhost} = '';
                   12769:                 }
1.386     raeburn  12770:                 if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
                   12771: #FIXME Need to obsolete published image
                   12772:                     delete($currsaml{$lonhost}{'img'});
                   12773:                     $changes{'saml'}{$lonhost} = 1;
                   12774:                 }
                   12775:                 if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
                   12776:                     $changes{'saml'}{$lonhost} = 1;
                   12777:                 }
                   12778:                 if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
                   12779:                     $changes{'saml'}{$lonhost} = 1;
                   12780:                 }
                   12781:                 if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
                   12782:                     $changes{'saml'}{$lonhost} = 1;
                   12783:                 }
                   12784:                 if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
                   12785:                     $changes{'saml'}{$lonhost} = 1;
                   12786:                 }
1.412     raeburn  12787:                 if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
                   12788:                     $changes{'saml'}{$lonhost} = 1;
                   12789:                 }
1.386     raeburn  12790:                 if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
                   12791:                     $changes{'saml'}{$lonhost} = 1;
                   12792:                 }
                   12793:             } else {
                   12794:                 $changes{'saml'}{$lonhost} = 1;
                   12795:             }
1.412     raeburn  12796:             foreach my $item ('text','alt','url','title','window','notsso') {
1.386     raeburn  12797:                 $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
                   12798:             }
                   12799:         } else {
1.425     raeburn  12800:             if ($saml{$lonhost}) {
1.389     raeburn  12801:                 $changes{'saml'}{$lonhost} = 1;
                   12802:                 delete($currsaml{$lonhost});
                   12803:             }
1.386     raeburn  12804:         }
                   12805:     }
                   12806:     foreach my $posshost (keys(%currsaml)) {
1.425     raeburn  12807:         unless (exists($domservers{$posshost})) {
                   12808:             delete($currsaml{$posshost});
1.386     raeburn  12809:         }
                   12810:     }
                   12811:     %{$loginhash{'login'}{'saml'}} = %currsaml;
                   12812:     if (@newsamlimgs) {
                   12813:         my $error;
                   12814:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12815:         if ($configuserok eq 'ok') {
                   12816:             if ($switchserver) {
                   12817:                 $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
                   12818:             } elsif ($author_ok eq 'ok') {
1.421     raeburn  12819:                 my $modified = [];
1.386     raeburn  12820:                 foreach my $lonhost (@newsamlimgs) {
                   12821:                     my $formelem = 'saml_img_'.$lonhost;
1.425     raeburn  12822:                     my ($result,$imgurl) =
1.421     raeburn  12823:                         &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
                   12824:                                                                 "login/saml/$lonhost",'','',
                   12825:                                                                 $env{'form.saml_img_'.$lonhost.'.filename'},
                   12826:                                                                 $modified);
1.386     raeburn  12827:                     if ($result eq 'ok') {
                   12828:                         $currsaml{$lonhost}{'img'} = $imgurl;
                   12829:                         $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
                   12830:                         $changes{'saml'}{$lonhost} = 1;
                   12831:                     } else {
                   12832:                         my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
                   12833:                                            $lonhost,$result);
                   12834:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12835:                     }
                   12836:                 }
1.421     raeburn  12837:                 &update_modify_urls($r,$modified);
1.386     raeburn  12838:             } else {
                   12839:                 $error = &mt("Upload of SSO button image 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);
                   12840:             }
                   12841:         } else {
                   12842:             $error = &mt("Upload of SSO button image file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
                   12843:         }
                   12844:         if ($error) {
                   12845:             &Apache::lonnet::logthis($error);
                   12846:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12847:         }
                   12848:     }
1.169     raeburn  12849:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  12850: 
                   12851:     my $defaulthelpfile = '/adm/loginproblems.html';
                   12852:     my $defaulttext = &mt('Default in use');
                   12853: 
1.1       raeburn  12854:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   12855:                                              $dom);
                   12856:     if ($putresult eq 'ok') {
1.188     raeburn  12857:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  12858:         my %defaultchecked = (
                   12859:                     'coursecatalog' => 'on',
1.188     raeburn  12860:                     'helpdesk'      => 'on',
1.42      raeburn  12861:                     'adminmail'     => 'off',
1.43      raeburn  12862:                     'newuser'       => 'off',
1.42      raeburn  12863:         );
1.55      raeburn  12864:         if (ref($domconfig{'login'}) eq 'HASH') {
                   12865:             foreach my $item (@toggles) {
                   12866:                 if ($defaultchecked{$item} eq 'on') { 
                   12867:                     if (($domconfig{'login'}{$item} eq '0') &&
                   12868:                         ($env{'form.'.$item} eq '1')) {
                   12869:                         $changes{$item} = 1;
                   12870:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12871:                               $domconfig{'login'}{$item} eq '1') &&
                   12872:                              ($env{'form.'.$item} eq '0')) {
                   12873:                         $changes{$item} = 1;
                   12874:                     }
                   12875:                 } elsif ($defaultchecked{$item} eq 'off') {
                   12876:                     if (($domconfig{'login'}{$item} eq '1') &&
                   12877:                         ($env{'form.'.$item} eq '0')) {
                   12878:                         $changes{$item} = 1;
                   12879:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12880:                               $domconfig{'login'}{$item} eq '0') &&
                   12881:                              ($env{'form.'.$item} eq '1')) {
                   12882:                         $changes{$item} = 1;
                   12883:                     }
1.42      raeburn  12884:                 }
                   12885:             }
1.41      raeburn  12886:         }
1.6       raeburn  12887:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  12888:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386     raeburn  12889:             if (exists($changes{'saml'})) {
                   12890:                 my $hostid_in_use;
                   12891:                 my @hosts = &Apache::lonnet::current_machine_ids();
                   12892:                 if (@hosts > 1) {
                   12893:                     foreach my $hostid (@hosts) {
                   12894:                         if (&Apache::lonnet::host_domain($hostid) eq $dom) {
                   12895:                             $hostid_in_use = $hostid;
                   12896:                             last;
                   12897:                         }
                   12898:                     }
                   12899:                 } else {
                   12900:                     $hostid_in_use = $r->dir_config('lonHostID');
                   12901:                 }
                   12902:                 if (($hostid_in_use) &&
                   12903:                     (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387     raeburn  12904:                     &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386     raeburn  12905:                 }
                   12906:                 if (ref($lastactref) eq 'HASH') {
                   12907:                     if (ref($changes{'saml'}) eq 'HASH') {
                   12908:                         my %updates;
                   12909:                         map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
                   12910:                         $lastactref->{'samllanding'} = \%updates;
                   12911:                     }
                   12912:                 }
                   12913:             }
1.212     raeburn  12914:             if (ref($lastactref) eq 'HASH') {
                   12915:                 $lastactref->{'domainconfig'} = 1;
                   12916:             }
1.1       raeburn  12917:             $resulttext = &mt('Changes made:').'<ul>';
                   12918:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   12919:                 if ($item eq 'loginvia') {
1.112     raeburn  12920:                     if (ref($changes{$item}) eq 'HASH') {
                   12921:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   12922:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  12923:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   12924:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   12925:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   12926:                                     $protocol = 'http' if ($protocol ne 'https');
                   12927:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   12928: 
                   12929:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   12930:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   12931:                                     } else {
                   12932:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   12933:                                     }
                   12934:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   12935:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   12936:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   12937:                                     }
                   12938:                                     $resulttext .= '</li>';
                   12939:                                 } else {
                   12940:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   12941:                                 }
1.112     raeburn  12942:                             } else {
1.128     raeburn  12943:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  12944:                             }
                   12945:                         }
1.128     raeburn  12946:                         $resulttext .= '</ul></li>';
1.112     raeburn  12947:                     }
1.168     raeburn  12948:                 } elsif ($item eq 'helpurl') {
                   12949:                     if (ref($changes{$item}) eq 'HASH') {
                   12950:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   12951:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   12952:                                 my ($chg,$link);
                   12953:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   12954:                                 if ($lang eq 'nolang') {
                   12955:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   12956:                                 } else {
                   12957:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   12958:                                 }
                   12959:                                 $resulttext .= '<li>'.$chg.'</li>';
                   12960:                             } else {
                   12961:                                 my $chg;
                   12962:                                 if ($lang eq 'nolang') {
                   12963:                                     $chg = &mt('custom log-in help file for no preferred language');
                   12964:                                 } else {
                   12965:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   12966:                                 }
                   12967:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   12968:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   12969:                                                       '?inhibitmenu=yes',$chg,600,500).
                   12970:                                                '</li>';
                   12971:                             }
                   12972:                         }
                   12973:                     }
1.256     raeburn  12974:                 } elsif ($item eq 'headtag') {
                   12975:                     if (ref($changes{$item}) eq 'HASH') {
                   12976:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12977:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12978:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   12979:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12980:                                 $resulttext .= '<li><a href="'.
                   12981:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   12982:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   12983:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   12984:                                 if ($possexempt{$lonhost}) {
                   12985:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   12986:                                 } else {
                   12987:                                     $resulttext .= &mt('included for any client IP');
                   12988:                                 }
                   12989:                                 $resulttext .= '</li>';
                   12990:                             }
                   12991:                         }
                   12992:                     }
1.386     raeburn  12993:                 } elsif ($item eq 'saml') {
                   12994:                     if (ref($changes{$item}) eq 'HASH') {
                   12995:                         my %notlt = (
                   12996:                                        text   => 'Text for log-in by SSO',
                   12997:                                        img    => 'SSO button image',
                   12998:                                        alt    => 'Alt text for button image',
                   12999:                                        url    => 'SSO URL',
                   13000:                                        title  => 'Tooltip for SSO link',
1.412     raeburn  13001:                                        window => 'Pop-up window if iframe',
1.386     raeburn  13002:                                        notsso => 'Text for non-SSO log-in',
                   13003:                                     );
                   13004:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   13005:                             if (ref($currsaml{$lonhost}) eq 'HASH') {
                   13006:                                 $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
                   13007:                                                '<ul>';
1.412     raeburn  13008:                                 foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386     raeburn  13009:                                     if ($currsaml{$lonhost}{$key} eq '') {
                   13010:                                         $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
                   13011:                                     } else {
                   13012:                                         my $value = "'$currsaml{$lonhost}{$key}'";
                   13013:                                         if ($key eq 'img') {
                   13014:                                             $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412     raeburn  13015:                                         } elsif ($key eq 'window') {
                   13016:                                             $value = 'On';
1.386     raeburn  13017:                                         }
                   13018:                                         $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                   13019:                                                                   $value).'</li>';
                   13020:                                     }
                   13021:                                 }
                   13022:                                 $resulttext .= '</ul></li>';
                   13023:                             } else {
                   13024:                                 $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
                   13025:                             }
                   13026:                         }
                   13027:                     }
1.169     raeburn  13028:                 } elsif ($item eq 'captcha') {
                   13029:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  13030:                         my $chgtxt;
1.169     raeburn  13031:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   13032:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   13033:                         } else {
                   13034:                             my %captchas = &captcha_phrases();
                   13035:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   13036:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   13037:                             } else {
                   13038:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   13039:                             }
                   13040:                         }
                   13041:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   13042:                     }
                   13043:                 } elsif ($item eq 'recaptchakeys') {
                   13044:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   13045:                         my ($privkey,$pubkey);
                   13046:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   13047:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   13048:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   13049:                         }
                   13050:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   13051:                         if (!$pubkey) {
                   13052:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   13053:                         } else {
                   13054:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   13055:                         }
                   13056:                         if (!$privkey) {
                   13057:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   13058:                         } else {
1.251     raeburn  13059:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  13060:                         }
                   13061:                         $chgtxt .= '</ul>';
                   13062:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   13063:                     }
1.269     raeburn  13064:                 } elsif ($item eq 'recaptchaversion') {
                   13065:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   13066:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  13067:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  13068:                                            '</li>';
                   13069:                         }
                   13070:                     }
1.41      raeburn  13071:                 } else {
                   13072:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   13073:                 }
1.1       raeburn  13074:             }
1.6       raeburn  13075:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  13076:         } else {
                   13077:             $resulttext = &mt('No changes made to log-in page settings');
                   13078:         }
                   13079:     } else {
1.11      albertel 13080:         $resulttext = '<span class="LC_error">'.
                   13081: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  13082:     }
1.6       raeburn  13083:     if ($errors) {
1.9       raeburn  13084:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  13085:                        $errors.'</ul>';
                   13086:     }
                   13087:     return $resulttext;
                   13088: }
                   13089: 
1.256     raeburn  13090: sub check_exempt_addresses {
                   13091:     my ($iplist) = @_;
                   13092:     $iplist =~ s/^\s+//;
                   13093:     $iplist =~ s/\s+$//;
                   13094:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   13095:     my (@okips,$new);
                   13096:     foreach my $ip (@poss_ips) {
                   13097:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   13098:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   13099:                 push(@okips,$ip);
                   13100:             }
                   13101:         }
                   13102:     }
                   13103:     if (@okips > 0) {
                   13104:         $new = join(',',@okips);
                   13105:     } else {
                   13106:         $new = '';
                   13107:     }
                   13108:     return $new;
                   13109: }
                   13110: 
1.6       raeburn  13111: sub color_font_choices {
                   13112:     my %choices =
                   13113:         &Apache::lonlocal::texthash (
                   13114:             img => "Header",
                   13115:             bgs => "Background colors",
                   13116:             links => "Link colors",
1.55      raeburn  13117:             images => "Images",
1.6       raeburn  13118:             font => "Font color",
1.201     raeburn  13119:             fontmenu => "Font menu",
1.76      raeburn  13120:             pgbg => "Page",
1.6       raeburn  13121:             tabbg => "Header",
                   13122:             sidebg => "Border",
                   13123:             link => "Link",
                   13124:             alink => "Active link",
                   13125:             vlink => "Visited link",
                   13126:         );
                   13127:     return %choices;
                   13128: }
                   13129: 
1.394     raeburn  13130: sub modify_ipaccess {
                   13131:     my ($dom,$lastactref,%domconfig) = @_;
                   13132:     my (@allpos,%changes,%confhash,$errors,$resulttext);
                   13133:     my (@items,%deletions,%itemids,@warnings);
                   13134:     my ($typeorder,$types) = &commblocktype_text();
                   13135:     if ($env{'form.ipaccess_add'}) {
                   13136:         my $name = $env{'form.ipaccess_name_add'};
                   13137:         my ($newid,$error) = &get_ipaccess_id($dom,$name);
                   13138:         if ($newid) {
                   13139:             $itemids{'add'} = $newid;
                   13140:             push(@items,'add');
                   13141:             $changes{$newid} = 1;
                   13142:         } else {
                   13143:             $error = &mt('Failed to acquire unique ID for new IP access control item');
                   13144:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13145:         }
                   13146:     }
                   13147:     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   13148:         my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
                   13149:         if (@todelete) {
                   13150:             map { $deletions{$_} = 1; } @todelete;
                   13151:         }
                   13152:         my $maxnum = $env{'form.ipaccess_maxnum'};
                   13153:         for (my $i=0; $i<$maxnum; $i++) {
                   13154:             my $itemid = $env{'form.ipaccess_id_'.$i};
                   13155:             $itemid =~ s/\D+//g;
                   13156:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   13157:                 if ($deletions{$itemid}) {
                   13158:                     $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
                   13159:                 } else {
                   13160:                     push(@items,$i);
                   13161:                     $itemids{$i} = $itemid;
                   13162:                 }
                   13163:             }
                   13164:         }
                   13165:     }
                   13166:     foreach my $idx (@items) {
                   13167:         my $itemid = $itemids{$idx};
                   13168:         next unless ($itemid);
                   13169:         my %current;
                   13170:         unless ($idx eq 'add') {
                   13171:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   13172:                 %current = %{$domconfig{'ipaccess'}{$itemid}};
                   13173:             }
                   13174:         }
                   13175:         my $position = $env{'form.ipaccess_pos_'.$itemid};
                   13176:         $position =~ s/\D+//g;
                   13177:         if ($position ne '') {
                   13178:             $allpos[$position] = $itemid;
                   13179:         }
                   13180:         my $name = $env{'form.ipaccess_name_'.$idx};
                   13181:         $name =~ s/^\s+|\s+$//g;
                   13182:         $confhash{$itemid}{'name'} = $name;
                   13183:         my $possrange = $env{'form.ipaccess_range_'.$idx};
                   13184:         $possrange =~ s/^\s+|\s+$//g;
                   13185:         unless ($possrange eq '') {
                   13186:             $possrange =~ s/[\r\n]+/\s/g;
                   13187:             $possrange =~ s/\s*-\s*/-/g;
                   13188:             $possrange =~ s/\s+/,/g;
                   13189:             $possrange =~ s/,+/,/g;
                   13190:             if ($possrange ne '') {
                   13191:                 my (@ok,$count);
1.425     raeburn  13192:                 $count = 0;
1.394     raeburn  13193:                 foreach my $poss (split(/\,/,$possrange)) {
                   13194:                     $count ++;
                   13195:                     $poss = &validate_ip_pattern($poss);
                   13196:                     if ($poss ne '') {
                   13197:                         push(@ok,$poss);
                   13198:                     }
                   13199:                 }
                   13200:                 my $diff = $count - scalar(@ok);
                   13201:                 if ($diff) {
                   13202:                     $errors .= '<li><span class="LC_error">'.
                   13203:                                &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
                   13204:                                    $diff,$name).
                   13205:                                '</span></li>';
                   13206:                 }
                   13207:                 if (@ok) {
                   13208:                     my @cidr_list;
                   13209:                     foreach my $item (@ok) {
                   13210:                         @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   13211:                     }
                   13212:                     $confhash{$itemid}{'ip'} = join(',',@cidr_list);
                   13213:                 }
                   13214:             }
                   13215:         }
                   13216:         foreach my $field ('name','ip') {
                   13217:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   13218:                 if ($current{$field} ne $confhash{$itemid}{$field}) {
                   13219:                     $changes{$itemid} = 1;
                   13220:                     last;
                   13221:                 }
                   13222:             }
                   13223:         }
                   13224:         $confhash{$itemid}{'commblocks'} = {};
1.425     raeburn  13225: 
1.394     raeburn  13226:         my %commblocks;
1.425     raeburn  13227:         map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394     raeburn  13228:         foreach my $type (@{$typeorder}) {
                   13229:             if ($commblocks{$type}) {
                   13230:                 $confhash{$itemid}{'commblocks'}{$type} = 'on';
                   13231:             }
                   13232:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   13233:                 if (ref($current{'commblocks'}) eq 'HASH') {
                   13234:                     if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
                   13235:                         $changes{$itemid} = 1;
                   13236:                     }
                   13237:                 } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
                   13238:                     $changes{$itemid} = 1;
                   13239:                 }
                   13240:             }
                   13241:         }
                   13242:         $confhash{$itemid}{'courses'} = {};
                   13243:         my %crsdeletions;
                   13244:         my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
                   13245:         if (@delcrs) {
                   13246:             map { $crsdeletions{$_} = 1; } @delcrs;
                   13247:         }
                   13248:         if (ref($current{'courses'}) eq 'HASH') {
                   13249:             foreach my $cid (sort(keys(%{$current{'courses'}}))) {
                   13250:                 if ($crsdeletions{$cid}) {
                   13251:                     $changes{$itemid} = 1;
                   13252:                 } else {
                   13253:                     $confhash{$itemid}{'courses'}{$cid} = 1;
                   13254:                 }
                   13255:             }
                   13256:         }
                   13257:         $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
                   13258:         $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425     raeburn  13259:         if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394     raeburn  13260:             ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
                   13261:             if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
                   13262:                                             $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
                   13263:                 $errors .= '<li><span class="LC_error">'.
                   13264:                            &mt('Invalid courseID [_1] omitted from list of allowed courses',
                   13265:                                $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
                   13266:                            '</span></li>';
                   13267:             } else {
                   13268:                 $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
                   13269:                 $changes{$itemid} = 1;
                   13270:             }
                   13271:         }
                   13272:     }
                   13273:     if (@allpos > 0) {
                   13274:         my $idx = 0;
                   13275:         foreach my $itemid (@allpos) {
                   13276:             if ($itemid ne '') {
                   13277:                 $confhash{$itemid}{'order'} = $idx;
                   13278:                 unless ($changes{$itemid}) {
                   13279:                     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   13280:                         if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   13281:                             if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
                   13282:                                 $changes{$itemid} = 1;
                   13283:                             }
                   13284:                         }
                   13285:                     }
                   13286:                 }
                   13287:                 $idx ++;
                   13288:             }
                   13289:         }
                   13290:     }
                   13291:     if (keys(%changes)) {
                   13292:         my %defaultshash = (
                   13293:                               ipaccess => \%confhash,
                   13294:                            );
                   13295:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   13296:                                                  $dom);
                   13297:         if ($putresult eq 'ok') {
                   13298:             my $cachetime = 1800;
                   13299:             &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
                   13300:             if (ref($lastactref) eq 'HASH') {
                   13301:                 $lastactref->{'ipaccess'} = 1;
                   13302:             }
                   13303:             $resulttext = &mt('Changes made:').'<ul>';
                   13304:             my %bynum;
                   13305:             foreach my $itemid (sort(keys(%changes))) {
                   13306:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   13307:                     my $position = $confhash{$itemid}{'order'};
                   13308:                     if ($position =~ /^\d+$/) {
                   13309:                         $bynum{$position} = $itemid;
                   13310:                     }
                   13311:                 }
                   13312:             }
                   13313:             if (keys(%deletions)) {
                   13314:                 foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
                   13315:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   13316:                 }
                   13317:             }
                   13318:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   13319:                 my $itemid = $bynum{$pos};
                   13320:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   13321:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
                   13322:                     my $position = $pos + 1;
                   13323:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   13324:                     if ($confhash{$itemid}{'ip'} eq '') {
                   13325:                         $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
                   13326:                     } else {
                   13327:                         $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
                   13328:                     }
                   13329:                     if (keys(%{$confhash{$itemid}{'commblocks'}})) {
                   13330:                         $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
                   13331:                                                   join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
                   13332:                                        '</li>';
                   13333:                     } else {
                   13334:                         $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
                   13335:                     }
                   13336:                     if (keys(%{$confhash{$itemid}{'courses'}})) {
                   13337:                         my @courses;
                   13338:                         foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425     raeburn  13339:                             my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394     raeburn  13340:                             push(@courses,$courseinfo{'description'}.' ('.$cid.')');
                   13341:                         }
                   13342:                         $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
                   13343:                                              join('</li><li>',@courses).'</li></ul>';
                   13344:                     } else {
                   13345:                         $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
                   13346:                     }
1.395     raeburn  13347:                     $resulttext .= '</ul></li>';
1.394     raeburn  13348:                 }
                   13349:             }
1.395     raeburn  13350:             $resulttext .= '</ul>';
1.394     raeburn  13351:         } else {
                   13352:             $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   13353:         }
                   13354:     } else {
                   13355:         $resulttext = &mt('No changes made');
                   13356:     }
                   13357:     if ($errors) {
                   13358:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   13359:                        $errors.'</ul></p>';
                   13360:     }
                   13361:     return $resulttext;
                   13362: }
                   13363: 
                   13364: sub get_ipaccess_id {
                   13365:     my ($domain,$location) = @_;
                   13366:     # get lock on ipaccess db
                   13367:     my $lockhash = {
                   13368:                       lock => $env{'user.name'}.
                   13369:                               ':'.$env{'user.domain'},
                   13370:                    };
                   13371:     my $tries = 0;
                   13372:     my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   13373:     my ($id,$error);
                   13374: 
                   13375:     while (($gotlock ne 'ok') && ($tries<10)) {
                   13376:         $tries ++;
                   13377:         sleep (0.1);
                   13378:         $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   13379:     }
                   13380:     if ($gotlock eq 'ok') {
                   13381:         my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
                   13382:         if ($currids{'lock'}) {
                   13383:             delete($currids{'lock'});
                   13384:             if (keys(%currids)) {
                   13385:                 my @curr = sort { $a <=> $b } keys(%currids);
                   13386:                 if ($curr[-1] =~ /^\d+$/) {
                   13387:                     $id = 1 + $curr[-1];
                   13388:                 }
                   13389:             } else {
                   13390:                 $id = 1;
                   13391:             }
                   13392:             if ($id) {
                   13393:                 unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
                   13394:                     $error = 'nostore';
                   13395:                 }
                   13396:             } else {
                   13397:                 $error = 'nonumber';
                   13398:             }
                   13399:         }
                   13400:         my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
                   13401:     } else {
                   13402:         $error = 'nolock';
                   13403:     }
                   13404:     return ($id,$error);
                   13405: }
                   13406: 
1.429     raeburn  13407: sub modify_authordefaults {
                   13408:     my ($dom,$lastactref,%domconfig) = @_;
                   13409: #
                   13410: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
                   13411: #
                   13412:     my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
                   13413:     if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13414:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   13415:             if ($key =~ /^webdav|authorquota$/) {
                   13416:                 $curr_quotas{$key} = $domconfig{'quotas'}{$key};
                   13417:             } else {
                   13418:                 $save_quotas{$key} = $domconfig{'quotas'}{$key};
                   13419:             }
                   13420:         }
                   13421:     }
                   13422:     my %staticdefaults = (
                   13423:                            'copyright'    => 'default',
                   13424:                            'sourceavail'  => 'closed',
                   13425:                            'nocodemirror' => 'off',
1.437     raeburn  13426:                            'daxecollapse' => 'off',
1.429     raeburn  13427:                            'domcoordacc'  => 'on',
                   13428:                            'editors'      => ['edit','xml'].
                   13429:                            'authorquota'  => 500,
                   13430:                            'webdav'       => 0,
                   13431:                          );
                   13432:     my %titles = &authordefaults_titles();
1.437     raeburn  13433:     foreach my $item ('nocodemirror','daxecollapse','domcoordacc') {
1.429     raeburn  13434:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   13435:             $confhash{$item} = $env{'form.'.$item};
                   13436:         }
                   13437:     }
                   13438:     if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
                   13439:         $confhash{'copyright'} = $1;
                   13440:     }
                   13441:     if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
                   13442:         $confhash{'sourceavail'} = $1;
                   13443:     }
                   13444:     my @posseditors =  &Apache::loncommon::get_env_multiple('form.author_editors');
                   13445:     my @okeditors = ('edit','xml','daxe');
                   13446:     my @editors;
                   13447:     foreach my $item (@posseditors) {
                   13448:         if (grep(/^\Q$item\E$/,@okeditors)) {
                   13449:             push(@editors,$item);
                   13450:         }
                   13451:     }
                   13452:     $confhash{'editors'} = \@editors;
1.436     raeburn  13453: 
1.429     raeburn  13454:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   13455:     my @insttypes;
                   13456:     if (ref($types) eq 'ARRAY') {
                   13457:         @insttypes = @{$types};
                   13458:     }
                   13459:     my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
                   13460:     my %webdav;
                   13461:     map { $webdav{$_} = 1; } @webdavon;
                   13462:     foreach my $type (@insttypes,'default') {
                   13463:         my $possquota = $env{'form.authorquota_'.$type};
                   13464:         if ($possquota =~ /^\d+$/) {
                   13465:             $save_quotas{'authorquota'}{$type} = $possquota;
                   13466:         }
                   13467:         if ($webdav{$type}) {
                   13468:             $save_quotas{'webdav'}{$type} = 1;
                   13469:         } else {
                   13470:             $save_quotas{'webdav'}{$type} = 0;
                   13471:         }
                   13472:     }
                   13473:     if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
                   13474:         $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
                   13475:     }
                   13476:     if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.437     raeburn  13477:         foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429     raeburn  13478:             if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
                   13479:                 $changes{$item} = 1;
                   13480:              }
                   13481:         }
                   13482:         if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436     raeburn  13483:             my @diffs =
1.429     raeburn  13484:                 &Apache::loncommon::compare_arrays($confhash{'editors'},
                   13485:                                                    $domconfig{'authordefaults'}{'editors'});
                   13486:             unless (@diffs == 0) {
                   13487:                 $changes{'editors'} = 1;
                   13488:             }
                   13489:         } else {
                   13490:             my @diffs =
                   13491:                 &Apache::loncommon::compare_arrays($confhash{'editors'},
                   13492:                                                    $staticdefaults{'editors'});
                   13493:             unless (@diffs == 0) {
                   13494:                 $changes{'editors'} = 1;
                   13495:             }
                   13496:         }
                   13497:     } else {
                   13498:         my @offon = ('off','on');
1.437     raeburn  13499:         foreach my $item ('nocodemirror','daxecollapse','domcoordacc') {
1.436     raeburn  13500:             if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429     raeburn  13501:                 $changes{$item} = 1; 
                   13502:             }
                   13503:         }
                   13504:         foreach my $item ('copyright','sourceavail') {
                   13505:             if ($confhash{$item} ne $staticdefaults{$item}) {
                   13506:                 $changes{$item} = 1;
                   13507:             }
                   13508:         }
                   13509:     }
                   13510:     foreach my $key ('authorquota','webdav') {
                   13511:         if (ref($curr_quotas{$key}) eq 'HASH') {
                   13512:             foreach my $type (@insttypes,'default') {
                   13513:                 if (exists($save_quotas{$key}{$type})) {
                   13514:                     if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
                   13515:                         $changes{$key}{$type} = 1;
                   13516:                     }
                   13517:                 } elsif (exists($curr_quotas{$key}{$type})) {
                   13518:                     $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
                   13519:                 } else {
                   13520:                     $save_quotas{$key}{$type} = $staticdefaults{$key};
                   13521:                 }
                   13522:             }
                   13523:         } else {
                   13524:             foreach my $type (@insttypes,'default') {
                   13525:                 if (exists($save_quotas{$key}{$type})) {
                   13526:                     unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
                   13527:                         $changes{$key}{$type} = 1;
                   13528:                     }
                   13529:                 } else {
                   13530:                     $save_quotas{$key}{$type} = $staticdefaults{$key};
                   13531:                 }
                   13532:             }
                   13533:         }
                   13534:     }
                   13535:     if (ref($curr_quotas{'webdav'}) eq 'HASH') {
                   13536:         if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436     raeburn  13537:             if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429     raeburn  13538:                 $changes{'webdav_LC_adv'} = 1;
                   13539:             }
                   13540:         } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
                   13541:             $changes{'webdav_LC_adv'} = 1;
                   13542:         }
                   13543:     } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
                   13544:         $changes{'webdav_LC_adv'} = 1;
                   13545:     }
                   13546:     my %confighash = (
                   13547:                         quotas  => \%save_quotas,
                   13548:                         authordefaults => \%confhash,
                   13549:                      );
                   13550:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
                   13551:                                              $dom);
                   13552:     my $resulttext;
                   13553:     if ($putresult eq 'ok') {
                   13554:         if (keys(%changes)) {
1.431     raeburn  13555:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429     raeburn  13556:             if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436     raeburn  13557:                 ($changes{'webdav_LC_adv'})) {
1.429     raeburn  13558:                 if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
                   13559:                     $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
                   13560:                 }
                   13561:                 if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
                   13562:                     (ref($save_quotas{'webdav'}) eq 'HASH')) {
                   13563:                     $domdefaults{'webdav'} = $save_quotas{'webdav'};
                   13564:                 }
                   13565:             }
                   13566:             $resulttext = &mt('Changes made:').'<ul>';
                   13567:             my $authoroverride;
1.437     raeburn  13568:             foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429     raeburn  13569:                 if (exists($changes{$key})) {
1.431     raeburn  13570:                     $domdefaults{$key} = $confhash{$key};
1.429     raeburn  13571:                     my $shown;
                   13572:                     unless ($authoroverride) {
                   13573:                         $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
                   13574:                         $authoroverride = 1;
                   13575:                     }
1.437     raeburn  13576:                     if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429     raeburn  13577:                         $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
                   13578:                     } elsif ($key eq 'copyright') {
                   13579:                         $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
                   13580:                     } elsif ($key eq 'sourceavail') {
                   13581:                         $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
                   13582:                     }
1.436     raeburn  13583:                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429     raeburn  13584:                 }
                   13585:             }
                   13586:             if ($authoroverride) {
                   13587:                 $resulttext .= '</ul></li>';
                   13588:             }
                   13589:             my $domcoordoverride;
                   13590:             foreach my $key ('editors','authorquota','webdav','webdav_LC_adv') {
                   13591:                 if (exists($changes{$key})) {
                   13592:                     my $shown;
                   13593:                     unless ($domcoordoverride) {
                   13594:                         $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
                   13595:                         $domcoordoverride = 1;
                   13596:                     }
                   13597:                     if ($key eq 'editors') {
1.431     raeburn  13598:                         if (ref($confhash{'editors'}) eq 'ARRAY') {
                   13599:                             $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
                   13600:                             if (@{$confhash{'editors'}}) {
                   13601:                                 $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
                   13602:                             } else {
                   13603:                                 $shown = &mt('None');
                   13604:                             }
1.429     raeburn  13605:                         }
                   13606:                     } elsif ($key eq 'authorquota') {
                   13607:                         foreach my $type (@insttypes) {
                   13608:                             $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
                   13609:                         }
                   13610:                         $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
                   13611:                     } elsif ($key eq 'webdav') {
                   13612:                         foreach my $type (@insttypes) {
                   13613:                             $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
                   13614:                         }
                   13615:                         $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
                   13616:                     } elsif ($key eq 'webdav_LC_adv') {
                   13617:                         if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
                   13618:                             $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
                   13619:                         } else {
                   13620:                             $shown = $titles{'none'};
                   13621:                         }
                   13622:                     }
                   13623:                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436     raeburn  13624:                 }
1.429     raeburn  13625:             }
                   13626:             if ($domcoordoverride) {
                   13627:                 $resulttext .= '</ul></li>';
                   13628:             }
1.431     raeburn  13629:             my $cachetime = 24*60*60;
                   13630:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   13631:             if (ref($lastactref) eq 'HASH') {
                   13632:                 $lastactref->{'domdefaults'} = 1;
                   13633:             }
1.429     raeburn  13634:         } else {
                   13635:             $resulttext = &mt('No changes made to Authoring Space defaults');
                   13636:         }
                   13637:     }
                   13638:     return $resulttext;
                   13639: }
                   13640: 
1.6       raeburn  13641: sub modify_rolecolors {
1.205     raeburn  13642:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  13643:     my ($resulttext,%rolehash);
                   13644:     $rolehash{'rolecolors'} = {};
1.55      raeburn  13645:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   13646:         if ($domconfig{'rolecolors'} eq '') {
                   13647:             $domconfig{'rolecolors'} = {};
                   13648:         }
                   13649:     }
1.9       raeburn  13650:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  13651:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   13652:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   13653:                                              $dom);
                   13654:     if ($putresult eq 'ok') {
                   13655:         if (keys(%changes) > 0) {
1.41      raeburn  13656:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  13657:             if (ref($lastactref) eq 'HASH') {
                   13658:                 $lastactref->{'domainconfig'} = 1;
                   13659:             }
1.6       raeburn  13660:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   13661:                                              $rolehash{'rolecolors'});
                   13662:         } else {
                   13663:             $resulttext = &mt('No changes made to default color schemes');
                   13664:         }
                   13665:     } else {
1.11      albertel 13666:         $resulttext = '<span class="LC_error">'.
                   13667: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  13668:     }
                   13669:     if ($errors) {
                   13670:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   13671:                        $errors.'</ul>';
                   13672:     }
                   13673:     return $resulttext;
                   13674: }
                   13675: 
                   13676: sub modify_colors {
1.9       raeburn  13677:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  13678:     my (%changes,%choices);
1.51      raeburn  13679:     my @bgs;
1.6       raeburn  13680:     my @links = ('link','alink','vlink');
1.41      raeburn  13681:     my @logintext;
1.6       raeburn  13682:     my @images;
                   13683:     my $servadm = $r->dir_config('lonAdmEMail');
                   13684:     my $errors;
1.200     raeburn  13685:     my %defaults;
1.6       raeburn  13686:     foreach my $role (@{$roles}) {
                   13687:         if ($role eq 'login') {
1.12      raeburn  13688:             %choices = &login_choices();
1.41      raeburn  13689:             @logintext = ('textcol','bgcol');
1.12      raeburn  13690:         } else {
                   13691:             %choices = &color_font_choices();
                   13692:         }
                   13693:         if ($role eq 'login') {
1.41      raeburn  13694:             @images = ('img','logo','domlogo','login');
1.51      raeburn  13695:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  13696:         } else {
                   13697:             @images = ('img');
1.200     raeburn  13698:             @bgs = ('pgbg','tabbg','sidebg');
                   13699:         }
                   13700:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   13701:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   13702:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   13703:         }
                   13704:         if ($role eq 'login') {
                   13705:             foreach my $item (@logintext) {
1.234     raeburn  13706:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   13707:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   13708:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   13709:                 }
                   13710:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  13711:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   13712:                 }
                   13713:             }
                   13714:         } else {
1.234     raeburn  13715:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   13716:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   13717:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   13718:             }
                   13719:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  13720:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   13721:             }
1.6       raeburn  13722:         }
1.200     raeburn  13723:         foreach my $item (@bgs) {
1.234     raeburn  13724:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   13725:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   13726:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   13727:             }
                   13728:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  13729:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   13730:             }
                   13731:         }
                   13732:         foreach my $item (@links) {
1.234     raeburn  13733:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   13734:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   13735:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   13736:             }
                   13737:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  13738:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   13739:             }
1.6       raeburn  13740:         }
1.46      raeburn  13741:         my ($configuserok,$author_ok,$switchserver) = 
                   13742:             &config_check($dom,$confname,$servadm);
1.9       raeburn  13743:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  13744:         if (ref($domconfig->{$role}) ne 'HASH') {
                   13745:             $domconfig->{$role} = {};
                   13746:         }
1.8       raeburn  13747:         foreach my $img (@images) {
1.402     raeburn  13748:             if ($role eq 'login') {
                   13749:                 if (($img eq 'img') || ($img eq 'logo')) {  
                   13750:                     if (defined($env{'form.login_showlogo_'.$img})) {
                   13751:                         $confhash->{$role}{'showlogo'}{$img} = 1;
                   13752:                     } else { 
                   13753:                         $confhash->{$role}{'showlogo'}{$img} = 0;
                   13754:                     }
                   13755:                 }
                   13756:                 if ($env{'form.login_alt_'.$img} ne '') {
                   13757:                     $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70      raeburn  13758:                 }
1.402     raeburn  13759:             }
1.18      albertel 13760: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   13761: 		 && !defined($domconfig->{$role}{$img})
                   13762: 		 && !$env{'form.'.$role.'_del_'.$img}
                   13763: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   13764: 		# import the old configured image from the .tab setting
                   13765: 		# if they haven't provided a new one 
                   13766: 		$domconfig->{$role}{$img} = 
                   13767: 		    $env{'form.'.$role.'_import_'.$img};
                   13768: 	    }
1.6       raeburn  13769:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  13770:                 my $error;
1.6       raeburn  13771:                 if ($configuserok eq 'ok') {
1.9       raeburn  13772:                     if ($switchserver) {
1.12      raeburn  13773:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  13774:                     } else {
                   13775:                         if ($author_ok eq 'ok') {
1.421     raeburn  13776:                             my $modified = [];
1.9       raeburn  13777:                             my ($result,$logourl) = 
1.421     raeburn  13778:                                 &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
                   13779:                                                                         $dom,$confname,$img,$width,$height,
                   13780:                                                                         '',$modified);
1.9       raeburn  13781:                             if ($result eq 'ok') {
                   13782:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  13783:                                 $changes{$role}{'images'}{$img} = 1;
1.421     raeburn  13784:                                 &update_modify_urls($r,$modified);
1.9       raeburn  13785:                             } else {
1.12      raeburn  13786:                                 $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  13787:                             }
                   13788:                         } else {
1.46      raeburn  13789:                             $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  13790:                         }
                   13791:                     }
                   13792:                 } else {
1.46      raeburn  13793:                     $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  13794:                 }
                   13795:                 if ($error) {
1.8       raeburn  13796:                     &Apache::lonnet::logthis($error);
1.11      albertel 13797:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  13798:                 }
                   13799:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  13800:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   13801:                     my $error;
                   13802:                     if ($configuserok eq 'ok') {
                   13803: # is confname an author?
                   13804:                         if ($switchserver eq '') {
                   13805:                             if ($author_ok eq 'ok') {
1.421     raeburn  13806:                                 my $modified = [];
1.9       raeburn  13807:                                 my ($result,$logourl) = 
1.421     raeburn  13808:                                     &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
                   13809:                                                                             $dom,$confname,$img,$width,$height,
                   13810:                                                                             '',$modified);
1.9       raeburn  13811:                                 if ($result eq 'ok') {
                   13812:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 13813: 				    $changes{$role}{'images'}{$img} = 1;
1.421     raeburn  13814:                                     &update_modify_urls($r,$modified);
1.9       raeburn  13815:                                 }
                   13816:                             }
                   13817:                         }
                   13818:                     }
1.6       raeburn  13819:                 }
                   13820:             }
                   13821:         }
                   13822:         if (ref($domconfig) eq 'HASH') {
                   13823:             if (ref($domconfig->{$role}) eq 'HASH') {
                   13824:                 foreach my $img (@images) {
                   13825:                     if ($domconfig->{$role}{$img} ne '') {
                   13826:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   13827:                             $confhash->{$role}{$img} = '';
1.12      raeburn  13828:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  13829:                         } else {
1.9       raeburn  13830:                             if ($confhash->{$role}{$img} eq '') {
                   13831:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   13832:                             }
1.6       raeburn  13833:                         }
                   13834:                     } else {
                   13835:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   13836:                             $confhash->{$role}{$img} = '';
1.12      raeburn  13837:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  13838:                         } 
                   13839:                     }
1.402     raeburn  13840:                     if ($role eq 'login') {
                   13841:                         if (($img eq 'logo') || ($img eq 'img')) {
                   13842:                             if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   13843:                                 if ($confhash->{$role}{'showlogo'}{$img} ne 
                   13844:                                     $domconfig->{$role}{'showlogo'}{$img}) {
                   13845:                                     $changes{$role}{'showlogo'}{$img} = 1; 
                   13846:                                 }
                   13847:                             } else {
                   13848:                                 if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   13849:                                     $changes{$role}{'showlogo'}{$img} = 1;
                   13850:                                 }
1.70      raeburn  13851:                             }
1.402     raeburn  13852:                         }
                   13853:                         if ($img ne 'login') {
                   13854:                             if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
                   13855:                                 if ($confhash->{$role}{'alttext'}{$img} ne
                   13856:                                     $domconfig->{$role}{'alttext'}{$img}) {
                   13857:                                     $changes{$role}{'alttext'}{$img} = 1;
                   13858:                                 }
                   13859:                             } else {
                   13860:                                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
                   13861:                                     $changes{$role}{'alttext'}{$img} = 1;
                   13862:                                 }
1.70      raeburn  13863:                             }
                   13864:                         }
                   13865:                     }
                   13866:                 }
1.6       raeburn  13867:                 if ($domconfig->{$role}{'font'} ne '') {
                   13868:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   13869:                         $changes{$role}{'font'} = 1;
                   13870:                     }
                   13871:                 } else {
                   13872:                     if ($confhash->{$role}{'font'}) {
                   13873:                         $changes{$role}{'font'} = 1;
                   13874:                     }
                   13875:                 }
1.107     raeburn  13876:                 if ($role ne 'login') {
                   13877:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   13878:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   13879:                             $changes{$role}{'fontmenu'} = 1;
                   13880:                         }
                   13881:                     } else {
                   13882:                         if ($confhash->{$role}{'fontmenu'}) {
                   13883:                             $changes{$role}{'fontmenu'} = 1;
                   13884:                         }
1.97      tempelho 13885:                     }
                   13886:                 }
1.6       raeburn  13887:                 foreach my $item (@bgs) {
                   13888:                     if ($domconfig->{$role}{$item} ne '') {
                   13889:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13890:                             $changes{$role}{'bgs'}{$item} = 1;
                   13891:                         } 
                   13892:                     } else {
                   13893:                         if ($confhash->{$role}{$item}) {
                   13894:                             $changes{$role}{'bgs'}{$item} = 1;
                   13895:                         }
                   13896:                     }
                   13897:                 }
                   13898:                 foreach my $item (@links) {
                   13899:                     if ($domconfig->{$role}{$item} ne '') {
                   13900:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13901:                             $changes{$role}{'links'}{$item} = 1;
                   13902:                         }
                   13903:                     } else {
                   13904:                         if ($confhash->{$role}{$item}) {
                   13905:                             $changes{$role}{'links'}{$item} = 1;
                   13906:                         }
                   13907:                     }
                   13908:                 }
1.41      raeburn  13909:                 foreach my $item (@logintext) {
                   13910:                     if ($domconfig->{$role}{$item} ne '') {
                   13911:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13912:                             $changes{$role}{'logintext'}{$item} = 1;
                   13913:                         }
                   13914:                     } else {
                   13915:                         if ($confhash->{$role}{$item}) {
                   13916:                             $changes{$role}{'logintext'}{$item} = 1;
                   13917:                         }
                   13918:                     }
                   13919:                 }
1.6       raeburn  13920:             } else {
                   13921:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13922:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  13923:             }
                   13924:         } else {
                   13925:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13926:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  13927:         }
                   13928:     }
                   13929:     return ($errors,%changes);
                   13930: }
                   13931: 
1.46      raeburn  13932: sub config_check {
                   13933:     my ($dom,$confname,$servadm) = @_;
                   13934:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   13935:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   13936:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   13937:                                                    $confname,$servadm);
                   13938:     if ($configuserok eq 'ok') {
                   13939:         $switchserver = &check_switchserver($dom,$confname);
                   13940:         if ($switchserver eq '') {
                   13941:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   13942:         }
                   13943:     }
                   13944:     return ($configuserok,$author_ok,$switchserver);
                   13945: }
                   13946: 
1.6       raeburn  13947: sub default_change_checker {
1.41      raeburn  13948:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  13949:     foreach my $item (@{$links}) {
                   13950:         if ($confhash->{$role}{$item}) {
                   13951:             $changes->{$role}{'links'}{$item} = 1;
                   13952:         }
                   13953:     }
                   13954:     foreach my $item (@{$bgs}) {
                   13955:         if ($confhash->{$role}{$item}) {
                   13956:             $changes->{$role}{'bgs'}{$item} = 1;
                   13957:         }
                   13958:     }
1.41      raeburn  13959:     foreach my $item (@{$logintext}) {
                   13960:         if ($confhash->{$role}{$item}) {
                   13961:             $changes->{$role}{'logintext'}{$item} = 1;
                   13962:         }
                   13963:     }
1.6       raeburn  13964:     foreach my $img (@{$images}) {
                   13965:         if ($env{'form.'.$role.'_del_'.$img}) {
                   13966:             $confhash->{$role}{$img} = '';
1.12      raeburn  13967:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  13968:         }
1.70      raeburn  13969:         if ($role eq 'login') {
                   13970:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   13971:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   13972:             }
1.402     raeburn  13973:             if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
                   13974:                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
                   13975:                     $changes->{$role}{'alttext'}{$img} = 1;
                   13976:                 }
                   13977:             }
1.70      raeburn  13978:         }
1.6       raeburn  13979:     }
                   13980:     if ($confhash->{$role}{'font'}) {
                   13981:         $changes->{$role}{'font'} = 1;
                   13982:     }
1.48      raeburn  13983: }
1.6       raeburn  13984: 
                   13985: sub display_colorchgs {
                   13986:     my ($dom,$changes,$roles,$confhash) = @_;
                   13987:     my (%choices,$resulttext);
                   13988:     if (!grep(/^login$/,@{$roles})) {
                   13989:         $resulttext = &mt('Changes made:').'<br />';
                   13990:     }
                   13991:     foreach my $role (@{$roles}) {
                   13992:         if ($role eq 'login') {
                   13993:             %choices = &login_choices();
                   13994:         } else {
                   13995:             %choices = &color_font_choices();
                   13996:         }
                   13997:         if (ref($changes->{$role}) eq 'HASH') {
                   13998:             if ($role ne 'login') {
                   13999:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   14000:             }
                   14001:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   14002:                 if ($role ne 'login') {
                   14003:                     $resulttext .= '<ul>';
                   14004:                 }
                   14005:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   14006:                     if ($role ne 'login') {
                   14007:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   14008:                     }
                   14009:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  14010:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   14011:                             if ($confhash->{$role}{$key}{$item}) {
                   14012:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   14013:                             } else {
                   14014:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   14015:                             }
1.402     raeburn  14016:                         } elsif (($role eq 'login') && ($key eq 'alttext')) {
                   14017:                             if ($confhash->{$role}{$key}{$item} ne '') {
1.403     raeburn  14018:                                 $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402     raeburn  14019:                                                $confhash->{$role}{$key}{$item}).'</li>';
                   14020:                             } else {
                   14021:                                 $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
                   14022:                             }
1.70      raeburn  14023:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  14024:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   14025:                         } else {
1.12      raeburn  14026:                             my $newitem = $confhash->{$role}{$item};
                   14027:                             if ($key eq 'images') {
1.306     raeburn  14028:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  14029:                             }
                   14030:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  14031:                         }
                   14032:                     }
                   14033:                     if ($role ne 'login') {
                   14034:                         $resulttext .= '</ul></li>';
                   14035:                     }
                   14036:                 } else {
                   14037:                     if ($confhash->{$role}{$key} eq '') {
                   14038:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   14039:                     } else {
                   14040:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   14041:                     }
                   14042:                 }
                   14043:                 if ($role ne 'login') {
                   14044:                     $resulttext .= '</ul>';
                   14045:                 }
                   14046:             }
                   14047:         }
                   14048:     }
1.3       raeburn  14049:     return $resulttext;
1.1       raeburn  14050: }
                   14051: 
1.9       raeburn  14052: sub thumb_dimensions {
                   14053:     return ('200','50');
                   14054: }
                   14055: 
1.16      raeburn  14056: sub check_dimensions {
                   14057:     my ($inputfile) = @_;
                   14058:     my ($fullwidth,$fullheight);
                   14059:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   14060:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   14061:             my $imageinfo = <PIPE>;
                   14062:             if (!close(PIPE)) {
                   14063:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   14064:             }
                   14065:             chomp($imageinfo);
                   14066:             my ($fullsize) = 
1.21      raeburn  14067:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  14068:             if ($fullsize) {
                   14069:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   14070:             }
                   14071:         }
                   14072:     }
                   14073:     return ($fullwidth,$fullheight);
                   14074: }
                   14075: 
1.9       raeburn  14076: sub check_configuser {
                   14077:     my ($uhome,$dom,$confname,$servadm) = @_;
                   14078:     my ($configuserok,%currroles);
                   14079:     if ($uhome eq 'no_host') {
                   14080:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.361     raeburn  14081:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  14082:         $configuserok = 
                   14083:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   14084:                              $configpass,'','','','','',undef,$servadm);
                   14085:     } else {
                   14086:         $configuserok = 'ok';
                   14087:         %currroles = 
                   14088:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   14089:     }
                   14090:     return ($configuserok,%currroles);
                   14091: }
                   14092: 
                   14093: sub check_authorstatus {
                   14094:     my ($dom,$confname,%currroles) = @_;
                   14095:     my $author_ok;
1.40      raeburn  14096:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  14097:         my $start = time;
                   14098:         my $end = 0;
                   14099:         $author_ok = 
                   14100:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  14101:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  14102:     } else {
                   14103:         $author_ok = 'ok';
                   14104:     }
                   14105:     return $author_ok;
                   14106: }
                   14107: 
1.421     raeburn  14108: sub update_modify_urls {
                   14109:     my ($r,$modified) = @_;
                   14110:     if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
                   14111:         push(@{$modified_urls},$modified);
                   14112:         unless ($registered_cleanup) {
                   14113:             my $handlers = $r->get_handlers('PerlCleanupHandler');
                   14114:             $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   14115:             $registered_cleanup=1;
1.9       raeburn  14116:         }
                   14117:     }
1.155     raeburn  14118: }
                   14119: 
                   14120: sub notifysubscribed {
                   14121:     foreach my $targetsource (@{$modified_urls}){
                   14122:         next unless (ref($targetsource) eq 'ARRAY');
                   14123:         my ($target,$source)=@{$targetsource};
                   14124:         if ($source ne '') {
1.316     raeburn  14125:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  14126:                 print $logfh "\nCleanup phase: Notifications\n";
                   14127:                 my @subscribed=&subscribed_hosts($target);
                   14128:                 foreach my $subhost (@subscribed) {
                   14129:                     print $logfh "\nNotifying host ".$subhost.':';
                   14130:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   14131:                     print $logfh $reply;
                   14132:                 }
                   14133:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   14134:                 foreach my $subhost (@subscribedmeta) {
                   14135:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   14136:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   14137:                                                         $subhost);
                   14138:                     print $logfh $reply;
                   14139:                 }
                   14140:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  14141:                 close($logfh);
1.155     raeburn  14142:             }
                   14143:         }
                   14144:     }
                   14145:     return OK;
                   14146: }
                   14147: 
                   14148: sub subscribed_hosts {
                   14149:     my ($target) = @_;
                   14150:     my @subscribed;
1.316     raeburn  14151:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  14152:         while (my $subline=<$fh>) {
                   14153:             if ($subline =~ /^($match_lonid):/) {
                   14154:                 my $host = $1;
                   14155:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   14156:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   14157:                         push(@subscribed,$host);
                   14158:                     }
                   14159:                 }
                   14160:             }
                   14161:         }
                   14162:     }
                   14163:     return @subscribed;
1.9       raeburn  14164: }
                   14165: 
                   14166: sub check_switchserver {
                   14167:     my ($dom,$confname) = @_;
1.424     raeburn  14168:     my ($allowed,$switchserver,$home);
                   14169:     if ($confname eq '') {
1.9       raeburn  14170:         $home = &Apache::lonnet::domain($dom,'primary');
1.424     raeburn  14171:     } else {
                   14172:         $home = &Apache::lonnet::homeserver($confname,$dom);
                   14173:         if ($home eq 'no_host') {
                   14174:             $home = &Apache::lonnet::domain($dom,'primary');
                   14175:         }
1.9       raeburn  14176:     }
                   14177:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 14178:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   14179:     if (!$allowed) {
1.426     raeburn  14180: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role='.
                   14181:                       &HTML::Entities::encode($env{'request.role'},'\'<>"&').
                   14182:                       '&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  14183:     }
                   14184:     return $switchserver;
                   14185: }
                   14186: 
1.1       raeburn  14187: sub modify_quotas {
1.216     raeburn  14188:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  14189:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  14190:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  14191:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   14192:         $validationfieldsref);
1.86      raeburn  14193:     if ($action eq 'quotas') {
1.429     raeburn  14194:         $context = 'tools';
1.163     raeburn  14195:     } else {
1.86      raeburn  14196:         $context = $action;
                   14197:     }
                   14198:     if ($context eq 'requestcourses') {
1.325     raeburn  14199:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  14200:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  14201:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   14202:         %titles = &courserequest_titles();
                   14203:         $toolregexp = join('|',@usertools);
                   14204:         %conditions = &courserequest_conditions();
1.216     raeburn  14205:         $confname = $dom.'-domainconfig';
                   14206:         my $servadm = $r->dir_config('lonAdmEMail');
                   14207:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  14208:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   14209:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  14210:     } elsif ($context eq 'requestauthor') {
                   14211:         @usertools = ('author');
                   14212:         %titles = &authorrequest_titles();
1.86      raeburn  14213:     } else {
1.430     raeburn  14214:         @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101     raeburn  14215:         %titles = &tool_titles();
1.86      raeburn  14216:     }
1.212     raeburn  14217:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  14218:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  14219:     foreach my $key (keys(%env)) {
1.101     raeburn  14220:         if ($context eq 'requestcourses') {
                   14221:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   14222:                 my $item = $1;
                   14223:                 my $type = $2;
                   14224:                 if ($type =~ /^limit_(.+)/) {
                   14225:                     $limithash{$item}{$1} = $env{$key};
                   14226:                 } else {
                   14227:                     $confhash{$item}{$type} = $env{$key};
                   14228:                 }
                   14229:             }
1.163     raeburn  14230:         } elsif ($context eq 'requestauthor') {
                   14231:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   14232:                 $confhash{$1} = $env{$key};
                   14233:             }
1.101     raeburn  14234:         } else {
1.86      raeburn  14235:             if ($key =~ /^form\.quota_(.+)$/) {
                   14236:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  14237:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  14238:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   14239:             }
1.72      raeburn  14240:         }
                   14241:     }
1.163     raeburn  14242:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  14243:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  14244:         @approvalnotify = sort(@approvalnotify);
                   14245:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325     raeburn  14246:         my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218     raeburn  14247:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   14248:         foreach my $type (@hasuniquecode) {
                   14249:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   14250:                 $confhash{'uniquecode'}{$type} = 1;
                   14251:             }
1.216     raeburn  14252:         }
1.242     raeburn  14253:         my (%newbook,%allpos);
1.216     raeburn  14254:         if ($context eq 'requestcourses') {
1.242     raeburn  14255:             foreach my $type ('textbooks','templates') {
                   14256:                 @{$allpos{$type}} = (); 
                   14257:                 my $invalid;
                   14258:                 if ($type eq 'textbooks') {
                   14259:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   14260:                 } else {
                   14261:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   14262:                 }
                   14263:                 if ($env{'form.'.$type.'_addbook'}) {
                   14264:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   14265:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   14266:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   14267:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   14268:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   14269:                         } else {
                   14270:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   14271:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   14272:                             $position =~ s/\D+//g;
                   14273:                             if ($position ne '') {
                   14274:                                 $allpos{$type}[$position] = $newbook{$type};
                   14275:                             }
1.216     raeburn  14276:                         }
1.242     raeburn  14277:                     } else {
                   14278:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  14279:                     }
                   14280:                 }
1.242     raeburn  14281:             } 
1.216     raeburn  14282:         }
1.102     raeburn  14283:         if (ref($domconfig{$action}) eq 'HASH') {
                   14284:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   14285:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   14286:                     $changes{'notify'}{'approval'} = 1;
                   14287:                 }
                   14288:             } else {
1.144     raeburn  14289:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  14290:                     $changes{'notify'}{'approval'} = 1;
                   14291:                 }
                   14292:             }
1.218     raeburn  14293:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   14294:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14295:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   14296:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   14297:                             $changes{'uniquecode'} = 1;
                   14298:                         }
                   14299:                     }
                   14300:                     unless ($changes{'uniquecode'}) {
                   14301:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   14302:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   14303:                                 $changes{'uniquecode'} = 1;
                   14304:                             }
                   14305:                         }
                   14306:                     }
                   14307:                } else {
                   14308:                    $changes{'uniquecode'} = 1;
                   14309:                }
                   14310:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14311:                 $changes{'uniquecode'} = 1;
1.216     raeburn  14312:             }
                   14313:             if ($context eq 'requestcourses') {
1.242     raeburn  14314:                 foreach my $type ('textbooks','templates') {
                   14315:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   14316:                         my %deletions;
                   14317:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   14318:                         if (@todelete) {
                   14319:                             map { $deletions{$_} = 1; } @todelete;
                   14320:                         }
                   14321:                         my %imgdeletions;
                   14322:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   14323:                         if (@todeleteimages) {
                   14324:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14325:                         }
                   14326:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   14327:                         for (my $i=0; $i<=$maxnum; $i++) {
                   14328:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   14329:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   14330:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   14331:                                 if ($deletions{$key}) {
                   14332:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   14333:                                         #FIXME need to obsolete item in RES space
                   14334:                                     }
                   14335:                                     next;
                   14336:                                 } else {
                   14337:                                     my $newpos = $env{'form.'.$itemid};
                   14338:                                     $newpos =~ s/\D+//g;
1.243     raeburn  14339:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  14340:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  14341:                                                  ($type eq 'templates'));
1.242     raeburn  14342:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   14343:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   14344:                                             $changes{$type}{$key} = 1;
                   14345:                                         }
                   14346:                                     }
                   14347:                                     $allpos{$type}[$newpos] = $key;
                   14348:                                 }
                   14349:                                 if ($imgdeletions{$key}) {
                   14350:                                     $changes{$type}{$key} = 1;
1.216     raeburn  14351:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  14352:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   14353:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  14354:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   14355:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   14356:                                     } else {
                   14357:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   14358:                                                                                       $cdom,$cnum,$type,$configuserok,
                   14359:                                                                                       $switchserver,$author_ok);
                   14360:                                         if ($imgurl) {
                   14361:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   14362:                                             $changes{$type}{$key} = 1; 
                   14363:                                         }
                   14364:                                         if ($error) {
                   14365:                                             &Apache::lonnet::logthis($error);
                   14366:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14367:                                         }
                   14368:                                     }
1.242     raeburn  14369:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   14370:                                     $confhash{$type}{$key}{'image'} = 
                   14371:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  14372:                                 }
                   14373:                             }
                   14374:                         }
                   14375:                     }
                   14376:                 }
                   14377:             }
1.102     raeburn  14378:         } else {
1.144     raeburn  14379:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  14380:                 $changes{'notify'}{'approval'} = 1;
                   14381:             }
1.218     raeburn  14382:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  14383:                 $changes{'uniquecode'} = 1;
                   14384:             }
                   14385:         }
                   14386:         if ($context eq 'requestcourses') {
1.242     raeburn  14387:             foreach my $type ('textbooks','templates') {
                   14388:                 if ($newbook{$type}) {
                   14389:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  14390:                     foreach my $item ('subject','title','publisher','author') {
                   14391:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   14392:                                  ($type eq 'template'));
1.242     raeburn  14393:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   14394:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   14395:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   14396:                         }
                   14397:                     }
                   14398:                     if ($type eq 'textbooks') {
                   14399:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   14400:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  14401:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   14402:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   14403:                             } else {
                   14404:                                 my ($imageurl,$error) =
                   14405:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   14406:                                                             $configuserok,$switchserver,$author_ok);
                   14407:                                 if ($imageurl) {
                   14408:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   14409:                                 }
                   14410:                                 if ($error) {
                   14411:                                     &Apache::lonnet::logthis($error);
                   14412:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14413:                                 }
1.242     raeburn  14414:                             }
                   14415:                         }
1.216     raeburn  14416:                     }
                   14417:                 }
1.242     raeburn  14418:                 if (@{$allpos{$type}} > 0) {
                   14419:                     my $idx = 0;
                   14420:                     foreach my $item (@{$allpos{$type}}) {
                   14421:                         if ($item ne '') {
                   14422:                             $confhash{$type}{$item}{'order'} = $idx;
                   14423:                             if (ref($domconfig{$action}) eq 'HASH') {
                   14424:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   14425:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   14426:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   14427:                                             $changes{$type}{$item} = 1;
                   14428:                                         }
1.216     raeburn  14429:                                     }
                   14430:                                 }
                   14431:                             }
1.242     raeburn  14432:                             $idx ++;
1.216     raeburn  14433:                         }
                   14434:                     }
                   14435:                 }
                   14436:             }
1.235     raeburn  14437:             if (ref($validationitemsref) eq 'ARRAY') {
                   14438:                 foreach my $item (@{$validationitemsref}) {
                   14439:                     if ($item eq 'fields') {
                   14440:                         my @changed;
                   14441:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   14442:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   14443:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   14444:                         }
1.266     raeburn  14445:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14446:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14447:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   14448:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   14449:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   14450:                                 } else {
                   14451:                                     @changed = @{$confhash{'validation'}{$item}};
                   14452:                                 }
1.235     raeburn  14453:                             } else {
                   14454:                                 @changed = @{$confhash{'validation'}{$item}};
                   14455:                             }
                   14456:                         } else {
                   14457:                             @changed = @{$confhash{'validation'}{$item}};
                   14458:                         }
                   14459:                         if (@changed) {
                   14460:                             if ($confhash{'validation'}{$item}) {
                   14461:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   14462:                             } else {
                   14463:                                 $changes{'validation'}{$item} = &mt('None');
                   14464:                             }
                   14465:                         }
                   14466:                     } else {
                   14467:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   14468:                         if ($item eq 'markup') {
                   14469:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   14470:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   14471:                             }
                   14472:                         }
1.266     raeburn  14473:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14474:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14475:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   14476:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   14477:                                 }
                   14478:                             } else {
                   14479:                                 if ($confhash{'validation'}{$item} ne '') {
                   14480:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   14481:                                 }
1.235     raeburn  14482:                             }
                   14483:                         } else {
                   14484:                             if ($confhash{'validation'}{$item} ne '') {
                   14485:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   14486:                             }
                   14487:                         }
                   14488:                     }
                   14489:                 }
                   14490:             }
                   14491:             if ($env{'form.validationdc'}) {
                   14492:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  14493:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  14494:                 if (exists($domcoords{$newval})) {
                   14495:                     $confhash{'validation'}{'dc'} = $newval;
                   14496:                 }
                   14497:             }
                   14498:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  14499:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14500:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14501:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   14502:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   14503:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   14504:                                     $changes{'validation'}{'dc'} = &mt('None');
                   14505:                                 } else {
                   14506:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   14507:                                 }
1.235     raeburn  14508:                             }
1.266     raeburn  14509:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   14510:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  14511:                         }
                   14512:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   14513:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   14514:                     }
                   14515:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   14516:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  14517:                 }
1.266     raeburn  14518:             } else {
                   14519:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14520:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14521:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   14522:                             $changes{'validation'}{'dc'} = &mt('None');
                   14523:                         }
                   14524:                     }
1.235     raeburn  14525:                 }
                   14526:             }
1.102     raeburn  14527:         }
                   14528:     } else {
1.86      raeburn  14529:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
                   14530:     }
1.72      raeburn  14531:     foreach my $item (@usertools) {
                   14532:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  14533:             my $unset; 
1.101     raeburn  14534:             if ($context eq 'requestcourses') {
1.104     raeburn  14535:                 $unset = '0';
                   14536:                 if ($type eq '_LC_adv') {
                   14537:                     $unset = '';
                   14538:                 }
1.101     raeburn  14539:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   14540:                     $confhash{$item}{$type} .= '=';
                   14541:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   14542:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   14543:                     }
                   14544:                 }
1.163     raeburn  14545:             } elsif ($context eq 'requestauthor') {
                   14546:                 $unset = '0';
                   14547:                 if ($type eq '_LC_adv') {
                   14548:                     $unset = '';
                   14549:                 }
1.72      raeburn  14550:             } else {
1.101     raeburn  14551:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   14552:                     $confhash{$item}{$type} = 1;
                   14553:                 } else {
                   14554:                     $confhash{$item}{$type} = 0;
                   14555:                 }
1.72      raeburn  14556:             }
1.86      raeburn  14557:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  14558:                 if ($action eq 'requestauthor') {
                   14559:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   14560:                         $changes{$type} = 1;
                   14561:                     }
                   14562:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  14563:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   14564:                         $changes{$item}{$type} = 1;
                   14565:                     }
                   14566:                 } else {
                   14567:                     if ($context eq 'requestcourses') {
1.104     raeburn  14568:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  14569:                             $changes{$item}{$type} = 1;
                   14570:                         }
                   14571:                     } else {
                   14572:                         if (!$confhash{$item}{$type}) {
                   14573:                             $changes{$item}{$type} = 1;
                   14574:                         }
                   14575:                     }
                   14576:                 }
                   14577:             } else {
                   14578:                 if ($context eq 'requestcourses') {
1.104     raeburn  14579:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  14580:                         $changes{$item}{$type} = 1;
                   14581:                     }
1.163     raeburn  14582:                 } elsif ($context eq 'requestauthor') {
                   14583:                     if ($confhash{$type} ne $unset) {
                   14584:                         $changes{$type} = 1;
                   14585:                     }
1.72      raeburn  14586:                 } else {
                   14587:                     if (!$confhash{$item}{$type}) {
                   14588:                         $changes{$item}{$type} = 1;
                   14589:                     }
                   14590:                 }
                   14591:             }
1.1       raeburn  14592:         }
                   14593:     }
1.163     raeburn  14594:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  14595:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   14596:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   14597:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   14598:                     if (exists($confhash{'defaultquota'}{$key})) {
                   14599:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   14600:                             $changes{'defaultquota'}{$key} = 1;
                   14601:                         }
                   14602:                     } else {
                   14603:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  14604:                     }
                   14605:                 }
1.86      raeburn  14606:             } else {
                   14607:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   14608:                     if (exists($confhash{'defaultquota'}{$key})) {
                   14609:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   14610:                             $changes{'defaultquota'}{$key} = 1;
                   14611:                         }
                   14612:                     } else {
                   14613:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  14614:                     }
1.1       raeburn  14615:                 }
                   14616:             }
1.197     raeburn  14617:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429     raeburn  14618:                 $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
                   14619:             }
                   14620:             if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
                   14621:                 $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197     raeburn  14622:             }
1.1       raeburn  14623:         }
1.86      raeburn  14624:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   14625:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   14626:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   14627:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   14628:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   14629:                             $changes{'defaultquota'}{$key} = 1;
                   14630:                         }
                   14631:                     } else {
                   14632:                         if (!exists($domconfig{'quotas'}{$key})) {
                   14633:                             $changes{'defaultquota'}{$key} = 1;
                   14634:                         }
1.72      raeburn  14635:                     }
                   14636:                 } else {
1.86      raeburn  14637:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  14638:                 }
1.1       raeburn  14639:             }
                   14640:         }
                   14641:     }
1.72      raeburn  14642: 
1.163     raeburn  14643:     if ($context eq 'requestauthor') {
                   14644:         $domdefaults{'requestauthor'} = \%confhash;
                   14645:     } else {
                   14646:         foreach my $key (keys(%confhash)) {
1.242     raeburn  14647:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  14648:                 $domdefaults{$key} = $confhash{$key};
                   14649:             }
1.163     raeburn  14650:         }
1.72      raeburn  14651:     }
1.163     raeburn  14652: 
1.1       raeburn  14653:     my %quotahash = (
1.86      raeburn  14654:                       $action => { %confhash }
1.1       raeburn  14655:                     );
                   14656:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   14657:                                              $dom);
                   14658:     if ($putresult eq 'ok') {
                   14659:         if (keys(%changes) > 0) {
1.72      raeburn  14660:             my $cachetime = 24*60*60;
                   14661:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  14662:             if (ref($lastactref) eq 'HASH') {
                   14663:                 $lastactref->{'domdefaults'} = 1;
                   14664:             }
1.1       raeburn  14665:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  14666:             unless (($context eq 'requestcourses') ||
1.163     raeburn  14667:                     ($context eq 'requestauthor')) {
1.86      raeburn  14668:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   14669:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   14670:                     foreach my $type (@{$types},'default') {
                   14671:                         if (defined($changes{'defaultquota'}{$type})) {
                   14672:                             my $typetitle = $usertypes->{$type};
                   14673:                             if ($type eq 'default') {
                   14674:                                 $typetitle = $othertitle;
                   14675:                             }
1.213     raeburn  14676:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  14677:                         }
                   14678:                     }
1.86      raeburn  14679:                     $resulttext .= '</ul></li>';
1.72      raeburn  14680:                 }
                   14681:             }
1.80      raeburn  14682:             my %newenv;
1.72      raeburn  14683:             foreach my $item (@usertools) {
1.163     raeburn  14684:                 my (%haschgs,%inconf);
                   14685:                 if ($context eq 'requestauthor') {
                   14686:                     %haschgs = %changes;
1.210     raeburn  14687:                     %inconf = %confhash;
1.163     raeburn  14688:                 } else {
                   14689:                     if (ref($changes{$item}) eq 'HASH') {
                   14690:                         %haschgs = %{$changes{$item}};
                   14691:                     }
                   14692:                     if (ref($confhash{$item}) eq 'HASH') {
                   14693:                         %inconf = %{$confhash{$item}};
                   14694:                     }
                   14695:                 }
                   14696:                 if (keys(%haschgs) > 0) {
1.80      raeburn  14697:                     my $newacc = 
                   14698:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   14699:                                                           $env{'user.domain'},
1.86      raeburn  14700:                                                           $item,'reload',$context);
1.210     raeburn  14701:                     if (($context eq 'requestcourses') ||
1.163     raeburn  14702:                         ($context eq 'requestauthor')) {
1.108     raeburn  14703:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   14704:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  14705:                         }
                   14706:                     } else {
                   14707:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   14708:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   14709:                         }
1.80      raeburn  14710:                     }
1.163     raeburn  14711:                     unless ($context eq 'requestauthor') {
                   14712:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   14713:                     }
1.72      raeburn  14714:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  14715:                         if ($haschgs{$type}) {
1.72      raeburn  14716:                             my $typetitle = $usertypes->{$type};
                   14717:                             if ($type eq 'default') {
                   14718:                                 $typetitle = $othertitle;
                   14719:                             } elsif ($type eq '_LC_adv') {
                   14720:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   14721:                             }
1.163     raeburn  14722:                             if ($inconf{$type}) {
1.101     raeburn  14723:                                 if ($context eq 'requestcourses') {
                   14724:                                     my $cond;
1.163     raeburn  14725:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  14726:                                         if ($1 eq '') {
                   14727:                                             $cond = &mt('(Automatic processing of any request).');
                   14728:                                         } else {
                   14729:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   14730:                                         }
                   14731:                                     } else { 
1.163     raeburn  14732:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  14733:                                     }
                   14734:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  14735:                                 } elsif ($context eq 'requestauthor') {
                   14736:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   14737:                                                              $titles{$inconf{$type}},$typetitle);
                   14738: 
1.101     raeburn  14739:                                 } else {
                   14740:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   14741:                                 }
1.72      raeburn  14742:                             } else {
1.104     raeburn  14743:                                 if ($type eq '_LC_adv') {
1.163     raeburn  14744:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  14745:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14746:                                     } else { 
                   14747:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   14748:                                     }
                   14749:                                 } else {
                   14750:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14751:                                 }
1.72      raeburn  14752:                             }
                   14753:                         }
1.26      raeburn  14754:                     }
1.163     raeburn  14755:                     unless ($context eq 'requestauthor') {
                   14756:                         $resulttext .= '</ul></li>';
                   14757:                     }
1.26      raeburn  14758:                 }
1.1       raeburn  14759:             }
1.163     raeburn  14760:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  14761:                 if (ref($changes{'notify'}) eq 'HASH') {
                   14762:                     if ($changes{'notify'}{'approval'}) {
                   14763:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   14764:                             if ($confhash{'notify'}{'approval'}) {
                   14765:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   14766:                             } else {
1.163     raeburn  14767:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  14768:                             }
                   14769:                         }
                   14770:                     }
                   14771:                 }
                   14772:             }
1.216     raeburn  14773:             if ($action eq 'requestcourses') {
                   14774:                 my @offon = ('off','on');
                   14775:                 if ($changes{'uniquecode'}) {
1.218     raeburn  14776:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14777:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   14778:                         $resulttext .= '<li>'.
                   14779:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   14780:                                        '</li>';
                   14781:                     } else {
                   14782:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   14783:                                        '</li>';
                   14784:                     }
1.216     raeburn  14785:                 }
1.242     raeburn  14786:                 foreach my $type ('textbooks','templates') {
                   14787:                     if (ref($changes{$type}) eq 'HASH') {
                   14788:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   14789:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   14790:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   14791:                             my $coursetitle = $coursehash{'description'};
                   14792:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   14793:                             $resulttext .= '<li>';
1.243     raeburn  14794:                             foreach my $item ('subject','title','publisher','author') {
                   14795:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   14796:                                          ($type eq 'templates'));
1.242     raeburn  14797:                                 my $name = $item.':';
                   14798:                                 $name =~ s/^(\w)/\U$1/;
                   14799:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   14800:                             }
                   14801:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   14802:                             if ($type eq 'textbooks') {
                   14803:                                 if ($confhash{$type}{$key}{'image'}) {
                   14804:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   14805:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   14806:                                                    ' alt="Textbook cover" />').'<br />';
                   14807:                                 }
                   14808:                             }
                   14809:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  14810:                         }
1.242     raeburn  14811:                         $resulttext .= '</ul></li>';
1.216     raeburn  14812:                     }
                   14813:                 }
1.235     raeburn  14814:                 if (ref($changes{'validation'}) eq 'HASH') {
                   14815:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   14816:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   14817:                         foreach my $item (@{$validationitemsref}) {
                   14818:                             if (exists($changes{'validation'}{$item})) {
                   14819:                                 if ($item eq 'markup') {
                   14820:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14821:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   14822:                                 } else {
                   14823:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14824:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   14825:                                 }
                   14826:                             }
                   14827:                         }
                   14828:                         if (exists($changes{'validation'}{'dc'})) {
                   14829:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   14830:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   14831:                         }
                   14832:                     }
                   14833:                 }
1.216     raeburn  14834:             }
1.1       raeburn  14835:             $resulttext .= '</ul>';
1.80      raeburn  14836:             if (keys(%newenv)) {
                   14837:                 &Apache::lonnet::appenv(\%newenv);
                   14838:             }
1.1       raeburn  14839:         } else {
1.86      raeburn  14840:             if ($context eq 'requestcourses') {
                   14841:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  14842:             } elsif ($context eq 'requestauthor') {
                   14843:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  14844:             } else {
1.90      weissno  14845:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  14846:             }
1.1       raeburn  14847:         }
                   14848:     } else {
1.11      albertel 14849:         $resulttext = '<span class="LC_error">'.
                   14850: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  14851:     }
1.216     raeburn  14852:     if ($errors) {
                   14853:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   14854:                        '<ul>'.$errors.'</ul></p>';
                   14855:     }
1.3       raeburn  14856:     return $resulttext;
1.1       raeburn  14857: }
                   14858: 
1.216     raeburn  14859: sub process_textbook_image {
1.242     raeburn  14860:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  14861:     my $filename = $env{'form.'.$caller.'.filename'};
                   14862:     my ($error,$url);
                   14863:     my ($width,$height) = (50,50);
                   14864:     if ($configuserok eq 'ok') {
                   14865:         if ($switchserver) {
                   14866:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   14867:                          $switchserver);
                   14868:         } elsif ($author_ok eq 'ok') {
1.421     raeburn  14869:             my $modified = [];
1.216     raeburn  14870:             my ($result,$imageurl) =
1.421     raeburn  14871:                 &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
                   14872:                                                         "$type/$cdom/$cnum/cover",$width,$height,
                   14873:                                                         '',$modified);
1.216     raeburn  14874:             if ($result eq 'ok') {
                   14875:                 $url = $imageurl;
1.421     raeburn  14876:                 &update_modify_urls($r,$modified);
1.216     raeburn  14877:             } else {
                   14878:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14879:             }
                   14880:         } else {
                   14881:             $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$author_ok);
                   14882:         }
                   14883:     } else {
                   14884:         $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$configuserok);
                   14885:     }
                   14886:     return ($url,$error);
                   14887: }
                   14888: 
1.267     raeburn  14889: sub modify_ltitools {
                   14890:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421     raeburn  14891:     my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
                   14892:     &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
                   14893: 
1.267     raeburn  14894:     my $confname = $dom.'-domainconfig';
                   14895:     my $servadm = $r->dir_config('lonAdmEMail');
                   14896:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421     raeburn  14897: 
                   14898:     my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
                   14899:     my $toolserror =
                   14900:         &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
                   14901:                                                $lastactref,$configuserok,$switchserver,$author_ok);
                   14902: 
                   14903:     my $home = &Apache::lonnet::domain($dom,'primary');
                   14904:     unless (($home eq 'no_host') || ($home eq '')) {
                   14905:         my @ids=&Apache::lonnet::current_machine_ids();
                   14906:         foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
                   14907:     }
                   14908: 
                   14909:     if (keys(%ltitoolschg)) {
                   14910:         foreach my $id (keys(%ltitoolschg)) {
                   14911:             if (ref($ltitoolschg{$id}) eq 'HASH') {
                   14912:                 foreach my $inner (keys(%{$ltitoolschg{$id}})) {
                   14913:                     if (($inner eq 'secret') || ($inner eq 'key')) {
                   14914:                         if ($is_home) {
                   14915:                             $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
                   14916:                         }
                   14917:                     }
                   14918:                 }
1.267     raeburn  14919:             }
1.421     raeburn  14920:         }
                   14921:         $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
                   14922:         if (keys(%ltitoolschg)) {
                   14923:             %newltitools = %ltitoolschg;
                   14924:         }
                   14925:     }
                   14926:     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                   14927:         foreach my $id (%{$domconfig{'ltitools'}}) {
                   14928:             next if ($id !~ /^\d+$/);
                   14929:             unless (exists($ltitoolschg{$id})) {
                   14930:                 if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
                   14931:                     foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
                   14932:                         if (($inner eq 'secret') || ($inner eq 'key')) {
                   14933:                             if ($is_home) {
                   14934:                                 $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
                   14935:                             }
                   14936:                         } else {
                   14937:                             $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
                   14938:                         }
                   14939:                     }
                   14940:                 } else {
                   14941:                     $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322     raeburn  14942:                 }
1.421     raeburn  14943:             }
                   14944:         }
                   14945:     }
                   14946:     if ($toolserror) {
                   14947:         $errors = '<li>'.$toolserror.'</li>';
                   14948:     }
                   14949:     if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
                   14950:         $resulttext = &mt('No changes made.');
                   14951:         if ($errors) {
                   14952:             $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
                   14953:                                  $errors.'</ul>';
                   14954:         }
                   14955:         return $resulttext;
                   14956:     }
                   14957:     my %ltitoolshash = (
                   14958:                           $action => { %newltitools }
                   14959:                        );
                   14960:     if (keys(%secchanges)) {
                   14961:         $ltitoolshash{'toolsec'} = \%newtoolsec;
                   14962:     }
                   14963:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
                   14964:     if ($putresult eq 'ok') {
                   14965:         my %keystore;
                   14966:         if ($is_home) {
                   14967:             my %toolsenchash = (
                   14968:                                    $action => { %newtoolsenc }
                   14969:                                );
                   14970:             &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423     raeburn  14971:             my $cachetime = 24*60*60;
                   14972:             &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421     raeburn  14973:             &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
                   14974:         }
                   14975:         $resulttext = &mt('Changes made:').'<ul>';
                   14976:         if (keys(%secchanges) > 0) {
1.423     raeburn  14977:             $resulttext .= &lti_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421     raeburn  14978:         }
                   14979:         if (keys(%ltitoolschg) > 0) {
                   14980:             $resulttext .= $ltitoolsoutput;
                   14981:         }
1.423     raeburn  14982:         my $cachetime = 24*60*60;
                   14983:         &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
                   14984:         if (ref($lastactref) eq 'HASH') {
                   14985:             $lastactref->{'ltitools'} = 1;
                   14986:         }
1.421     raeburn  14987:     } else {
                   14988:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   14989:     }
                   14990:     if ($errors) {
                   14991:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   14992:                        $errors.'</ul></p>';
                   14993:     }
                   14994:     return $resulttext;
                   14995: }
                   14996: 
                   14997: sub fetch_secrets {
                   14998:     my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
                   14999:     my %keyset;
                   15000:     %{$currsec} = ();
                   15001:     $newsec->{'private'}{'keys'} = [];
                   15002:     $newsec->{'encrypt'} = {};
                   15003:     $newsec->{'rules'} = {};
                   15004:     if ($context eq 'ltisec') {
                   15005:         $newsec->{'linkprot'} = {};
                   15006:     }
                   15007:     if (ref($domconfig->{$context}) eq 'HASH') {
                   15008:         %{$currsec} = %{$domconfig->{$context}};
                   15009:         if ($context eq 'ltisec') {
                   15010:             if (ref($currsec->{'linkprot'}) eq 'HASH') {
                   15011:                 foreach my $id (keys(%{$currsec->{'linkprot'}})) {
                   15012:                     unless ($id =~ /^\d+$/) {
                   15013:                         delete($currsec->{'linkprot'}{$id});
1.297     raeburn  15014:                     }
1.267     raeburn  15015:                 }
                   15016:             }
1.421     raeburn  15017:         }
                   15018:         if (ref($currsec->{'private'}) eq 'HASH') {
                   15019:             if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
                   15020:                 $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
                   15021:                 map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267     raeburn  15022:             }
1.421     raeburn  15023:         }
                   15024:     }
                   15025:     my @items= ('crs','dom');
                   15026:     if ($context eq 'ltisec') {
                   15027:         push(@items,'consumers');
                   15028:     }
                   15029:     foreach my $item (@items) {
                   15030:         my $formelement;
                   15031:         if (($context eq 'toolsec') || ($item eq 'consumers')) {
                   15032:             $formelement = 'form.'.$context.'_'.$item;
                   15033:         } else {
                   15034:             $formelement = 'form.'.$context.'_'.$item.'linkprot';
                   15035:         }
                   15036:         if ($env{$formelement}) {
                   15037:             $newsec->{'encrypt'}{$item} = 1;
                   15038:             if (ref($currsec->{'encrypt'}) eq 'HASH') {
                   15039:                 unless ($currsec->{'encrypt'}{$item}) {
                   15040:                     $secchanges->{'encrypt'} = 1;
                   15041:                 }
                   15042:             } else {
                   15043:                 $secchanges->{'encrypt'} = 1;
1.267     raeburn  15044:             }
1.421     raeburn  15045:         } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
                   15046:             if ($currsec->{'encrypt'}{$item}) {
                   15047:                 $secchanges->{'encrypt'} = 1;
1.323     raeburn  15048:             }
1.421     raeburn  15049:         }
                   15050:     }
                   15051:     my $secrets;
                   15052:     if ($context eq 'ltisec') {
                   15053:         $secrets = 'ltisecrets';
                   15054:     } else {
                   15055:         $secrets = 'toolsecrets';
                   15056:     }
                   15057:     unless (exists($currsec->{'rules'})) {
                   15058:         $currsec->{'rules'} = {};
                   15059:     }
                   15060:     &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
                   15061: 
                   15062:     my @ids=&Apache::lonnet::current_machine_ids();
                   15063:     my %servers = &Apache::lonnet::get_servers($dom,'library');
                   15064: 
                   15065:     foreach my $hostid (keys(%servers)) {
                   15066:         if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
                   15067:             my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
                   15068:             if (exists($env{$keyitem})) {
                   15069:                 $env{$keyitem} =~ s/(`)/'/g;
                   15070:                 if ($keyset{$hostid}) {
                   15071:                     if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
                   15072:                         if ($env{$keyitem} ne '') {
                   15073:                             $secchanges->{'private'} = 1;
                   15074:                             $newkeyset->{$hostid} = $env{$keyitem};
                   15075:                         }
1.296     raeburn  15076:                     }
1.421     raeburn  15077:                 } elsif ($env{$keyitem} ne '') {
                   15078:                     unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
                   15079:                         push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296     raeburn  15080:                     }
1.421     raeburn  15081:                     $secchanges->{'private'} = 1;
                   15082:                     $newkeyset->{$hostid} = $env{$keyitem};
1.267     raeburn  15083:                 }
                   15084:             }
1.421     raeburn  15085:         }
                   15086:     }
                   15087: }
                   15088: 
                   15089: sub store_security {
1.424     raeburn  15090:     my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421     raeburn  15091:     return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
                   15092:                    (ref($keystore) eq 'HASH'));
                   15093:     if (keys(%{$secchanges})) {
                   15094:         if ($secchanges->{'private'}) {
                   15095:             my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
                   15096:             foreach my $hostid (keys(%{$newkeyset})) {
                   15097:                 my $storehash = {
                   15098:                                    key => $newkeyset->{$hostid},
                   15099:                                    who => $env{'user.name'}.':'.$env{'user.domain'},
                   15100:                                 };
                   15101:                 $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
                   15102:                                                                   $dom,$hostid);
                   15103:             }
                   15104:         }
                   15105:     }
                   15106: }
                   15107: 
                   15108: sub lti_security_results {
1.423     raeburn  15109:     my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421     raeburn  15110:     my $output;
1.423     raeburn  15111:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   15112:     my $needs_update;
1.421     raeburn  15113:     foreach my $item (keys(%{$secchanges})) {
                   15114:         if ($item eq 'encrypt') {
1.423     raeburn  15115:             $needs_update = 1;
1.421     raeburn  15116:             my %encrypted;
                   15117:             if ($context eq 'lti') {
                   15118:                 %encrypted = (
                   15119:                               crs  => {
                   15120:                                         on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
                   15121:                                         off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
                   15122:                                       },
                   15123:                               dom => {
                   15124:                                        on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
                   15125:                                        off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
                   15126:                                      },
                   15127:                               consumers => {
                   15128:                                              on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
                   15129:                                              off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
                   15130:                                            },
                   15131:                              );
1.267     raeburn  15132:             } else {
1.421     raeburn  15133:                 %encrypted = (
                   15134:                               crs  => {
                   15135:                                         on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
                   15136:                                         off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
                   15137:                                       },
                   15138:                               dom => {
                   15139:                                        on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
                   15140:                                        off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
                   15141:                                      },
                   15142:                              );
                   15143:             }
                   15144:             my @types= ('crs','dom');
                   15145:             if ($context eq 'lti') {
1.423     raeburn  15146:                 foreach my $type (@types) {
                   15147:                     undef($domdefaults{'linkprotenc_'.$type});
                   15148:                 }
1.421     raeburn  15149:                 push(@types,'consumers');
1.423     raeburn  15150:                 undef($domdefaults{'ltienc_consumers'});
                   15151:             } elsif ($context eq 'ltitools') {
                   15152:                 foreach my $type (@types) {
                   15153:                     undef($domdefaults{'toolenc_'.$type});
                   15154:                 }
1.267     raeburn  15155:             }
1.421     raeburn  15156:             foreach my $type (@types) {
                   15157:                 my $shown = $encrypted{$type}{'off'};
                   15158:                 if (ref($newsec->{$item}) eq 'HASH') {
                   15159:                     if ($newsec->{$item}{$type}) {
1.423     raeburn  15160:                         if ($context eq 'lti') {
                   15161:                             if ($type eq 'consumers') {
                   15162:                                 $domdefaults{'ltienc_consumers'} = 1;
                   15163:                             } else {
                   15164:                                 $domdefaults{'linkprotenc_'.$type} = 1;
                   15165:                             }
                   15166:                         } elsif ($context eq 'ltitools') {
                   15167:                             $domdefaults{'toolenc_'.$type} = 1;
                   15168:                         }
1.421     raeburn  15169:                         $shown = $encrypted{$type}{'on'};
1.319     raeburn  15170:                     }
1.267     raeburn  15171:                 }
1.421     raeburn  15172:                 $output .= '<li>'.$shown.'</li>';
1.267     raeburn  15173:             }
1.421     raeburn  15174:         } elsif ($item eq 'rules') {
                   15175:             my %titles = &Apache::lonlocal::texthash(
                   15176:                                       min   => 'Minimum password length',
                   15177:                                       max   => 'Maximum password length',
                   15178:                                       chars => 'Required characters',
                   15179:                          );
                   15180:             foreach my $rule ('min','max') {
                   15181:                 if ($newsec->{rules}{$rule} eq '') {
                   15182:                     if ($rule eq 'min') {
                   15183:                         $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
                   15184:                                    ' '.&mt('Default of [_1] will be used',
                   15185:                                            $Apache::lonnet::passwdmin).'</li>';
                   15186:                     } else {
                   15187:                         $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                   15188:                     }
                   15189:                 } else {
                   15190:                     $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
                   15191:                 }
                   15192:             }
                   15193:             if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
                   15194:                 if (@{$newsec->{'rules'}{'chars'}} > 0) {
                   15195:                     my %rulenames = &Apache::lonlocal::texthash(
                   15196:                                              uc => 'At least one upper case letter',
                   15197:                                              lc => 'At least one lower case letter',
                   15198:                                              num => 'At least one number',
                   15199:                                              spec => 'At least one non-alphanumeric',
                   15200:                                     );
                   15201:                     my $needed = '<ul><li>'.
                   15202:                                  join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
                   15203:                                  '</li></ul>';
                   15204:                     $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   15205:                 } else {
                   15206:                     $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267     raeburn  15207:                 }
1.421     raeburn  15208:             } else {
                   15209:                 $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267     raeburn  15210:             }
1.421     raeburn  15211:         } elsif ($item eq 'private') {
1.423     raeburn  15212:             $needs_update = 1;
                   15213:             if ($context eq 'lti') {
                   15214:                 undef($domdefaults{'ltiprivhosts'});
                   15215:             } elsif ($context eq 'ltitools') {
                   15216:                 undef($domdefaults{'toolprivhosts'});
                   15217:             }
1.421     raeburn  15218:             if (keys(%{$newkeyset})) {
1.423     raeburn  15219:                 my @privhosts;
1.421     raeburn  15220:                 foreach my $hostid (sort(keys(%{$newkeyset}))) {
                   15221:                     if ($keystore->{$hostid} eq 'ok') {
                   15222:                         $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423     raeburn  15223:                         unless (grep(/^\Q$hostid\E$/,@privhosts)) {
                   15224:                             push(@privhosts,$hostid);
                   15225:                         }
                   15226:                     }
                   15227:                 }
                   15228:                 if (@privhosts) {
                   15229:                     if ($context eq 'lti') {
                   15230:                         $domdefaults{'ltiprivhosts'} = \@privhosts;
                   15231:                     } elsif ($context eq 'ltitools') {
                   15232:                         $domdefaults{'toolprivhosts'} = \@privhosts;
1.267     raeburn  15233:                     }
                   15234:                 }
                   15235:             }
1.421     raeburn  15236:         } elsif ($item eq 'linkprot') {
                   15237:             next;
1.434     raeburn  15238:         } elsif ($item eq 'suggested') {
                   15239:             if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
                   15240:                 (ref($newsec->{'suggested'}) eq 'HASH')) {
                   15241:                 my $suggestions;
                   15242:                 foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
                   15243:                     if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
                   15244:                         my $name = $newsec->{'suggested'}->{$id}->{'name'};
                   15245:                         my $info = $newsec->{'suggested'}->{$id}->{'info'};
                   15246:                         $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
                   15247:                                                &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
                   15248:                                         '</li>';
                   15249:                     } else {
                   15250:                         $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
                   15251:                                                    $newsec->{'suggested'}->{$id}).'</li>';
                   15252:                     }
                   15253:                 }
                   15254:                 if ($suggestions) {
                   15255:                     $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
                   15256:                                '<ul>'.$suggestions.'</ul>'.
                   15257:                                '</li>';
                   15258:                 }
                   15259:             }
1.267     raeburn  15260:         }
                   15261:     }
1.423     raeburn  15262:     if ($needs_update) {
                   15263:         my $cachetime = 24*60*60;
                   15264:         &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   15265:     }
1.421     raeburn  15266:     return $output;
                   15267: }
                   15268: 
                   15269: sub modify_proctoring {
                   15270:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   15271:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15272:     my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
                   15273:     my $confname = $dom.'-domainconfig';
                   15274:     my $servadm = $r->dir_config('lonAdmEMail');
1.372     raeburn  15275:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   15276:     my %providernames = &proctoring_providernames();
                   15277:     my $maxnum = scalar(keys(%providernames));
                   15278: 
                   15279:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   15280:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   15281:     if (ref($requref) eq 'HASH') {
                   15282:         %requserfields = %{$requref};
                   15283:     }
                   15284:     if (ref($opturef) eq 'HASH') {
                   15285:         %optuserfields = %{$opturef};
                   15286:     }
                   15287:     if (ref($defref) eq 'HASH') {
                   15288:         %defaults = %{$defref};
                   15289:     }
                   15290:     if (ref($extref) eq 'HASH') {
                   15291:         %extended = %{$extref};
                   15292:     }
                   15293:     if (ref($crsref) eq 'HASH') {
                   15294:         %crsconf = %{$crsref};
                   15295:     }
                   15296:     if (ref($rolesref) eq 'ARRAY') {
                   15297:         @courseroles = @{$rolesref};
                   15298:     }
                   15299:     if (ref($ltiref) eq 'ARRAY') {
                   15300:         @ltiroles = @{$ltiref};
                   15301:     }
                   15302: 
                   15303:     if (ref($domconfig{$action}) eq 'HASH') {
                   15304:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
                   15305:         if (@todeleteimages) {
                   15306:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   15307:         }
                   15308:     }
                   15309:     my %customadds;
                   15310:     my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
                   15311:     if (@newcustom) {
                   15312:         map { $customadds{$_} = 1; } @newcustom;
                   15313:     }
                   15314:     foreach my $provider (sort(keys(%providernames))) {
                   15315:         $confhash{$provider} = {};
                   15316:         my $pos = $env{'form.proctoring_pos_'.$provider};
                   15317:         $pos =~ s/\D+//g;
                   15318:         $allpos[$pos] = $provider;
                   15319:         my (%current,%currentenc);
                   15320:         my $showroles = 0;
                   15321:         if (ref($domconfig{$action}) eq 'HASH') {
                   15322:             if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   15323:                 %current = %{$domconfig{$action}{$provider}};
                   15324:                 foreach my $item ('key','secret') { 
                   15325:                     $currentenc{$item} = $current{$item};
                   15326:                     delete($current{$item});
                   15327:                 }
                   15328:             }
                   15329:         }
                   15330:         if ($env{'form.proctoring_available_'.$provider}) {
                   15331:             $confhash{$provider}{'available'} = 1;
                   15332:             unless ($current{'available'}) {
                   15333:                 $changes{$provider} = 1;
                   15334:             }
                   15335:         } else {
                   15336:             %{$confhash{$provider}} = %current;
                   15337:             %{$encconfhash{$provider}} = %currentenc;
                   15338:             $confhash{$provider}{'available'} = 0;
                   15339:             if ($current{'available'}) {
                   15340:                 $changes{$provider} = 1;
                   15341:             }
                   15342:         }
                   15343:         if ($confhash{$provider}{'available'}) {
                   15344:             foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
                   15345:                 my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
                   15346:                 if ($field eq 'lifetime') {
                   15347:                     if ($possval =~ /^\d+$/) {
                   15348:                         $confhash{$provider}{$field} = $possval;
                   15349:                     }
                   15350:                 } elsif ($field eq 'version') {
                   15351:                     if ($possval =~ /^\d+\.\d+$/) {
                   15352:                         $confhash{$provider}{$field} = $possval;
                   15353:                     }
                   15354:                 } elsif ($field eq 'sigmethod') {
                   15355:                     if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
                   15356:                         $confhash{$provider}{$field} = $possval;
                   15357:                     }
                   15358:                 } elsif ($field eq 'url') {
                   15359:                     $confhash{$provider}{$field} = $possval;
                   15360:                 } elsif (($field eq 'key') || ($field eq 'secret')) {
                   15361:                     $encconfhash{$provider}{$field} = $possval;
                   15362:                     unless ($currentenc{$field} eq $possval) {
                   15363:                         $changes{$provider} = 1;
                   15364:                     }
                   15365:                 }
                   15366:                 unless (($field eq 'key') || ($field eq 'secret')) {
                   15367:                     unless ($current{$field} eq $confhash{$provider}{$field}) {
                   15368:                         $changes{$provider} = 1;
                   15369:                     }
                   15370:                 }
                   15371:             }
                   15372:             if ($imgdeletions{$provider}) {
                   15373:                 $changes{$provider} = 1;
                   15374:             } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
                   15375:                 my ($imageurl,$error) =
                   15376:                     &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
                   15377:                                               $configuserok,$switchserver,$author_ok);
                   15378:                 if ($imageurl) {
                   15379:                     $confhash{$provider}{'image'} = $imageurl;
                   15380:                     $changes{$provider} = 1; 
                   15381:                 }
                   15382:                 if ($error) {
                   15383:                     &Apache::lonnet::logthis($error);
                   15384:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15385:                 }
                   15386:             } elsif (exists($current{'image'})) {
                   15387:                 $confhash{$provider}{'image'} = $current{'image'};
                   15388:             }
                   15389:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15390:                 if (@{$requserfields{$provider}} > 0) {
                   15391:                     if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15392:                         if ($env{'form.proctoring_userincdom_'.$provider}) {
                   15393:                             $confhash{$provider}{'incdom'} = 1;
                   15394:                         }
                   15395:                         unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
                   15396:                             $changes{$provider} = 1;
                   15397:                         }
                   15398:                     }
                   15399:                     if (grep(/^roles$/,@{$requserfields{$provider}})) {
                   15400:                         $showroles = 1;
                   15401:                     }
                   15402:                 }
                   15403:             }
                   15404:             $confhash{$provider}{'fields'} = [];
                   15405:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   15406:                 if (@{$optuserfields{$provider}} > 0) {
                   15407:                     my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
                   15408:                     foreach my $field (@{$optuserfields{$provider}}) {
                   15409:                         if (grep(/^\Q$field\E$/,@optfields)) {
                   15410:                             push(@{$confhash{$provider}{'fields'}},$field);
                   15411:                         }
                   15412:                     }
                   15413:                 }
                   15414:                 if (ref($current{'fields'}) eq 'ARRAY') {
                   15415:                     unless ($changes{$provider}) {
                   15416:                         my @new = sort(@{$confhash{$provider}{'fields'}});
                   15417:                         my @old = sort(@{$current{'fields'}}); 
                   15418:                         my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15419:                         if (@diffs) {
                   15420:                             $changes{$provider} = 1;
                   15421:                         }
                   15422:                     }
                   15423:                 } elsif (@{$confhash{$provider}{'fields'}}) {
                   15424:                     $changes{$provider} = 1;
                   15425:                 }
                   15426:             }
                   15427:             if (ref($defaults{$provider}) eq 'ARRAY') {  
                   15428:                 if (@{$defaults{$provider}} > 0) {
                   15429:                     my %options;
                   15430:                     if (ref($extended{$provider}) eq 'HASH') {
                   15431:                         %options = %{$extended{$provider}};
                   15432:                     }
                   15433:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
                   15434:                     foreach my $field (@{$defaults{$provider}}) {
                   15435:                         if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   15436:                             my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
                   15437:                             if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
                   15438:                                 push(@{$confhash{$provider}{'defaults'}},$poss); 
                   15439:                             }
                   15440:                         } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
                   15441:                             foreach my $inner (keys(%{$options{$field}})) {
                   15442:                                 if (ref($options{$field}{$inner}) eq 'ARRAY') {
                   15443:                                     my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15444:                                     if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
                   15445:                                         $confhash{$provider}{'defaults'}{$inner} = $poss;
                   15446:                                     }
                   15447:                                 } else {
                   15448:                                     $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15449:                                 }
                   15450:                             }
                   15451:                         } else {
                   15452:                             if (grep(/^\Q$field\E$/,@checked)) {
                   15453:                                 push(@{$confhash{$provider}{'defaults'}},$field);
                   15454:                             }
                   15455:                         }
                   15456:                     }
                   15457:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15458:                         if (ref($current{'defaults'}) eq 'ARRAY') {
                   15459:                             unless ($changes{$provider}) {
                   15460:                                 my @new = sort(@{$confhash{$provider}{'defaults'}});
                   15461:                                 my @old = sort(@{$current{'defaults'}});
                   15462:                                 my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15463:                                 if (@diffs) {
                   15464:                                     $changes{$provider} = 1; 
                   15465:                                 }
                   15466:                             }
                   15467:                         } elsif (ref($current{'defaults'}) eq 'ARRAY') {
                   15468:                             if (@{$current{'defaults'}}) {
                   15469:                                 $changes{$provider} = 1;
                   15470:                             }
                   15471:                         }
                   15472:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15473:                         if (ref($current{'defaults'}) eq 'HASH') {
                   15474:                             unless ($changes{$provider}) {
                   15475:                                 foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
                   15476:                                     unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
                   15477:                                         $changes{$provider} = 1;
                   15478:                                         last;
                   15479:                                     }
                   15480:                                 }
                   15481:                             }
                   15482:                             unless ($changes{$provider}) {
                   15483:                                 foreach my $key (keys(%{$current{'defaults'}})) {
                   15484:                                     unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
                   15485:                                         $changes{$provider} = 1;
                   15486:                                         last;
                   15487:                                     }
                   15488:                                 }
                   15489:                             }
                   15490:                         } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
                   15491:                             $changes{$provider} = 1;
                   15492:                         }
                   15493:                     }
                   15494:                 }
                   15495:             }
                   15496:             if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15497:                 if (@{$crsconf{$provider}} > 0) {
                   15498:                     $confhash{$provider}{'crsconf'} = [];
                   15499:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
                   15500:                     foreach my $crsfield (@{$crsconf{$provider}}) {
                   15501:                         if (grep(/^\Q$crsfield\E$/,@checked)) {
                   15502:                             push(@{$confhash{$provider}{'crsconf'}},$crsfield);
                   15503:                         }
                   15504:                     }
                   15505:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   15506:                         unless ($changes{$provider}) {  
                   15507:                             my @new = sort(@{$confhash{$provider}{'crsconf'}});
                   15508:                             my @old = sort(@{$current{'crsconf'}});
                   15509:                             my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15510:                             if (@diffs) {
                   15511:                                 $changes{$provider} = 1;
                   15512:                             }
                   15513:                         }
                   15514:                     } elsif (@{$confhash{$provider}{'crsconf'}}) {
                   15515:                         $changes{$provider} = 1;
                   15516:                     }
                   15517:                 }
                   15518:             }
                   15519:             if ($showroles) {
                   15520:                 $confhash{$provider}{'roles'} = {};
                   15521:                 foreach my $role (@courseroles) {
                   15522:                     my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
                   15523:                     if (grep(/^\Q$poss\E$/,@ltiroles)) {
                   15524:                         $confhash{$provider}{'roles'}{$role} = $poss;
                   15525:                     }
                   15526:                 }
                   15527:                 unless ($changes{$provider}) {
                   15528:                     if (ref($current{'roles'}) eq 'HASH') {
                   15529:                         foreach my $role (keys(%{$current{'roles'}})) {
                   15530:                             unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
                   15531:                                 $changes{$provider} = 1;
                   15532:                                 last
                   15533:                             }
                   15534:                         }
                   15535:                         unless ($changes{$provider}) {
                   15536:                             foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
                   15537:                                 unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
                   15538:                                     $changes{$provider} = 1;
                   15539:                                     last;
                   15540:                                 }
                   15541:                             }
                   15542:                         }
                   15543:                     } elsif (keys(%{$confhash{$provider}{'roles'}})) {
                   15544:                         $changes{$provider} = 1;
                   15545:                     }
                   15546:                 }
                   15547:             }
                   15548:             if (ref($current{'custom'}) eq 'HASH') {
                   15549:                 my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
                   15550:                 foreach my $key (keys(%{$current{'custom'}})) {
                   15551:                     if (grep(/^\Q$key\E$/,@customdels)) {
                   15552:                         $changes{$provider} = 1;
                   15553:                     } else {
                   15554:                         $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
                   15555:                         if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
                   15556:                             $changes{$provider} = 1;
                   15557:                         }
                   15558:                     }
                   15559:                 }
                   15560:             }
                   15561:             if ($customadds{$provider}) {
                   15562:                 my $name = $env{'form.proctoring_custom_name_'.$provider};
                   15563:                 $name =~ s/(`)/'/g;
                   15564:                 $name =~ s/^\s+//;
                   15565:                 $name =~ s/\s+$//;
                   15566:                 my $value = $env{'form.proctoring_custom_value_'.$provider};
                   15567:                 $value =~ s/(`)/'/g;
                   15568:                 $value =~ s/^\s+//;
                   15569:                 $value =~ s/\s+$//;
                   15570:                 if ($name ne '') {
                   15571:                     $confhash{$provider}{'custom'}{$name} = $value;
                   15572:                     $changes{$provider} = 1;
                   15573:                 }
                   15574:             }
                   15575:         }
                   15576:     }
                   15577:     if (@allpos > 0) {
                   15578:         my $idx = 0;
                   15579:         foreach my $provider (@allpos) {
                   15580:             if ($provider ne '') {
                   15581:                 $confhash{$provider}{'order'} = $idx;
                   15582:                 unless ($changes{$provider}) {
                   15583:                     if (ref($domconfig{$action}) eq 'HASH') {
                   15584:                         if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   15585:                             if ($domconfig{$action}{$provider}{'order'} ne $idx) {
                   15586:                                 $changes{$provider} = 1;
                   15587:                             }
                   15588:                         }
                   15589:                     }
                   15590:                 }
                   15591:                 $idx ++;
                   15592:             }
                   15593:         }
                   15594:     }
                   15595:     my %proc_hash = (
                   15596:                           $action => { %confhash }
                   15597:                        );
                   15598:     my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
                   15599:                                              $dom);
                   15600:     if ($putresult eq 'ok') {
                   15601:         my %proc_enchash = (
                   15602:                              $action => { %encconfhash }
                   15603:                          );
1.384     raeburn  15604:         &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372     raeburn  15605:         if (keys(%changes) > 0) {
                   15606:             my $cachetime = 24*60*60;
                   15607:             my %procall = %confhash;
                   15608:             foreach my $provider (keys(%procall)) {
                   15609:                 if (ref($encconfhash{$provider}) eq 'HASH') {
                   15610:                     foreach my $key ('key','secret') {
                   15611:                         $procall{$provider}{$key} = $encconfhash{$provider}{$key};
                   15612:                     }
                   15613:                 }
                   15614:             }
                   15615:             &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
                   15616:             if (ref($lastactref) eq 'HASH') {
                   15617:                 $lastactref->{'proctoring'} = 1;
                   15618:             }
                   15619:             $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
                   15620:             my %bynum;
                   15621:             foreach my $provider (sort(keys(%changes))) {
                   15622:                 my $position = $confhash{$provider}{'order'};
                   15623:                 $bynum{$position} = $provider;
                   15624:             }
                   15625:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15626:                 my $provider = $bynum{$pos};
                   15627:                 my %lt = &proctoring_titles($provider);
                   15628:                 my %fieldtitles = &proctoring_fieldtitles($provider);
                   15629:                 if (!$confhash{$provider}{'available'}) {
                   15630:                     $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
                   15631:                 } else {
                   15632:                     $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
                   15633:                     if ($confhash{$provider}{'image'}) {
                   15634:                         $resulttext .= '&nbsp;'.
                   15635:                                        '<img src="'.$confhash{$provider}{'image'}.'"'.
                   15636:                                        ' alt="'.&mt('Proctoring icon').'" />';
                   15637:                     }
                   15638:                     $resulttext .= '<ul>';
                   15639:                     my $position = $pos + 1;
                   15640:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15641:                     foreach my $key ('version','sigmethod','url','lifetime') {
                   15642:                         if ($confhash{$provider}{$key} ne '') {
                   15643:                             $resulttext .= '<li>'.$lt{$key}.':&nbsp;'.$confhash{$provider}{$key}.'</li>';
                   15644:                         }
                   15645:                     }
                   15646:                     if ($encconfhash{$provider}{'key'} ne '') {
                   15647:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfhash{$provider}{'key'}.'</li>';
                   15648:                     }
                   15649:                     if ($encconfhash{$provider}{'secret'} ne '') {
                   15650:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15651:                         my $num = length($encconfhash{$provider}{'secret'});
                   15652:                         $resulttext .= ('*'x$num).'</li>';
                   15653:                     }
                   15654:                     my (@fields,$showroles);
                   15655:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15656:                         push(@fields,@{$requserfields{$provider}});
                   15657:                     }
                   15658:                     if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
                   15659:                         push(@fields,@{$confhash{$provider}{'fields'}});
                   15660:                     } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
                   15661:                         push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
                   15662:                     }
                   15663:                     if (@fields) {
                   15664:                         if (grep(/^roles$/,@fields)) {
                   15665:                             $showroles = 1;
                   15666:                         }
                   15667:                         $resulttext .= '<li>'.$lt{'udsl'}.':&nbsp;"'.
                   15668:                                        join('", "', map { $lt{$_}; } @fields).'"</li>';
                   15669:                     }
                   15670:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15671:                         if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15672:                             if ($confhash{$provider}{'incdom'}) {
                   15673:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
                   15674:                             } else { 
                   15675:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
                   15676:                             }
                   15677:                         }
                   15678:                     }
                   15679:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15680:                         if (@{$confhash{$provider}{'defaults'}} > 0) {
                   15681:                             $resulttext .= '<li>'.$lt{'defa'};
                   15682:                             foreach my $field (@{$confhash{$provider}{'defaults'}}) {
                   15683:                                 $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15684:                             }
                   15685:                             $resulttext =~ s/,$//;
                   15686:                             $resulttext .= '</li>';
                   15687:                         }
                   15688:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15689:                         if (keys(%{$confhash{$provider}{'defaults'}})) {
                   15690:                             $resulttext .= '<li>'.$lt{'defa'}.':&nbsp;<ul>';
                   15691:                             foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
                   15692:                                 if ($confhash{$provider}{'defaults'}{$key} ne '') {
                   15693:                                     $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
                   15694:                                 }
                   15695:                             }
                   15696:                             $resulttext .= '</ul></li>';
                   15697:                         }
                   15698:                     }
                   15699:                     if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15700:                         if (@{$crsconf{$provider}} > 0) {
                   15701:                             $resulttext .= '<li>'.&mt('Configurable in course:');
                   15702:                             my $numconfig = 0;
                   15703:                             if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
                   15704:                                 if (@{$confhash{$provider}{'crsconf'}} > 0) {
                   15705:                                     foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
                   15706:                                         $numconfig ++;
                   15707:                                         if ($provider eq 'examity') {
                   15708:                                             $resulttext .= ' "'.$lt{'crs'.$field}.'",';
                   15709:                                         } else {
                   15710:                                             $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15711:                                         }
                   15712:                                     }
                   15713:                                     $resulttext =~ s/,$//;
                   15714:                                 }
                   15715:                             }
                   15716:                             if (!$numconfig) {
                   15717:                                 $resulttext .= '&nbsp;'.&mt('None');
                   15718:                             }
                   15719:                             $resulttext .= '</li>';
                   15720:                         }
                   15721:                     }
                   15722:                     if ($showroles) {
                   15723:                         if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
                   15724:                             my $rolemaps;
                   15725:                             foreach my $role (@courseroles) {
                   15726:                                 if ($confhash{$provider}{'roles'}{$role}) {
                   15727:                                     $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   15728:                                                  $confhash{$provider}{'roles'}{$role}.',';
                   15729:                                 }
                   15730:                             }
                   15731:                             if ($rolemaps) {
                   15732:                                 $rolemaps =~ s/,$//;
                   15733:                                 $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15734:                             }
                   15735:                         }
                   15736:                     }
                   15737:                     if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
                   15738:                         my $customlist;
                   15739:                         if (keys(%{$confhash{$provider}{'custom'}})) {
                   15740:                             foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
                   15741:                                 $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
                   15742:                             }
                   15743:                             $customlist =~ s/,$//;
                   15744:                         }
                   15745:                         if ($customlist) {
                   15746:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
                   15747:                         }
                   15748:                     } 
                   15749:                     $resulttext .= '</ul></li>';
                   15750:                 }
                   15751:             }
                   15752:             $resulttext .= '</ul>';
                   15753:         } else {
                   15754:             $resulttext = &mt('No changes made.');
                   15755:         }
                   15756:     } else {
                   15757:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15758:     }
                   15759:     if ($errors) {
                   15760:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15761:                        $errors.'</ul>';
                   15762:     }
                   15763:     return $resulttext;
                   15764: }
                   15765: 
                   15766: sub process_proctoring_image {
                   15767:     my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
                   15768:     my $filename = $env{'form.'.$caller.'.filename'};
                   15769:     my ($error,$url);
                   15770:     my ($width,$height) = (21,21);
                   15771:     if ($configuserok eq 'ok') {
                   15772:         if ($switchserver) {
                   15773:             $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
                   15774:                          $switchserver);
                   15775:         } elsif ($author_ok eq 'ok') {
1.421     raeburn  15776:             my $modified = [];
1.372     raeburn  15777:             my ($result,$imageurl,$madethumb) =
1.421     raeburn  15778:                 &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
                   15779:                                                         "proctoring/$provider/icon",$width,$height,
                   15780:                                                         '',$modified);
1.372     raeburn  15781:             if ($result eq 'ok') {
                   15782:                 if ($madethumb) {
                   15783:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   15784:                     my $imagethumb = "$path/tn-".$imagefile;
                   15785:                     $url = $imagethumb;
                   15786:                 } else {
                   15787:                     $url = $imageurl;
                   15788:                 }
1.421     raeburn  15789:                 &update_modify_urls($r,$modified);
1.372     raeburn  15790:             } else {
                   15791:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   15792:             }
                   15793:         } else {
                   15794:             $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$author_ok);
                   15795:         }
                   15796:     } else {
                   15797:         $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$configuserok);
                   15798:     }
                   15799:     return ($url,$error);
                   15800: }
                   15801: 
1.320     raeburn  15802: sub modify_lti {
                   15803:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   15804:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424     raeburn  15805:     my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320     raeburn  15806:     my (%posslti,%posslticrs,%posscrstype);
                   15807:     my @courseroles = ('cc','in','ta','ep','st');
                   15808:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   15809:     my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392     raeburn  15810:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  15811:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   15812:                                official   => 'Official',
                   15813:                                unofficial => 'Unofficial',
                   15814:                                community  => 'Community',
                   15815:                                textbook   => 'Textbook',
                   15816:                                placement  => 'Placement Test',
1.392     raeburn  15817:                                lti        => 'LTI Provider',
1.320     raeburn  15818:     );
1.325     raeburn  15819:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320     raeburn  15820:     my %lt = &lti_names();
                   15821:     map { $posslti{$_} = 1; } @ltiroles;
                   15822:     map { $posslticrs{$_} = 1; } @lticourseroles;
                   15823:     map { $posscrstype{$_} = 1; } @coursetypes;
1.325     raeburn  15824: 
1.326     raeburn  15825:     my %menutitles = &ltimenu_titles();
1.421     raeburn  15826:     my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326     raeburn  15827: 
1.421     raeburn  15828:     &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405     raeburn  15829: 
1.406     raeburn  15830:     my (%linkprotchg,$linkprotoutput,$is_home);
                   15831:     my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
                   15832:                                                            \%linkprotchg,'domain');
                   15833:     my $home = &Apache::lonnet::domain($dom,'primary');
                   15834:     unless (($home eq 'no_host') || ($home eq '')) {
                   15835:         my @ids=&Apache::lonnet::current_machine_ids();
                   15836:         foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
                   15837:     }
                   15838: 
                   15839:     if (keys(%linkprotchg)) {
                   15840:         $secchanges{'linkprot'} = 1;
                   15841:         my %oldlinkprot;
                   15842:         if (ref($currltisec{'linkprot'}) eq 'HASH') {
                   15843:             %oldlinkprot = %{$currltisec{'linkprot'}};
                   15844:         }
                   15845:         foreach my $id (keys(%linkprotchg)) {
                   15846:             if (ref($linkprotchg{$id}) eq 'HASH') {
                   15847:                 foreach my $inner (keys(%{$linkprotchg{$id}})) {
                   15848:                     if (($inner eq 'secret') || ($inner eq 'key')) {
                   15849:                         if ($is_home) {
                   15850:                             $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
                   15851:                         }
                   15852:                     }
                   15853:                 }
                   15854:             } else {
                   15855:                 $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
                   15856:             }
                   15857:         }
                   15858:         $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
                   15859:         if (keys(%linkprotchg)) {
                   15860:             %{$newltisec{'linkprot'}} = %linkprotchg;
                   15861:         }
                   15862:     }
                   15863:     if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434     raeburn  15864:         foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406     raeburn  15865:             next if ($id !~ /^\d+$/);
                   15866:             unless (exists($linkprotchg{$id})) {
                   15867:                 if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
                   15868:                     foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
                   15869:                         if (($inner eq 'secret') || ($inner eq 'key')) {
                   15870:                             if ($is_home) {
                   15871:                                 $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
                   15872:                             }
                   15873:                         } else {
                   15874:                             $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
                   15875:                         }
                   15876:                     }
                   15877:                 } else {
                   15878:                     $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
                   15879:                 }
                   15880:             }
                   15881:         }
                   15882:     }
                   15883:     if ($proterror) {
                   15884:         $errors .= '<li>'.$proterror.'</li>';
                   15885:     }
1.434     raeburn  15886: 
                   15887:     my (%delsuggested,%suggids,@suggested);;
                   15888:     if (ref($currltisec{'suggested'}) eq 'HASH') {
                   15889:         my $maxnum = $env{'form.linkprot_suggested_maxnum'};
                   15890:         my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
                   15891:         for (my $i=0; $i<$maxnum; $i++) {
                   15892:             my $itemid = $env{'form.linkprot_suggested_id_'.$i};
                   15893:             $itemid =~ s/\D+//g;
                   15894:             if ($itemid) {
                   15895:                 if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
                   15896:                     push(@suggested,$i);
                   15897:                     $suggids{$i} = $itemid;
                   15898:                     if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
                   15899:                         if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
                   15900:                             $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
                   15901:                         }
                   15902:                     } else {
                   15903:                         if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
                   15904:                             $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
                   15905:                         } else {
                   15906:                             $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
                   15907:                             $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
                   15908:                             $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
                   15909:                             $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
                   15910:                             if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
                   15911:                                 ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
                   15912:                                 $secchanges{'suggested'}{$itemid} = 1;
                   15913:                             }
                   15914:                         }
                   15915:                     }
                   15916:                 }
                   15917:             }
                   15918:         }
                   15919:     }
                   15920:     foreach my $key (keys(%delsuggested)) {
                   15921:         $newltisec{'suggested'}{$key} = $delsuggested{$key};
                   15922:         $secchanges{'suggested'}{$key} = 1;
                   15923:     }
                   15924:     if (($env{'form.linkprot_suggested_add'}) &&
                   15925:         ($env{'form.linkprot_suggested_name_add'} ne '')) {
                   15926:         $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
                   15927:         $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
                   15928:         my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
                   15929:         if ($newsuggid) {
                   15930:             $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
                   15931:             $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
                   15932:             $secchanges{'suggested'}{$newsuggid} = 1;
                   15933:         } else {
                   15934:             my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
                   15935:             if ($errormsg) {
                   15936:                 $error .= ' ('.$errormsg.')';
                   15937:             }
                   15938:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15939:         }
                   15940:     }
1.320     raeburn  15941:     my (@items,%deletions,%itemids);
                   15942:     if ($env{'form.lti_add'}) {
                   15943:         my $consumer = $env{'form.lti_consumer_add'};
                   15944:         $consumer =~ s/(`)/'/g;
1.434     raeburn  15945:         ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320     raeburn  15946:         if ($newid) {
                   15947:             $itemids{'add'} = $newid;
                   15948:             push(@items,'add');
                   15949:             $changes{$newid} = 1;
                   15950:         } else {
                   15951:             my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434     raeburn  15952:             if ($errormsg) {
                   15953:                 $error .= ' ('.$errormsg.')';
                   15954:             }
1.320     raeburn  15955:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15956:         }
                   15957:     }
                   15958:     if (ref($domconfig{$action}) eq 'HASH') {
                   15959:         my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
                   15960:         if (@todelete) {
                   15961:             map { $deletions{$_} = 1; } @todelete;
                   15962:         }
                   15963:         my $maxnum = $env{'form.lti_maxnum'};
1.390     raeburn  15964:         for (my $i=0; $i<$maxnum; $i++) {
1.320     raeburn  15965:             my $itemid = $env{'form.lti_id_'.$i};
                   15966:             $itemid =~ s/\D+//g;
                   15967:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15968:                 if ($deletions{$itemid}) {
                   15969:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
                   15970:                 } else {
1.390     raeburn  15971:                     push(@items,$i);
                   15972:                     $itemids{$i} = $itemid;
1.320     raeburn  15973:                 }
                   15974:             }
                   15975:         }
                   15976:     }
1.424     raeburn  15977:     my (%keystore,$secstored);
                   15978:     if ($is_home) {
                   15979:         &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
                   15980:     }
                   15981: 
                   15982:     my ($cipher,$privnum);
                   15983:     if ((@items > 0) && ($is_home)) {
                   15984:         ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
                   15985:                                              $newltisec{'encrypt'},$keystore{$home});
                   15986:     }
1.320     raeburn  15987:     foreach my $idx (@items) {
                   15988:         my $itemid = $itemids{$idx};
                   15989:         next unless ($itemid);
1.424     raeburn  15990:         my %currlti;
                   15991:         unless ($idx eq 'add') {
                   15992:             if (ref($domconfig{$action}) eq 'HASH') {
                   15993:                 if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15994:                     %currlti = %{$domconfig{$action}{$itemid}};
                   15995:                 }
                   15996:             }
                   15997:         }
1.390     raeburn  15998:         my $position = $env{'form.lti_pos_'.$itemid};
1.320     raeburn  15999:         $position =~ s/\D+//g;
                   16000:         if ($position ne '') {
                   16001:             $allpos[$position] = $itemid;
                   16002:         }
1.424     raeburn  16003:         foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320     raeburn  16004:             my $formitem = 'form.lti_'.$item.'_'.$idx;
                   16005:             $env{$formitem} =~ s/(`)/'/g;
                   16006:             if ($item eq 'lifetime') {
                   16007:                 $env{$formitem} =~ s/[^\d.]//g;
                   16008:             }
                   16009:             if ($env{$formitem} ne '') {
1.424     raeburn  16010:                 $confhash{$itemid}{$item} = $env{$formitem};
                   16011:                 unless (($idx eq 'add') || ($changes{$itemid})) {
                   16012:                     if ($currlti{$item} ne $confhash{$itemid}{$item}) {
                   16013:                         $changes{$itemid} = 1;
1.320     raeburn  16014:                     }
                   16015:                 }
                   16016:             }
                   16017:         }
                   16018:         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
                   16019:             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
                   16020:         }
1.345     raeburn  16021:         if ($confhash{$itemid}{'requser'}) {
                   16022:             if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405     raeburn  16023:                 $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345     raeburn  16024:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
                   16025:                 $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
                   16026:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
                   16027:                 my $mapuser = $env{'form.lti_customuser_'.$idx};
                   16028:                 $mapuser =~ s/(`)/'/g;
1.405     raeburn  16029:                 $mapuser =~ s/^\s+|\s+$//g;
                   16030:                 $confhash{$itemid}{'mapuser'} = $mapuser;
1.345     raeburn  16031:             }
                   16032:             my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
                   16033:             my @makeuser;
                   16034:             foreach my $ltirole (sort(@possmakeuser)) {
                   16035:                 if ($posslti{$ltirole}) {
                   16036:                     push(@makeuser,$ltirole);
                   16037:                 }
                   16038:             }
                   16039:             $confhash{$itemid}{'makeuser'} = \@makeuser;
                   16040:             if (@makeuser) {
                   16041:                 my $lcauth = $env{'form.lti_lcauth_'.$idx};
                   16042:                 if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
                   16043:                     $confhash{$itemid}{'lcauth'} = $lcauth;
                   16044:                     if ($lcauth ne 'internal') {
                   16045:                         my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
                   16046:                         $lcauthparm =~ s/^(\s+|\s+)$//g;
                   16047:                         $lcauthparm =~ s/`//g;
                   16048:                         if ($lcauthparm ne '') {
                   16049:                             $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
                   16050:                         }
                   16051:                     }
                   16052:                 } else {
                   16053:                     $confhash{$itemid}{'lcauth'} = 'lti';
                   16054:                 }
1.320     raeburn  16055:             }
1.345     raeburn  16056:             my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
                   16057:             if (@possinstdata) {
                   16058:                 foreach my $field (@possinstdata) {
                   16059:                     if (exists($fieldtitles{$field})) {
                   16060:                         push(@{$confhash{$itemid}{'instdata'}});
1.325     raeburn  16061:                     }
                   16062:                 }
                   16063:             }
1.363     raeburn  16064:             if ($env{'form.lti_callback_'.$idx}) {
                   16065:                 if ($env{'form.lti_callbackparam_'.$idx}) {
                   16066:                     my $callback = $env{'form.lti_callbackparam_'.$idx};
                   16067:                     $callback =~ s/^\s+|\s+$//g;
                   16068:                     $confhash{$itemid}{'callback'} = $callback;
                   16069:                 }
                   16070:             }
1.391     raeburn  16071:             foreach my $field ('topmenu','inlinemenu') {
1.345     raeburn  16072:                 if ($env{'form.lti_'.$field.'_'.$idx}) {
                   16073:                     $confhash{$itemid}{$field} = 1;
                   16074:                 }
1.320     raeburn  16075:             }
1.345     raeburn  16076:             if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   16077:                 $confhash{$itemid}{lcmenu} = [];
                   16078:                 my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   16079:                 foreach my $field (@possmenu) {
                   16080:                     if (exists($menutitles{$field})) {
                   16081:                         if ($field eq 'grades') {
                   16082:                             next unless ($env{'form.lti_inlinemenu_'.$idx});
                   16083:                         }
                   16084:                         push(@{$confhash{$itemid}{lcmenu}},$field);
1.326     raeburn  16085:                     }
                   16086:                 }
                   16087:             }
1.391     raeburn  16088:             if ($confhash{$itemid}{'crsinc'}) {
                   16089:                 if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
                   16090:                     ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
                   16091:                     $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
                   16092:                 } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                   16093:                     my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
                   16094:                     $mapcrs =~ s/(`)/'/g;
                   16095:                     $mapcrs =~ s/^\s+|\s+$//g;
                   16096:                     $confhash{$itemid}{'mapcrs'} = $mapcrs;
                   16097:                 }
                   16098:                 my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                   16099:                 my @crstypes;
                   16100:                 foreach my $type (sort(@posstypes)) {
                   16101:                     if ($posscrstype{$type}) {
                   16102:                         push(@crstypes,$type);
                   16103:                     }
                   16104:                 }
                   16105:                 $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392     raeburn  16106:                 if ($env{'form.lti_storecrs_'.$idx}) {
                   16107:                     $confhash{$itemid}{'storecrs'} = 1;
                   16108:                 }       
1.391     raeburn  16109:                 if ($env{'form.lti_makecrs_'.$idx}) {
                   16110:                     $confhash{$itemid}{'makecrs'} = 1;
                   16111:                 }
                   16112:                 foreach my $ltirole (@lticourseroles) {
                   16113:                     my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                   16114:                     if (grep(/^\Q$possrole\E$/,@courseroles)) {
                   16115:                         $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
                   16116:                     }
                   16117:                 }
                   16118:                 my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
                   16119:                 my @selfenroll;
                   16120:                 foreach my $type (sort(@possenroll)) {
                   16121:                     if ($posslticrs{$type}) {
                   16122:                         push(@selfenroll,$type);
                   16123:                     }
                   16124:                 }
                   16125:                 $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                   16126:                 if ($env{'form.lti_crssec_'.$idx}) {
                   16127:                     if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                   16128:                         $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                   16129:                     } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                   16130:                         my $section = $env{'form.lti_customsection_'.$idx};
                   16131:                         $section =~ s/(`)/'/g;
                   16132:                         $section =~ s/^\s+|\s+$//g;
                   16133:                         if ($section ne '') {
                   16134:                             $confhash{$itemid}{'section'} = $section;
                   16135:                         }
                   16136:                     }
                   16137:                 }
                   16138:                 foreach my $field ('passback','roster') {
                   16139:                     if ($env{'form.lti_'.$field.'_'.$idx}) {
                   16140:                         $confhash{$itemid}{$field} = 1;
                   16141:                     }
                   16142:                 }
                   16143:                 if ($env{'form.lti_passback_'.$idx}) {
                   16144:                     if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                   16145:                         $confhash{$itemid}{'passbackformat'} = '1.0';
                   16146:                     } else {
                   16147:                         $confhash{$itemid}{'passbackformat'} = '1.1';
1.337     raeburn  16148:                     }
                   16149:                 }
1.391     raeburn  16150:             }
                   16151:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   16152:                 if ($confhash{$itemid}{'crsinc'}) {
1.392     raeburn  16153:                     foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424     raeburn  16154:                         if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320     raeburn  16155:                             $changes{$itemid} = 1;
                   16156:                         }
1.345     raeburn  16157:                     }
                   16158:                     unless ($changes{$itemid}) {
1.424     raeburn  16159:                         if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
                   16160:                             if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320     raeburn  16161:                                 $changes{$itemid} = 1;
                   16162:                             }
                   16163:                         }
1.345     raeburn  16164:                     }
1.391     raeburn  16165:                     foreach my $field ('mapcrstype','selfenroll') {
                   16166:                         unless ($changes{$itemid}) {
1.424     raeburn  16167:                             if (ref($currlti{$field}) eq 'ARRAY') {
1.391     raeburn  16168:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424     raeburn  16169:                                     my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391     raeburn  16170:                                                                                    $confhash{$itemid}{$field});
                   16171:                                     if (@diffs) {
                   16172:                                         $changes{$itemid} = 1;
                   16173:                                     }
1.424     raeburn  16174:                                 } elsif (@{$currlti{$field}} > 0) {
1.391     raeburn  16175:                                     $changes{$itemid} = 1;
                   16176:                                 }
                   16177:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   16178:                                 if (@{$confhash{$itemid}{$field}} > 0) {
1.320     raeburn  16179:                                     $changes{$itemid} = 1;
                   16180:                                 }
                   16181:                             }
1.391     raeburn  16182:                         }
                   16183:                     }
                   16184:                     unless ($changes{$itemid}) {
1.424     raeburn  16185:                         if (ref($currlti{'maproles'}) eq 'HASH') {
1.391     raeburn  16186:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424     raeburn  16187:                                 foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
                   16188:                                     if ($currlti{'maproles'}{$ltirole} ne 
1.391     raeburn  16189:                                         $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345     raeburn  16190:                                         $changes{$itemid} = 1;
                   16191:                                         last;
                   16192:                                     }
                   16193:                                 }
1.391     raeburn  16194:                                 unless ($changes{$itemid}) {
                   16195:                                     foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                   16196:                                         if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
1.424     raeburn  16197:                                             $currlti{'maproles'}{$ltirole}) {
1.391     raeburn  16198:                                             $changes{$itemid} = 1;
                   16199:                                             last;
                   16200:                                         }
                   16201:                                     }
                   16202:                                 }
1.424     raeburn  16203:                             } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391     raeburn  16204:                                 $changes{$itemid} = 1;
1.345     raeburn  16205:                             }
1.391     raeburn  16206:                         } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   16207:                             unless ($changes{$itemid}) {
                   16208:                                 if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                   16209:                                     $changes{$itemid} = 1;
                   16210:                                 }
                   16211:                             }
                   16212:                         }
                   16213:                     }
                   16214:                 }
                   16215:                 unless ($changes{$itemid}) {
                   16216:                     foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424     raeburn  16217:                         if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345     raeburn  16218:                             $changes{$itemid} = 1;
1.320     raeburn  16219:                         }
1.391     raeburn  16220:                     }
                   16221:                     unless ($changes{$itemid}) {
                   16222:                         foreach my $field ('makeuser','lcmenu') {
1.424     raeburn  16223:                             if (ref($currlti{$field}) eq 'ARRAY') {
1.391     raeburn  16224:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424     raeburn  16225:                                     my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391     raeburn  16226:                                                                                    $confhash{$itemid}{$field});
                   16227:                                     if (@diffs) {
                   16228:                                         $changes{$itemid} = 1;
                   16229:                                     }
1.424     raeburn  16230:                                 } elsif (@{$currlti{$field}} > 0) {
1.391     raeburn  16231:                                     $changes{$itemid} = 1;
                   16232:                                 }
                   16233:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   16234:                                 if (@{$confhash{$itemid}{$field}} > 0) {
                   16235:                                     $changes{$itemid} = 1;
                   16236:                                 }
1.345     raeburn  16237:                             }
1.320     raeburn  16238:                         }
                   16239:                     }
                   16240:                 }
                   16241:             }
                   16242:         }
1.424     raeburn  16243:         if ($is_home) {
                   16244:             my $keyitem = 'form.lti_key_'.$idx;
                   16245:             $env{$keyitem} =~ s/(`)/'/g;
                   16246:             if ($env{$keyitem} ne '') {
                   16247:                 $ltienc{$itemid}{'key'} = $env{$keyitem};
                   16248:                 unless ($changes{$itemid}) {
                   16249:                     if ($currlti{'key'} ne $env{$keyitem}) {
                   16250:                         $changes{$itemid} = 1;
                   16251:                     }
                   16252:                 }
                   16253:             }
                   16254:             my $secretitem = 'form.lti_secret_'.$idx;
                   16255:             $env{$secretitem} =~ s/(`)/'/g;
                   16256:             if ($currlti{'usable'}) {
                   16257:                 if ($env{'form.lti_changesecret_'.$idx}) {
                   16258:                     if ($env{$secretitem} ne '') {
                   16259:                         if ($privnum && $cipher) {
                   16260:                             $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
                   16261:                             $confhash{$itemid}{'cipher'} = $privnum;
                   16262:                         } else {
                   16263:                             $ltienc{$itemid}{'secret'} = $env{$secretitem};
                   16264:                         }
                   16265:                         $changes{$itemid} = 1;
                   16266:                     }
                   16267:                 } else {
                   16268:                     $ltienc{$itemid}{'secret'} = $currlti{'secret'};
                   16269:                     $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
                   16270:                 }
                   16271:                 if (ref($ltienc{$itemid}) eq 'HASH') {
                   16272:                     if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
                   16273:                         $confhash{$itemid}{'usable'} = 1;
                   16274:                     }
                   16275:                 }
                   16276:             } elsif ($env{$secretitem} ne '') {
                   16277:                 if ($privnum && $cipher) {
                   16278:                     $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
                   16279:                     $confhash{$itemid}{'cipher'} = $privnum;
                   16280:                 } else {
                   16281:                     $ltienc{$itemid}{'secret'} = $env{$secretitem};
                   16282:                 }
                   16283:                 if (ref($ltienc{$itemid}) eq 'HASH') {
                   16284:                     if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
                   16285:                         $confhash{$itemid}{'usable'} = 1;
                   16286:                     }
                   16287:                 }
                   16288:                 $changes{$itemid} = 1;
                   16289:             }
                   16290:         }
                   16291:         unless ($changes{$itemid}) {
                   16292:             foreach my $key (keys(%currlti)) {
                   16293:                 if (ref($currlti{$key}) eq 'HASH') {
                   16294:                     if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   16295:                         foreach my $innerkey (keys(%{$currlti{$key}})) {
                   16296:                             unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   16297:                                 $changes{$itemid} = 1;
                   16298:                                 last;
                   16299:                             }
                   16300:                         }
                   16301:                     } elsif (keys(%{$currlti{$key}}) > 0) {
                   16302:                         $changes{$itemid} = 1;
                   16303:                     }
                   16304:                 }
                   16305:                 last if ($changes{$itemid});
                   16306:             }
                   16307:         }
1.320     raeburn  16308:     }
                   16309:     if (@allpos > 0) {
                   16310:         my $idx = 0;
                   16311:         foreach my $itemid (@allpos) {
                   16312:             if ($itemid ne '') {
                   16313:                 $confhash{$itemid}{'order'} = $idx;
                   16314:                 if (ref($domconfig{$action}) eq 'HASH') {
                   16315:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   16316:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   16317:                             $changes{$itemid} = 1;
                   16318:                         }
                   16319:                     }
                   16320:                 }
                   16321:                 $idx ++;
                   16322:             }
                   16323:         }
                   16324:     }
1.424     raeburn  16325: 
                   16326:     if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
                   16327:         return &mt('No changes made.');
                   16328:     }
                   16329: 
1.320     raeburn  16330:     my %ltihash = (
1.405     raeburn  16331:                       $action => { %confhash }
                   16332:                   );
1.424     raeburn  16333:     my %ltienchash;
                   16334: 
                   16335:     if ($is_home) {
                   16336:         %ltienchash = (
                   16337:                          $action => { %ltienc }
                   16338:                       );
                   16339:     }
1.405     raeburn  16340:     if (keys(%secchanges)) {
                   16341:         $ltihash{'ltisec'} = \%newltisec;
1.406     raeburn  16342:         if ($secchanges{'linkprot'}) {
                   16343:             if ($is_home) {
                   16344:                 $ltienchash{'linkprot'} = \%newltienc;
                   16345:             }
                   16346:         }
1.405     raeburn  16347:     }
                   16348:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320     raeburn  16349:     if ($putresult eq 'ok') {
1.424     raeburn  16350:         if (keys(%ltienchash)) {
                   16351:             &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405     raeburn  16352:         }
                   16353:         $resulttext = &mt('Changes made:').'<ul>';
                   16354:         if (keys(%secchanges) > 0) {
1.423     raeburn  16355:             $resulttext .= &lti_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421     raeburn  16356:             if (exists($secchanges{'linkprot'})) {
                   16357:                 $resulttext .= $linkprotoutput;
1.405     raeburn  16358:             }
                   16359:         }
1.320     raeburn  16360:         if (keys(%changes) > 0) {
                   16361:             my $cachetime = 24*60*60;
1.424     raeburn  16362:             &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320     raeburn  16363:             if (ref($lastactref) eq 'HASH') {
                   16364:                 $lastactref->{'lti'} = 1;
                   16365:             }
                   16366:             my %bynum;
                   16367:             foreach my $itemid (sort(keys(%changes))) {
1.424     raeburn  16368:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   16369:                     my $position = $confhash{$itemid}{'order'};
                   16370:                     $bynum{$position} = $itemid;
                   16371:                 }
1.320     raeburn  16372:             }
                   16373:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   16374:                 my $itemid = $bynum{$pos};
1.424     raeburn  16375:                 if (ref($confhash{$itemid}) eq 'HASH') {
1.390     raeburn  16376:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320     raeburn  16377:                     my $position = $pos + 1;
                   16378:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   16379:                     foreach my $item ('version','lifetime') {
                   16380:                         if ($confhash{$itemid}{$item} ne '') {
                   16381:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   16382:                         }
                   16383:                     }
1.424     raeburn  16384:                     if ($ltienc{$itemid}{'key'} ne '') {
                   16385:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$ltienc{$itemid}{'key'}.'</li>';
1.320     raeburn  16386:                     }
1.424     raeburn  16387:                     if ($ltienc{$itemid}{'secret'} ne '') {
                   16388:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;['.&mt('not shown').']</li>';
1.320     raeburn  16389:                     }
1.345     raeburn  16390:                     if ($confhash{$itemid}{'requser'}) {
1.391     raeburn  16391:                         if ($confhash{$itemid}{'callback'}) {
                   16392:                             $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
                   16393:                         } else {
1.392     raeburn  16394:                             $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391     raeburn  16395:                         }
1.345     raeburn  16396:                         if ($confhash{$itemid}{'mapuser'}) {
                   16397:                             my $shownmapuser;
                   16398:                             if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                   16399:                                 $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                   16400:                             } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                   16401:                                 $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                   16402:                             } else {
                   16403:                                 $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320     raeburn  16404:                             }
1.345     raeburn  16405:                             $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320     raeburn  16406:                         }
1.345     raeburn  16407:                         if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                   16408:                             if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                   16409:                                 $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                   16410:                                                           join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                   16411:                                 if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                   16412:                                     $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                   16413:                                 } else {
                   16414:                                     $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                   16415:                                                        $confhash{$itemid}{'lcauth'});
                   16416:                                     if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                   16417:                                         $resulttext .= '; '.&mt('a randomly generated password will be created');
                   16418:                                     } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                   16419:                                         if ($confhash{$itemid}{'lcauthparm'} ne '') {
                   16420:                                             $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                   16421:                                         }
                   16422:                                     } else {
                   16423:                                         $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                   16424:                                     }
                   16425:                                 }
                   16426:                                 $resulttext .= '</li>';
                   16427:                             } else {
                   16428:                                 $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                   16429:                             }
1.320     raeburn  16430:                         }
1.345     raeburn  16431:                         if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                   16432:                             if (@{$confhash{$itemid}{'instdata'}} > 0) {
                   16433:                                 $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                   16434:                                                           join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325     raeburn  16435:                             } else {
1.345     raeburn  16436:                                 $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325     raeburn  16437:                             }
1.320     raeburn  16438:                         }
1.391     raeburn  16439:                         foreach my $item ('topmenu','inlinemenu') {
1.345     raeburn  16440:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   16441:                             if ($confhash{$itemid}{$item}) {
                   16442:                                 $resulttext .= &mt('Yes');
                   16443:                             } else {
                   16444:                                 $resulttext .= &mt('No');
1.337     raeburn  16445:                             }
1.345     raeburn  16446:                             $resulttext .= '</li>';
1.320     raeburn  16447:                         }
1.345     raeburn  16448:                         if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   16449:                             if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   16450:                                 $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391     raeburn  16451:                                                join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
                   16452:                             } else {
                   16453:                                 $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
                   16454:                             }
                   16455:                         }
                   16456:                         if ($confhash{$itemid}{'crsinc'}) {
                   16457:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   16458:                                 my $rolemaps;
                   16459:                                 foreach my $role (@ltiroles) {
                   16460:                                     if ($confhash{$itemid}{'maproles'}{$role}) {
                   16461:                                         $rolemaps .= ('&nbsp;'x2).$role.'='.
                   16462:                                                      &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                   16463:                                                                                 'Course').',';
                   16464:                                     }
                   16465:                                 }
                   16466:                                 if ($rolemaps) {
                   16467:                                     $rolemaps =~ s/,$//;
                   16468:                                     $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   16469:                                 }
                   16470:                             }
                   16471:                             if ($confhash{$itemid}{'mapcrs'}) {
                   16472:                                 $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                   16473:                             }
                   16474:                             if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                   16475:                                 if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                   16476:                                     $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                   16477:                                                    join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                   16478:                                                    '</li>';
                   16479:                                 } else {
                   16480:                                     $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                   16481:                                 }
                   16482:                             }
1.392     raeburn  16483:                             if ($confhash{$itemid}{'storecrs'}) {
                   16484:                                 $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
                   16485:                             }
1.391     raeburn  16486:                             if ($confhash{$itemid}{'makecrs'}) {
                   16487:                                 $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
                   16488:                             } else {
                   16489:                                 $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
                   16490:                             }
                   16491:                             if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                   16492:                                 if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                   16493:                                     $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                   16494:                                                               join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                   16495:                                                    '</li>';
                   16496:                                 } else {
                   16497:                                     $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                   16498:                                 }
                   16499:                             }
                   16500:                             if ($confhash{$itemid}{'section'}) {
                   16501:                                 if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                   16502:                                     $resulttext .= '<li>'.&mt('User section from standard field:').
                   16503:                                                          ' (course_section_sourcedid)'.'</li>';  
                   16504:                                 } else {
                   16505:                                     $resulttext .= '<li>'.&mt('User section from:').' '.
                   16506:                                                           $confhash{$itemid}{'section'}.'</li>';
                   16507:                                 }
1.345     raeburn  16508:                             } else {
1.391     raeburn  16509:                                 $resulttext .= '<li>'.&mt('No section assignment').'</li>';
                   16510:                             }
                   16511:                             foreach my $item ('passback','roster','topmenu','inlinemenu') {
                   16512:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   16513:                                 if ($confhash{$itemid}{$item}) {
                   16514:                                     $resulttext .= &mt('Yes');
                   16515:                                     if ($item eq 'passback') {
                   16516:                                         if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                   16517:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                   16518:                                         } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                   16519:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                   16520:                                         }
                   16521:                                     }
                   16522:                                 } else {
                   16523:                                     $resulttext .= &mt('No');
                   16524:                                 }
                   16525:                                 $resulttext .= '</li>';
                   16526:                             }
                   16527:                             if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   16528:                                 if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   16529:                                     $resulttext .= '<li>'.&mt('Menu items:').' '.
                   16530:                                                    join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                   16531:                                 } else {
                   16532:                                     $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                   16533:                                 }
1.345     raeburn  16534:                             }
1.326     raeburn  16535:                         }
                   16536:                     }
1.320     raeburn  16537:                     $resulttext .= '</ul></li>';
                   16538:                 }
                   16539:             }
1.424     raeburn  16540:             if (keys(%deletions)) {
                   16541:                 foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
                   16542:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   16543:                 }
                   16544:             }
1.320     raeburn  16545:         }
1.405     raeburn  16546:         $resulttext .= '</ul>';
1.424     raeburn  16547:         if (ref($lastactref) eq 'HASH') {
1.434     raeburn  16548:             if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
                   16549:                 &Apache::lonnet::get_domain_defaults($dom,1);
1.424     raeburn  16550:                 $lastactref->{'domdefaults'} = 1;
                   16551:             }
                   16552:         }
1.320     raeburn  16553:     } else {
                   16554:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   16555:     }
                   16556:     if ($errors) {
                   16557:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   16558:                        $errors.'</ul>';
                   16559:     }
                   16560:     return $resulttext;
                   16561: }
                   16562: 
1.424     raeburn  16563: sub get_priv_creds {
                   16564:     my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
                   16565:     my ($needenc,$cipher,$privnum);
                   16566:     my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
                   16567:     if (($encchg) && (ref($encrypt) eq 'HASH')) {
                   16568:         $needenc = $encrypt->{'consumers'} 
                   16569:     } else {
                   16570:         $needenc = $domdefs{'ltienc_consumers'};
                   16571:     }
                   16572:     if ($needenc) {
                   16573:         if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
                   16574:                                      (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
                   16575:                         my %privhash  = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
                   16576:             my $privkey = $privhash{'key'};
                   16577:             $privnum = $privhash{'version'};
                   16578:             if (($privnum) && ($privkey ne '')) {
                   16579:                 $cipher = Crypt::CBC->new({'key'     => $privkey,
                   16580:                                           'cipher'  => 'DES'});
                   16581:             }
                   16582:         }
                   16583:     }
                   16584:     return ($cipher,$privnum);
                   16585: }
                   16586: 
1.320     raeburn  16587: sub get_lti_id {
1.434     raeburn  16588:     my ($domain,$consumer,$dbname) = @_;
                   16589:     unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
                   16590:         return ('','invalid db');
                   16591:     }
                   16592:     # get lock on db
1.320     raeburn  16593:     my $lockhash = {
                   16594:                       lock => $env{'user.name'}.
                   16595:                               ':'.$env{'user.domain'},
                   16596:                    };
                   16597:     my $tries = 0;
1.434     raeburn  16598:     my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320     raeburn  16599:     my ($id,$error);
                   16600: 
                   16601:     while (($gotlock ne 'ok') && ($tries<10)) {
                   16602:         $tries ++;
                   16603:         sleep (0.1);
1.434     raeburn  16604:         $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320     raeburn  16605:     }
                   16606:     if ($gotlock eq 'ok') {
1.434     raeburn  16607:         my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320     raeburn  16608:         if ($currids{'lock'}) {
                   16609:             delete($currids{'lock'});
                   16610:             if (keys(%currids)) {
                   16611:                 my @curr = sort { $a <=> $b } keys(%currids);
                   16612:                 if ($curr[-1] =~ /^\d+$/) {
                   16613:                     $id = 1 + $curr[-1];
                   16614:                 }
                   16615:             } else {
                   16616:                 $id = 1;
                   16617:             }
                   16618:             if ($id) {
1.434     raeburn  16619:                 unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320     raeburn  16620:                     $error = 'nostore';
                   16621:                 }
                   16622:             } else {
                   16623:                 $error = 'nonumber';
                   16624:             }
                   16625:         }
1.434     raeburn  16626:         my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320     raeburn  16627:     } else {
                   16628:         $error = 'nolock';
                   16629:     }
                   16630:     return ($id,$error);
                   16631: }
                   16632: 
1.3       raeburn  16633: sub modify_autoenroll {
1.205     raeburn  16634:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  16635:     my ($resulttext,%changes);
                   16636:     my %currautoenroll;
                   16637:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   16638:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   16639:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   16640:         }
                   16641:     }
                   16642:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   16643:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  16644:                   sender => 'Sender for notification messages',
1.274     raeburn  16645:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399     raeburn  16646:                   autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  16647:     my @offon = ('off','on');
1.17      raeburn  16648:     my $sender_uname = $env{'form.sender_uname'};
                   16649:     my $sender_domain = $env{'form.sender_domain'};
                   16650:     if ($sender_domain eq '') {
                   16651:         $sender_uname = '';
                   16652:     } elsif ($sender_uname eq '') {
                   16653:         $sender_domain = '';
                   16654:     }
1.129     raeburn  16655:     my $coowners = $env{'form.autoassign_coowners'};
1.399     raeburn  16656:     my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
                   16657:     $autofailsafe =~ s{^\s+|\s+$}{}g;
                   16658:     if ($autofailsafe =~ /\D/) {
                   16659:         undef($autofailsafe);
                   16660:     }
1.274     raeburn  16661:     my $failsafe = $env{'form.autoenroll_failsafe'};
1.399     raeburn  16662:     unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
                   16663:         $failsafe = 'off';
1.400     raeburn  16664:         undef($autofailsafe);
1.274     raeburn  16665:     }
1.1       raeburn  16666:     my %autoenrollhash =  (
1.129     raeburn  16667:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   16668:                                        'sender_uname' => $sender_uname,
                   16669:                                        'sender_domain' => $sender_domain,
                   16670:                                        'co-owners' => $coowners,
1.399     raeburn  16671:                                        'autofailsafe' => $autofailsafe,
1.400     raeburn  16672:                                        'failsafe' => $failsafe,
1.1       raeburn  16673:                                 }
                   16674:                      );
1.4       raeburn  16675:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   16676:                                              $dom);
1.1       raeburn  16677:     if ($putresult eq 'ok') {
                   16678:         if (exists($currautoenroll{'run'})) {
                   16679:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   16680:                  $changes{'run'} = 1;
                   16681:              }
                   16682:         } elsif ($autorun) {
                   16683:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  16684:                  $changes{'run'} = 1;
1.1       raeburn  16685:             }
                   16686:         }
1.17      raeburn  16687:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  16688:             $changes{'sender'} = 1;
                   16689:         }
1.17      raeburn  16690:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  16691:             $changes{'sender'} = 1;
                   16692:         }
1.129     raeburn  16693:         if ($currautoenroll{'co-owners'} ne '') {
                   16694:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   16695:                 $changes{'coowners'} = 1;
                   16696:             }
                   16697:         } elsif ($coowners) {
                   16698:             $changes{'coowners'} = 1;
1.274     raeburn  16699:         }
1.399     raeburn  16700:         if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274     raeburn  16701:             $changes{'autofailsafe'} = 1;
                   16702:         }
1.399     raeburn  16703:         if ($currautoenroll{'failsafe'} ne $failsafe) {
                   16704:             $changes{'failsafe'} = 1;
                   16705:         }
1.1       raeburn  16706:         if (keys(%changes) > 0) {
                   16707:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  16708:             if ($changes{'run'}) {
1.1       raeburn  16709:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   16710:             }
                   16711:             if ($changes{'sender'}) {
1.17      raeburn  16712:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   16713:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   16714:                 } else {
                   16715:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   16716:                 }
1.1       raeburn  16717:             }
1.129     raeburn  16718:             if ($changes{'coowners'}) {
                   16719:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   16720:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16721:                 if (ref($lastactref) eq 'HASH') {
                   16722:                     $lastactref->{'domainconfig'} = 1;
                   16723:                 }
1.129     raeburn  16724:             }
1.274     raeburn  16725:             if ($changes{'autofailsafe'}) {
1.399     raeburn  16726:                 if ($autofailsafe ne '') {
                   16727:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274     raeburn  16728:                 } else {
1.399     raeburn  16729:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274     raeburn  16730:                 }
1.399     raeburn  16731:             }
                   16732:             if ($changes{'failsafe'}) {
                   16733:                 if ($failsafe eq 'off') {
                   16734:                     unless ($changes{'autofailsafe'}) {
                   16735:                         $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
                   16736:                     }
                   16737:                 } elsif ($failsafe eq 'zero') {
                   16738:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
                   16739:                 } else {
                   16740:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
                   16741:                 }
                   16742:             }
                   16743:             if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274     raeburn  16744:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   16745:                 if (ref($lastactref) eq 'HASH') {
                   16746:                     $lastactref->{'domdefaults'} = 1;
                   16747:                 }
                   16748:             }
1.1       raeburn  16749:             $resulttext .= '</ul>';
                   16750:         } else {
                   16751:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   16752:         }
                   16753:     } else {
1.11      albertel 16754:         $resulttext = '<span class="LC_error">'.
                   16755: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16756:     }
1.3       raeburn  16757:     return $resulttext;
1.1       raeburn  16758: }
                   16759: 
                   16760: sub modify_autoupdate {
1.3       raeburn  16761:     my ($dom,%domconfig) = @_;
1.1       raeburn  16762:     my ($resulttext,%currautoupdate,%fields,%changes);
                   16763:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   16764:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   16765:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   16766:         }
                   16767:     }
                   16768:     my @offon = ('off','on');
                   16769:     my %title = &Apache::lonlocal::texthash (
1.385     raeburn  16770:                     run        => 'Auto-update:',
                   16771:                     classlists => 'Updates to user information in classlists?',
                   16772:                     unexpired  => 'Skip updates for users without active or future roles?',
                   16773:                     lastactive => 'Skip updates for inactive users?',
1.1       raeburn  16774:                 );
1.44      raeburn  16775:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  16776:     my %fieldtitles = &Apache::lonlocal::texthash (
                   16777:                         id => 'Student/Employee ID',
1.20      raeburn  16778:                         permanentemail => 'E-mail address',
1.1       raeburn  16779:                         lastname => 'Last Name',
                   16780:                         firstname => 'First Name',
                   16781:                         middlename => 'Middle Name',
1.132     raeburn  16782:                         generation => 'Generation',
1.1       raeburn  16783:                       );
1.142     raeburn  16784:     $othertitle = &mt('All users');
1.1       raeburn  16785:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  16786:         $othertitle = &mt('Other users');
1.1       raeburn  16787:     }
                   16788:     foreach my $key (keys(%env)) {
                   16789:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  16790:             my ($usertype,$item) = ($1,$2);
                   16791:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   16792:                 if ($usertype eq 'default') {   
                   16793:                     push(@{$fields{$1}},$2);
                   16794:                 } elsif (ref($types) eq 'ARRAY') {
                   16795:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   16796:                         push(@{$fields{$1}},$2);
                   16797:                     }
                   16798:                 }
                   16799:             }
1.1       raeburn  16800:         }
                   16801:     }
1.131     raeburn  16802:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   16803:     @lockablenames = sort(@lockablenames);
                   16804:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   16805:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16806:         if (@changed) {
                   16807:             $changes{'lockablenames'} = 1;
                   16808:         }
                   16809:     } else {
                   16810:         if (@lockablenames) {
                   16811:             $changes{'lockablenames'} = 1;
                   16812:         }
                   16813:     }
1.1       raeburn  16814:     my %updatehash = (
                   16815:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   16816:                                       classlists => $env{'form.classlists'},
1.385     raeburn  16817:                                       unexpired  => $env{'form.unexpired'},
1.1       raeburn  16818:                                       fields => {%fields},
1.131     raeburn  16819:                                       lockablenames => \@lockablenames,
1.1       raeburn  16820:                                     }
                   16821:                      );
1.385     raeburn  16822:     my $lastactivedays;
                   16823:     if ($env{'form.lastactive'}) {
                   16824:         $lastactivedays = $env{'form.lastactivedays'};
                   16825:         $lastactivedays =~ s/^\s+|\s+$//g;
                   16826:         unless ($lastactivedays =~ /^\d+$/) {
                   16827:             undef($lastactivedays);
                   16828:             $env{'form.lastactive'} = 0;
                   16829:         }
                   16830:     }
                   16831:     $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1       raeburn  16832:     foreach my $key (keys(%currautoupdate)) {
1.385     raeburn  16833:         if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1       raeburn  16834:             if (exists($updatehash{autoupdate}{$key})) {
                   16835:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   16836:                     $changes{$key} = 1;
                   16837:                 }
                   16838:             }
                   16839:         } elsif ($key eq 'fields') {
                   16840:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  16841:                 foreach my $item (@{$types},'default') {
1.1       raeburn  16842:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   16843:                         my $change = 0;
                   16844:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   16845:                             if (!exists($fields{$item})) {
                   16846:                                 $change = 1;
1.132     raeburn  16847:                                 last;
1.1       raeburn  16848:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  16849:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  16850:                                     $change = 1;
1.132     raeburn  16851:                                     last;
1.1       raeburn  16852:                                 }
                   16853:                             }
                   16854:                         }
                   16855:                         if ($change) {
                   16856:                             push(@{$changes{$key}},$item);
                   16857:                         }
1.26      raeburn  16858:                     } 
1.1       raeburn  16859:                 }
                   16860:             }
1.131     raeburn  16861:         } elsif ($key eq 'lockablenames') {
                   16862:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   16863:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16864:                 if (@changed) {
                   16865:                     $changes{'lockablenames'} = 1;
                   16866:                 }
                   16867:             } else {
                   16868:                 if (@lockablenames) {
                   16869:                     $changes{'lockablenames'} = 1;
                   16870:                 }
                   16871:             }
                   16872:         }
                   16873:     }
                   16874:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   16875:         if (@lockablenames) {
                   16876:             $changes{'lockablenames'} = 1;
1.1       raeburn  16877:         }
                   16878:     }
1.385     raeburn  16879:     unless (grep(/^unexpired$/,keys(%currautoupdate))) {
                   16880:         if ($updatehash{'autoupdate'}{'unexpired'}) {
                   16881:             $changes{'unexpired'} = 1;
                   16882:         }
                   16883:     }
                   16884:     unless (grep(/^lastactive$/,keys(%currautoupdate))) {
                   16885:         if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
                   16886:             $changes{'lastactive'} = 1;
                   16887:         }
                   16888:     }
1.26      raeburn  16889:     foreach my $item (@{$types},'default') {
                   16890:         if (defined($fields{$item})) {
                   16891:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  16892:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   16893:                     my $change = 0;
                   16894:                     if (ref($fields{$item}) eq 'ARRAY') {
                   16895:                         foreach my $type (@{$fields{$item}}) {
                   16896:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   16897:                                 $change = 1;
                   16898:                                 last;
                   16899:                             }
                   16900:                         }
                   16901:                     }
                   16902:                     if ($change) {
                   16903:                         push(@{$changes{'fields'}},$item);
                   16904:                     }
                   16905:                 } else {
1.26      raeburn  16906:                     push(@{$changes{'fields'}},$item);
                   16907:                 }
                   16908:             } else {
                   16909:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  16910:             }
                   16911:         }
                   16912:     }
                   16913:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   16914:                                              $dom);
                   16915:     if ($putresult eq 'ok') {
                   16916:         if (keys(%changes) > 0) {
                   16917:             $resulttext = &mt('Changes made:').'<ul>';
                   16918:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  16919:                 if ($key eq 'lockablenames') {
                   16920:                     $resulttext .= '<li>';
                   16921:                     if (@lockablenames) {
                   16922:                         $usertypes->{'default'} = $othertitle;
                   16923:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   16924:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   16925:                     } else {
                   16926:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   16927:                     }
                   16928:                     $resulttext .= '</li>';
                   16929:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  16930:                     foreach my $item (@{$changes{$key}}) {
                   16931:                         my @newvalues;
                   16932:                         foreach my $type (@{$fields{$item}}) {
                   16933:                             push(@newvalues,$fieldtitles{$type});
                   16934:                         }
1.3       raeburn  16935:                         my $newvaluestr;
                   16936:                         if (@newvalues > 0) {
                   16937:                             $newvaluestr = join(', ',@newvalues);
                   16938:                         } else {
                   16939:                             $newvaluestr = &mt('none');
1.6       raeburn  16940:                         }
1.1       raeburn  16941:                         if ($item eq 'default') {
1.26      raeburn  16942:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  16943:                         } else {
1.26      raeburn  16944:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  16945:                         }
                   16946:                     }
                   16947:                 } else {
                   16948:                     my $newvalue;
                   16949:                     if ($key eq 'run') {
                   16950:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385     raeburn  16951:                     } elsif ($key eq 'lastactive') {
                   16952:                         $newvalue = $offon[$env{'form.lastactive'}];
                   16953:                         unless ($lastactivedays eq '') {
                   16954:                             $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
                   16955:                         }
1.1       raeburn  16956:                     } else {
                   16957:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  16958:                     }
1.1       raeburn  16959:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   16960:                 }
                   16961:             }
                   16962:             $resulttext .= '</ul>';
                   16963:         } else {
1.3       raeburn  16964:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  16965:         }
                   16966:     } else {
1.11      albertel 16967:         $resulttext = '<span class="LC_error">'.
                   16968: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16969:     }
1.3       raeburn  16970:     return $resulttext;
1.1       raeburn  16971: }
                   16972: 
1.125     raeburn  16973: sub modify_autocreate {
                   16974:     my ($dom,%domconfig) = @_;
                   16975:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   16976:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   16977:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   16978:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   16979:         }
                   16980:     }
                   16981:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   16982:                  req => 'Auto-creation of validated requests for official courses',
                   16983:                  xmldc => 'Identity of course creator of courses from XML files',
                   16984:                );
                   16985:     my @types = ('xml','req');
                   16986:     foreach my $item (@types) {
                   16987:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   16988:         $newvals{$item} =~ s/\D//g;
                   16989:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   16990:     }
                   16991:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  16992:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  16993:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   16994:         $newvals{'xmldc'} = '';
                   16995:     } 
                   16996:     %autocreatehash =  (
                   16997:                         autocreate => { xml => $newvals{'xml'},
                   16998:                                         req => $newvals{'req'},
                   16999:                                       }
                   17000:                        );
                   17001:     if ($newvals{'xmldc'} ne '') {
                   17002:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   17003:     }
                   17004:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   17005:                                              $dom);
                   17006:     if ($putresult eq 'ok') {
                   17007:         my @items = @types;
                   17008:         if ($newvals{'xml'}) {
                   17009:             push(@items,'xmldc');
                   17010:         }
                   17011:         foreach my $item (@items) {
                   17012:             if (exists($currautocreate{$item})) {
                   17013:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   17014:                     $changes{$item} = 1;
                   17015:                 }
                   17016:             } elsif ($newvals{$item}) {
                   17017:                 $changes{$item} = 1;
                   17018:             }
                   17019:         }
                   17020:         if (keys(%changes) > 0) {
                   17021:             my @offon = ('off','on'); 
                   17022:             $resulttext = &mt('Changes made:').'<ul>';
                   17023:             foreach my $item (@types) {
                   17024:                 if ($changes{$item}) {
                   17025:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  17026:                     $resulttext .= '<li>'.
                   17027:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   17028:                                        '<b>','</b>').
                   17029:                                    '</li>';
1.125     raeburn  17030:                 }
                   17031:             }
                   17032:             if ($changes{'xmldc'}) {
                   17033:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   17034:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  17035:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  17036:             }
                   17037:             $resulttext .= '</ul>';
                   17038:         } else {
                   17039:             $resulttext = &mt('No changes made to auto-creation settings');
                   17040:         }
                   17041:     } else {
                   17042:         $resulttext = '<span class="LC_error">'.
                   17043:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17044:     }
                   17045:     return $resulttext;
                   17046: }
                   17047: 
1.23      raeburn  17048: sub modify_directorysrch {
1.295     raeburn  17049:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  17050:     my ($resulttext,%changes);
                   17051:     my %currdirsrch;
                   17052:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   17053:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   17054:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   17055:         }
                   17056:     }
1.277     raeburn  17057:     my %title = ( available => 'Institutional directory search available',
                   17058:                   localonly => 'Other domains can search institution',
                   17059:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  17060:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  17061:                   searchby => 'Search types',
                   17062:                   searchtypes => 'Search latitude');
                   17063:     my @offon = ('off','on');
1.24      raeburn  17064:     my @otherdoms = ('Yes','No');
1.23      raeburn  17065: 
1.25      raeburn  17066:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  17067:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   17068:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   17069: 
1.44      raeburn  17070:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  17071:     if (keys(%{$usertypes}) == 0) {
                   17072:         @cansearch = ('default');
                   17073:     } else {
                   17074:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   17075:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   17076:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   17077:                     push(@{$changes{'cansearch'}},$type);
                   17078:                 }
1.23      raeburn  17079:             }
1.26      raeburn  17080:             foreach my $type (@cansearch) {
                   17081:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   17082:                     push(@{$changes{'cansearch'}},$type);
                   17083:                 }
1.23      raeburn  17084:             }
1.26      raeburn  17085:         } else {
                   17086:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  17087:         }
                   17088:     }
                   17089: 
                   17090:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   17091:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   17092:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   17093:                 push(@{$changes{'searchby'}},$by);
                   17094:             }
                   17095:         }
                   17096:         foreach my $by (@searchby) {
                   17097:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   17098:                 push(@{$changes{'searchby'}},$by);
                   17099:             }
                   17100:         }
                   17101:     } else {
                   17102:         push(@{$changes{'searchby'}},@searchby);
                   17103:     }
1.25      raeburn  17104: 
                   17105:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   17106:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   17107:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   17108:                 push(@{$changes{'searchtypes'}},$type);
                   17109:             }
                   17110:         }
                   17111:         foreach my $type (@searchtypes) {
                   17112:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   17113:                 push(@{$changes{'searchtypes'}},$type);
                   17114:             }
                   17115:         }
                   17116:     } else {
                   17117:         if (exists($currdirsrch{'searchtypes'})) {
                   17118:             foreach my $type (@searchtypes) {  
                   17119:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   17120:                     push(@{$changes{'searchtypes'}},$type);
                   17121:                 }
                   17122:             }
                   17123:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   17124:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   17125:             }   
                   17126:         } else {
                   17127:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   17128:         }
                   17129:     }
                   17130: 
1.23      raeburn  17131:     my %dirsrch_hash =  (
                   17132:             directorysrch => { available => $env{'form.dirsrch_available'},
                   17133:                                cansearch => \@cansearch,
1.277     raeburn  17134:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   17135:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   17136:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  17137:                                searchby => \@searchby,
1.25      raeburn  17138:                                searchtypes => \@searchtypes,
1.23      raeburn  17139:                              }
                   17140:             );
                   17141:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   17142:                                              $dom);
                   17143:     if ($putresult eq 'ok') {
                   17144:         if (exists($currdirsrch{'available'})) {
                   17145:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   17146:                  $changes{'available'} = 1;
                   17147:              }
                   17148:         } else {
                   17149:             if ($env{'form.dirsrch_available'} eq '1') {
                   17150:                 $changes{'available'} = 1;
                   17151:             }
                   17152:         }
1.277     raeburn  17153:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  17154:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   17155:                 $changes{'lcavailable'} = 1;
                   17156:             }
1.277     raeburn  17157:         } else {
                   17158:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   17159:                 $changes{'lcavailable'} = 1;
                   17160:             }
                   17161:         }
1.24      raeburn  17162:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  17163:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   17164:                 $changes{'localonly'} = 1;
                   17165:             }
1.24      raeburn  17166:         } else {
1.277     raeburn  17167:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  17168:                 $changes{'localonly'} = 1;
                   17169:             }
                   17170:         }
1.277     raeburn  17171:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  17172:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   17173:                 $changes{'lclocalonly'} = 1;
                   17174:             }
1.277     raeburn  17175:         } else {
                   17176:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   17177:                 $changes{'lclocalonly'} = 1;
                   17178:             }
                   17179:         }
1.23      raeburn  17180:         if (keys(%changes) > 0) {
                   17181:             $resulttext = &mt('Changes made:').'<ul>';
                   17182:             if ($changes{'available'}) {
                   17183:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   17184:             }
1.277     raeburn  17185:             if ($changes{'lcavailable'}) {
                   17186:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   17187:             }
1.24      raeburn  17188:             if ($changes{'localonly'}) {
1.277     raeburn  17189:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  17190:             }
1.277     raeburn  17191:             if ($changes{'lclocalonly'}) {
                   17192:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  17193:             }
1.23      raeburn  17194:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   17195:                 my $chgtext;
1.26      raeburn  17196:                 if (ref($usertypes) eq 'HASH') {
                   17197:                     if (keys(%{$usertypes}) > 0) {
                   17198:                         foreach my $type (@{$types}) {
                   17199:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   17200:                                 $chgtext .= $usertypes->{$type}.'; ';
                   17201:                             }
                   17202:                         }
                   17203:                         if (grep(/^default$/,@cansearch)) {
                   17204:                             $chgtext .= $othertitle;
                   17205:                         } else {
                   17206:                             $chgtext =~ s/\; $//;
                   17207:                         }
1.210     raeburn  17208:                         $resulttext .=
1.178     raeburn  17209:                             '<li>'.
                   17210:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   17211:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   17212:                             '</li>';
1.23      raeburn  17213:                     }
                   17214:                 }
                   17215:             }
                   17216:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   17217:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   17218:                 my $chgtext;
                   17219:                 foreach my $type (@{$titleorder}) {
                   17220:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   17221:                         if (defined($searchtitles->{$type})) {
                   17222:                             $chgtext .= $searchtitles->{$type}.'; ';
                   17223:                         }
                   17224:                     }
                   17225:                 }
                   17226:                 $chgtext =~ s/\; $//;
                   17227:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   17228:             }
1.25      raeburn  17229:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   17230:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   17231:                 my $chgtext;
                   17232:                 foreach my $type (@{$srchtypeorder}) {
                   17233:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   17234:                         if (defined($srchtypes_desc->{$type})) {
                   17235:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   17236:                         }
                   17237:                     }
                   17238:                 }
                   17239:                 $chgtext =~ s/\; $//;
1.178     raeburn  17240:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  17241:             }
                   17242:             $resulttext .= '</ul>';
1.295     raeburn  17243:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   17244:             if (ref($lastactref) eq 'HASH') {
                   17245:                 $lastactref->{'directorysrch'} = 1;
                   17246:             }
1.23      raeburn  17247:         } else {
1.277     raeburn  17248:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  17249:         }
                   17250:     } else {
                   17251:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  17252:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   17253:     }
                   17254:     return $resulttext;
                   17255: }
                   17256: 
1.28      raeburn  17257: sub modify_contacts {
1.205     raeburn  17258:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  17259:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   17260:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   17261:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   17262:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   17263:         }
                   17264:     }
1.286     raeburn  17265:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  17266:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  17267:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350     raeburn  17268:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340     raeburn  17269:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   17270:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286     raeburn  17271:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  17272:     foreach my $type (@mailings) {
                   17273:         @{$newsetting{$type}} = 
                   17274:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   17275:         foreach my $item (@contacts) {
                   17276:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   17277:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   17278:             } else {
                   17279:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   17280:             }
1.289     raeburn  17281:         }
1.28      raeburn  17282:         $others{$type} = $env{'form.'.$type.'_others'};
                   17283:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  17284:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17285:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   17286:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  17287:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   17288:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   17289:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   17290:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   17291:             }
1.134     raeburn  17292:         }
1.28      raeburn  17293:     }
                   17294:     foreach my $item (@contacts) {
                   17295:         $to{$item} = $env{'form.'.$item};
                   17296:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   17297:     }
1.203     raeburn  17298:     foreach my $item (@toggles) {
                   17299:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   17300:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   17301:         }
                   17302:     }
1.340     raeburn  17303:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   17304:     foreach my $item (@lonstatus) {
                   17305:         if ($item eq 'excluded') {
                   17306:             my (%serverhomes,@excluded);
                   17307:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   17308:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   17309:             if (@possexcluded) {
                   17310:                 foreach my $id (sort(@possexcluded)) {
                   17311:                     if ($serverhomes{$id}) {
                   17312:                         push(@excluded,$id);
                   17313:                     }
                   17314:                 }
                   17315:             }
                   17316:             if (@excluded) {
                   17317:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   17318:             }
                   17319:         } elsif ($item eq 'weights') {
1.377     raeburn  17320:             foreach my $type ('E','W','N','U') {
1.340     raeburn  17321:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   17322:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   17323:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   17324:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   17325:                             $env{'form.error'.$item.'_'.$type};
                   17326:                     }
                   17327:                 }
                   17328:             }
                   17329:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   17330:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   17331:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   17332:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   17333:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   17334:                 }
                   17335:             }
                   17336:         }
                   17337:     }
1.286     raeburn  17338:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   17339:         foreach my $field (@{$fields}) {
                   17340:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   17341:                 my $value = $env{'form.helpform_'.$field};
                   17342:                 $value =~ s/^\s+|\s+$//g;
                   17343:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  17344:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  17345:                     if ($field eq 'screenshot') {
                   17346:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   17347:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  17348:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  17349:                         }
                   17350:                     }
                   17351:                 }
                   17352:             }
                   17353:         }
                   17354:     }
1.315     raeburn  17355:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   17356:     my (@statuses,%usertypeshash,@overrides);
                   17357:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   17358:         @statuses = @{$types};
                   17359:         if (ref($usertypes) eq 'HASH') {
                   17360:             %usertypeshash = %{$usertypes};
                   17361:         }
                   17362:     }
                   17363:     if (@statuses) {
                   17364:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   17365:         foreach my $type (@possoverrides) {
                   17366:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   17367:                 push(@overrides,$type);
                   17368:             }
                   17369:         }
                   17370:         if (@overrides) {
                   17371:             foreach my $type (@overrides) {
                   17372:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   17373:                 foreach my $item (@contacts) {
                   17374:                     if (grep(/^\Q$item\E$/,@standard)) {
                   17375:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   17376:                         $newsetting{'override_'.$type}{$item} = 1;
                   17377:                     } else {
                   17378:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   17379:                         $newsetting{'override_'.$type}{$item} = 0;
                   17380:                     }
                   17381:                 }
                   17382:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   17383:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   17384:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   17385:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   17386:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   17387:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   17388:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   17389:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   17390:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   17391:                 }
1.425     raeburn  17392:             }
1.315     raeburn  17393:         }
                   17394:     }
1.28      raeburn  17395:     if (keys(%currsetting) > 0) {
                   17396:         foreach my $item (@contacts) {
                   17397:             if ($to{$item} ne $currsetting{$item}) {
                   17398:                 $changes{$item} = 1;
                   17399:             }
                   17400:         }
                   17401:         foreach my $type (@mailings) {
                   17402:             foreach my $item (@contacts) {
                   17403:                 if (ref($currsetting{$type}) eq 'HASH') {
                   17404:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   17405:                         push(@{$changes{$type}},$item);
                   17406:                     }
                   17407:                 } else {
                   17408:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   17409:                 }
                   17410:             }
                   17411:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   17412:                 push(@{$changes{$type}},'others');
                   17413:             }
1.289     raeburn  17414:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17415:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   17416:                     push(@{$changes{$type}},'bcc'); 
                   17417:                 }
1.286     raeburn  17418:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   17419:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   17420:                     push(@{$changes{$type}},'include');
                   17421:                 }
                   17422:             }
                   17423:         }
                   17424:         if (ref($fields) eq 'ARRAY') {
                   17425:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   17426:                 foreach my $field (@{$fields}) {
                   17427:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   17428:                         push(@{$changes{'helpform'}},$field);
                   17429:                     }
                   17430:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   17431:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   17432:                             push(@{$changes{'helpform'}},'maxsize');
                   17433:                         }
                   17434:                     }
                   17435:                 }
                   17436:             } else {
                   17437:                 foreach my $field (@{$fields}) {
                   17438:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   17439:                         push(@{$changes{'helpform'}},$field);
                   17440:                     }
                   17441:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   17442:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   17443:                             push(@{$changes{'helpform'}},'maxsize');
                   17444:                         }
                   17445:                     }
                   17446:                 }
1.134     raeburn  17447:             }
1.28      raeburn  17448:         }
1.315     raeburn  17449:         if (@statuses) {
1.425     raeburn  17450:             if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315     raeburn  17451:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   17452:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   17453:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   17454:                             foreach my $item (@contacts,'bcc','others','include') {
1.425     raeburn  17455:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315     raeburn  17456:                                     push(@{$changes{'overrides'}},$key);
                   17457:                                     last;
                   17458:                                 }
                   17459:                             }
                   17460:                         } else {
                   17461:                             push(@{$changes{'overrides'}},$key);
                   17462:                         }
                   17463:                     }
                   17464:                 }
                   17465:                 foreach my $key (@overrides) {
                   17466:                     unless (exists($currsetting{'overrides'}{$key})) {
                   17467:                         push(@{$changes{'overrides'}},$key);
                   17468:                     }
                   17469:                 }
                   17470:             } else {
                   17471:                 foreach my $key (@overrides) {
1.425     raeburn  17472:                     push(@{$changes{'overrides'}},$key);
1.315     raeburn  17473:                 }
                   17474:             }
                   17475:         }
1.340     raeburn  17476:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   17477:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   17478:                 if ($key eq 'excluded') {
                   17479:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   17480:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   17481:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   17482:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   17483:                             my @diffs =
                   17484:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   17485:                                                                    $currsetting{'lonstatus'}{$key});
                   17486:                             if (@diffs) {
                   17487:                                 push(@{$changes{'lonstatus'}},$key);
                   17488:                             }
                   17489:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   17490:                             push(@{$changes{'lonstatus'}},$key);
                   17491:                         }
                   17492:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   17493:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   17494:                         push(@{$changes{'lonstatus'}},$key);
                   17495:                     }
                   17496:                 } elsif ($key eq 'weights') {
                   17497:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   17498:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   17499:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  17500:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  17501:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   17502:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   17503:                                     push(@{$changes{'lonstatus'}},$key);
                   17504:                                     last;
                   17505:                                 }
                   17506:                             }
                   17507:                         } else {
1.341     raeburn  17508:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  17509:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   17510:                                     push(@{$changes{'lonstatus'}},$key);
                   17511:                                     last;
                   17512:                                 }
                   17513:                             }
                   17514:                         }
                   17515:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  17516:                         foreach my $type ('E','W','N','U') {
1.340     raeburn  17517:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   17518:                                 push(@{$changes{'lonstatus'}},$key);
                   17519:                                 last;
                   17520:                             }
                   17521:                         }
                   17522:                     }
                   17523:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   17524:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   17525:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   17526:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   17527:                                 push(@{$changes{'lonstatus'}},$key);
                   17528:                             }
                   17529:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   17530:                             push(@{$changes{'lonstatus'}},$key);
                   17531:                         }
                   17532:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   17533:                         push(@{$changes{'lonstatus'}},$key);
                   17534:                     }
                   17535:                 }
                   17536:             }
                   17537:         } else {
                   17538:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   17539:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   17540:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   17541:                         push(@{$changes{'lonstatus'}},$key);
                   17542:                     }
                   17543:                 }
                   17544:             }
                   17545:         }
1.28      raeburn  17546:     } else {
                   17547:         my %default;
                   17548:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   17549:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   17550:         $default{'errormail'} = 'adminemail';
                   17551:         $default{'packagesmail'} = 'adminemail';
                   17552:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  17553:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  17554:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  17555:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  17556:         $default{'updatesmail'} = 'adminemail';
1.350     raeburn  17557:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  17558:         foreach my $item (@contacts) {
                   17559:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  17560:                $changes{$item} = 1;
1.203     raeburn  17561:            }
1.28      raeburn  17562:         }
                   17563:         foreach my $type (@mailings) {
                   17564:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   17565:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   17566:             }
                   17567:             if ($others{$type} ne '') {
                   17568:                 push(@{$changes{$type}},'others');
1.134     raeburn  17569:             }
1.286     raeburn  17570:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17571:                 if ($bcc{$type} ne '') {
                   17572:                     push(@{$changes{$type}},'bcc');
                   17573:                 }
1.286     raeburn  17574:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   17575:                     push(@{$changes{$type}},'include');
                   17576:                 }
1.134     raeburn  17577:             }
1.28      raeburn  17578:         }
1.286     raeburn  17579:         if (ref($fields) eq 'ARRAY') {
                   17580:             foreach my $field (@{$fields}) {
                   17581:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   17582:                     push(@{$changes{'helpform'}},$field);
                   17583:                 }
                   17584:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   17585:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   17586:                         push(@{$changes{'helpform'}},'maxsize');
                   17587:                     }
                   17588:                 }
                   17589:             }
1.289     raeburn  17590:         }
1.340     raeburn  17591:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   17592:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   17593:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   17594:                     push(@{$changes{'lonstatus'}},$key);
                   17595:                 }
                   17596:             }
                   17597:         }
1.28      raeburn  17598:     }
1.203     raeburn  17599:     foreach my $item (@toggles) {
                   17600:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   17601:             $changes{$item} = 1;
                   17602:         } elsif ((!$env{'form.'.$item}) &&
                   17603:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   17604:             $changes{$item} = 1;
                   17605:         }
                   17606:     }
1.28      raeburn  17607:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   17608:                                              $dom);
                   17609:     if ($putresult eq 'ok') {
                   17610:         if (keys(%changes) > 0) {
1.205     raeburn  17611:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  17612:             if (ref($lastactref) eq 'HASH') {
                   17613:                 $lastactref->{'domainconfig'} = 1;
                   17614:             }
1.28      raeburn  17615:             my ($titles,$short_titles)  = &contact_titles();
                   17616:             $resulttext = &mt('Changes made:').'<ul>';
                   17617:             foreach my $item (@contacts) {
                   17618:                 if ($changes{$item}) {
                   17619:                     $resulttext .= '<li>'.$titles->{$item}.
                   17620:                                     &mt(' set to: ').
                   17621:                                     '<span class="LC_cusr_emph">'.
                   17622:                                     $to{$item}.'</span></li>';
                   17623:                 }
                   17624:             }
                   17625:             foreach my $type (@mailings) {
                   17626:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  17627:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  17628:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  17629:                     } else {
                   17630:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   17631:                     }
1.28      raeburn  17632:                     my @text;
                   17633:                     foreach my $item (@{$newsetting{$type}}) {
                   17634:                         push(@text,$short_titles->{$item});
                   17635:                     }
                   17636:                     if ($others{$type} ne '') {
                   17637:                         push(@text,$others{$type});
                   17638:                     }
1.286     raeburn  17639:                     if (@text) {
                   17640:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   17641:                                        join(', ',@text).'</span>';
                   17642:                     }
                   17643:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17644:                         if ($bcc{$type} ne '') {
1.286     raeburn  17645:                             my $bcctext;
                   17646:                             if (@text) {
1.289     raeburn  17647:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  17648:                             } else {
                   17649:                                 $bcctext = '(Bcc)';
                   17650:                             }
                   17651:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   17652:                         } elsif (!@text) {
                   17653:                             $resulttext .= &mt('No one');
1.425     raeburn  17654:                         }
1.289     raeburn  17655:                         if ($includestr{$type} ne '') {
1.286     raeburn  17656:                             if ($includeloc{$type} eq 'b') {
                   17657:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   17658:                             } elsif ($includeloc{$type} eq 's') {
                   17659:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   17660:                             }
1.134     raeburn  17661:                         }
1.286     raeburn  17662:                     } elsif (!@text) {
                   17663:                         $resulttext .= &mt('No recipients');
1.134     raeburn  17664:                     }
                   17665:                     $resulttext .= '</li>';
1.28      raeburn  17666:                 }
                   17667:             }
1.315     raeburn  17668:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   17669:                 my @deletions;
                   17670:                 foreach my $type (@{$changes{'overrides'}}) {
                   17671:                     if ($usertypeshash{$type}) {
                   17672:                         if (grep(/^\Q$type\E/,@overrides)) {
                   17673:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   17674:                                                       $usertypeshash{$type}).'<ul><li>';
                   17675:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   17676:                                 my @text;
                   17677:                                 foreach my $item (@contacts) {
1.425     raeburn  17678:                                     if ($newsetting{'override_'.$type}{$item}) {
1.315     raeburn  17679:                                         push(@text,$short_titles->{$item});
                   17680:                                     }
                   17681:                                 }
                   17682:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   17683:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   17684:                                 }
1.425     raeburn  17685: 
1.315     raeburn  17686:                                 if (@text) {
                   17687:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   17688:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   17689:                                 }
                   17690:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   17691:                                     my $bcctext;
                   17692:                                     if (@text) {
                   17693:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   17694:                                     } else {
                   17695:                                         $bcctext = '(Bcc)';
                   17696:                                     }
                   17697:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   17698:                                 } elsif (!@text) {
                   17699:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   17700:                                 }
                   17701:                                 $resulttext .= '</li>';
                   17702:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   17703:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   17704:                                     if ($loc eq 'b') {
                   17705:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   17706:                                     } elsif ($loc eq 's') {
                   17707:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   17708:                                     }
                   17709:                                 }
                   17710:                             }
                   17711:                             $resulttext .= '</li></ul></li>';
                   17712:                         } else {
                   17713:                             push(@deletions,$usertypeshash{$type});
                   17714:                         }
                   17715:                     }
                   17716:                 }
                   17717:                 if (@deletions) {
                   17718:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   17719:                                               join(', ',@deletions)).'</li>';
                   17720:                 }
                   17721:             }
1.203     raeburn  17722:             my @offon = ('off','on');
1.340     raeburn  17723:             my $corelink = &core_link_msu();
1.203     raeburn  17724:             if ($changes{'reporterrors'}) {
                   17725:                 $resulttext .= '<li>'.
                   17726:                                &mt('E-mail error reports to [_1] set to "'.
                   17727:                                    $offon[$env{'form.reporterrors'}].'".',
1.340     raeburn  17728:                                    $corelink).
1.203     raeburn  17729:                                '</li>';
                   17730:             }
                   17731:             if ($changes{'reportupdates'}) {
                   17732:                 $resulttext .= '<li>'.
                   17733:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   17734:                                     $offon[$env{'form.reportupdates'}].'".',
1.340     raeburn  17735:                                     $corelink).
1.203     raeburn  17736:                                 '</li>';
                   17737:             }
1.340     raeburn  17738:             if ($changes{'reportstatus'}) {
                   17739:                 $resulttext .= '<li>'.
                   17740:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   17741:                                     $offon[$env{'form.reportstatus'}].'".',
                   17742:                                     $corelink).
                   17743:                                 '</li>';
                   17744:             }
                   17745:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   17746:                 $resulttext .= '<li>'.
                   17747:                                &mt('Nightly status check e-mail settings').':<ul>';
                   17748:                 my (%defval,%use_def,%shown);
                   17749:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   17750:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   17751:                 $defval{'weights'} =
1.341     raeburn  17752:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340     raeburn  17753:                 $defval{'excluded'} = &mt('None');
                   17754:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   17755:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   17756:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   17757:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   17758:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   17759:                             } elsif ($item eq 'weights') {
                   17760:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341     raeburn  17761:                                     foreach my $type ('E','W','N','U') {
1.340     raeburn  17762:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   17763:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   17764:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   17765:                                         } else {
                   17766:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   17767:                                         }
                   17768:                                         $shown{$item} .= ', ';
                   17769:                                     }
                   17770:                                     $shown{$item} =~ s/, $//;
                   17771:                                 } else {
                   17772:                                     $shown{$item} = $defval{$item};
                   17773:                                 }
                   17774:                             } elsif ($item eq 'excluded') {
                   17775:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   17776:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   17777:                                 } else {
                   17778:                                     $shown{$item} = $defval{$item};
                   17779:                                 }
                   17780:                             }
                   17781:                         } else {
                   17782:                             $shown{$item} = $defval{$item};
                   17783:                         }
                   17784:                     }
                   17785:                 } else {
                   17786:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   17787:                         $shown{$item} = $defval{$item};
                   17788:                     }
                   17789:                 }
                   17790:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   17791:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   17792:                                           $shown{$item}).'</li>';
                   17793:                 }
                   17794:                 $resulttext .= '</ul></li>';
                   17795:             }
1.286     raeburn  17796:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   17797:                 my (@optional,@required,@unused,$maxsizechg);
                   17798:                 foreach my $field (@{$changes{'helpform'}}) {
                   17799:                     if ($field eq 'maxsize') {
                   17800:                         $maxsizechg = 1;
                   17801:                         next;
                   17802:                     }
                   17803:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  17804:                         push(@optional,$field);
1.286     raeburn  17805:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   17806:                         push(@unused,$field);
                   17807:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  17808:                         push(@required,$field);
1.286     raeburn  17809:                     }
                   17810:                 }
                   17811:                 if (@optional) {
                   17812:                     $resulttext .= '<li>'.
                   17813:                                    &mt('Help form fields changed to "Optional": [_1].',
                   17814:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   17815:                                    '</li>';
                   17816:                 }
                   17817:                 if (@required) {
                   17818:                     $resulttext .= '<li>'.
                   17819:                                    &mt('Help form fields changed to "Required": [_1].',
                   17820:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   17821:                                    '</li>';
                   17822:                 }
                   17823:                 if (@unused) {
                   17824:                     $resulttext .= '<li>'.
                   17825:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   17826:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   17827:                                    '</li>';
                   17828:                 }
                   17829:                 if ($maxsizechg) {
                   17830:                     $resulttext .= '<li>'.
                   17831:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   17832:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   17833:                                    '</li>';
                   17834:                 }
                   17835:             }
1.28      raeburn  17836:             $resulttext .= '</ul>';
                   17837:         } else {
1.288     raeburn  17838:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  17839:         }
                   17840:     } else {
                   17841:         $resulttext = '<span class="LC_error">'.
                   17842:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   17843:     }
                   17844:     return $resulttext;
                   17845: }
                   17846: 
1.357     raeburn  17847: sub modify_privacy {
1.427     raeburn  17848:     my ($dom,$lastactref,%domconfig) = @_;
1.357     raeburn  17849:     my ($resulttext,%current,%changes);
                   17850:     if (ref($domconfig{'privacy'}) eq 'HASH') {
                   17851:         %current = %{$domconfig{'privacy'}};
                   17852:     }
                   17853:     my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
                   17854:     my @items = ('domain','author','course','community');
                   17855:     my %names = &Apache::lonlocal::texthash (
                   17856:                    domain => 'Assigned domain role(s)',
                   17857:                    author => 'Assigned co-author role(s)',
                   17858:                    course => 'Assigned course role(s)',
1.416     raeburn  17859:                    community => 'Assigned community role(s)',
1.357     raeburn  17860:                 );
                   17861:     my %roles = &Apache::lonlocal::texthash (
                   17862:                    domain => 'Domain role',
                   17863:                    author => 'Co-author role',
                   17864:                    course => 'Course role',
                   17865:                    community => 'Community role',
                   17866:                 );
                   17867:     my %titles = &Apache::lonlocal::texthash (
                   17868:                   approval => 'Approval for role in different domain',
                   17869:                   othdom   => 'User information available in other domain',
                   17870:                   priv     => 'Information viewable by privileged user in same domain',
                   17871:                   unpriv   => 'Information viewable by unprivileged user in same domain',
                   17872:                   instdom  => 'Other domain shares institution/provider',
                   17873:                   extdom   => 'Other domain has different institution/provider',
                   17874:                   none     => 'Not allowed',
                   17875:                   user     => 'User authorizes',
                   17876:                   domain   => 'Domain Coordinator authorizes',
                   17877:                   auto     => 'Unrestricted',
1.418     raeburn  17878:                   notify   => 'Notify when role needs authorization',
1.357     raeburn  17879:     );
                   17880:     my %fieldnames = &Apache::lonlocal::texthash (
                   17881:                         id => 'Student/Employee ID',
                   17882:                         permanentemail => 'E-mail address',
                   17883:                         lastname => 'Last Name',
                   17884:                         firstname => 'First Name',
                   17885:                         middlename => 'Middle Name',
                   17886:                         generation => 'Generation',
                   17887:     );
                   17888:     my ($othertitle,$usertypes,$types) =
                   17889:         &Apache::loncommon::sorted_inst_types($dom);
                   17890:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   17891:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   17892: 
                   17893:     my %privacyhash = (
                   17894:                        'approval' => {
                   17895:                                        instdom => {},
                   17896:                                        extdom  => {},
                   17897:                                      },
                   17898:                        'othdom'   => {},
                   17899:                        'priv'     => {},
                   17900:                        'unpriv'   => {},
                   17901:                       );
                   17902:     foreach my $item (@items) {
                   17903:         if (@instdoms > 1) {
1.416     raeburn  17904:             if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357     raeburn  17905:                 $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
                   17906:             }
                   17907:             if (ref($current{'approval'}) eq 'HASH') {
                   17908:                 if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                   17909:                     unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                   17910:                         $changes{'approval'} = 1;
                   17911:                     }
                   17912:                 }
                   17913:             } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   17914:                 $changes{'approval'} = 1;
                   17915:             }
                   17916:         }
                   17917:         if (keys(%by_location) > 0) {
                   17918:             if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   17919:                 $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
                   17920:             }
                   17921:             if (ref($current{'approval'}) eq 'HASH') {
                   17922:                 if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                   17923:                     unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                   17924:                         $changes{'approval'} = 1;
                   17925:                     }
                   17926:                 }
                   17927:             } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   17928:                 $changes{'approval'} = 1;
                   17929:             }
                   17930:         }
                   17931:         foreach my $status ('priv','unpriv') {
                   17932:             my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
                   17933:             my @newvalues;
                   17934:             foreach my $field (@possibles) {
                   17935:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17936:                     $privacyhash{$status}{$item}{$field} = 1;
                   17937:                     push(@newvalues,$field);
                   17938:                 }
                   17939:             }
                   17940:             @newvalues = sort(@newvalues);
                   17941:             if (ref($current{$status}) eq 'HASH') {
                   17942:                 if (ref($current{$status}{$item}) eq 'HASH') {
                   17943:                     my @currvalues = sort(keys(%{$current{$status}{$item}}));
                   17944:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17945:                     if (@diffs > 0) {
                   17946:                         $changes{$status} = 1;
                   17947:                     }
                   17948:                 }
                   17949:             } else {
                   17950:                 my @stdfields;
                   17951:                 foreach my $field (@fields) {
                   17952:                     if ($field eq 'id') {
                   17953:                         next if ($status eq 'unpriv');
                   17954:                         next if (($status eq 'priv') && ($item eq 'community'));
                   17955:                     }
                   17956:                     push(@stdfields,$field);
                   17957:                 }
                   17958:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17959:                 if (@diffs > 0) {
                   17960:                     $changes{$status} = 1;
                   17961:                 }
                   17962:             }
                   17963:         }
                   17964:     }
                   17965:     if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   17966:         my @statuses;
                   17967:         if (ref($types) eq 'ARRAY') {
                   17968:             @statuses = @{$types};
                   17969:         }
                   17970:         foreach my $type (@statuses,'default') {
                   17971:             my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
                   17972:             my @newvalues;
                   17973:             foreach my $field (sort(@possfields)) {
                   17974:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17975:                     $privacyhash{'othdom'}{$type}{$field} = 1;
                   17976:                     push(@newvalues,$field);
                   17977:                 }
                   17978:             }
                   17979:             @newvalues = sort(@newvalues);
                   17980:             if (ref($current{'othdom'}) eq 'HASH') {
                   17981:                 if (ref($current{'othdom'}{$type}) eq 'HASH') {
                   17982:                     my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                   17983:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17984:                     if (@diffs > 0) {
                   17985:                         $changes{'othdom'} = 1;
                   17986:                     }
                   17987:                 }
                   17988:             } else {
                   17989:                 my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   17990:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17991:                 if (@diffs > 0) {
                   17992:                     $changes{'othdom'} = 1;
                   17993:                 }
                   17994:             }
                   17995:         }
1.417     raeburn  17996:         my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
                   17997:         my %notify;
                   17998:         foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
                   17999:             if (exists($domcoords{$possdc})) {
                   18000:                 $notify{$possdc} = 1;
                   18001:             }
                   18002:         }
                   18003:         my $notify = join(',',sort(keys(%notify)));
                   18004:         if ($current{'notify'} ne $notify) {
                   18005:             $changes{'notify'} = 1;
                   18006:         }
                   18007:         $privacyhash{'notify'} = $notify;
1.357     raeburn  18008:     }
                   18009:     my %confighash = (
                   18010:                         privacy => \%privacyhash,
                   18011:                      );
                   18012:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   18013:     if ($putresult eq 'ok') {
                   18014:         if (keys(%changes) > 0) {
                   18015:             $resulttext = &mt('Changes made: ').'<ul>';
1.417     raeburn  18016:             foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357     raeburn  18017:                 if ($changes{$key}) {
                   18018:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   18019:                     if ($key eq 'approval') {
                   18020:                         if (keys(%{$privacyhash{$key}{instdom}})) {
                   18021:                             $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                   18022:                             foreach my $item (@items) {
                   18023:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                   18024:                             }
                   18025:                             $resulttext .= '</ul></li>';
                   18026:                         }
                   18027:                         if (keys(%{$privacyhash{$key}{extdom}})) {
                   18028:                             $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                   18029:                             foreach my $item (@items) {
                   18030:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                   18031:                             }
                   18032:                             $resulttext .= '</ul></li>';
                   18033:                         }
1.417     raeburn  18034:                     } elsif ($key eq 'notify') {
                   18035:                         if ($privacyhash{$key}) {
                   18036:                             foreach my $dc (split(/,/,$privacyhash{$key})) {
                   18037:                                 my ($dcname,$dcdom) = split(/:/,$dc);
                   18038:                                 $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
                   18039:                             }
                   18040:                         } else {
                   18041:                             $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
                   18042:                         }
1.357     raeburn  18043:                     } elsif ($key eq 'othdom') {
                   18044:                         my @statuses;
                   18045:                         if (ref($types) eq 'ARRAY') {
                   18046:                             @statuses = @{$types};
                   18047:                         }
                   18048:                         if (ref($privacyhash{$key}) eq 'HASH') {
                   18049:                             foreach my $status (@statuses,'default') {
                   18050:                                 if ($status eq 'default') {
                   18051:                                     $resulttext .= '<li>'.$othertitle.': ';
                   18052:                                 } elsif (ref($usertypes) eq 'HASH') {
                   18053:                                     $resulttext .= '<li>'.$usertypes->{$status}.': ';
                   18054:                                 } else {
                   18055:                                     next;
                   18056:                                 }
                   18057:                                 if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                   18058:                                     if (keys(%{$privacyhash{$key}{$status}})) {
                   18059:                                         $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                   18060:                                     } else {
                   18061:                                         $resulttext .= &mt('none');
                   18062:                                     }
                   18063:                                 }
                   18064:                                 $resulttext .= '</li>';
                   18065:                             }
                   18066:                         }
                   18067:                     } else {
                   18068:                         foreach my $item (@items) {
                   18069:                             if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                   18070:                                 $resulttext .= '<li>'.$names{$item}.': ';
                   18071:                                 if (keys(%{$privacyhash{$key}{$item}})) {
                   18072:                                     $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                   18073:                                 } else {
                   18074:                                     $resulttext .= &mt('none');
                   18075:                                 }
                   18076:                                 $resulttext .= '</li>';
                   18077:                             }
                   18078:                         }
                   18079:                     }
                   18080:                     $resulttext .= '</ul></li>';
                   18081:                 }
                   18082:             }
1.421     raeburn  18083:             $resulttext .= '</ul>';
1.427     raeburn  18084:             if ($changes{'approval'}) {
                   18085:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   18086:                 delete($domdefaults{'userapprovals'});
                   18087:                 if (ref($privacyhash{'approval'}) eq 'HASH') {
                   18088:                     foreach my $domtype ('instdom','extdom') {
                   18089:                         if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
                   18090:                             foreach my $roletype ('domain','author','course','community') {
                   18091:                                 if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
                   18092:                                     $domdefaults{'userapprovals'} = 1;
                   18093:                                     last;
                   18094:                                 }
                   18095:                             }
                   18096:                         }
                   18097:                         last if ($domdefaults{'userapprovals'});               
                   18098:                     }
                   18099:                 }
                   18100:                 my $cachetime = 24*60*60;
                   18101:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18102:                 if (ref($lastactref) eq 'HASH') {
                   18103:                     $lastactref->{'domdefaults'} = 1;
                   18104:                 }
                   18105:             }
1.357     raeburn  18106:         } else {
                   18107:             $resulttext = &mt('No changes made to user information settings');
                   18108:         }
                   18109:     } else {
                   18110:         $resulttext = '<span class="LC_error">'.
                   18111:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18112:     }
                   18113:     return $resulttext;
                   18114: }
                   18115: 
1.354     raeburn  18116: sub modify_passwords {
                   18117:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355     raeburn  18118:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   18119:         $updatedefaults,$updateconf);
1.354     raeburn  18120:     my $customfn = 'resetpw.html';
                   18121:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   18122:         %current = %{$domconfig{'passwords'}};
                   18123:     }
                   18124:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18125:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   18126:     if (ref($types) eq 'ARRAY') {
                   18127:         @oktypes = @{$types};
                   18128:     }
                   18129:     push(@oktypes,'default');
                   18130: 
                   18131:     my %titles = &Apache::lonlocal::texthash (
                   18132:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   18133:         intauth_check  => 'Check bcrypt cost if authenticated',
                   18134:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   18135:         permanent      => 'Permanent e-mail address',
                   18136:         critical       => 'Critical notification address',
                   18137:         notify         => 'Notification address',
                   18138:         min            => 'Minimum password length',
                   18139:         max            => 'Maximum password length',
                   18140:         chars          => 'Required characters',
                   18141:         expire         => 'Password expiration (days)',
1.356     raeburn  18142:         numsaved       => 'Number of previous passwords to save',
1.354     raeburn  18143:         reset          => 'Resetting Forgotten Password',
                   18144:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   18145:         rules          => 'Rules for LON-CAPA Passwords',
                   18146:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   18147:         username       => 'Username',
                   18148:         email          => 'E-mail address',
                   18149:     );
                   18150: 
                   18151: #
                   18152: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   18153: #
                   18154:     my (%curr_defaults,%save_defaults);
                   18155:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   18156:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   18157:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   18158:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   18159:             } else {
                   18160:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   18161:             }
                   18162:         }
                   18163:     }
                   18164:     my %staticdefaults = (
                   18165:         'resetlink'      => 2,
                   18166:         'resetcase'      => \@oktypes,
                   18167:         'resetprelink'   => 'both',
                   18168:         'resetemail'     => ['critical','notify','permanent'],
                   18169:         'intauth_cost'   => 10,
                   18170:         'intauth_check'  => 0,
                   18171:         'intauth_switch' => 0,
                   18172:     );
1.365     raeburn  18173:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354     raeburn  18174:     foreach my $type (@oktypes) {
                   18175:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   18176:     }
                   18177:     my $linklife = $env{'form.passwords_link'};
                   18178:     $linklife =~ s/^\s+|\s+$//g;
                   18179:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   18180:         $newvalues{'resetlink'} = $linklife;
                   18181:         if ($current{'resetlink'}) {
                   18182:             if ($current{'resetlink'} ne $linklife) {
                   18183:                 $changes{'reset'} = 1;
                   18184:             }
1.368     raeburn  18185:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18186:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   18187:                 $changes{'reset'} = 1;
                   18188:             }
                   18189:         }
                   18190:     } elsif ($current{'resetlink'}) {
                   18191:         $changes{'reset'} = 1;
                   18192:     }
                   18193:     my @casesens;
                   18194:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   18195:     foreach my $case (sort(@posscase)) {
                   18196:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   18197:             push(@casesens,$case);
                   18198:         }
                   18199:     }
                   18200:     $newvalues{'resetcase'} = \@casesens;
                   18201:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   18202:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   18203:         if (@diffs > 0) {
                   18204:             $changes{'reset'} = 1;
                   18205:         }
1.368     raeburn  18206:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18207:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   18208:         if (@diffs > 0) {
                   18209:             $changes{'reset'} = 1;
                   18210:         }
                   18211:     }
                   18212:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   18213:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   18214:         if (exists($current{'resetprelink'})) {
                   18215:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   18216:                 $changes{'reset'} = 1;
                   18217:             }
1.368     raeburn  18218:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18219:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   18220:                 $changes{'reset'} = 1;
                   18221:             }
                   18222:         }
                   18223:     } elsif ($current{'resetprelink'}) {
                   18224:         $changes{'reset'} = 1;
                   18225:     }
                   18226:     foreach my $type (@oktypes) {
                   18227:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   18228:         my @postlink;
                   18229:         foreach my $item (sort(@possplink)) {
                   18230:             if ($item =~ /^(email|username)$/) {
                   18231:                 push(@postlink,$item);
                   18232:             }
                   18233:         }
                   18234:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   18235:         unless ($changes{'reset'}) {
                   18236:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   18237:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   18238:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   18239:                     if (@diffs > 0) {
                   18240:                         $changes{'reset'} = 1;
                   18241:                     }
                   18242:                 } else {
                   18243:                     $changes{'reset'} = 1;
                   18244:                 }
1.368     raeburn  18245:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18246:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   18247:                 if (@diffs > 0) {
                   18248:                     $changes{'reset'} = 1;
                   18249:                 }
                   18250:             }
                   18251:         }
                   18252:     }
                   18253:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   18254:     my @resetemail;
                   18255:     foreach my $item (sort(@possemailsrc)) {
                   18256:         if ($item =~ /^(permanent|critical|notify)$/) {
                   18257:             push(@resetemail,$item);
                   18258:         }
                   18259:     }
                   18260:     $newvalues{'resetemail'} = \@resetemail;
                   18261:     unless ($changes{'reset'}) {
                   18262:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   18263:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   18264:             if (@diffs > 0) {
                   18265:                 $changes{'reset'} = 1;
                   18266:             }
1.368     raeburn  18267:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18268:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   18269:             if (@diffs > 0) {
                   18270:                 $changes{'reset'} = 1;
                   18271:             }
                   18272:         }
                   18273:     }
                   18274:     if ($env{'form.passwords_stdtext'} == 0) {
                   18275:         $newvalues{'resetremove'} = 1;
                   18276:         unless ($current{'resetremove'}) {
                   18277:             $changes{'reset'} = 1;
                   18278:         }
                   18279:     } elsif ($current{'resetremove'}) {
                   18280:         $changes{'reset'} = 1;
                   18281:     }
                   18282:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   18283:         my $servadm = $r->dir_config('lonAdmEMail');
                   18284:         my ($configuserok,$author_ok,$switchserver) =
                   18285:             &config_check($dom,$confname,$servadm);
                   18286:         my $error;
                   18287:         if ($configuserok eq 'ok') {
                   18288:             if ($switchserver) {
                   18289:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   18290:             } else {
                   18291:                 if ($author_ok eq 'ok') {
1.421     raeburn  18292:                     my $modified = [];
1.354     raeburn  18293:                     my ($result,$customurl) =
1.421     raeburn  18294:                         &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
                   18295:                                                                 $confname,'customtext/resetpw','','',$customfn,
                   18296:                                                                 $modified);
1.354     raeburn  18297:                     if ($result eq 'ok') {
                   18298:                         $newvalues{'resetcustom'} = $customurl;
                   18299:                         $changes{'reset'} = 1;
1.421     raeburn  18300:                         &update_modify_urls($r,$modified);
1.354     raeburn  18301:                     } else {
                   18302:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   18303:                     }
                   18304:                 } else {
                   18305:                     $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].",$customfn,$confname,$dom,$author_ok);
                   18306:                 }
                   18307:             }
                   18308:         } else {
                   18309:             $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customfn,$confname,$dom,$configuserok);
                   18310:         }
                   18311:         if ($error) {
                   18312:             &Apache::lonnet::logthis($error);
                   18313:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   18314:         }
                   18315:     } elsif ($current{'resetcustom'}) {
                   18316:         if ($env{'form.passwords_custom_del'}) {
                   18317:             $changes{'reset'} = 1;
                   18318:         } else {
                   18319:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   18320:         }
                   18321:     }
                   18322:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   18323:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   18324:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   18325:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   18326:             $changes{'intauth'} = 1;
                   18327:         }
                   18328:     } else {
                   18329:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   18330:     }
                   18331:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   18332:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   18333:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   18334:             $changes{'intauth'} = 1;
                   18335:         }
                   18336:     } else {
                   18337:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   18338:     }
                   18339:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   18340:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   18341:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   18342:             $changes{'intauth'} = 1;
                   18343:         }
                   18344:     } else {
                   18345:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   18346:     }
                   18347:     foreach my $item ('cost','check','switch') {
                   18348:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   18349:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   18350:             $updatedefaults = 1;
                   18351:         }
                   18352:     }
1.405     raeburn  18353:     &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359     raeburn  18354:     my %crsownerchg = (
                   18355:                         by => [],
                   18356:                         for => [],
                   18357:                       );
                   18358:     foreach my $item ('by','for') {
                   18359:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   18360:         foreach my $type (sort(@posstypes)) {
                   18361:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   18362:                 push(@{$crsownerchg{$item}},$type);
                   18363:             }
                   18364:         }
                   18365:     }
                   18366:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   18367:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   18368:         foreach my $item ('by','for') {
                   18369:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   18370:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   18371:                 if (@diffs > 0) {
                   18372:                     $changes{'crsownerchg'} = 1;
                   18373:                     last;
                   18374:                 }
                   18375:             }
                   18376:         }
1.368     raeburn  18377:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359     raeburn  18378:         foreach my $item ('by','for') {
                   18379:             if (@{$crsownerchg{$item}} > 0) {
                   18380:                 $changes{'crsownerchg'} = 1;
                   18381:                 last;
                   18382:             }
1.354     raeburn  18383:         }
                   18384:     }
                   18385: 
                   18386:     my %confighash = (
                   18387:                         defaults  => \%save_defaults,
                   18388:                         passwords => \%newvalues,
                   18389:                      );
                   18390:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   18391: 
                   18392:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   18393:     if ($putresult eq 'ok') {
                   18394:         if (keys(%changes) > 0) {
                   18395:             $resulttext = &mt('Changes made: ').'<ul>';
                   18396:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   18397:                 if ($changes{$key}) {
1.355     raeburn  18398:                     unless ($key eq 'intauth') {
                   18399:                         $updateconf = 1;
                   18400:                     }
1.354     raeburn  18401:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   18402:                     if ($key eq 'reset') {
                   18403:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   18404:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   18405:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   18406:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369     raeburn  18407:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   18408:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   18409:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   18410:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   18411:                             }
1.354     raeburn  18412:                         } else {
                   18413:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   18414:                         }
                   18415:                         if ($confighash{'passwords'}{'resetlink'}) {
                   18416:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   18417:                         } else {
                   18418:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   18419:                                                   &mt('Will default to 2 hours').'</li>';
                   18420:                         }
                   18421:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   18422:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   18423:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   18424:                             } else {
                   18425:                                 my $casesens;
                   18426:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   18427:                                     if ($type eq 'default') {
                   18428:                                         $casesens .= $othertitle.', ';
                   18429:                                     } elsif ($usertypes->{$type} ne '') {
                   18430:                                         $casesens .= $usertypes->{$type}.', ';
                   18431:                                     }
                   18432:                                 }
                   18433:                                 $casesens =~ s/\Q, \E$//;
                   18434:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   18435:                             }
                   18436:                         } else {
                   18437:                             $resulttext .= '<li>'.&mt('Case-sensitivity not set for "Forgot Password" web form').' '.&mt('Will default to case-sensitive for username and/or e-mail address for all').'</li>';
                   18438:                         }
                   18439:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   18440:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   18441:                         } else {
                   18442:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   18443:                         }
                   18444:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   18445:                             my $output;
                   18446:                             if (ref($types) eq 'ARRAY') {
                   18447:                                 foreach my $type (@{$types}) {
                   18448:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   18449:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   18450:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   18451:                                         } else {
                   18452:                                             $output .= $usertypes->{$type}.' -- '.
                   18453:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   18454:                                         }
                   18455:                                     }
                   18456:                                 }
                   18457:                             }
                   18458:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   18459:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   18460:                                     $output .= $othertitle.' -- '.&mt('none');
                   18461:                                 } else {
                   18462:                                     $output .= $othertitle.' -- '.
                   18463:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   18464:                                 }
                   18465:                             }
                   18466:                             if ($output) {
                   18467:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   18468:                             } else {
                   18469:                                 $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
                   18470:                             }
                   18471:                         } else {
                   18472:                             $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
                   18473:                         }
                   18474:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   18475:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   18476:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   18477:                             } else {
                   18478:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   18479:                             }
                   18480:                         } else {
1.379     raeburn  18481:                             $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.354     raeburn  18482:                         }
                   18483:                         if ($confighash{'passwords'}{'resetremove'}) {
                   18484:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   18485:                         } else {
                   18486:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   18487:                         }
                   18488:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   18489:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369     raeburn  18490:                                                                             &mt('custom text'),600,500,undef,undef,
                   18491:                                                                             undef,undef,'background-color:#ffffff');
                   18492:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354     raeburn  18493:                         } else {
                   18494:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   18495:                         }
                   18496:                     } elsif ($key eq 'intauth') {
                   18497:                         foreach my $item ('cost','switch','check') {
                   18498:                             my $value = $save_defaults{$key.'_'.$item};
                   18499:                             if ($item eq 'switch') {
                   18500:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   18501:                                                      0 => 'No',
                   18502:                                                      1 => 'Yes',
                   18503:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   18504:                                                  );
                   18505:                                 if ($value =~ /^(0|1|2)$/) {
                   18506:                                     $value = $optiondesc{$value};
                   18507:                                 } else {
                   18508:                                     $value = &mt('none -- defaults to No');
                   18509:                                 }
                   18510:                             } elsif ($item eq 'check') {
                   18511:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   18512:                                                      0 => 'No',
                   18513:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   18514:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   18515:                                                  );
                   18516:                                 if ($value =~ /^(0|1|2)$/) {
                   18517:                                     $value = $optiondesc{$value};
                   18518:                                 } else {
                   18519:                                     $value = &mt('none -- defaults to No');
                   18520:                                 }
                   18521:                             }
                   18522:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   18523:                         }
                   18524:                     } elsif ($key eq 'rules') {
1.356     raeburn  18525:                         foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  18526:                             if ($confighash{'passwords'}{$rule} eq '') {
                   18527:                                 if ($rule eq 'min') {
1.356     raeburn  18528:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365     raeburn  18529:                                                    ' '.&mt('Default of [_1] will be used',
                   18530:                                                            $Apache::lonnet::passwdmin).'</li>';
1.356     raeburn  18531:                                 } else {
                   18532:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354     raeburn  18533:                                 }
                   18534:                             } else {
                   18535:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   18536:                             }
                   18537:                         }
1.370     raeburn  18538:                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   18539:                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   18540:                                 my %rulenames = &Apache::lonlocal::texthash(
                   18541:                                                      uc => 'At least one upper case letter',
                   18542:                                                      lc => 'At least one lower case letter',
                   18543:                                                      num => 'At least one number',
                   18544:                                                      spec => 'At least one non-alphanumeric',
                   18545:                                                    );
                   18546:                                 my $needed = '<ul><li>'.
                   18547:                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425     raeburn  18548:                                              '</li></ul>';
1.370     raeburn  18549:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   18550:                             } else {
                   18551:                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   18552:                             }
                   18553:                         } else {
                   18554:                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   18555:                         }
1.354     raeburn  18556:                     } elsif ($key eq 'crsownerchg') {
1.359     raeburn  18557:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   18558:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   18559:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   18560:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   18561:                             } else {
                   18562:                                 my %crsownerstr;
                   18563:                                 foreach my $item ('by','for') {
                   18564:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   18565:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   18566:                                             if ($type eq 'default') {
                   18567:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   18568:                                             } elsif ($usertypes->{$type} ne '') {
                   18569:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   18570:                                             }
                   18571:                                         }
                   18572:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   18573:                                     }
                   18574:                                 }
                   18575:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   18576:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   18577:                             }
1.354     raeburn  18578:                         } else {
1.359     raeburn  18579:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354     raeburn  18580:                         }
                   18581:                     }
                   18582:                     $resulttext .= '</ul></li>';
                   18583:                 }
                   18584:             }
                   18585:             $resulttext .= '</ul>';
                   18586:         } else {
                   18587:             $resulttext = &mt('No changes made to password settings');
                   18588:         }
1.355     raeburn  18589:         my $cachetime = 24*60*60;
1.354     raeburn  18590:         if ($updatedefaults) {
                   18591:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18592:             if (ref($lastactref) eq 'HASH') {
                   18593:                 $lastactref->{'domdefaults'} = 1;
                   18594:             }
                   18595:         }
1.355     raeburn  18596:         if ($updateconf) {
                   18597:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   18598:             if (ref($lastactref) eq 'HASH') {
                   18599:                 $lastactref->{'passwdconf'} = 1;
                   18600:             }
                   18601:         }
1.354     raeburn  18602:     } else {
                   18603:         $resulttext = '<span class="LC_error">'.
                   18604:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18605:     }
                   18606:     if ($errors) {
                   18607:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   18608:                        $errors.'</ul></p>';
                   18609:     }
                   18610:     return $resulttext;
                   18611: }
                   18612: 
1.405     raeburn  18613: sub password_rule_changes {
                   18614:     my ($prefix,$newvalues,$current,$changes) = @_;
                   18615:     return unless ((ref($newvalues) eq 'HASH') &&
                   18616:                    (ref($current) eq 'HASH') &&
                   18617:                    (ref($changes) eq 'HASH'));
                   18618:     my (@rules,%staticdefaults);
                   18619:     if ($prefix eq 'passwords') {
                   18620:         @rules = ('min','max','expire','numsaved');
1.421     raeburn  18621:     } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405     raeburn  18622:         @rules = ('min','max');
                   18623:     }
                   18624:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
                   18625:     foreach my $rule (@rules) {
                   18626:         $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
                   18627:         my $ruleok;
                   18628:         if ($rule eq 'expire') {
                   18629:             if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
                   18630:                 ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
                   18631:                 $ruleok = 1;
                   18632:             }
                   18633:         } elsif ($rule eq 'min') {
                   18634:             if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
                   18635:                 if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
                   18636:                     $ruleok = 1;
                   18637:                 }
                   18638:             }
                   18639:         } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
                   18640:                  ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
                   18641:             $ruleok = 1;
                   18642:         }
                   18643:         if ($ruleok) {
                   18644:             $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
                   18645:             if (exists($current->{$rule})) {
                   18646:                 if ($newvalues->{$rule} ne $current->{$rule}) {
                   18647:                     $changes->{'rules'} = 1;
                   18648:                 }
                   18649:             } elsif ($rule eq 'min') {
                   18650:                 if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
                   18651:                     $changes->{'rules'} = 1;
                   18652:                 }
                   18653:             } else {
                   18654:                 $changes->{'rules'} = 1;
                   18655:             }
                   18656:         } elsif (exists($current->{$rule})) {
                   18657:             $changes->{'rules'} = 1;
                   18658:         }
                   18659:     }
                   18660:     my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
                   18661:     my @chars;
                   18662:     foreach my $item (sort(@posschars)) {
                   18663:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   18664:             push(@chars,$item);
                   18665:         }
                   18666:     }
                   18667:     $newvalues->{'chars'} = \@chars;
                   18668:     unless ($changes->{'rules'}) {
                   18669:         if (ref($current->{'chars'}) eq 'ARRAY') {
                   18670:             my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
                   18671:             if (@diffs > 0) {
                   18672:                 $changes->{'rules'} = 1;
                   18673:             }
                   18674:         } else {
                   18675:             if (@chars > 0) {
                   18676:                 $changes->{'rules'} = 1;
                   18677:             }
                   18678:         }
                   18679:     }
                   18680:     return;
                   18681: }
                   18682: 
1.28      raeburn  18683: sub modify_usercreation {
1.27      raeburn  18684:     my ($dom,%domconfig) = @_;
1.224     raeburn  18685:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  18686:     my $warningmsg;
1.27      raeburn  18687:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   18688:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  18689:             if ($key eq 'cancreate') {
                   18690:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   18691:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  18692:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   18693:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18694:                         } else {
1.224     raeburn  18695:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18696:                         }
                   18697:                     }
                   18698:                 }
                   18699:             } elsif ($key eq 'email_rule') {
                   18700:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   18701:             } else {
                   18702:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   18703:             }
1.27      raeburn  18704:         }
                   18705:     }
                   18706:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  18707:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  18708:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  18709:     foreach my $item(@contexts) {
1.224     raeburn  18710:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  18711:     }
1.34      raeburn  18712:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18713:         foreach my $item (@contexts) {
1.224     raeburn  18714:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   18715:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  18716:             }
1.27      raeburn  18717:         }
1.34      raeburn  18718:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   18719:         foreach my $item (@contexts) {
1.43      raeburn  18720:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  18721:                 if ($cancreate{$item} ne 'any') {
                   18722:                     push(@{$changes{'cancreate'}},$item);
                   18723:                 }
                   18724:             } else {
                   18725:                 if ($cancreate{$item} ne 'none') {
                   18726:                     push(@{$changes{'cancreate'}},$item);
                   18727:                 }
1.27      raeburn  18728:             }
                   18729:         }
                   18730:     } else {
1.43      raeburn  18731:         foreach my $item (@contexts)  {
1.34      raeburn  18732:             push(@{$changes{'cancreate'}},$item);
                   18733:         }
1.27      raeburn  18734:     }
1.34      raeburn  18735: 
1.27      raeburn  18736:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   18737:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   18738:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   18739:                 push(@{$changes{'username_rule'}},$type);
                   18740:             }
                   18741:         }
                   18742:         foreach my $type (@username_rule) {
                   18743:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   18744:                 push(@{$changes{'username_rule'}},$type);
                   18745:             }
                   18746:         }
                   18747:     } else {
                   18748:         push(@{$changes{'username_rule'}},@username_rule);
                   18749:     }
                   18750: 
1.32      raeburn  18751:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   18752:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   18753:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   18754:                 push(@{$changes{'id_rule'}},$type);
                   18755:             }
                   18756:         }
                   18757:         foreach my $type (@id_rule) {
                   18758:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   18759:                 push(@{$changes{'id_rule'}},$type);
                   18760:             }
                   18761:         }
                   18762:     } else {
                   18763:         push(@{$changes{'id_rule'}},@id_rule);
                   18764:     }
                   18765: 
1.43      raeburn  18766:     my @authen_contexts = ('author','course','domain');
1.325     raeburn  18767:     my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  18768:     my %authhash;
1.43      raeburn  18769:     foreach my $item (@authen_contexts) {
1.28      raeburn  18770:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   18771:         foreach my $auth (@authtypes) {
                   18772:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   18773:                 $authhash{$item}{$auth} = 1;
                   18774:             } else {
                   18775:                 $authhash{$item}{$auth} = 0;
                   18776:             }
                   18777:         }
                   18778:     }
                   18779:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  18780:         foreach my $item (@authen_contexts) {
1.28      raeburn  18781:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   18782:                 foreach my $auth (@authtypes) {
                   18783:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   18784:                         push(@{$changes{'authtypes'}},$item);
                   18785:                         last;
                   18786:                     }
                   18787:                 }
                   18788:             }
                   18789:         }
                   18790:     } else {
1.43      raeburn  18791:         foreach my $item (@authen_contexts) {
1.28      raeburn  18792:             push(@{$changes{'authtypes'}},$item);
                   18793:         }
                   18794:     }
                   18795: 
1.224     raeburn  18796:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   18797:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   18798:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   18799:     $save_usercreate{'id_rule'} = \@id_rule;
                   18800:     $save_usercreate{'username_rule'} = \@username_rule,
                   18801:     $save_usercreate{'authtypes'} = \%authhash;
                   18802: 
1.27      raeburn  18803:     my %usercreation_hash =  (
1.224     raeburn  18804:         usercreation     => \%save_usercreate,
                   18805:     );
1.27      raeburn  18806: 
                   18807:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   18808:                                              $dom);
1.50      raeburn  18809: 
1.224     raeburn  18810:     if ($putresult eq 'ok') {
                   18811:         if (keys(%changes) > 0) {
                   18812:             $resulttext = &mt('Changes made:').'<ul>';
                   18813:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   18814:                 my %lt = &usercreation_types();
                   18815:                 foreach my $type (@{$changes{'cancreate'}}) {
                   18816:                     my $chgtext = $lt{$type}.', ';
                   18817:                     if ($cancreate{$type} eq 'none') {
                   18818:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   18819:                     } elsif ($cancreate{$type} eq 'any') {
                   18820:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   18821:                     } elsif ($cancreate{$type} eq 'official') {
                   18822:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   18823:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   18824:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   18825:                     }
                   18826:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   18827:                 }
                   18828:             }
                   18829:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   18830:                 my ($rules,$ruleorder) = 
                   18831:                     &Apache::lonnet::inst_userrules($dom,'username');
                   18832:                 my $chgtext = '<ul>';
                   18833:                 foreach my $type (@username_rule) {
                   18834:                     if (ref($rules->{$type}) eq 'HASH') {
                   18835:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   18836:                     }
                   18837:                 }
                   18838:                 $chgtext .= '</ul>';
                   18839:                 if (@username_rule > 0) {
                   18840:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   18841:                 } else {
                   18842:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   18843:                 }
                   18844:             }
                   18845:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   18846:                 my ($idrules,$idruleorder) = 
                   18847:                     &Apache::lonnet::inst_userrules($dom,'id');
                   18848:                 my $chgtext = '<ul>';
                   18849:                 foreach my $type (@id_rule) {
                   18850:                     if (ref($idrules->{$type}) eq 'HASH') {
                   18851:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   18852:                     }
                   18853:                 }
                   18854:                 $chgtext .= '</ul>';
                   18855:                 if (@id_rule > 0) {
                   18856:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   18857:                 } else {
                   18858:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   18859:                 }
                   18860:             }
                   18861:             my %authname = &authtype_names();
                   18862:             my %context_title = &context_names();
                   18863:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   18864:                 my $chgtext = '<ul>';
                   18865:                 foreach my $type (@{$changes{'authtypes'}}) {
                   18866:                     my @allowed;
                   18867:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   18868:                     foreach my $auth (@authtypes) {
                   18869:                         if ($authhash{$type}{$auth}) {
                   18870:                             push(@allowed,$authname{$auth});
                   18871:                         }
                   18872:                     }
                   18873:                     if (@allowed > 0) {
                   18874:                         $chgtext .= join(', ',@allowed).'</li>';
                   18875:                     } else {
                   18876:                         $chgtext .= &mt('none').'</li>';
                   18877:                     }
                   18878:                 }
                   18879:                 $chgtext .= '</ul>';
                   18880:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   18881:                 $resulttext .= '</li>';
                   18882:             }
                   18883:             $resulttext .= '</ul>';
                   18884:         } else {
                   18885:             $resulttext = &mt('No changes made to user creation settings');
                   18886:         }
                   18887:     } else {
                   18888:         $resulttext = '<span class="LC_error">'.
                   18889:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18890:     }
                   18891:     if ($warningmsg ne '') {
                   18892:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   18893:     }
                   18894:     return $resulttext;
                   18895: }
                   18896: 
                   18897: sub modify_selfcreation {
1.305     raeburn  18898:     my ($dom,$lastactref,%domconfig) = @_;
                   18899:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   18900:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   18901:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  18902:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   18903:     if (ref($typesref) eq 'ARRAY') {
                   18904:         @types = @{$typesref};
                   18905:     }
                   18906:     if (ref($usertypesref) eq 'HASH') {
                   18907:         %usertypes = %{$usertypesref};
1.228     raeburn  18908:     }
1.303     raeburn  18909:     $usertypes{'default'} = $othertitle;
1.224     raeburn  18910: #
                   18911: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   18912: #
                   18913:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   18914:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   18915:             if ($key eq 'cancreate') {
                   18916:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   18917:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   18918:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  18919:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   18920:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   18921:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   18922:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  18923:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  18924:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18925:                         } else {
                   18926:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18927:                         }
                   18928:                     }
                   18929:                 }
                   18930:             } elsif ($key eq 'email_rule') {
                   18931:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   18932:             } else {
                   18933:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   18934:             }
                   18935:         }
                   18936:     }
                   18937: #
                   18938: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   18939: #
                   18940:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   18941:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   18942:             if ($key eq 'selfcreate') {
                   18943:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18944:             } else {
                   18945:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18946:             }
                   18947:         }
                   18948:     }
1.305     raeburn  18949: #
                   18950: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   18951: #
                   18952:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   18953:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   18954:             if ($key eq 'inststatusguest') {
                   18955:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18956:             } else {
                   18957:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18958:             }
                   18959:         }
                   18960:     }
1.224     raeburn  18961: 
                   18962:     my @contexts = ('selfcreate');
                   18963:     @{$cancreate{'selfcreate'}} = ();
                   18964:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  18965:     if (@types) {
                   18966:         @{$cancreate{'statustocreate'}} = ();
                   18967:     }
1.236     raeburn  18968:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  18969:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  18970:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  18971:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  18972:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  18973:     my %selfcreatetypes = (
                   18974:                              sso   => 'users authenticated by institutional single sign on',
                   18975:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  18976:                              email => 'users verified by e-mail',
1.50      raeburn  18977:                           );
1.224     raeburn  18978: #
                   18979: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   18980: # is permitted.
                   18981: #
1.305     raeburn  18982:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  18983: 
1.305     raeburn  18984:     my (@statuses,%email_rule);
1.228     raeburn  18985:     foreach my $item ('login','sso','email') {
1.224     raeburn  18986:         if ($item eq 'email') {
1.236     raeburn  18987:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  18988:                 if (@types) {
                   18989:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   18990:                     foreach my $status (@poss_statuses) {
                   18991:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   18992:                             push(@statuses,$status);
                   18993:                         }
                   18994:                     }
                   18995:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   18996:                 } else {
                   18997:                     push(@statuses,'default');
                   18998:                 }
                   18999:                 if (@statuses) {
                   19000:                     my %curr_rule;
                   19001:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   19002:                         foreach my $type (@statuses) {
                   19003:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  19004:                         }
1.305     raeburn  19005:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   19006:                         foreach my $type (@statuses) {
                   19007:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   19008:                         }
                   19009:                     }
                   19010:                     push(@{$cancreate{'selfcreate'}},'email');
                   19011:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   19012:                     my %curremaildom;
                   19013:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   19014:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   19015:                     }
                   19016:                     foreach my $type (@statuses) {
                   19017:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   19018:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   19019:                         }
                   19020:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   19021:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   19022:                         }
                   19023:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   19024: #
                   19025: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   19026: #
                   19027:                             my $chosen = $1;
                   19028:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   19029:                                 my $emaildom;
                   19030:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425     raeburn  19031:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305     raeburn  19032:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   19033:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   19034:                                         if (exists($curremaildom{$type}{$chosen})) {
                   19035:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   19036:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   19037:                                             }
                   19038:                                         } elsif ($emaildom ne '') {
                   19039:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   19040:                                         }
                   19041:                                     } elsif ($emaildom ne '') {
                   19042:                                         push(@{$changes{'cancreate'}},'emaildomain');
1.425     raeburn  19043:                                     }
1.305     raeburn  19044:                                 }
                   19045:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   19046:                             } elsif ($chosen eq 'custom') {
                   19047:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   19048:                                 $email_rule{$type} = [];
                   19049:                                 if (ref($emailrules) eq 'HASH') {
                   19050:                                     foreach my $rule (@possemail_rules) {
                   19051:                                         if (exists($emailrules->{$rule})) {
                   19052:                                             push(@{$email_rule{$type}},$rule);
                   19053:                                         }
                   19054:                                     }
                   19055:                                 }
                   19056:                                 if (@{$email_rule{$type}}) {
                   19057:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   19058:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   19059:                                         if (@{$curr_rule{$type}} > 0) {
                   19060:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   19061:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   19062:                                                     push(@{$changes{'email_rule'}},$type);
                   19063:                                                 }
                   19064:                                             }
                   19065:                                         }
                   19066:                                         foreach my $type (@{$email_rule{$type}}) {
                   19067:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   19068:                                                 push(@{$changes{'email_rule'}},$type);
                   19069:                                             }
                   19070:                                         }
                   19071:                                     } else {
                   19072:                                         push(@{$changes{'email_rule'}},$type);
                   19073:                                     }
                   19074:                                 }
                   19075:                             } else {
                   19076:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   19077:                             }
                   19078:                         }
                   19079:                     }
                   19080:                     if (@types) {
                   19081:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19082:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   19083:                             if (@changed) {
                   19084:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   19085:                             }
                   19086:                         } else {
                   19087:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   19088:                         }
                   19089:                     }
                   19090:                 } else {
                   19091:                     delete($env{'form.cancreate_email'});
                   19092:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19093:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   19094:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   19095:                         }
                   19096:                     }
                   19097:                 }
                   19098:             } else {
                   19099:                 $save_inststatus{'inststatusguest'} = [];
                   19100:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19101:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   19102:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  19103:                     }
                   19104:                 }
1.224     raeburn  19105:             }
                   19106:         } else {
                   19107:             if ($env{'form.cancreate_'.$item}) {
                   19108:                 push(@{$cancreate{'selfcreate'}},$item);
                   19109:             }
                   19110:         }
                   19111:     }
1.305     raeburn  19112:     my (%userinfo,%savecaptcha);
1.224     raeburn  19113:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   19114: #
1.228     raeburn  19115: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   19116: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  19117: #
1.236     raeburn  19118: 
1.244     raeburn  19119:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  19120:         push(@contexts,'emailusername');
1.305     raeburn  19121:         if (@statuses) {
                   19122:             foreach my $type (@statuses) {
1.228     raeburn  19123:                 if (ref($infofields) eq 'ARRAY') {
                   19124:                     foreach my $field (@{$infofields}) {
                   19125:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   19126:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   19127:                         }
                   19128:                     }
1.224     raeburn  19129:                 }
                   19130:             }
                   19131:         }
                   19132: #
                   19133: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  19134: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  19135: #
                   19136: 
                   19137:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   19138:         @approvalnotify = sort(@approvalnotify);
                   19139:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   19140:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   19141:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   19142:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   19143:                     push(@{$changes{'cancreate'}},'notify');
                   19144:                 }
                   19145:             } else {
                   19146:                 if ($cancreate{'notify'}{'approval'}) {
                   19147:                     push(@{$changes{'cancreate'}},'notify');
                   19148:                 }
                   19149:             }
                   19150:         } elsif ($cancreate{'notify'}{'approval'}) {
                   19151:             push(@{$changes{'cancreate'}},'notify');
                   19152:         }
                   19153: 
                   19154:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   19155:     }
                   19156: #  
1.236     raeburn  19157: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  19158: # institutional log-in.
                   19159: #
                   19160:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   19161:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   19162:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   19163:             $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.').' '.
                   19164:                           &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.');
                   19165:         }
                   19166:     }
                   19167:     my @fields = ('lastname','firstname','middlename','generation',
                   19168:                   'permanentemail','id');
1.240     raeburn  19169:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  19170:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19171: #
                   19172: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   19173: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   19174: # may self-create accounts 
                   19175: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   19176: # which the user may supply, if institutional data is unavailable.
                   19177: #
                   19178:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  19179:         if (@types) {
1.305     raeburn  19180:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   19181:             push(@contexts,'statustocreate');
1.303     raeburn  19182:             foreach my $type (@types) {
1.224     raeburn  19183:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   19184:                 foreach my $field (@fields) {
                   19185:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   19186:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   19187:                     } else {
                   19188:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   19189:                     }
                   19190:                 }
                   19191:             }
                   19192:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  19193:                 foreach my $type (@types) {
1.224     raeburn  19194:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   19195:                         foreach my $field (@fields) {
                   19196:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   19197:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   19198:                                 push(@{$changes{'selfcreate'}},$type);
                   19199:                                 last;
                   19200:                             }
                   19201:                         }
                   19202:                     }
                   19203:                 }
                   19204:             } else {
1.303     raeburn  19205:                 foreach my $type (@types) {
1.224     raeburn  19206:                     push(@{$changes{'selfcreate'}},$type);
                   19207:                 }
                   19208:             }
                   19209:         }
1.240     raeburn  19210:         foreach my $field (@shibfields) {
                   19211:             if ($env{'form.shibenv_'.$field} ne '') {
                   19212:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   19213:             }
                   19214:         }
                   19215:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   19216:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   19217:                 foreach my $field (@shibfields) {
                   19218:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   19219:                         push(@{$changes{'cancreate'}},'shibenv');
                   19220:                     }
                   19221:                 }
                   19222:             } else {
                   19223:                 foreach my $field (@shibfields) {
                   19224:                     if ($env{'form.shibenv_'.$field}) {
                   19225:                         push(@{$changes{'cancreate'}},'shibenv');
                   19226:                         last;
                   19227:                     }
                   19228:                 }
                   19229:             }
                   19230:         }
1.224     raeburn  19231:     }
                   19232:     foreach my $item (@contexts) {
                   19233:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   19234:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   19235:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   19236:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   19237:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19238:                             push(@{$changes{'cancreate'}},$item);
                   19239:                         }
                   19240:                     }
                   19241:                 }
                   19242:             }
                   19243:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   19244:                 foreach my $type (@{$cancreate{$item}}) {
                   19245:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   19246:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19247:                             push(@{$changes{'cancreate'}},$item);
                   19248:                         }
                   19249:                     }
                   19250:                 }
                   19251:             }
                   19252:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   19253:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  19254:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   19255:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   19256:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   19257:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  19258:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19259:                                     push(@{$changes{'cancreate'}},$item);
                   19260:                                 }
                   19261:                             }
                   19262:                         }
1.305     raeburn  19263:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   19264:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  19265:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19266:                                 push(@{$changes{'cancreate'}},$item);
                   19267:                             }
1.224     raeburn  19268:                         }
                   19269:                     }
                   19270:                 }
1.305     raeburn  19271:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   19272:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   19273:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   19274:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   19275:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  19276:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19277:                                         push(@{$changes{'cancreate'}},$item);
                   19278:                                     }
                   19279:                                 }
                   19280:                             } else {
                   19281:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19282:                                     push(@{$changes{'cancreate'}},$item);
                   19283:                                 }
                   19284:                             }
                   19285:                         }
1.305     raeburn  19286:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   19287:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  19288:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19289:                                 push(@{$changes{'cancreate'}},$item);
                   19290:                             }
1.224     raeburn  19291:                         }
                   19292:                     }
                   19293:                 }
                   19294:             }
                   19295:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   19296:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   19297:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   19298:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19299:                         push(@{$changes{'cancreate'}},$item);
                   19300:                     }
                   19301:                 }
1.305     raeburn  19302:             }
                   19303:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   19304:             if (ref($cancreate{$item}) eq 'HASH') {
                   19305:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19306:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  19307:                 }
                   19308:             }
                   19309:         } elsif ($item eq 'emailusername') {
1.228     raeburn  19310:             if (ref($cancreate{$item}) eq 'HASH') {
                   19311:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   19312:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   19313:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   19314:                             if ($cancreate{$item}{$type}{$field}) {
                   19315:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19316:                                     push(@{$changes{'cancreate'}},$item);
                   19317:                                 }
                   19318:                                 last;
                   19319:                             }
                   19320:                         }
                   19321:                     }
                   19322:                 }
1.224     raeburn  19323:             }
                   19324:         }
                   19325:     }
                   19326: #
                   19327: # Populate %save_usercreate hash with updates to self-creation configuration.
                   19328: #
                   19329:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   19330:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  19331:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  19332:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   19333:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   19334:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   19335:     }
1.236     raeburn  19336:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   19337:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   19338:     }
1.303     raeburn  19339:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   19340:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   19341:     }
1.305     raeburn  19342:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   19343:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   19344:     }
1.303     raeburn  19345:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   19346:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   19347:     }
1.224     raeburn  19348:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   19349:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   19350:     }
1.240     raeburn  19351:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   19352:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   19353:     }
1.224     raeburn  19354:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  19355:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  19356: 
                   19357:     my %userconfig_hash = (
                   19358:             usercreation     => \%save_usercreate,
                   19359:             usermodification => \%save_usermodify,
1.305     raeburn  19360:             inststatus       => \%save_inststatus,
1.224     raeburn  19361:     );
1.305     raeburn  19362: 
1.224     raeburn  19363:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   19364:                                              $dom);
                   19365: #
1.305     raeburn  19366: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  19367: #
1.27      raeburn  19368:     if ($putresult eq 'ok') {
                   19369:         if (keys(%changes) > 0) {
                   19370:             $resulttext = &mt('Changes made:').'<ul>';
                   19371:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  19372:                 my %lt = &selfcreation_types();
1.34      raeburn  19373:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  19374:                     my $chgtext = '';
1.45      raeburn  19375:                     if ($type eq 'selfcreate') {
1.50      raeburn  19376:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  19377:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  19378:                         } else {
1.224     raeburn  19379:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   19380:                                         '<ul>';
1.50      raeburn  19381:                             foreach my $case (@{$cancreate{$type}}) {
                   19382:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   19383:                             }
                   19384:                             $chgtext .= '</ul>';
1.100     raeburn  19385:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   19386:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   19387:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   19388:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  19389:                                             $chgtext .= '<span class="LC_warning">'.
                   19390:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   19391:                                                         '</span><br />';
                   19392:                                         }
                   19393:                                     }
                   19394:                                 }
                   19395:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  19396:                                     if (!@statuses) {
                   19397:                                         $chgtext .= '<span class="LC_warning">'.
                   19398:                                                     &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
                   19399:                                                     '</span><br />';
1.303     raeburn  19400: 
1.100     raeburn  19401:                                     }
                   19402:                                 }
                   19403:                             }
1.43      raeburn  19404:                         }
1.240     raeburn  19405:                     } elsif ($type eq 'shibenv') {
                   19406:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  19407:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  19408:                         } else {
                   19409:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   19410:                                         '<ul>';
                   19411:                             foreach my $field (@shibfields) {
                   19412:                                 next if ($cancreate{$type}{$field} eq '');
                   19413:                                 if ($field eq 'inststatus') {
                   19414:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   19415:                                 } else {
                   19416:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   19417:                                 }
                   19418:                             }
                   19419:                             $chgtext .= '</ul>';
1.303     raeburn  19420:                         }
1.93      raeburn  19421:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  19422:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   19423:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   19424:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   19425:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  19426:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  19427:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  19428:                                         $chgtext .= '<br />'.
                   19429:                                                     '<span class="LC_warning">'.
                   19430:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   19431:                                                     '</span>';
                   19432:                                     }
1.303     raeburn  19433:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  19434:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  19435:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   19436:                                     } else {
                   19437:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   19438:                                     }
                   19439:                                     $chgtext .= '<ul>';
                   19440:                                     foreach my $case (@{$cancreate{$type}}) {
                   19441:                                         if ($case eq 'default') {
                   19442:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   19443:                                         } else {
1.303     raeburn  19444:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  19445:                                         }
                   19446:                                     }
1.100     raeburn  19447:                                     $chgtext .= '</ul>';
                   19448:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  19449:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  19450:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   19451:                                                     '</span>';
1.100     raeburn  19452:                                     }
                   19453:                                 }
                   19454:                             } else {
                   19455:                                 if (@{$cancreate{$type}} == 0) {
                   19456:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   19457:                                 } else {
                   19458:                                     $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  19459:                                 }
                   19460:                             }
1.303     raeburn  19461:                             $chgtext .= '<br />';
1.93      raeburn  19462:                         }
1.236     raeburn  19463:                     } elsif ($type eq 'selfcreateprocessing') {
                   19464:                         my %choices = &Apache::lonlocal::texthash (
                   19465:                                                                     automatic => 'Automatic approval',
                   19466:                                                                     approval  => 'Queued for approval',
                   19467:                                                                   );
1.305     raeburn  19468:                         if (@types) {
                   19469:                             if (@statuses) {
1.425     raeburn  19470:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309     raeburn  19471:                                             '<ul>';
1.305     raeburn  19472:                                 foreach my $status (@statuses) {
                   19473:                                     if ($status eq 'default') {
                   19474:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  19475:                                     } else {
1.305     raeburn  19476:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  19477:                                     }
                   19478:                                 }
                   19479:                                 $chgtext .= '</ul>';
                   19480:                             }
                   19481:                         } else {
                   19482:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   19483:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   19484:                         }
                   19485:                     } elsif ($type eq 'emailverified') {
                   19486:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  19487:                                                                     all   => 'Same as e-mail',
                   19488:                                                                     first => 'Omit @domain',
                   19489:                                                                     free  => 'Free to choose',
1.303     raeburn  19490:                                                                   );
1.305     raeburn  19491:                         if (@types) {
                   19492:                             if (@statuses) {
1.303     raeburn  19493:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   19494:                                             '<ul>';
1.305     raeburn  19495:                                 foreach my $status (@statuses) {
1.362     raeburn  19496:                                     if ($status eq 'default') {
1.305     raeburn  19497:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  19498:                                     } else {
1.305     raeburn  19499:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  19500:                                     }
                   19501:                                 }
                   19502:                                 $chgtext .= '</ul>';
                   19503:                             }
                   19504:                         } else {
1.305     raeburn  19505:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  19506:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  19507:                         }
1.305     raeburn  19508:                     } elsif ($type eq 'emailoptions') {
                   19509:                         my %options = &Apache::lonlocal::texthash (
                   19510:                                                                     any     => 'Any e-mail',
                   19511:                                                                     inst    => 'Institutional only',
                   19512:                                                                     noninst => 'Non-institutional only',
                   19513:                                                                     custom  => 'Custom restrictions',
                   19514:                                                                   );
                   19515:                         if (@types) {
                   19516:                             if (@statuses) {
                   19517:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   19518:                                             '<ul>';
                   19519:                                 foreach my $status (@statuses) {
                   19520:                                     if ($type eq 'default') {
                   19521:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   19522:                                     } else {
                   19523:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  19524:                                     }
                   19525:                                 }
1.305     raeburn  19526:                                 $chgtext .= '</ul>';
                   19527:                             }
                   19528:                         } else {
                   19529:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   19530:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   19531:                             } else {
                   19532:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   19533:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  19534:                             }
1.305     raeburn  19535:                         }
                   19536:                     } elsif ($type eq 'emaildomain') {
                   19537:                         my $output;
                   19538:                         if (@statuses) {
                   19539:                             foreach my $type (@statuses) {
                   19540:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   19541:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   19542:                                         if ($type eq 'default') {
                   19543:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19544:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   19545:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19546:                                             } else {
                   19547:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   19548:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   19549:                                             }
1.303     raeburn  19550:                                         } else {
1.305     raeburn  19551:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19552:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   19553:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19554:                                             } else {
                   19555:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421     raeburn  19556:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305     raeburn  19557:                                             }
1.303     raeburn  19558:                                         }
1.305     raeburn  19559:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   19560:                                         if ($type eq 'default') {
                   19561:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19562:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   19563:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19564:                                             } else {
                   19565:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   19566:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   19567:                                             }
1.303     raeburn  19568:                                         } else {
1.305     raeburn  19569:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19570:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   19571:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19572:                                             } else {
                   19573:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421     raeburn  19574:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305     raeburn  19575:                                             }
1.303     raeburn  19576:                                         }
                   19577:                                     }
                   19578:                                 }
                   19579:                             }
1.305     raeburn  19580:                         }
                   19581:                         if ($output ne '') {
                   19582:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   19583:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  19584:                         }
1.165     raeburn  19585:                     } elsif ($type eq 'captcha') {
1.224     raeburn  19586:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  19587:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   19588:                         } else {
                   19589:                             my %captchas = &captcha_phrases();
1.224     raeburn  19590:                             if ($captchas{$savecaptcha{$type}}) {
                   19591:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  19592:                             } else {
1.210     raeburn  19593:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  19594:                             }
                   19595:                         }
                   19596:                     } elsif ($type eq 'recaptchakeys') {
                   19597:                         my ($privkey,$pubkey);
1.224     raeburn  19598:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   19599:                             $pubkey = $savecaptcha{$type}{'public'};
                   19600:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  19601:                         }
                   19602:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   19603:                         if (!$pubkey) {
                   19604:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   19605:                         } else {
                   19606:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   19607:                         }
                   19608:                         if (!$privkey) {
                   19609:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   19610:                         } else {
                   19611:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   19612:                         }
                   19613:                         $chgtext .= '</ul>';
1.269     raeburn  19614:                     } elsif ($type eq 'recaptchaversion') {
                   19615:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  19616:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  19617:                         }
1.224     raeburn  19618:                     } elsif ($type eq 'emailusername') {
                   19619:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  19620:                             if (@statuses) {
                   19621:                                 foreach my $type (@statuses) {
1.228     raeburn  19622:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   19623:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  19624:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  19625:                                                     '<ul>';
                   19626:                                             foreach my $field (@{$infofields}) {
                   19627:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   19628:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   19629:                                                 }
                   19630:                                             }
1.245     raeburn  19631:                                             $chgtext .= '</ul>';
                   19632:                                         } else {
1.303     raeburn  19633:                                             $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228     raeburn  19634:                                         }
                   19635:                                     } else {
1.303     raeburn  19636:                                         $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224     raeburn  19637:                                     }
                   19638:                                 }
                   19639:                             }
                   19640:                         }
                   19641:                     } elsif ($type eq 'notify') {
1.303     raeburn  19642:                         my $numapprove = 0;
1.224     raeburn  19643:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   19644:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   19645:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  19646:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   19647:                                     $numapprove ++;
1.224     raeburn  19648:                                 }
                   19649:                             }
1.43      raeburn  19650:                         }
1.303     raeburn  19651:                         unless ($numapprove) {
                   19652:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   19653:                         }
1.34      raeburn  19654:                     }
1.224     raeburn  19655:                     if ($chgtext) {
                   19656:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  19657:                     }
                   19658:                 }
                   19659:             }
1.305     raeburn  19660:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  19661:                 my ($emailrules,$emailruleorder) =
                   19662:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  19663:                 foreach my $type (@{$changes{'email_rule'}}) {
                   19664:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   19665:                         my $chgtext = '<ul>';
                   19666:                         foreach my $rule (@{$email_rule{$type}}) {
                   19667:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   19668:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   19669:                             }
                   19670:                         }
                   19671:                         $chgtext .= '</ul>';
1.310     raeburn  19672:                         my $typename;
1.305     raeburn  19673:                         if (@types) {
                   19674:                             if ($type eq 'default') {
                   19675:                                 $typename = $othertitle;
                   19676:                             } else {
                   19677:                                 $typename = $usertypes{$type};
1.425     raeburn  19678:                             }
1.305     raeburn  19679:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   19680:                         }
                   19681:                         if (@{$email_rule{$type}} > 0) {
                   19682:                             $resulttext .= '<li>'.
                   19683:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   19684:                                                $usertypes{$type}).
                   19685:                                            $chgtext.
                   19686:                                            '</li>';
                   19687:                         } else {
                   19688:                             $resulttext .= '<li>'.
1.310     raeburn  19689:                                            &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
1.305     raeburn  19690:                                            '</li>'.
1.310     raeburn  19691:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  19692:                         }
1.43      raeburn  19693:                     }
                   19694:                 }
1.305     raeburn  19695:             }
                   19696:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   19697:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19698:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   19699:                         my $chgtext = '<ul>';
                   19700:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   19701:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   19702:                         }
                   19703:                         $chgtext .= '</ul>';
                   19704:                         $resulttext .= '<li>'.
                   19705:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   19706:                                           $chgtext.
                   19707:                                        '</li>';
                   19708:                     } else {
                   19709:                         $resulttext .= '<li>'.
                   19710:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   19711:                                        '</li>';
                   19712:                     }
1.43      raeburn  19713:                 }
                   19714:             }
1.224     raeburn  19715:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   19716:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   19717:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19718:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   19719:                     my $typename = $type;
1.303     raeburn  19720:                     if (keys(%usertypes) > 0) {
                   19721:                         if ($usertypes{$type} ne '') {
                   19722:                             $typename = $usertypes{$type};
1.224     raeburn  19723:                         }
                   19724:                     }
                   19725:                     my @modifiable;
                   19726:                     $resulttext .= '<li>'.
                   19727:                                     &mt('Self-creation of account by users with status: [_1]',
                   19728:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   19729:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   19730:                     foreach my $field (@fields) {
                   19731:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   19732:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  19733:                         }
                   19734:                     }
1.224     raeburn  19735:                     if (@modifiable > 0) {
                   19736:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  19737:                     } else {
1.224     raeburn  19738:                         $resulttext .= &mt('none');
1.43      raeburn  19739:                     }
1.224     raeburn  19740:                     $resulttext .= '</li>';
1.28      raeburn  19741:                 }
1.224     raeburn  19742:                 $resulttext .= '</ul></li>';
1.28      raeburn  19743:             }
1.27      raeburn  19744:             $resulttext .= '</ul>';
1.305     raeburn  19745:             my $cachetime = 24*60*60;
                   19746:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   19747:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   19748:             if (ref($lastactref) eq 'HASH') {
                   19749:                 $lastactref->{'domdefaults'} = 1;
                   19750:             }
1.27      raeburn  19751:         } else {
1.224     raeburn  19752:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  19753:         }
                   19754:     } else {
                   19755:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  19756:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19757:     }
1.43      raeburn  19758:     if ($warningmsg ne '') {
                   19759:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   19760:     }
1.23      raeburn  19761:     return $resulttext;
                   19762: }
                   19763: 
1.165     raeburn  19764: sub process_captcha {
1.369     raeburn  19765:     my ($container,$changes,$newsettings,$currsettings) = @_;
                   19766:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165     raeburn  19767:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   19768:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   19769:         $newsettings->{'captcha'} = 'original';
                   19770:     }
1.369     raeburn  19771:     my %current;
                   19772:     if (ref($currsettings) eq 'HASH') {
                   19773:         %current = %{$currsettings};
                   19774:     }
                   19775:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  19776:         if ($container eq 'cancreate') {
1.169     raeburn  19777:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19778:                 push(@{$changes->{'cancreate'}},'captcha');
                   19779:             } elsif (!defined($changes->{'cancreate'})) {
                   19780:                 $changes->{'cancreate'} = ['captcha'];
                   19781:             }
1.368     raeburn  19782:         } elsif ($container eq 'passwords') {
                   19783:             $changes->{'reset'} = 1;
1.169     raeburn  19784:         } else {
                   19785:             $changes->{'captcha'} = 1;
1.165     raeburn  19786:         }
                   19787:     }
1.269     raeburn  19788:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  19789:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   19790:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   19791:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  19792:         $newpub =~ s/[^\w\-]//g;
                   19793:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  19794:         $newsettings->{'recaptchakeys'} = {
                   19795:                                              public  => $newpub,
                   19796:                                              private => $newpriv,
                   19797:                                           };
1.269     raeburn  19798:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   19799:         $newversion =~ s/\D//g;
                   19800:         if ($newversion ne '2') {
                   19801:             $newversion = 1;
                   19802:         }
                   19803:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  19804:     }
1.369     raeburn  19805:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   19806:         $currpub = $current{'recaptchakeys'}{'public'};
                   19807:         $currpriv = $current{'recaptchakeys'}{'private'};
1.179     raeburn  19808:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   19809:             $newsettings->{'recaptchakeys'} = {
                   19810:                                                  public  => '',
                   19811:                                                  private => '',
                   19812:                                               }
                   19813:         }
1.165     raeburn  19814:     }
1.369     raeburn  19815:     if ($current{'captcha'} eq 'recaptcha') {
                   19816:         $currversion = $current{'recaptchaversion'};
1.269     raeburn  19817:         if ($currversion ne '2') {
                   19818:             $currversion = 1;
                   19819:         }
                   19820:     }
                   19821:     if ($currversion ne $newversion) {
                   19822:         if ($container eq 'cancreate') {
                   19823:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19824:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   19825:             } elsif (!defined($changes->{'cancreate'})) {
                   19826:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   19827:             }
1.368     raeburn  19828:         } elsif ($container eq 'passwords') {
                   19829:             $changes->{'reset'} = 1;
1.269     raeburn  19830:         } else {
                   19831:             $changes->{'recaptchaversion'} = 1;
                   19832:         }
                   19833:     }
1.165     raeburn  19834:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  19835:         if ($container eq 'cancreate') {
                   19836:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19837:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   19838:             } elsif (!defined($changes->{'cancreate'})) {
                   19839:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   19840:             }
1.368     raeburn  19841:         } elsif ($container eq 'passwords') {
                   19842:             $changes->{'reset'} = 1;
1.169     raeburn  19843:         } else {
1.210     raeburn  19844:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  19845:         }
                   19846:     }
                   19847:     return;
                   19848: }
                   19849: 
1.33      raeburn  19850: sub modify_usermodification {
                   19851:     my ($dom,%domconfig) = @_;
1.224     raeburn  19852:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  19853:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   19854:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  19855:             if ($key eq 'selfcreate') {
                   19856:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   19857:             } else {  
                   19858:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   19859:             }
1.33      raeburn  19860:         }
                   19861:     }
1.224     raeburn  19862:     my @contexts = ('author','course');
1.33      raeburn  19863:     my %context_title = (
                   19864:                            author => 'In author context',
                   19865:                            course => 'In course context',
                   19866:                         );
                   19867:     my @fields = ('lastname','firstname','middlename','generation',
                   19868:                   'permanentemail','id');
                   19869:     my %roles = (
                   19870:                   author => ['ca','aa'],
                   19871:                   course => ['st','ep','ta','in','cr'],
                   19872:                 );
                   19873:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19874:     foreach my $context (@contexts) {
                   19875:         foreach my $role (@{$roles{$context}}) {
                   19876:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   19877:             foreach my $item (@fields) {
                   19878:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   19879:                     $modifyhash{$context}{$role}{$item} = 1;
                   19880:                 } else {
                   19881:                     $modifyhash{$context}{$role}{$item} = 0;
                   19882:                 }
                   19883:             }
                   19884:         }
                   19885:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   19886:             foreach my $role (@{$roles{$context}}) {
                   19887:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   19888:                     foreach my $field (@fields) {
                   19889:                         if ($modifyhash{$context}{$role}{$field} ne 
                   19890:                                 $curr_usermodification{$context}{$role}{$field}) {
                   19891:                             push(@{$changes{$context}},$role);
                   19892:                             last;
                   19893:                         }
                   19894:                     }
                   19895:                 }
                   19896:             }
                   19897:         } else {
                   19898:             foreach my $context (@contexts) {
                   19899:                 foreach my $role (@{$roles{$context}}) {
                   19900:                     push(@{$changes{$context}},$role);
                   19901:                 }
                   19902:             }
                   19903:         }
                   19904:     }
                   19905:     my %usermodification_hash =  (
                   19906:                                    usermodification => \%modifyhash,
                   19907:                                  );
                   19908:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   19909:                                              \%usermodification_hash,$dom);
                   19910:     if ($putresult eq 'ok') {
                   19911:         if (keys(%changes) > 0) {
                   19912:             $resulttext = &mt('Changes made: ').'<ul>';
                   19913:             foreach my $context (@contexts) {
                   19914:                 if (ref($changes{$context}) eq 'ARRAY') {
                   19915:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   19916:                     if (ref($changes{$context}) eq 'ARRAY') {
                   19917:                         foreach my $role (@{$changes{$context}}) {
                   19918:                             my $rolename;
1.224     raeburn  19919:                             if ($role eq 'cr') {
                   19920:                                 $rolename = &mt('Custom');
1.33      raeburn  19921:                             } else {
1.224     raeburn  19922:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  19923:                             }
                   19924:                             my @modifiable;
1.224     raeburn  19925:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  19926:                             foreach my $field (@fields) {
                   19927:                                 if ($modifyhash{$context}{$role}{$field}) {
                   19928:                                     push(@modifiable,$fieldtitles{$field});
                   19929:                                 }
                   19930:                             }
                   19931:                             if (@modifiable > 0) {
                   19932:                                 $resulttext .= join(', ',@modifiable);
                   19933:                             } else {
                   19934:                                 $resulttext .= &mt('none'); 
                   19935:                             }
                   19936:                             $resulttext .= '</li>';
                   19937:                         }
                   19938:                         $resulttext .= '</ul></li>';
                   19939:                     }
                   19940:                 }
                   19941:             }
                   19942:             $resulttext .= '</ul>';
                   19943:         } else {
                   19944:             $resulttext = &mt('No changes made to user modification settings');
                   19945:         }
                   19946:     } else {
                   19947:         $resulttext = '<span class="LC_error">'.
                   19948:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19949:     }
                   19950:     return $resulttext;
                   19951: }
                   19952: 
1.43      raeburn  19953: sub modify_defaults {
1.212     raeburn  19954:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  19955:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  19956:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  19957:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354     raeburn  19958:                  'portal_def');
1.325     raeburn  19959:     my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43      raeburn  19960:     foreach my $item (@items) {
                   19961:         $newvalues{$item} = $env{'form.'.$item};
                   19962:         if ($item eq 'auth_def') {
                   19963:             if ($newvalues{$item} ne '') {
                   19964:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   19965:                     push(@errors,$item);
                   19966:                 }
                   19967:             }
                   19968:         } elsif ($item eq 'lang_def') {
                   19969:             if ($newvalues{$item} ne '') {
                   19970:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   19971:                     my $langcode = $1;
1.103     raeburn  19972:                     if ($langcode ne 'x_chef') {
                   19973:                         if (code2language($langcode) eq '') {
                   19974:                             push(@errors,$item);
                   19975:                         }
1.43      raeburn  19976:                     }
                   19977:                 } else {
                   19978:                     push(@errors,$item);
                   19979:                 }
                   19980:             }
1.54      raeburn  19981:         } elsif ($item eq 'timezone_def') {
                   19982:             if ($newvalues{$item} ne '') {
1.62      raeburn  19983:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  19984:                     push(@errors,$item);   
                   19985:                 }
                   19986:             }
1.68      raeburn  19987:         } elsif ($item eq 'datelocale_def') {
                   19988:             if ($newvalues{$item} ne '') {
                   19989:                 my @datelocale_ids = DateTime::Locale->ids();
                   19990:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   19991:                     push(@errors,$item);
                   19992:                 }
                   19993:             }
1.141     raeburn  19994:         } elsif ($item eq 'portal_def') {
                   19995:             if ($newvalues{$item} ne '') {
1.414     raeburn  19996:                 if ($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])\/?$/) {
                   19997:                     foreach my $field ('email','web') {
                   19998:                         if ($env{'form.'.$item.'_'.$field}) {
                   19999:                             $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
                   20000:                         }
                   20001:                     }
                   20002:                 } else {
1.141     raeburn  20003:                     push(@errors,$item);
                   20004:                 }
                   20005:             }
1.43      raeburn  20006:         }
                   20007:         if (grep(/^\Q$item\E$/,@errors)) {
                   20008:             $newvalues{$item} = $domdefaults{$item};
1.414     raeburn  20009:             if ($item eq 'portal_def') {
                   20010:                 if ($domdefaults{$item}) {
                   20011:                     foreach my $field ('email','web') {
                   20012:                         if (exists($domdefaults{$item.'_'.$field})) {
                   20013:                             $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
                   20014:                         }
                   20015:                     }
                   20016:                 }
                   20017:             }
1.43      raeburn  20018:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   20019:             $changes{$item} = 1;
                   20020:         }
1.414     raeburn  20021:         if ($item eq 'portal_def') {
                   20022:             unless (grep(/^\Q$item\E$/,@errors)) {
1.425     raeburn  20023:                 if ($newvalues{$item} eq '') {
1.414     raeburn  20024:                     foreach my $field ('email','web') {
                   20025:                         if (exists($domdefaults{$item.'_'.$field})) {
                   20026:                             delete($domdefaults{$item.'_'.$field});
                   20027:                         }
                   20028:                     }
                   20029:                 } else {
                   20030:                     unless ($changes{$item}) {
                   20031:                         foreach my $field ('email','web') {
                   20032:                             if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
                   20033:                                 $changes{$item} = 1;
                   20034:                                 last;
                   20035:                             }
                   20036:                         }
                   20037:                     }
                   20038:                     foreach my $field ('email','web') {
                   20039:                         if ($newvalues{$item.'_'.$field}) {
                   20040:                             $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
                   20041:                         } elsif (exists($domdefaults{$item.'_'.$field})) {
                   20042:                             delete($domdefaults{$item.'_'.$field});
                   20043:                         }
                   20044:                     }
                   20045:                 }
                   20046:             }
                   20047:         }
1.72      raeburn  20048:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  20049:     }
1.354     raeburn  20050:     my %staticdefaults = (
                   20051:                            'intauth_cost'   => 10,
                   20052:                            'intauth_check'  => 0,
                   20053:                            'intauth_switch' => 0,
                   20054:                          );
                   20055:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   20056:         if (exists($domdefaults{$item})) {
                   20057:             $newvalues{$item} = $domdefaults{$item};
                   20058:         } else {
                   20059:             $newvalues{$item} = $staticdefaults{$item};
                   20060:         }
                   20061:     }
1.409     raeburn  20062:     my ($unamemaprules,$ruleorder);
                   20063:     my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
                   20064:     if (@possunamemaprules) {
                   20065:         ($unamemaprules,$ruleorder) =
                   20066:             &Apache::lonnet::inst_userrules($dom,'unamemap');
                   20067:         if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   20068:             if (@{$ruleorder} > 0) {
                   20069:                 my %possrules;
                   20070:                 map { $possrules{$_} = 1; } @possunamemaprules;
                   20071:                 foreach my $rule (@{$ruleorder}) {
                   20072:                     if ($possrules{$rule}) {
                   20073:                         push(@{$newvalues{'unamemap_rule'}},$rule);
                   20074:                     }
                   20075:                 }
                   20076:             }
                   20077:         }
                   20078:     }
                   20079:     if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
                   20080:         if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   20081:             my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
                   20082:                                                                $newvalues{'unamemap_rule'});
                   20083:             if (@rulediffs) {
                   20084:                 $changes{'unamemap_rule'} = 1;
                   20085:                 $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
                   20086:             }
                   20087:         } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
                   20088:             $changes{'unamemap_rule'} = 1;
                   20089:             delete($domdefaults{'unamemap_rule'});
                   20090:         }
                   20091:     } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   20092:         if (@{$newvalues{'unamemap_rule'}} > 0) {
                   20093:             $changes{'unamemap_rule'} = 1;
                   20094:             $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
                   20095:         }
                   20096:     }
1.43      raeburn  20097:     my %defaults_hash = (
1.72      raeburn  20098:                          defaults => \%newvalues,
                   20099:                         );
1.43      raeburn  20100:     my $title = &defaults_titles();
1.236     raeburn  20101: 
                   20102:     my $currinststatus;
                   20103:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   20104:         $currinststatus = $domconfig{'inststatus'};
                   20105:     } else {
                   20106:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   20107:         $currinststatus = {
                   20108:                              inststatustypes => $usertypes,
                   20109:                              inststatusorder => $types,
                   20110:                              inststatusguest => [],
                   20111:                           };
                   20112:     }
                   20113:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   20114:     my @allpos;
                   20115:     my %alltypes;
1.305     raeburn  20116:     my @inststatusguest;
                   20117:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   20118:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   20119:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   20120:                 push(@inststatusguest,$type);
                   20121:             }
                   20122:         }
                   20123:     }
                   20124:     my ($currtitles,$currorder);
1.236     raeburn  20125:     if (ref($currinststatus) eq 'HASH') {
                   20126:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   20127:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   20128:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   20129:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   20130:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   20131:                     }
                   20132:                 }
                   20133:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   20134:                     my $position = $env{'form.inststatus_pos_'.$type};
                   20135:                     $position =~ s/\D+//g;
                   20136:                     $allpos[$position] = $type;
                   20137:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   20138:                     $alltypes{$type} =~ s/`//g;
                   20139:                 }
                   20140:             }
                   20141:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   20142:             $currtitles =~ s/,$//;
                   20143:         }
                   20144:     }
                   20145:     if ($env{'form.addinststatus'}) {
                   20146:         my $newtype = $env{'form.addinststatus'};
                   20147:         $newtype =~ s/\W//g;
                   20148:         unless (exists($alltypes{$newtype})) {
                   20149:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   20150:             $alltypes{$newtype} =~ s/`//g; 
                   20151:             my $position = $env{'form.addinststatus_pos'};
                   20152:             $position =~ s/\D+//g;
                   20153:             if ($position ne '') {
                   20154:                 $allpos[$position] = $newtype;
                   20155:             }
                   20156:         }
                   20157:     }
1.305     raeburn  20158:     my @orderedstatus;
1.236     raeburn  20159:     foreach my $type (@allpos) {
                   20160:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   20161:             push(@orderedstatus,$type);
                   20162:         }
                   20163:     }
                   20164:     foreach my $type (keys(%alltypes)) {
                   20165:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   20166:             delete($alltypes{$type});
                   20167:         }
                   20168:     }
                   20169:     $defaults_hash{'inststatus'} = {
                   20170:                                      inststatustypes => \%alltypes,
                   20171:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  20172:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  20173:                                    };
                   20174:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   20175:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   20176:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   20177:         }
                   20178:     }
                   20179:     if ($currorder ne join(',',@orderedstatus)) {
                   20180:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   20181:     }
                   20182:     my $newtitles;
                   20183:     foreach my $item (@orderedstatus) {
                   20184:         $newtitles .= $alltypes{$item}.',';
                   20185:     }
                   20186:     $newtitles =~ s/,$//;
                   20187:     if ($currtitles ne $newtitles) {
                   20188:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   20189:     }
1.43      raeburn  20190:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   20191:                                              $dom);
                   20192:     if ($putresult eq 'ok') {
                   20193:         if (keys(%changes) > 0) {
                   20194:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  20195:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  20196:             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";
                   20197:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  20198:                 if ($item eq 'inststatus') {
                   20199:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  20200:                         if (@orderedstatus) {
1.236     raeburn  20201:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   20202:                             foreach my $type (@orderedstatus) { 
                   20203:                                 $resulttext .= $alltypes{$type}.', ';
                   20204:                             }
                   20205:                             $resulttext =~ s/, $//;
                   20206:                             $resulttext .= '</li>';
1.305     raeburn  20207:                         } else {
1.425     raeburn  20208:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236     raeburn  20209:                         }
                   20210:                     }
1.409     raeburn  20211:                 } elsif ($item eq 'unamemap_rule') {
                   20212:                     if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   20213:                         my @rulenames;
                   20214:                         if (ref($unamemaprules) eq 'HASH') {
                   20215:                             foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
                   20216:                                 if (ref($unamemaprules->{$rule}) eq 'HASH') {
                   20217:                                     push(@rulenames,$unamemaprules->{$rule}->{'name'});
                   20218:                                 }
                   20219:                             }
                   20220:                         }
                   20221:                         if (@rulenames) {
                   20222:                             $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
                   20223:                                                      '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
                   20224:                                            '</li>';
                   20225:                         } else {
                   20226:                             $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
                   20227:                         }
                   20228:                     } else {
                   20229:                         $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
                   20230:                     }
1.236     raeburn  20231:                 } else {
                   20232:                     my $value = $env{'form.'.$item};
                   20233:                     if ($value eq '') {
                   20234:                         $value = &mt('none');
                   20235:                     } elsif ($item eq 'auth_def') {
                   20236:                         my %authnames = &authtype_names();
                   20237:                         my %shortauth = (
                   20238:                                           internal   => 'int',
                   20239:                                           krb4       => 'krb4',
                   20240:                                           krb5       => 'krb5',
                   20241:                                           localauth  => 'loc',
1.325     raeburn  20242:                                           lti        => 'lti',
1.236     raeburn  20243:                         );
                   20244:                         $value = $authnames{$shortauth{$value}};
                   20245:                     }
                   20246:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414     raeburn  20247:                     $mailmsgtext .= "$title->{$item} set to $value\n";
                   20248:                     if ($item eq 'portal_def') {
                   20249:                         if ($env{'form.'.$item} ne '') {
                   20250:                             foreach my $field ('email','web') {
                   20251:                                 $value = $env{'form.'.$item.'_'.$field};
                   20252:                                 if ($value) {
                   20253:                                     $value = &mt('Yes');
                   20254:                                 } else {
                   20255:                                     $value = &mt('No');
                   20256:                                 }
                   20257:                                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
                   20258:                             }
                   20259:                         }
                   20260:                     }
1.43      raeburn  20261:                 }
                   20262:             }
                   20263:             $resulttext .= '</ul>';
                   20264:             $mailmsgtext .= "\n";
                   20265:             my $cachetime = 24*60*60;
1.72      raeburn  20266:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  20267:             if (ref($lastactref) eq 'HASH') {
                   20268:                 $lastactref->{'domdefaults'} = 1;
                   20269:             }
1.68      raeburn  20270:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  20271:                 my $notify = 1;
                   20272:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   20273:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   20274:                         $notify = 0;
                   20275:                     }
                   20276:                 }
                   20277:                 if ($notify) {
                   20278:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   20279:                                                "LON-CAPA Domain Settings Change - $dom",
                   20280:                                                $mailmsgtext);
                   20281:                 }
1.54      raeburn  20282:             }
1.43      raeburn  20283:         } else {
1.54      raeburn  20284:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  20285:         }
                   20286:     } else {
                   20287:         $resulttext = '<span class="LC_error">'.
                   20288:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   20289:     }
                   20290:     if (@errors > 0) {
                   20291:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   20292:         foreach my $item (@errors) {
                   20293:             $resulttext .= ' "'.$title->{$item}.'",';
                   20294:         }
                   20295:         $resulttext =~ s/,$//;
                   20296:     }
                   20297:     return $resulttext;
                   20298: }
                   20299: 
1.46      raeburn  20300: sub modify_scantron {
1.205     raeburn  20301:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  20302:     my ($resulttext,%confhash,%changes,$errors);
                   20303:     my $custom = 'custom.tab';
                   20304:     my $default = 'default.tab';
                   20305:     my $servadm = $r->dir_config('lonAdmEMail');
1.346     raeburn  20306:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  20307:         &config_check($dom,$confname,$servadm);
                   20308:     if ($env{'form.scantronformat.filename'} ne '') {
                   20309:         my $error;
                   20310:         if ($configuserok eq 'ok') {
                   20311:             if ($switchserver) {
1.130     raeburn  20312:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  20313:             } else {
                   20314:                 if ($author_ok eq 'ok') {
1.421     raeburn  20315:                     my $modified = [];
1.46      raeburn  20316:                     my ($result,$scantronurl) =
1.421     raeburn  20317:                         &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
                   20318:                                                                 $confname,'scantron','','',$custom,
                   20319:                                                                 $modified);
1.46      raeburn  20320:                     if ($result eq 'ok') {
                   20321:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  20322:                         $changes{'scantronformat'} = 1;
1.421     raeburn  20323:                         &update_modify_urls($r,$modified);
1.46      raeburn  20324:                     } else {
                   20325:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   20326:                     }
                   20327:                 } else {
                   20328:                     $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);
                   20329:                 }
                   20330:             }
                   20331:         } else {
                   20332:             $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);
                   20333:         }
                   20334:         if ($error) {
                   20335:             &Apache::lonnet::logthis($error);
                   20336:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   20337:         }
                   20338:     }
1.48      raeburn  20339:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   20340:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   20341:             if ($env{'form.scantronformat_del'}) {
                   20342:                 $confhash{'scantron'}{'scantronformat'} = '';
                   20343:                 $changes{'scantronformat'} = 1;
1.347     raeburn  20344:             } else {
                   20345:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46      raeburn  20346:             }
                   20347:         }
                   20348:     }
1.347     raeburn  20349:     my @options = ('hdr','pad','rem');
1.346     raeburn  20350:     my @fields = &scantroncsv_fields();
                   20351:     my %titles = &scantronconfig_titles();
1.347     raeburn  20352:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346     raeburn  20353:     my ($newdat,$currdat,%newcol,%currcol);
                   20354:     if (grep(/^dat$/,@formats)) {
                   20355:         $confhash{'scantron'}{config}{dat} = 1;
                   20356:         $newdat = 1;
                   20357:     } else {
                   20358:         $newdat = 0;
                   20359:     }
                   20360:     if (grep(/^csv$/,@formats)) {
                   20361:         my %bynum;
                   20362:         foreach my $field (@fields) {
                   20363:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   20364:                 my $posscol = $1;
                   20365:                 if (($posscol < 20) && (!$bynum{$posscol})) {
1.347     raeburn  20366:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346     raeburn  20367:                     $bynum{$posscol} = $field;
                   20368:                     $newcol{$field} = $posscol;
                   20369:                 }
                   20370:             }
                   20371:         }
1.347     raeburn  20372:         if (keys(%newcol)) {
                   20373:             foreach my $option (@options) {
                   20374:                 if ($env{'form.scantroncsv_'.$option}) {
                   20375:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   20376:                 }
                   20377:             }
                   20378:         }
1.346     raeburn  20379:     }
                   20380:     $currdat = 1;
                   20381:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   20382:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347     raeburn  20383:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346     raeburn  20384:                 $currdat = 0;
                   20385:             }
                   20386:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  20387:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   20388:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   20389:                 }
1.346     raeburn  20390:             }
                   20391:         }
                   20392:     }
                   20393:     if ($currdat != $newdat) {
                   20394:         $changes{'config'} = 1;
                   20395:     } else {
                   20396:         foreach my $field (@fields) {
                   20397:             if ($currcol{$field} ne '') {
                   20398:                 if ($currcol{$field} ne $newcol{$field}) {
                   20399:                     $changes{'config'} = 1;
                   20400:                     last;
1.347     raeburn  20401:                 }
1.346     raeburn  20402:             } elsif ($newcol{$field} ne '') {
                   20403:                 $changes{'config'} = 1;
                   20404:                 last;
                   20405:             }
                   20406:         }
                   20407:     }
1.46      raeburn  20408:     if (keys(%confhash) > 0) {
                   20409:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   20410:                                                  $dom);
                   20411:         if ($putresult eq 'ok') {
                   20412:             if (keys(%changes) > 0) {
1.48      raeburn  20413:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   20414:                     $resulttext = &mt('Changes made:').'<ul>';
1.346     raeburn  20415:                     if ($changes{'scantronformat'}) {
                   20416:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   20417:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   20418:                         } else {
                   20419:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   20420:                         }
                   20421:                     }
1.347     raeburn  20422:                     if ($changes{'config'}) {
1.346     raeburn  20423:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   20424:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   20425:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   20426:                             }
                   20427:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  20428:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   20429:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   20430:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   20431:                                         foreach my $field (@fields) {
                   20432:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   20433:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   20434:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   20435:                                             }
                   20436:                                         }
                   20437:                                         $resulttext .= '</ul></li>';
                   20438:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   20439:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   20440:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   20441:                                                 foreach my $option (@options) {
                   20442:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   20443:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   20444:                                                     }
                   20445:                                                 }
                   20446:                                                 $resulttext .= '</ul></li>';
                   20447:                                             }
1.346     raeburn  20448:                                         }
                   20449:                                     }
                   20450:                                 }
                   20451:                             }
                   20452:                         } else {
                   20453:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   20454:                         }
1.46      raeburn  20455:                     }
1.48      raeburn  20456:                     $resulttext .= '</ul>';
                   20457:                 } else {
1.130     raeburn  20458:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  20459:                 }
                   20460:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  20461:                 if (ref($lastactref) eq 'HASH') {
                   20462:                     $lastactref->{'domainconfig'} = 1;
                   20463:                 }
1.46      raeburn  20464:             } else {
1.346     raeburn  20465:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  20466:             }
                   20467:         } else {
                   20468:             $resulttext = '<span class="LC_error">'.
                   20469:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   20470:         }
                   20471:     } else {
1.130     raeburn  20472:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  20473:     }
                   20474:     if ($errors) {
1.353     raeburn  20475:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   20476:                        $errors.'</ul></p>';
1.46      raeburn  20477:     }
                   20478:     return $resulttext;
                   20479: }
                   20480: 
1.48      raeburn  20481: sub modify_coursecategories {
1.239     raeburn  20482:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  20483:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   20484:         $cathash);
1.48      raeburn  20485:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  20486:     my @catitems = ('unauth','auth');
                   20487:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  20488:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  20489:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   20490:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   20491:             $changes{'togglecats'} = 1;
                   20492:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   20493:         }
                   20494:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   20495:             $changes{'categorize'} = 1;
                   20496:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   20497:         }
1.120     raeburn  20498:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   20499:             $changes{'togglecatscomm'} = 1;
                   20500:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   20501:         }
                   20502:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   20503:             $changes{'categorizecomm'} = 1;
                   20504:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  20505: 
                   20506:         }
                   20507:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   20508:             $changes{'togglecatsplace'} = 1;
                   20509:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   20510:         }
                   20511:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   20512:             $changes{'categorizeplace'} = 1;
                   20513:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  20514:         }
1.238     raeburn  20515:         foreach my $item (@catitems) {
                   20516:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   20517:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   20518:                     $changes{$item} = 1;
                   20519:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   20520:                 }
                   20521:             }
                   20522:         }
1.57      raeburn  20523:     } else {
                   20524:         $changes{'togglecats'} = 1;
                   20525:         $changes{'categorize'} = 1;
1.124     raeburn  20526:         $changes{'togglecatscomm'} = 1;
                   20527:         $changes{'categorizecomm'} = 1;
1.272     raeburn  20528:         $changes{'togglecatsplace'} = 1;
                   20529:         $changes{'categorizeplace'} = 1;
1.87      raeburn  20530:         $domconfig{'coursecategories'} = {
                   20531:                                              togglecats => $env{'form.togglecats'},
                   20532:                                              categorize => $env{'form.categorize'},
1.124     raeburn  20533:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   20534:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  20535:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   20536:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  20537:                                          };
1.238     raeburn  20538:         foreach my $item (@catitems) {
                   20539:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   20540:                 $changes{$item} = 1;
                   20541:             }
                   20542:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   20543:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   20544:             }
                   20545:         }
1.57      raeburn  20546:     }
                   20547:     if (ref($cathash) eq 'HASH') {
                   20548:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  20549:             push (@deletecategory,'instcode::0');
                   20550:         }
1.120     raeburn  20551:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   20552:             push(@deletecategory,'communities::0');
                   20553:         }
1.272     raeburn  20554:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   20555:             push(@deletecategory,'placement::0');
                   20556:         }
1.48      raeburn  20557:     }
1.57      raeburn  20558:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   20559:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  20560:         if (@deletecategory > 0) {
                   20561:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  20562:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  20563:             foreach my $item (@deletecategory) {
1.57      raeburn  20564:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   20565:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  20566:                     $deletions{$item} = 1;
1.57      raeburn  20567:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  20568:                 }
                   20569:             }
                   20570:         }
1.57      raeburn  20571:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  20572:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  20573:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  20574:                 $reorderings{$item} = 1;
1.57      raeburn  20575:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  20576:             }
                   20577:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   20578:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   20579:                 my $newdepth = $depth+1;
                   20580:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  20581:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  20582:                 $adds{$newitem} = 1; 
                   20583:             }
                   20584:             if ($env{'form.subcat_'.$item} ne '') {
                   20585:                 my $newcat = $env{'form.subcat_'.$item};
                   20586:                 my $newdepth = $depth+1;
                   20587:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  20588:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  20589:                 $adds{$newitem} = 1;
                   20590:             }
                   20591:         }
                   20592:     }
                   20593:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  20594:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  20595:             my $newitem = 'instcode::0';
1.57      raeburn  20596:             if ($cathash->{$newitem} eq '') {  
                   20597:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  20598:                 $adds{$newitem} = 1;
                   20599:             }
                   20600:         } else {
                   20601:             my $newitem = 'instcode::0';
1.57      raeburn  20602:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  20603:             $adds{$newitem} = 1;
                   20604:         }
                   20605:     }
1.120     raeburn  20606:     if ($env{'form.communities'} eq '1') {
                   20607:         if (ref($cathash) eq 'HASH') {
                   20608:             my $newitem = 'communities::0';
                   20609:             if ($cathash->{$newitem} eq '') {
                   20610:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   20611:                 $adds{$newitem} = 1;
                   20612:             }
                   20613:         } else {
                   20614:             my $newitem = 'communities::0';
                   20615:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   20616:             $adds{$newitem} = 1;
                   20617:         }
                   20618:     }
1.272     raeburn  20619:     if ($env{'form.placement'} eq '1') {
                   20620:         if (ref($cathash) eq 'HASH') {
                   20621:             my $newitem = 'placement::0';
                   20622:             if ($cathash->{$newitem} eq '') {
                   20623:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   20624:                 $adds{$newitem} = 1;
                   20625:             }
                   20626:         } else {
                   20627:             my $newitem = 'placement::0';
                   20628:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   20629:             $adds{$newitem} = 1;
                   20630:         }
                   20631:     }
1.48      raeburn  20632:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  20633:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  20634:             ($env{'form.addcategory_name'} ne 'communities') &&
                   20635:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  20636:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   20637:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   20638:             $adds{$newitem} = 1;
                   20639:         }
1.48      raeburn  20640:     }
1.57      raeburn  20641:     my $putresult;
1.48      raeburn  20642:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   20643:         if (keys(%deletions) > 0) {
                   20644:             foreach my $key (keys(%deletions)) {
                   20645:                 if ($predelallitems{$key} ne '') {
                   20646:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   20647:                 }
                   20648:             }
                   20649:         }
                   20650:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  20651:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  20652:         if (ref($chkcats[0]) eq 'ARRAY') {
                   20653:             my $depth = 0;
                   20654:             my $chg = 0;
                   20655:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   20656:                 my $name = $chkcats[0][$i];
                   20657:                 my $item;
                   20658:                 if ($name eq '') {
                   20659:                     $chg ++;
                   20660:                 } else {
                   20661:                     $item = &escape($name).'::0';
                   20662:                     if ($chg) {
1.57      raeburn  20663:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  20664:                     }
                   20665:                     $depth ++; 
1.57      raeburn  20666:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  20667:                     $depth --;
                   20668:                 }
                   20669:             }
                   20670:         }
1.57      raeburn  20671:     }
                   20672:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   20673:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  20674:         if ($putresult eq 'ok') {
1.57      raeburn  20675:             my %title = (
1.120     raeburn  20676:                          togglecats     => 'Show/Hide a course in catalog',
                   20677:                          categorize     => 'Assign a category to a course',
                   20678:                          togglecatscomm => 'Show/Hide a community in catalog',
                   20679:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  20680:                         );
                   20681:             my %level = (
1.120     raeburn  20682:                          dom  => 'set in Domain ("Modify Course/Community")',
                   20683:                          crs  => 'set in Course ("Course Configuration")',
                   20684:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  20685:                          none     => 'No catalog',
                   20686:                          std      => 'Standard catalog',
                   20687:                          domonly  => 'Domain-only catalog',
                   20688:                          codesrch => 'Code search form',
1.57      raeburn  20689:                         );
1.48      raeburn  20690:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  20691:             if ($changes{'togglecats'}) {
                   20692:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   20693:             }
                   20694:             if ($changes{'categorize'}) {
                   20695:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  20696:             }
1.120     raeburn  20697:             if ($changes{'togglecatscomm'}) {
                   20698:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   20699:             }
                   20700:             if ($changes{'categorizecomm'}) {
                   20701:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   20702:             }
1.238     raeburn  20703:             if ($changes{'unauth'}) {
                   20704:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   20705:             }
                   20706:             if ($changes{'auth'}) {
                   20707:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   20708:             }
1.57      raeburn  20709:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   20710:                 my $cathash;
                   20711:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   20712:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   20713:                 } else {
                   20714:                     $cathash = {};
                   20715:                 } 
                   20716:                 my (@cats,@trails,%allitems);
                   20717:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   20718:                 if (keys(%deletions) > 0) {
                   20719:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   20720:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   20721:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   20722:                     }
                   20723:                     $resulttext .= '</ul></li>';
                   20724:                 }
                   20725:                 if (keys(%reorderings) > 0) {
                   20726:                     my %sort_by_trail;
                   20727:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   20728:                     foreach my $key (keys(%reorderings)) {
                   20729:                         if ($allitems{$key} ne '') {
                   20730:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   20731:                         }
1.48      raeburn  20732:                     }
1.57      raeburn  20733:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   20734:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   20735:                     }
                   20736:                     $resulttext .= '</ul></li>';
1.48      raeburn  20737:                 }
1.57      raeburn  20738:                 if (keys(%adds) > 0) {
                   20739:                     my %sort_by_trail;
                   20740:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   20741:                     foreach my $key (keys(%adds)) {
                   20742:                         if ($allitems{$key} ne '') {
                   20743:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   20744:                         }
                   20745:                     }
                   20746:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   20747:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  20748:                     }
1.57      raeburn  20749:                     $resulttext .= '</ul></li>';
1.48      raeburn  20750:                 }
1.364     raeburn  20751:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   20752:                 if (ref($lastactref) eq 'HASH') {
                   20753:                     $lastactref->{'cats'} = 1;
                   20754:                 }
1.48      raeburn  20755:             }
                   20756:             $resulttext .= '</ul>';
1.239     raeburn  20757:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  20758:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   20759:                 if ($changes{'auth'}) {
                   20760:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   20761:                 }
                   20762:                 if ($changes{'unauth'}) {
                   20763:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   20764:                 }
                   20765:                 my $cachetime = 24*60*60;
                   20766:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  20767:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  20768:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  20769:                 }
                   20770:             }
1.48      raeburn  20771:         } else {
                   20772:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  20773:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  20774:         }
                   20775:     } else {
1.120     raeburn  20776:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  20777:     }
                   20778:     return $resulttext;
                   20779: }
                   20780: 
1.69      raeburn  20781: sub modify_serverstatuses {
                   20782:     my ($dom,%domconfig) = @_;
                   20783:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   20784:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   20785:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   20786:     }
                   20787:     my @pages = &serverstatus_pages();
                   20788:     foreach my $type (@pages) {
                   20789:         $newserverstatus{$type}{'namedusers'} = '';
                   20790:         $newserverstatus{$type}{'machines'} = '';
                   20791:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   20792:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   20793:             my @okusers;
                   20794:             foreach my $user (@users) {
                   20795:                 my ($uname,$udom) = split(/:/,$user);
                   20796:                 if (($udom =~ /^$match_domain$/) &&   
                   20797:                     (&Apache::lonnet::domain($udom)) &&
                   20798:                     ($uname =~ /^$match_username$/)) {
                   20799:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   20800:                         push(@okusers,$user);
                   20801:                     }
                   20802:                 }
                   20803:             }
                   20804:             if (@okusers > 0) {
                   20805:                  @okusers = sort(@okusers);
                   20806:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   20807:             }
                   20808:         }
                   20809:         if (defined($env{'form.'.$type.'_machines'})) {
                   20810:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   20811:             my @okmachines;
                   20812:             foreach my $ip (@machines) {
                   20813:                 my @parts = split(/\./,$ip);
                   20814:                 next if (@parts < 4);
                   20815:                 my $badip = 0;
                   20816:                 for (my $i=0; $i<4; $i++) {
                   20817:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   20818:                         $badip = 1;
                   20819:                         last;
                   20820:                     }
                   20821:                 }
                   20822:                 if (!$badip) {
                   20823:                     push(@okmachines,$ip);     
                   20824:                 }
                   20825:             }
                   20826:             @okmachines = sort(@okmachines);
                   20827:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   20828:         }
                   20829:     }
                   20830:     my %serverstatushash =  (
                   20831:                                 serverstatuses => \%newserverstatus,
                   20832:                             );
                   20833:     foreach my $type (@pages) {
1.83      raeburn  20834:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  20835:             my (@current,@new);
1.83      raeburn  20836:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  20837:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   20838:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   20839:                 }
                   20840:             }
                   20841:             if ($newserverstatus{$type}{$setting} ne '') {
                   20842:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  20843:             }
                   20844:             if (@current > 0) {
                   20845:                 if (@new > 0) {
                   20846:                     foreach my $item (@current) {
                   20847:                         if (!grep(/^\Q$item\E$/,@new)) {
                   20848:                             $changes{$type}{$setting} = 1;
1.82      raeburn  20849:                             last;
                   20850:                         }
                   20851:                     }
1.84      raeburn  20852:                     foreach my $item (@new) {
                   20853:                         if (!grep(/^\Q$item\E$/,@current)) {
                   20854:                             $changes{$type}{$setting} = 1;
                   20855:                             last;
1.82      raeburn  20856:                         }
                   20857:                     }
                   20858:                 } else {
1.83      raeburn  20859:                     $changes{$type}{$setting} = 1;
1.69      raeburn  20860:                 }
1.83      raeburn  20861:             } elsif (@new > 0) {
                   20862:                 $changes{$type}{$setting} = 1;
1.69      raeburn  20863:             }
                   20864:         }
                   20865:     }
                   20866:     if (keys(%changes) > 0) {
1.81      raeburn  20867:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  20868:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   20869:                                                  \%serverstatushash,$dom);
                   20870:         if ($putresult eq 'ok') {
                   20871:             $resulttext .= &mt('Changes made:').'<ul>';
                   20872:             foreach my $type (@pages) {
1.84      raeburn  20873:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  20874:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  20875:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  20876:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   20877:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   20878:                         } else {
                   20879:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   20880:                         }
1.84      raeburn  20881:                     }
                   20882:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  20883:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   20884:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   20885:                         } else {
                   20886:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   20887:                         }
                   20888: 
                   20889:                     }
                   20890:                     $resulttext .= '</ul></li>';
                   20891:                 }
                   20892:             }
                   20893:             $resulttext .= '</ul>';
                   20894:         } else {
                   20895:             $resulttext = '<span class="LC_error">'.
                   20896:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   20897: 
                   20898:         }
                   20899:     } else {
                   20900:         $resulttext = &mt('No changes made to access to server status pages');
                   20901:     }
                   20902:     return $resulttext;
                   20903: }
                   20904: 
1.118     jms      20905: sub modify_helpsettings {
1.285     raeburn  20906:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  20907:     my ($resulttext,$errors,%changes,%helphash);
                   20908:     my %defaultchecked = ('submitbugs' => 'on');
                   20909:     my @offon = ('off','on');
1.118     jms      20910:     my @toggles = ('submitbugs');
1.285     raeburn  20911:     my %current = ('submitbugs' => '',
                   20912:                    'adhoc'      => {},
                   20913:                   );
1.118     jms      20914:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  20915:         %current = %{$domconfig{'helpsettings'}};
                   20916:     }
1.285     raeburn  20917:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  20918:     foreach my $item (@toggles) {
                   20919:         if ($defaultchecked{$item} eq 'on') { 
                   20920:             if ($current{$item} eq '') {
                   20921:                 if ($env{'form.'.$item} eq '0') {
                   20922:                     $changes{$item} = 1;
                   20923:                 }
                   20924:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   20925:                 $changes{$item} = 1;
                   20926:             }
                   20927:         } elsif ($defaultchecked{$item} eq 'off') {
                   20928:             if ($current{$item} eq '') {
                   20929:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  20930:                     $changes{$item} = 1;
                   20931:                 }
1.282     raeburn  20932:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   20933:                 $changes{$item} = 1;
                   20934:             }
                   20935:         }
                   20936:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   20937:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   20938:         }
                   20939:     }
1.285     raeburn  20940:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  20941:     my $confname = $dom.'-domainconfig';
                   20942:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  20943:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   20944:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  20945:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  20946:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  20947:     my %lt = &Apache::lonlocal::texthash(
                   20948:                     s      => 'system',
                   20949:                     d      => 'domain',
                   20950:                     order  => 'Display order',
                   20951:                     access => 'Role usage',
1.291     raeburn  20952:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  20953:                     dh     => 'All with domain helpdesk role',
                   20954:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  20955:                     none   => 'None',
                   20956:                     status => 'Determined based on institutional status',
                   20957:                     inc    => 'Include all, but exclude specific personnel',
                   20958:                     exc    => 'Exclude all, but include specific personnel',
                   20959:     );
                   20960:     for (my $num=0; $num<=$maxnum; $num++) {
                   20961:         my ($prefix,$identifier,$rolename,%curr);
                   20962:         if ($num == $maxnum) {
                   20963:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   20964:             $identifier = 'custhelp'.$num;
                   20965:             $prefix = 'helproles_'.$num;
                   20966:             $rolename = $env{'form.custhelpname'.$num};
                   20967:             $rolename=~s/[^A-Za-z0-9]//gs;
                   20968:             next if ($rolename eq '');
                   20969:             next if (exists($existing{'rolesdef_'.$rolename}));
                   20970:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20971:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20972:                                                      $newprivs{'c'},$confname,$dom);
                   20973:             if ($result ne 'ok') {
                   20974:                 $errors .= '<li><span class="LC_error">'.
                   20975:                            &mt('An error occurred storing the new custom role: [_1]',
                   20976:                            $result).'</span></li>';
                   20977:                 next;
                   20978:             } else {
                   20979:                 $changedprivs{$rolename} = \%newprivs;
                   20980:                 $newrole = $rolename;
                   20981:             }
                   20982:         } else {
                   20983:             $prefix = 'helproles_'.$num;
                   20984:             $rolename = $env{'form.'.$prefix};
                   20985:             next if ($rolename eq '');
                   20986:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   20987:             $identifier = 'custhelp'.$num;
                   20988:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20989:             my %currprivs;
1.289     raeburn  20990:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  20991:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   20992:             foreach my $level ('c','d','s') {
                   20993:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   20994:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20995:                                                              $newprivs{'c'},$confname,$dom);
                   20996:                     if ($result ne 'ok') {
                   20997:                         $errors .= '<li><span class="LC_error">'.
                   20998:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   20999:                                        $rolename,$result).'</span></li>';
                   21000:                     } else {
                   21001:                         $changedprivs{$rolename} = \%newprivs;
                   21002:                     }
                   21003:                     last;
                   21004:                 }
                   21005:             }
                   21006:             if (ref($current{'adhoc'}) eq 'HASH') {
                   21007:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   21008:                     %curr = %{$current{'adhoc'}{$rolename}};
                   21009:                 }
                   21010:             }
                   21011:         }
                   21012:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   21013:         $newpos =~ s/\D+//g;
                   21014:         $allpos[$newpos] = $rolename;
                   21015:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   21016:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   21017:         if ($curr{'desc'}) {
                   21018:             if ($curr{'desc'} ne $newdesc) {
                   21019:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   21020:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   21021:             }
                   21022:         } elsif ($newdesc ne '') {
                   21023:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   21024:             $newsettings{$rolename}{'desc'} = $newdesc;
                   21025:         }
                   21026:         my $access = $env{'form.'.$prefix.'_access'};
                   21027:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   21028:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   21029:             if ($access eq 'status') {
                   21030:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   21031:                 if (scalar(@statuses) == 0) {
1.289     raeburn  21032:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  21033:                 } else {
                   21034:                     my (@shownstatus,$numtypes);
                   21035:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   21036:                     if (ref($types) eq 'ARRAY') {
                   21037:                         $numtypes = scalar(@{$types});
                   21038:                         foreach my $type (sort(@statuses)) {
                   21039:                             if ($type eq 'default') {
                   21040:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   21041:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   21042:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   21043:                                 push(@shownstatus,$usertypes->{$type});
                   21044:                             }
                   21045:                         }
                   21046:                     }
                   21047:                     if (grep(/^default$/,@statuses)) {
                   21048:                         push(@shownstatus,$othertitle);
                   21049:                     }
                   21050:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   21051:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   21052:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   21053:                     } else {
                   21054:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   21055:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   21056:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   21057:                             if (@diffs) {
                   21058:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   21059:                             }
                   21060:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   21061:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  21062:                         }
1.166     raeburn  21063:                     }
                   21064:                 }
1.285     raeburn  21065:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   21066:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   21067:                 my @newspecstaff;
                   21068:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   21069:                 foreach my $person (sort(@personnel)) {
                   21070:                     if ($domhelpdesk{$person}) {
                   21071:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   21072:                     }
                   21073:                 }
                   21074:                 if (ref($curr{$access}) eq 'ARRAY') {
                   21075:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   21076:                     if (@diffs) {
                   21077:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   21078:                     }
                   21079:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   21080:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   21081:                 }
                   21082:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   21083:                     my ($uname,$udom) = split(/:/,$person);
                   21084:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   21085:                 }
                   21086:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  21087:             }
1.285     raeburn  21088:         } else {
                   21089:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   21090:         }
                   21091:         unless ($curr{'access'} eq $access) {
                   21092:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   21093:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  21094:         }
                   21095:     }
1.285     raeburn  21096:     if (@allpos > 0) {
                   21097:         my $idx = 0;
                   21098:         foreach my $rolename (@allpos) {
                   21099:             if ($rolename ne '') {
                   21100:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   21101:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   21102:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   21103:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   21104:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  21105:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  21106:                         }
                   21107:                     }
1.282     raeburn  21108:                 }
1.285     raeburn  21109:                 $idx ++;
1.166     raeburn  21110:             }
                   21111:         }
1.118     jms      21112:     }
1.123     jms      21113:     my $putresult;
                   21114:     if (keys(%changes) > 0) {
1.166     raeburn  21115:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  21116:         if ($putresult eq 'ok') {
1.285     raeburn  21117:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   21118:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   21119:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   21120:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   21121:                 }
                   21122:             }
                   21123:             my $cachetime = 24*60*60;
                   21124:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21125:             if (ref($lastactref) eq 'HASH') {
                   21126:                 $lastactref->{'domdefaults'} = 1;
                   21127:             }
                   21128:         } else {
                   21129:             $errors .= '<li><span class="LC_error">'.
                   21130:                        &mt('An error occurred storing the settings: [_1]',
                   21131:                            $putresult).'</span></li>';
                   21132:         }
                   21133:     }
                   21134:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   21135:         $resulttext = &mt('Changes made:').'<ul>';
                   21136:         my (%shownprivs,@levelorder);
                   21137:         @levelorder = ('c','d','s');
                   21138:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  21139:             foreach my $item (sort(keys(%changes))) {
                   21140:                 if ($item eq 'submitbugs') {
                   21141:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   21142:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   21143:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  21144:                 } elsif ($item eq 'customrole') {
                   21145:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  21146:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   21147:                         my %keytext = &Apache::lonlocal::texthash(
                   21148:                                                                    order  => 'Order',
                   21149:                                                                    desc   => 'Role description',
                   21150:                                                                    access => 'Role usage',
1.300     droeschl 21151:                                                                    status => 'Allowed institutional types',
1.285     raeburn  21152:                                                                    exc    => 'Allowed personnel',
                   21153:                                                                    inc    => 'Disallowed personnel',
                   21154:                         );
1.282     raeburn  21155:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  21156:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   21157:                                 if ($role eq $newrole) {
                   21158:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   21159:                                                               $role).'<ul>';
                   21160:                                 } else {
                   21161:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   21162:                                                               $role).'<ul>';
                   21163:                                 }
                   21164:                                 foreach my $key (@keyorder) {
                   21165:                                     if ($changes{'customrole'}{$role}{$key}) {
                   21166:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   21167:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   21168:                                                        '</li>';
                   21169:                                     }
                   21170:                                 }
                   21171:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   21172:                                     $shownprivs{$role} = 1;
                   21173:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   21174:                                     foreach my $level (@levelorder) {
                   21175:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   21176:                                             next if ($item eq '');
                   21177:                                             my ($priv) = split(/\&/,$item,2);
                   21178:                                             if (&Apache::lonnet::plaintext($priv)) {
                   21179:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   21180:                                                 unless ($level eq 'c') {
                   21181:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   21182:                                                 }
                   21183:                                                 $resulttext .= '</li>';
                   21184:                                             }
                   21185:                                         }
                   21186:                                     }
                   21187:                                     $resulttext .= '</ul>';
                   21188:                                 }
                   21189:                                 $resulttext .= '</ul></li>';
                   21190:                             }
                   21191:                         }
                   21192:                     }
                   21193:                 }
                   21194:             }
                   21195:         }
                   21196:         if (keys(%changedprivs)) {
                   21197:             foreach my $role (sort(keys(%changedprivs))) {
                   21198:                 unless ($shownprivs{$role}) {
                   21199:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   21200:                                               $role).'<ul>'.
                   21201:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   21202:                     foreach my $level (@levelorder) {
                   21203:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   21204:                             next if ($item eq '');
                   21205:                             my ($priv) = split(/\&/,$item,2);
                   21206:                             if (&Apache::lonnet::plaintext($priv)) {
                   21207:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   21208:                                 unless ($level eq 'c') {
                   21209:                                     $resulttext .= ' ('.$lt{$level}.')';
                   21210:                                 }
                   21211:                                 $resulttext .= '</li>';
                   21212:                             }
1.282     raeburn  21213:                         }
                   21214:                     }
1.285     raeburn  21215:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  21216:                 }
                   21217:             }
                   21218:         }
1.285     raeburn  21219:         $resulttext .= '</ul>';
                   21220:     } else {
                   21221:         $resulttext = &mt('No changes made to help settings');
1.118     jms      21222:     }
                   21223:     if ($errors) {
1.168     raeburn  21224:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  21225:                                     $errors.'</ul>';
1.118     jms      21226:     }
                   21227:     return $resulttext;
                   21228: }
                   21229: 
1.121     raeburn  21230: sub modify_coursedefaults {
1.212     raeburn  21231:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  21232:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  21233:     my %defaultchecked = (
                   21234:                            'canuse_pdfforms' => 'off',
                   21235:                            'uselcmath'       => 'on',
1.398     raeburn  21236:                            'usejsme'         => 'on',
                   21237:                            'inline_chem'     => 'on',
1.404     raeburn  21238:                            'ltiauth'         => 'off',
1.257     raeburn  21239:                          );
1.404     raeburn  21240:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198     raeburn  21241:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  21242:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428     raeburn  21243:                    'coursequota_official','coursequota_unofficial','coursequota_community',
                   21244:                    'coursequota_textbook','coursequota_placement','mysqltables_official',
                   21245:                    'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
                   21246:                    'mysqltables_placement');
1.271     raeburn  21247:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  21248:     my %staticdefaults = (
                   21249:                            anonsurvey_threshold => 10,
                   21250:                            uploadquota          => 500,
1.428     raeburn  21251:                            coursequota          => 20,
1.257     raeburn  21252:                            postsubmit           => 60,
1.276     raeburn  21253:                            mysqltables          => 172800,
1.422     raeburn  21254:                            domexttool           => 1,
1.432     raeburn  21255:                            crsauthor            => 1,
1.438   ! raeburn  21256:                            crseditors           => ['edit','xml'],
1.198     raeburn  21257:                          );
1.314     raeburn  21258:     my %texoptions = (
                   21259:                         MathJax  => 'MathJax',
                   21260:                         mimetex  => &mt('Convert to Images'),
                   21261:                         tth      => &mt('TeX to HTML'),
                   21262:                      );
1.438   ! raeburn  21263: 
        !          21264:     my @editors = ('edit','xml','daxe');
        !          21265:     my %editornames = &crseditor_titles();
        !          21266: 
1.121     raeburn  21267:     $defaultshash{'coursedefaults'} = {};
                   21268: 
                   21269:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   21270:         if ($domconfig{'coursedefaults'} eq '') {
                   21271:             $domconfig{'coursedefaults'} = {};
                   21272:         }
                   21273:     }
                   21274: 
                   21275:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   21276:         foreach my $item (@toggles) {
                   21277:             if ($defaultchecked{$item} eq 'on') {
                   21278:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   21279:                     ($env{'form.'.$item} eq '0')) {
                   21280:                     $changes{$item} = 1;
1.192     raeburn  21281:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  21282:                     $changes{$item} = 1;
                   21283:                 }
                   21284:             } elsif ($defaultchecked{$item} eq 'off') {
                   21285:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   21286:                     ($env{'form.'.$item} eq '1')) {
                   21287:                     $changes{$item} = 1;
                   21288:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   21289:                     $changes{$item} = 1;
                   21290:                 }
                   21291:             }
                   21292:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   21293:         }
1.198     raeburn  21294:         foreach my $item (@numbers) {
                   21295:             my ($currdef,$newdef);
1.208     raeburn  21296:             $newdef = $env{'form.'.$item};
1.198     raeburn  21297:             if ($item eq 'anonsurvey_threshold') {
                   21298:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   21299:                 $newdef =~ s/\D//g;
                   21300:                 if ($newdef eq '' || $newdef < 1) {
                   21301:                     $newdef = 1;
                   21302:                 }
                   21303:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   21304:             } else {
1.428     raeburn  21305:                 my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276     raeburn  21306:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   21307:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  21308:                 }
                   21309:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  21310:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  21311:             }
                   21312:             if ($currdef ne $newdef) {
                   21313:                 if ($item eq 'anonsurvey_threshold') {
                   21314:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   21315:                         $changes{$item} = 1;
                   21316:                     }
1.428     raeburn  21317:                 } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289     raeburn  21318:                     my $setting = $1;
1.276     raeburn  21319:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   21320:                         $changes{$setting} = 1;
1.198     raeburn  21321:                     }
                   21322:                 }
1.139     raeburn  21323:             }
                   21324:         }
1.314     raeburn  21325:         my $texengine;
                   21326:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   21327:             $texengine = $env{'form.texengine'};
1.349     raeburn  21328:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   21329:             if ($currdef eq '') {
                   21330:                 unless ($texengine eq $Apache::lonnet::deftex) {
1.314     raeburn  21331:                     $changes{'texengine'} = 1;
                   21332:                 }
1.349     raeburn  21333:             } elsif ($currdef ne $texengine) {
1.314     raeburn  21334:                 $changes{'texengine'} = 1;
                   21335:             }
                   21336:         }
                   21337:         if ($texengine ne '') {
                   21338:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   21339:         }
1.264     raeburn  21340:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   21341:         my @currclonecode;
                   21342:         if (ref($currclone) eq 'HASH') {
                   21343:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   21344:                 @currclonecode = @{$currclone->{'instcode'}};
                   21345:             }
                   21346:         }
                   21347:         my $newclone;
1.289     raeburn  21348:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  21349:             $newclone = $env{'form.canclone'};
                   21350:         }
                   21351:         if ($newclone eq 'instcode') {
                   21352:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   21353:             my (%codedefaults,@code_order,@clonecode);
                   21354:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   21355:                                                     \@code_order);
                   21356:             foreach my $item (@code_order) {
                   21357:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   21358:                     push(@clonecode,$item);
                   21359:                 }
                   21360:             }
                   21361:             if (@clonecode) {
                   21362:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   21363:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   21364:                 if (@diffs) {
                   21365:                     $changes{'canclone'} = 1;
                   21366:                 }
                   21367:             } else {
                   21368:                 $newclone eq '';
                   21369:             }
                   21370:         } elsif ($newclone ne '') {
1.289     raeburn  21371:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   21372:         }
1.264     raeburn  21373:         if ($newclone ne $currclone) {
                   21374:             $changes{'canclone'} = 1;
                   21375:         }
1.257     raeburn  21376:         my %credits;
                   21377:         foreach my $type (@types) {
                   21378:             unless ($type eq 'community') {
                   21379:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   21380:                 $credits{$type} =~ s/[^\d.]+//g;
                   21381:             }
                   21382:         }
                   21383:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   21384:             ($env{'form.coursecredits'} eq '1')) {
                   21385:             $changes{'coursecredits'} = 1;
                   21386:             foreach my $type (keys(%credits)) {
                   21387:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   21388:             }
                   21389:         } else {
1.289     raeburn  21390:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  21391:                 foreach my $type (@types) {
                   21392:                     unless ($type eq 'community') {
1.289     raeburn  21393:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  21394:                             $changes{'coursecredits'} = 1;
                   21395:                         }
                   21396:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   21397:                     }
                   21398:                 }
                   21399:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   21400:                 foreach my $type (@types) {
                   21401:                     unless ($type eq 'community') {
                   21402:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   21403:                             $changes{'coursecredits'} = 1;
                   21404:                             last;
                   21405:                         }
                   21406:                     }
                   21407:                 }
                   21408:             }
                   21409:         }
                   21410:         if ($env{'form.postsubmit'} eq '1') {
                   21411:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   21412:             my %currtimeout;
                   21413:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   21414:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   21415:                     $changes{'postsubmit'} = 1;
                   21416:                 }
                   21417:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   21418:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   21419:                 }
                   21420:             } else {
                   21421:                 $changes{'postsubmit'} = 1;
                   21422:             }
                   21423:             foreach my $type (@types) {
                   21424:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   21425:                 $timeout =~ s/\D//g;
                   21426:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   21427:                     $timeout = '';
                   21428:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   21429:                     $timeout = '0';
                   21430:                 }
                   21431:                 unless ($timeout eq '') {
                   21432:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   21433:                 }
                   21434:                 if (exists($currtimeout{$type})) {
                   21435:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  21436:                         $changes{'postsubmit'} = 1;
1.257     raeburn  21437:                     }
                   21438:                 } elsif ($timeout ne '') {
                   21439:                     $changes{'postsubmit'} = 1;
                   21440:                 }
                   21441:             }
                   21442:         } else {
                   21443:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   21444:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   21445:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   21446:                     $changes{'postsubmit'} = 1;
                   21447:                 }
                   21448:             } else {
                   21449:                 $changes{'postsubmit'} = 1;
                   21450:             }
1.192     raeburn  21451:         }
1.438   ! raeburn  21452:         my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
        !          21453:             %posscrseditors);
1.422     raeburn  21454:         map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425     raeburn  21455:         map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432     raeburn  21456:         map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438   ! raeburn  21457:         map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422     raeburn  21458:         if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
                   21459:             %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
                   21460:         } else {
                   21461:            foreach my $type (@types) {
                   21462:                if ($staticdefaults{'domexttool'}) {
                   21463:                    $olddomexttool{$type} = 1;
                   21464:                } else {
                   21465:                    $olddomexttool{$type} = 0;
                   21466:                }
                   21467:             }
                   21468:         }
                   21469:         if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425     raeburn  21470:             %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422     raeburn  21471:         } else {
                   21472:             foreach my $type (@types) {
                   21473:                if ($staticdefaults{'exttool'}) {
                   21474:                    $oldexttool{$type} = 1;
                   21475:                } else {
                   21476:                    $oldexttool{$type} = 0;
                   21477:                }
                   21478:             }
                   21479:         }
1.432     raeburn  21480:         if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
                   21481:             %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
                   21482:         } else {
                   21483:             foreach my $type (@types) {
                   21484:                if ($staticdefaults{'crsauthor'}) {
                   21485:                    $oldcrsauthor{$type} = 1;
                   21486:                } else {
                   21487:                    $oldcrsauthor{$type} = 0;
                   21488:                }
                   21489:             }
                   21490:         }
1.438   ! raeburn  21491:         my @newcrseditors = ();
        !          21492:         foreach my $editor (@editors) {
        !          21493:             if ($posscrseditors{$editor}) {
        !          21494:                 push(@newcrseditors,$editor);
        !          21495:             }
        !          21496:         }
        !          21497:         if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
        !          21498:             my @diffs =
        !          21499:                 &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
        !          21500:                                                    \@newcrseditors);
        !          21501:             if (@diffs) {
        !          21502:                 $changes{'crseditors'} = 1; 
        !          21503:             }
        !          21504:         } else {
        !          21505:             my @diffs =
        !          21506:                 &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
        !          21507:                                                    \@newcrseditors);
        !          21508:             unless (@diffs == 0) {
        !          21509:                 $changes{'crseditors'} = 1;
        !          21510:             }       
        !          21511:         }
1.422     raeburn  21512:         foreach my $type (@types) {
                   21513:             unless ($newdomexttool{$type}) {
                   21514:                 $newdomexttool{$type} = 0;
                   21515:             }
                   21516:             unless ($newexttool{$type}) {
                   21517:                 $newexttool{$type} = 0;
                   21518:             }
1.432     raeburn  21519:             unless ($newcrsauthor{$type}) {
                   21520:                 $newcrsauthor{$type} = 0;
                   21521:             }
1.422     raeburn  21522:             if ($newdomexttool{$type} != $olddomexttool{$type}) {
                   21523:                 $changes{'domexttool'} = 1;
                   21524:             }
                   21525:             if ($newexttool{$type} != $oldexttool{$type}) {
                   21526:                 $changes{'exttool'} = 1;
                   21527:             }
1.432     raeburn  21528:             if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
                   21529:                 $changes{'crsauthor'} = 1;
                   21530:             }
1.422     raeburn  21531:         }
                   21532:         $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
                   21533:         $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432     raeburn  21534:         $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438   ! raeburn  21535:         $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121     raeburn  21536:     }
                   21537:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21538:                                              $dom);
                   21539:     if ($putresult eq 'ok') {
                   21540:         if (keys(%changes) > 0) {
1.213     raeburn  21541:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  21542:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  21543:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398     raeburn  21544:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422     raeburn  21545:                 ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432     raeburn  21546:                 ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422     raeburn  21547:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
                   21548:                                   'ltiauth') {
1.257     raeburn  21549:                     if ($changes{$item}) {
                   21550:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   21551:                     }
1.289     raeburn  21552:                 }
1.192     raeburn  21553:                 if ($changes{'coursecredits'}) {
                   21554:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  21555:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   21556:                             $domdefaults{$type.'credits'} =
                   21557:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   21558:                         }
                   21559:                     }
                   21560:                 }
                   21561:                 if ($changes{'postsubmit'}) {
                   21562:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   21563:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   21564:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   21565:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   21566:                                 $domdefaults{$type.'postsubtimeout'} =
                   21567:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   21568:                             }
                   21569:                         }
1.192     raeburn  21570:                     }
                   21571:                 }
1.198     raeburn  21572:                 if ($changes{'uploadquota'}) {
                   21573:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   21574:                         foreach my $type (@types) {
                   21575:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   21576:                         }
                   21577:                     }
                   21578:                 }
1.428     raeburn  21579:                 if ($changes{'coursequota'}) {
                   21580:                     if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
                   21581:                         foreach my $type (@types) {
                   21582:                             $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
                   21583:                         }
                   21584:                     }
                   21585:                 }
1.264     raeburn  21586:                 if ($changes{'canclone'}) {
                   21587:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   21588:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   21589:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   21590:                             if (@clonecodes) {
                   21591:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   21592:                             }
                   21593:                         }
                   21594:                     } else {
                   21595:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   21596:                     }
                   21597:                 }
1.422     raeburn  21598:                 if ($changes{'domexttool'}) {
                   21599:                     if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
                   21600:                         foreach my $type (@types) {
                   21601:                             $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
                   21602:                         }
                   21603:                     }
                   21604:                 }
                   21605:                 if ($changes{'exttool'}) {
                   21606:                     if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
                   21607:                         foreach my $type (@types) {
                   21608:                             $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
                   21609:                         }
                   21610:                     }
                   21611:                 }
1.432     raeburn  21612:                 if ($changes{'crsauthor'}) {
                   21613:                     if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
                   21614:                         foreach my $type (@types) {
                   21615:                             $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
                   21616:                         }
                   21617:                     }
                   21618:                 }
1.438   ! raeburn  21619:                 if ($changes{'crseditors'}) {
        !          21620:                     if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
        !          21621:                         $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
        !          21622:                     }
        !          21623:                 }
1.121     raeburn  21624:                 my $cachetime = 24*60*60;
                   21625:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  21626:                 if (ref($lastactref) eq 'HASH') {
                   21627:                     $lastactref->{'domdefaults'} = 1;
                   21628:                 }
1.121     raeburn  21629:             }
                   21630:             $resulttext = &mt('Changes made:').'<ul>';
                   21631:             foreach my $item (sort(keys(%changes))) {
                   21632:                 if ($item eq 'canuse_pdfforms') {
                   21633:                     if ($env{'form.'.$item} eq '1') {
                   21634:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   21635:                     } else {
                   21636:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   21637:                     }
1.257     raeburn  21638:                 } elsif ($item eq 'uselcmath') {
                   21639:                     if ($env{'form.'.$item} eq '1') {
                   21640:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   21641:                     } else {
                   21642:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   21643:                     }
                   21644:                 } elsif ($item eq 'usejsme') {
                   21645:                     if ($env{'form.'.$item} eq '1') {
                   21646:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   21647:                     } else {
1.289     raeburn  21648:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  21649:                     }
1.398     raeburn  21650:                 } elsif ($item eq 'inline_chem') {
                   21651:                     if ($env{'form.'.$item} eq '1') {
                   21652:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
                   21653:                     } else {
                   21654:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
                   21655:                     }
1.314     raeburn  21656:                 } elsif ($item eq 'texengine') {
                   21657:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   21658:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   21659:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   21660:                     }
1.139     raeburn  21661:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  21662:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  21663:                 } elsif ($item eq 'uploadquota') {
                   21664:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   21665:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   21666:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   21667:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  21668:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  21669:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  21670:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   21671:                                        '</ul>'.
                   21672:                                        '</li>';
                   21673:                     } else {
                   21674:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   21675:                     }
1.428     raeburn  21676:                 } elsif ($item eq 'coursequota') {
                   21677:                     if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
                   21678:                         $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
                   21679:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
                   21680:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
                   21681:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
                   21682:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
                   21683:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
                   21684:                                        '</ul>'.
                   21685:                                        '</li>';
                   21686:                     } else {
                   21687:                         $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
                   21688:                     }
1.276     raeburn  21689:                 } elsif ($item eq 'mysqltables') {
                   21690:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   21691:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   21692:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   21693:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   21694:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   21695:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   21696:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   21697:                                        '</ul>'.
                   21698:                                        '</li>';
                   21699:                     } else {
                   21700:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   21701:                     }
1.257     raeburn  21702:                 } elsif ($item eq 'postsubmit') {
                   21703:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   21704:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   21705:                     } else {
                   21706:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  21707:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  21708:                             $resulttext .= &mt('durations:').'<ul>';
                   21709:                             foreach my $type (@types) {
                   21710:                                 $resulttext .= '<li>';
                   21711:                                 my $timeout;
                   21712:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   21713:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   21714:                                 }
                   21715:                                 my $display;
                   21716:                                 if ($timeout eq '0') {
                   21717:                                     $display = &mt('unlimited');
                   21718:                                 } elsif ($timeout eq '') {
                   21719:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   21720:                                 } else {
                   21721:                                     $display = &mt('[quant,_1,second]',$timeout);
                   21722:                                 }
                   21723:                                 if ($type eq 'community') {
                   21724:                                     $resulttext .= &mt('Communities');
                   21725:                                 } elsif ($type eq 'official') {
                   21726:                                     $resulttext .= &mt('Official courses');
                   21727:                                 } elsif ($type eq 'unofficial') {
                   21728:                                     $resulttext .= &mt('Unofficial courses');
                   21729:                                 } elsif ($type eq 'textbook') {
                   21730:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  21731:                                 } elsif ($type eq 'placement') {
                   21732:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  21733:                                 }
                   21734:                                 $resulttext .= ' -- '.$display.'</li>';
                   21735:                             }
                   21736:                             $resulttext .= '</ul>';
                   21737:                         }
1.289     raeburn  21738:                         $resulttext .= '</li>';
1.257     raeburn  21739:                     }
1.192     raeburn  21740:                 } elsif ($item eq 'coursecredits') {
                   21741:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   21742:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  21743:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   21744:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  21745:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   21746:                         } else {
                   21747:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   21748:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   21749:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  21750:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  21751:                                            '</ul>'.
                   21752:                                            '</li>';
                   21753:                         }
                   21754:                     } else {
                   21755:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   21756:                     }
1.264     raeburn  21757:                 } elsif ($item eq 'canclone') {
                   21758:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   21759:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   21760:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   21761:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   21762:                         }
                   21763:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   21764:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   21765:                     } else {
1.289     raeburn  21766:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  21767:                     }
1.404     raeburn  21768:                 } elsif ($item eq 'ltiauth') {
                   21769:                     if ($env{'form.'.$item} eq '1') {
                   21770:                         $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
                   21771:                     } else {
                   21772:                         $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
                   21773:                     }
1.432     raeburn  21774:                 } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422     raeburn  21775:                     my @noyes = (&mt('no'),&mt('yes'));
1.432     raeburn  21776:                     my %status = (
                   21777:                                    domexttool => {
                   21778:                                                   ishash => &mt('External Tools defined in the domain may be used as follows:'), 
                   21779:                                                   default => &mt('External Tools defined in the domain may be used in all course types, by default'),
                   21780:                                                  },
                   21781:                                    exttool => {
                   21782:                                                   ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
                   21783:                                                   default => &mt('External Tools can not be defined in any course types, by default'),
                   21784:                                               },
                   21785:                                    crsauthor => {
                   21786:                                                   ishash => &mt('Standard Problems can be created within course containers as follows:'),
                   21787:                                                   default => &mt('Standard Problems can be created within any course type, by default'),
                   21788:                                                 },
                   21789:                                  );
                   21790:                                    
                   21791:                     if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
                   21792:                         $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
                   21793:                                        '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
                   21794:                                        '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
                   21795:                                        '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
                   21796:                                        '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
                   21797:                                        '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422     raeburn  21798:                                        '</ul>'.
                   21799:                                        '</li>';
                   21800:                     } else {
1.432     raeburn  21801:                         $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422     raeburn  21802:                     }
1.438   ! raeburn  21803:                 } elsif ($item eq 'crseditors') {
        !          21804:                     if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
        !          21805:                         my $shown;
        !          21806:                         if (@{$defaultshash{'coursedefaults'}{$item}}) {
        !          21807:                             $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
        !          21808:                         } else {
        !          21809:                             $shown = &mt('None');
        !          21810:                         }
        !          21811:                         $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
        !          21812:                     }
1.140     raeburn  21813:                 }
1.121     raeburn  21814:             }
                   21815:             $resulttext .= '</ul>';
                   21816:         } else {
                   21817:             $resulttext = &mt('No changes made to course defaults');
                   21818:         }
                   21819:     } else {
                   21820:         $resulttext = '<span class="LC_error">'.
                   21821:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   21822:     }
                   21823:     return $resulttext;
                   21824: }
                   21825: 
1.231     raeburn  21826: sub modify_selfenrollment {
                   21827:     my ($dom,$lastactref,%domconfig) = @_;
                   21828:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  21829:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  21830:     my %titles = &tool_titles();
1.232     raeburn  21831:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   21832:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  21833:     $ordered{'default'} = ['types','registered','approval','limit'];
                   21834: 
                   21835:     my (%roles,%shown,%toplevel);
                   21836:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   21837: 
                   21838:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   21839:         if ($domconfig{'selfenrollment'} eq '') {
                   21840:             $domconfig{'selfenrollment'} = {};
                   21841:         }
                   21842:     }
                   21843:     %toplevel = (
                   21844:                   admin      => 'Configuration Rights',
                   21845:                   default    => 'Default settings',
                   21846:                   validation => 'Validation of self-enrollment requests',
                   21847:                 );
1.233     raeburn  21848:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  21849: 
                   21850:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   21851:         foreach my $item (@{$ordered{'admin'}}) {
                   21852:             foreach my $type (@types) {
                   21853:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   21854:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   21855:                 } else {
                   21856:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   21857:                 }
                   21858:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   21859:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   21860:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   21861:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   21862:                             push(@{$changes{'admin'}{$type}},$item);
                   21863:                         }
                   21864:                     } else {
                   21865:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   21866:                             push(@{$changes{'admin'}{$type}},$item);
                   21867:                         }
                   21868:                     }
                   21869:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   21870:                     push(@{$changes{'admin'}{$type}},$item);
                   21871:                 }
                   21872:             }
                   21873:         }
                   21874:     }
                   21875: 
                   21876:     foreach my $item (@{$ordered{'default'}}) {
                   21877:         foreach my $type (@types) {
                   21878:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   21879:             if ($item eq 'types') {
                   21880:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   21881:                     $value = '';
                   21882:                 }
                   21883:             } elsif ($item eq 'registered') {
                   21884:                 unless ($value eq '1') {
                   21885:                     $value = 0;
                   21886:                 }
                   21887:             } elsif ($item eq 'approval') {
                   21888:                 unless ($value =~ /^[012]$/) {
                   21889:                     $value = 0;
                   21890:                 }
                   21891:             } else {
                   21892:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   21893:                     $value = 'none';
                   21894:                 }
                   21895:             }
                   21896:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   21897:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   21898:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   21899:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   21900:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   21901:                          push(@{$changes{'default'}{$type}},$item);
                   21902:                     }
                   21903:                 } else {
                   21904:                     push(@{$changes{'default'}{$type}},$item);
                   21905:                 }
                   21906:             } else {
                   21907:                 push(@{$changes{'default'}{$type}},$item);
                   21908:             }
                   21909:             if ($item eq 'limit') {
                   21910:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   21911:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   21912:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   21913:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   21914:                     }
                   21915:                 } else {
                   21916:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   21917:                 }
                   21918:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   21919:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   21920:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   21921:                          push(@{$changes{'default'}{$type}},'cap');
                   21922:                     }
                   21923:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   21924:                     push(@{$changes{'default'}{$type}},'cap');
                   21925:                 }
                   21926:             }
                   21927:         }
                   21928:     }
                   21929: 
                   21930:     foreach my $item (@{$itemsref}) {
                   21931:         if ($item eq 'fields') {
                   21932:             my @changed;
                   21933:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   21934:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   21935:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   21936:             }
                   21937:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   21938:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   21939:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   21940:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   21941:                 } else {
                   21942:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   21943:                 }
                   21944:             } else {
                   21945:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   21946:             }
                   21947:             if (@changed) {
                   21948:                 if ($selfenrollhash{'validation'}{$item}) { 
                   21949:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   21950:                 } else {
                   21951:                     $changes{'validation'}{$item} = &mt('None');
                   21952:                 }
                   21953:             }
                   21954:         } else {
                   21955:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   21956:             if ($item eq 'markup') {
                   21957:                if ($env{'form.selfenroll_validation_'.$item}) {
                   21958:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   21959:                }
                   21960:             }
                   21961:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   21962:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   21963:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   21964:                 }
                   21965:             }
                   21966:         }
                   21967:     }
                   21968: 
                   21969:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   21970:                                              $dom);
                   21971:     if ($putresult eq 'ok') {
                   21972:         if (keys(%changes) > 0) {
                   21973:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   21974:             $resulttext = &mt('Changes made:').'<ul>';
                   21975:             foreach my $key ('admin','default','validation') {
                   21976:                 if (ref($changes{$key}) eq 'HASH') {
                   21977:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   21978:                     if ($key eq 'validation') {
                   21979:                         foreach my $item (@{$itemsref}) {
                   21980:                             if (exists($changes{$key}{$item})) {
                   21981:                                 if ($item eq 'markup') {
                   21982:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   21983:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   21984:                                 } else {  
                   21985:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   21986:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   21987:                                 }
                   21988:                             }
                   21989:                         }
                   21990:                     } else {
                   21991:                         foreach my $type (@types) {
                   21992:                             if ($type eq 'community') {
                   21993:                                 $roles{'1'} = &mt('Community personnel');
                   21994:                             } else {
                   21995:                                 $roles{'1'} = &mt('Course personnel');
                   21996:                             }
                   21997:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  21998:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   21999:                                     if ($key eq 'admin') {
                   22000:                                         my @mgrdc = ();
                   22001:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   22002:                                             foreach my $item (@{$ordered{'admin'}}) {
                   22003:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   22004:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   22005:                                                         push(@mgrdc,$item);
                   22006:                                                     }
                   22007:                                                 }
                   22008:                                             }
                   22009:                                             if (@mgrdc) {
                   22010:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   22011:                                             } else {
                   22012:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   22013:                                             }
                   22014:                                         }
                   22015:                                     } else {
                   22016:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   22017:                                             foreach my $item (@{$ordered{$key}}) {
                   22018:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   22019:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   22020:                                                         $selfenrollhash{$key}{$type}{$item};
                   22021:                                                 }
                   22022:                                             }
                   22023:                                         }
                   22024:                                     }
                   22025:                                 }
1.231     raeburn  22026:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   22027:                                 foreach my $item (@{$ordered{$key}}) {
                   22028:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   22029:                                         $resulttext .= '<li>';
                   22030:                                         if ($key eq 'admin') {
                   22031:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   22032:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   22033:                                         } else {
                   22034:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   22035:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   22036:                                         }
                   22037:                                         $resulttext .= '</li>';
                   22038:                                     }
                   22039:                                 }
                   22040:                                 $resulttext .= '</ul></li>';
                   22041:                             }
                   22042:                         }
                   22043:                         $resulttext .= '</ul></li>'; 
                   22044:                     }
                   22045:                 }
1.305     raeburn  22046:             }
                   22047:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   22048:                 my $cachetime = 24*60*60;
                   22049:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   22050:                 if (ref($lastactref) eq 'HASH') {
                   22051:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  22052:                 }
1.231     raeburn  22053:             }
                   22054:             $resulttext .= '</ul>';
                   22055:         } else {
                   22056:             $resulttext = &mt('No changes made to self-enrollment settings');
                   22057:         }
                   22058:     } else {
                   22059:         $resulttext = '<span class="LC_error">'.
                   22060:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   22061:     }
                   22062:     return $resulttext;
                   22063: }
                   22064: 
1.373     raeburn  22065: sub modify_wafproxy {
                   22066:     my ($dom,$action,$lastactref,%domconfig) = @_;
                   22067:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  22068:     my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
                   22069:         %wafproxy,%changes,%expirecache,%expiresaml);
1.373     raeburn  22070:     foreach my $server (sort(keys(%servers))) {
                   22071:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   22072:         if ($serverhome eq $server) {
                   22073:             my $serverdom = &Apache::lonnet::host_domain($server);
                   22074:             if ($serverdom eq $dom) {
                   22075:                 $canset{$server} = 1;
                   22076:             }
                   22077:         }
                   22078:     }
1.381     raeburn  22079:     if (ref($domconfig{'wafproxy'}) eq 'HASH') {
                   22080:         %{$values{$dom}} = ();
                   22081:         if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
                   22082:             %curralias = %{$domconfig{'wafproxy'}{'alias'}};
                   22083:         }
1.388     raeburn  22084:         if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
                   22085:             %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
                   22086:         }
1.382     raeburn  22087:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381     raeburn  22088:             $currvalue{$item} = $domconfig{'wafproxy'}{$item};
                   22089:         }
                   22090:     }
1.373     raeburn  22091:     my $output;
                   22092:     if (keys(%canset)) {
                   22093:         %{$wafproxy{'alias'}} = ();
1.388     raeburn  22094:         %{$wafproxy{'saml'}} = ();
1.373     raeburn  22095:         foreach my $key (sort(keys(%canset))) {
1.381     raeburn  22096:             if ($env{'form.wafproxy_'.$dom}) {
                   22097:                 $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
                   22098:                 $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
                   22099:                 if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
                   22100:                     $changes{'alias'} = 1;
                   22101:                 }
1.388     raeburn  22102:                 if ($env{'form.wafproxy_alias_saml_'.$key}) {
                   22103:                     $wafproxy{'saml'}{$key} = 1;
                   22104:                 }
                   22105:                 if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
                   22106:                     $changes{'saml'} = 1;
                   22107:                 }
1.381     raeburn  22108:             } else {
                   22109:                 $wafproxy{'alias'}{$key} = '';
1.388     raeburn  22110:                 $wafproxy{'saml'}{$key} = '';
1.381     raeburn  22111:                 if ($curralias{$key}) {
                   22112:                     $changes{'alias'} = 1;
                   22113:                 }
1.388     raeburn  22114:                 if ($currsaml{$key}) {
                   22115:                     $changes{'saml'} = 1;
                   22116:                 }
1.373     raeburn  22117:             }
                   22118:             if ($wafproxy{'alias'}{$key} eq '') {
                   22119:                 if ($curralias{$key}) {
                   22120:                     $expirecache{$key} = 1;
                   22121:                 }
                   22122:                 delete($wafproxy{'alias'}{$key});
                   22123:             }
1.388     raeburn  22124:             if ($wafproxy{'saml'}{$key} eq '') {
                   22125:                 if ($currsaml{$key}) {
                   22126:                     $expiresaml{$key} = 1;
                   22127:                 }
                   22128:                 delete($wafproxy{'saml'}{$key});
                   22129:             }
1.373     raeburn  22130:         }
                   22131:         unless (keys(%{$wafproxy{'alias'}})) {
                   22132:             delete($wafproxy{'alias'});
                   22133:         }
1.388     raeburn  22134:         unless (keys(%{$wafproxy{'saml'}})) {
                   22135:             delete($wafproxy{'saml'});
                   22136:         }
                   22137:         # Localization for values in %warn occurs in &mt() calls separately.
1.373     raeburn  22138:         my %warn = (
                   22139:                      trusted => 'trusted IP range(s)',
1.381     raeburn  22140:                      vpnint => 'internal IP range(s) for VPN sessions(s)',
                   22141:                      vpnext => 'IP range(s) for backend WAF connections',
1.373     raeburn  22142:                    );
1.382     raeburn  22143:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  22144:             my $possible = $env{'form.wafproxy_'.$item};
                   22145:             $possible =~ s/^\s+|\s+$//g;
                   22146:             if ($possible ne '') {
1.381     raeburn  22147:                 if ($item eq 'remoteip') {
                   22148:                     if ($possible =~ /^[mhn]$/) {
                   22149:                         $wafproxy{$item} = $possible;
                   22150:                     }
                   22151:                 } elsif ($item eq 'ipheader') {
                   22152:                     if ($wafproxy{'remoteip'} eq 'h') {
                   22153:                         $wafproxy{$item} = $possible;
                   22154:                     }
1.382     raeburn  22155:                 } elsif ($item eq 'sslopt') {
                   22156:                     if ($possible =~ /^0|1$/) {
                   22157:                         $wafproxy{$item} = $possible;
                   22158:                     }
1.373     raeburn  22159:                 } else {
                   22160:                     my (@ok,$count);
1.381     raeburn  22161:                     if (($item eq 'vpnint') || ($item eq 'vpnext')) {
                   22162:                         unless ($env{'form.wafproxy_vpnaccess'}) {
                   22163:                             $possible = '';
                   22164:                         }
                   22165:                     } elsif ($item eq 'trusted') {
                   22166:                         unless ($wafproxy{'remoteip'} eq 'h') {
                   22167:                             $possible = '';
                   22168:                         }
                   22169:                     }
                   22170:                     unless ($possible eq '') {
                   22171:                         $possible =~ s/[\r\n]+/\s/g;
                   22172:                         $possible =~ s/\s*-\s*/-/g;
                   22173:                         $possible =~ s/\s+/,/g;
1.393     raeburn  22174:                         $possible =~ s/,+/,/g;
1.381     raeburn  22175:                     }
1.373     raeburn  22176:                     $count = 0;
1.381     raeburn  22177:                     if ($possible ne '') {
1.373     raeburn  22178:                         foreach my $poss (split(/\,/,$possible)) {
                   22179:                             $count ++;
1.393     raeburn  22180:                             $poss = &validate_ip_pattern($poss);
                   22181:                             if ($poss ne '') {
1.373     raeburn  22182:                                 push(@ok,$poss);
                   22183:                             }
                   22184:                         }
                   22185:                         my $diff = $count - scalar(@ok);
                   22186:                         if ($diff) {
                   22187:                             push(@warnings,'<li>'.
                   22188:                                  &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
                   22189:                                      $diff,$warn{$item}).
                   22190:                                  '</li>');
                   22191:                         }
1.393     raeburn  22192:                         if (@ok) {
                   22193:                             my @cidr_list;
                   22194:                             foreach my $item (@ok) {
                   22195:                                 @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   22196:                             }
                   22197:                             $wafproxy{$item} = join(',',@cidr_list);
                   22198:                         }
1.373     raeburn  22199:                     }
                   22200:                 }
1.381     raeburn  22201:                 if ($wafproxy{$item} ne $currvalue{$item}) {
1.373     raeburn  22202:                     $changes{$item} = 1;
                   22203:                 }
1.381     raeburn  22204:             } elsif ($currvalue{$item}) {
                   22205:                 $changes{$item} = 1;
1.425     raeburn  22206:             }
1.381     raeburn  22207:         }
                   22208:     } else {
                   22209:         if (keys(%curralias)) {
                   22210:             $changes{'alias'} = 1;
1.388     raeburn  22211:         }
                   22212:         if (keys(%currsaml)) {
                   22213:             $changes{'saml'} = 1;
1.425     raeburn  22214:         }
1.381     raeburn  22215:         if (keys(%currvalue)) {
                   22216:             foreach my $key (keys(%currvalue)) {
                   22217:                 $changes{$key} = 1;
1.373     raeburn  22218:             }
                   22219:         }
                   22220:     }
                   22221:     if (keys(%changes)) {
                   22222:         my %defaultshash = (
                   22223:                               wafproxy => \%wafproxy,
1.425     raeburn  22224:                            );
1.373     raeburn  22225:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22226:                                                  $dom);
                   22227:         if ($putresult eq 'ok') {
                   22228:             my $cachetime = 24*60*60;
                   22229:             my (%domdefaults,$updatedomdefs);
1.382     raeburn  22230:             foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  22231:                 if ($changes{$item}) {
                   22232:                     unless ($updatedomdefs) {
                   22233:                         %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   22234:                         $updatedomdefs = 1;
                   22235:                     }
                   22236:                     if ($wafproxy{$item}) {
                   22237:                         $domdefaults{'waf_'.$item} = $wafproxy{$item};
                   22238:                     } elsif (exists($domdefaults{'waf_'.$item})) {
                   22239:                         delete($domdefaults{'waf_'.$item});
1.425     raeburn  22240:                     }
1.373     raeburn  22241:                 }
                   22242:             }
                   22243:             if ($updatedomdefs) {
                   22244:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   22245:                 if (ref($lastactref) eq 'HASH') {
                   22246:                     $lastactref->{'domdefaults'} = 1;
                   22247:                 }
                   22248:             }
                   22249:             if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
                   22250:                 my %updates = %expirecache;
                   22251:                 foreach my $key (keys(%expirecache)) {
                   22252:                     &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
                   22253:                 }
                   22254:                 if (ref($wafproxy{'alias'}) eq 'HASH') {
                   22255:                     my $cachetime = 24*60*60;
                   22256:                     foreach my $key (keys(%{$wafproxy{'alias'}})) {
                   22257:                         $updates{$key} = 1;
                   22258:                         &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
                   22259:                                                       $cachetime);
                   22260:                     }
                   22261:                 }
                   22262:                 if (ref($lastactref) eq 'HASH') {
                   22263:                     $lastactref->{'proxyalias'} = \%updates;
                   22264:                 }
                   22265:             }
1.388     raeburn  22266:             if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
                   22267:                 my %samlupdates = %expiresaml;
                   22268:                 foreach my $key (keys(%expiresaml)) {
                   22269:                     &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
                   22270:                 }
                   22271:                 if (ref($wafproxy{'saml'}) eq 'HASH') {
                   22272:                     my $cachetime = 24*60*60;
                   22273:                     foreach my $key (keys(%{$wafproxy{'saml'}})) {
                   22274:                         $samlupdates{$key} = 1;
                   22275:                         &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
                   22276:                                                       $cachetime);
                   22277:                     }
                   22278:                 }
                   22279:                 if (ref($lastactref) eq 'HASH') {
                   22280:                     $lastactref->{'proxysaml'} = \%samlupdates;
                   22281:                 }
                   22282:             }
1.373     raeburn  22283:             $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401     raeburn  22284:             foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  22285:                 if ($changes{$item}) {
                   22286:                     if ($item eq 'alias') {
                   22287:                         my $numaliased = 0;
                   22288:                         if (ref($wafproxy{'alias'}) eq 'HASH') {
                   22289:                             my $shown;
                   22290:                             if (keys(%{$wafproxy{'alias'}})) {
                   22291:                                 foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
                   22292:                                     $shown .= '<li>'.&mt('[_1] aliased by [_2]',
                   22293:                                                          &Apache::lonnet::hostname($server),
                   22294:                                                          $wafproxy{'alias'}{$server}).'</li>';
                   22295:                                     $numaliased ++;
                   22296:                                 }
                   22297:                                 if ($numaliased) {
                   22298:                                     $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
                   22299:                                                           '<ul>'.$shown.'</ul>').'</li>';
                   22300:                                 }
                   22301:                             }
                   22302:                         }
                   22303:                         unless ($numaliased) {
                   22304:                             $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
                   22305:                         }
1.388     raeburn  22306:                     } elsif ($item eq 'saml') {
1.425     raeburn  22307:                         my $shown;
1.388     raeburn  22308:                         if (ref($wafproxy{'saml'}) eq 'HASH') {
                   22309:                             if (keys(%{$wafproxy{'saml'}})) {
                   22310:                                 $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
                   22311:                             }
                   22312:                         }
                   22313:                         if ($shown) {
1.396     raeburn  22314:                             $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388     raeburn  22315:                                                   $shown).'</li>';
                   22316:                         } else {
1.396     raeburn  22317:                             $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388     raeburn  22318:                         }
1.373     raeburn  22319:                     } else {
1.381     raeburn  22320:                         if ($item eq 'remoteip') {
                   22321:                             my %ip_methods = &remoteip_methods();
                   22322:                             if ($wafproxy{$item} =~ /^[mh]$/) {
                   22323:                                 $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
                   22324:                                                       $ip_methods{$wafproxy{$item}}).'</li>';
                   22325:                             } else {
                   22326:                                 if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
                   22327:                                     $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
                   22328:                                                '</li>';
                   22329:                                 } else {
                   22330:                                     $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
                   22331:                                 }
                   22332:                             }
                   22333:                         } elsif ($item eq 'ipheader') {
1.373     raeburn  22334:                             if ($wafproxy{$item}) {
1.381     raeburn  22335:                                 $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373     raeburn  22336:                                                       $wafproxy{$item}).'</li>';
                   22337:                             } else {
1.381     raeburn  22338:                                 $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373     raeburn  22339:                             }
                   22340:                         } elsif ($item eq 'trusted') {
                   22341:                             if ($wafproxy{$item}) {
1.381     raeburn  22342:                                 $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373     raeburn  22343:                                                       $wafproxy{$item}).'</li>';
                   22344:                             } else {
                   22345:                                 $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
                   22346:                             }
1.381     raeburn  22347:                         } elsif ($item eq 'vpnint') {
                   22348:                             if ($wafproxy{$item}) {
                   22349:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
                   22350:                                                        $wafproxy{$item}).'</li>';
                   22351:                             } else {
                   22352:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
                   22353:                             }
                   22354:                         } elsif ($item eq 'vpnext') {
1.373     raeburn  22355:                             if ($wafproxy{$item}) {
1.381     raeburn  22356:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373     raeburn  22357:                                                        $wafproxy{$item}).'</li>';
                   22358:                             } else {
1.381     raeburn  22359:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373     raeburn  22360:                             }
1.382     raeburn  22361:                         } elsif ($item eq 'sslopt') {
                   22362:                             if ($wafproxy{$item}) {
                   22363:                                 $output .= '<li>'.&mt('WAF/Reverse Proxy expected to forward requests to https on LON-CAPA node, regardless of original protocol in web browser (http or https).').'</li>';
                   22364:                             } else {
                   22365:                                 $output .= '<li>'.&mt('WAF/Reverse Proxy expected to preserve original protocol in web browser (either http or https) when forwarding to LON-CAPA node.').'</li>';
                   22366:                             }
1.373     raeburn  22367:                         }
                   22368:                     }
                   22369:                 }
                   22370:             }
1.420     raeburn  22371:             $output .= '</ul>';
1.373     raeburn  22372:         } else {
                   22373:             $output = '<span class="LC_error">'.
                   22374:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   22375:         }
                   22376:     } elsif (keys(%canset)) {
                   22377:         $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
                   22378:     }
                   22379:     if (@warnings) {
                   22380:         $output .= '<br />'.&mt('Warnings:').'<ul>'.
                   22381:                        join("\n",@warnings).'</ul>';
                   22382:     }
                   22383:     return $output;
                   22384: }
                   22385: 
                   22386: sub validate_ip_pattern {
                   22387:     my ($pattern) = @_;
                   22388:     if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
                   22389:         my ($start,$end) = ($1,$2);
                   22390:         if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393     raeburn  22391:             if (($start !~ m{/}) && ($end !~ m{/})) {
                   22392:                 return $start.'-'.$end;
                   22393:             }
                   22394:         }
                   22395:     } elsif ($pattern ne '') {
                   22396:         $pattern = &Net::CIDR::cidrvalidate($pattern);
                   22397:         if ($pattern ne '') {
                   22398:             return $pattern;
1.373     raeburn  22399:         }
                   22400:     }
1.393     raeburn  22401:     return;
1.373     raeburn  22402: }
                   22403: 
1.137     raeburn  22404: sub modify_usersessions {
1.212     raeburn  22405:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  22406:     my @hostingtypes = ('version','excludedomain','includedomain');
                   22407:     my @offloadtypes = ('primary','default');
                   22408:     my %types = (
                   22409:                   remote => \@hostingtypes,
                   22410:                   hosted => \@hostingtypes,
                   22411:                   spares => \@offloadtypes,
                   22412:                 );
                   22413:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  22414:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  22415:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   22416:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  22417:     my @locations = sort(keys(%by_location));
1.137     raeburn  22418:     my (%defaultshash,%changes);
                   22419:     foreach my $prefix (@prefixes) {
                   22420:         $defaultshash{'usersessions'}{$prefix} = {};
                   22421:     }
1.212     raeburn  22422:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  22423:     my $resulttext;
1.138     raeburn  22424:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  22425:     foreach my $prefix (@prefixes) {
1.145     raeburn  22426:         next if ($prefix eq 'spares');
                   22427:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  22428:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   22429:             if ($type eq 'version') {
                   22430:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   22431:                 my $okvalue;
                   22432:                 if ($value ne '') {
                   22433:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   22434:                         $okvalue = $value;
                   22435:                     }
                   22436:                 }
                   22437:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   22438:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   22439:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   22440:                             if ($inuse == 0) {
                   22441:                                 $changes{$prefix}{$type} = 1;
                   22442:                             } else {
                   22443:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   22444:                                     $changes{$prefix}{$type} = 1;
                   22445:                                 }
                   22446:                                 if ($okvalue ne '') {
                   22447:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22448:                                 } 
                   22449:                             }
                   22450:                         } else {
                   22451:                             if (($inuse == 1) && ($okvalue ne '')) {
                   22452:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22453:                                 $changes{$prefix}{$type} = 1;
                   22454:                             }
                   22455:                         }
                   22456:                     } else {
                   22457:                         if (($inuse == 1) && ($okvalue ne '')) {
                   22458:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22459:                             $changes{$prefix}{$type} = 1;
                   22460:                         }
                   22461:                     }
                   22462:                 } else {
                   22463:                     if (($inuse == 1) && ($okvalue ne '')) {
                   22464:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22465:                         $changes{$prefix}{$type} = 1;
                   22466:                     }
                   22467:                 }
                   22468:             } else {
                   22469:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   22470:                 my @okvals;
                   22471:                 foreach my $val (@vals) {
1.138     raeburn  22472:                     if ($val =~ /:/) {
                   22473:                         my @items = split(/:/,$val);
                   22474:                         foreach my $item (@items) {
                   22475:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   22476:                                 push(@okvals,$item);
                   22477:                             }
                   22478:                         }
                   22479:                     } else {
                   22480:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   22481:                             push(@okvals,$val);
                   22482:                         }
1.137     raeburn  22483:                     }
                   22484:                 }
                   22485:                 @okvals = sort(@okvals);
                   22486:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   22487:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   22488:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   22489:                             if ($inuse == 0) {
                   22490:                                 $changes{$prefix}{$type} = 1; 
                   22491:                             } else {
                   22492:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22493:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   22494:                                 if (@changed > 0) {
                   22495:                                     $changes{$prefix}{$type} = 1;
                   22496:                                 }
                   22497:                             }
                   22498:                         } else {
                   22499:                             if ($inuse == 1) {
                   22500:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22501:                                 $changes{$prefix}{$type} = 1;
                   22502:                             }
                   22503:                         } 
                   22504:                     } else {
                   22505:                         if ($inuse == 1) {
                   22506:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22507:                             $changes{$prefix}{$type} = 1;
                   22508:                         }
                   22509:                     }
                   22510:                 } else {
                   22511:                     if ($inuse == 1) {
                   22512:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22513:                         $changes{$prefix}{$type} = 1;
                   22514:                     }
                   22515:                 }
                   22516:             }
                   22517:         }
                   22518:     }
1.145     raeburn  22519: 
                   22520:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  22521:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  22522:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   22523:     my $savespares;
                   22524: 
                   22525:     foreach my $lonhost (sort(keys(%servers))) {
                   22526:         my $serverhomeID =
                   22527:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  22528:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  22529:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   22530:         my %spareschg;
                   22531:         foreach my $type (@{$types{'spares'}}) {
                   22532:             my @okspares;
                   22533:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   22534:             foreach my $server (@checked) {
1.152     raeburn  22535:                 if (&Apache::lonnet::hostname($server) ne '') {
                   22536:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   22537:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   22538:                             push(@okspares,$server);
                   22539:                         }
1.145     raeburn  22540:                     }
                   22541:                 }
                   22542:             }
                   22543:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   22544:             my $newspare;
1.152     raeburn  22545:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   22546:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  22547:                     $newspare = $new;
                   22548:                 }
                   22549:             }
1.152     raeburn  22550:             my @spares;
                   22551:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   22552:                 @spares = sort(@okspares,$newspare);
                   22553:             } else {
                   22554:                 @spares = sort(@okspares);
                   22555:             }
                   22556:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  22557:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   22558:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  22559:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  22560:                     if (@diffs > 0) {
                   22561:                         $spareschg{$type} = 1;
                   22562:                     }
                   22563:                 }
                   22564:             }
                   22565:         }
                   22566:         if (keys(%spareschg) > 0) {
                   22567:             $changes{'spares'}{$lonhost} = \%spareschg;
                   22568:         }
                   22569:     }
1.261     raeburn  22570:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371     raeburn  22571:     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261     raeburn  22572:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   22573:     my @okoffload;
                   22574:     if (@offloadnow) {
                   22575:         foreach my $server (@offloadnow) {
                   22576:             if (&Apache::lonnet::hostname($server) ne '') {
                   22577:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   22578:                     push(@okoffload,$server);
                   22579:                 }
                   22580:             }
                   22581:         }
                   22582:         if (@okoffload) {
                   22583:             foreach my $lonhost (@okoffload) {
                   22584:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   22585:             }
                   22586:         }
                   22587:     }
1.371     raeburn  22588:     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   22589:     my @okoffloadoth;
                   22590:     if (@offloadoth) {
                   22591:         foreach my $server (@offloadoth) {
                   22592:             if (&Apache::lonnet::hostname($server) ne '') {
                   22593:                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   22594:                     push(@okoffloadoth,$server);
                   22595:                 }
                   22596:             }
                   22597:         }
                   22598:         if (@okoffloadoth) {
                   22599:             foreach my $lonhost (@okoffloadoth) {
                   22600:                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   22601:             }
                   22602:         }
                   22603:     }
1.145     raeburn  22604:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   22605:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   22606:             if (ref($changes{'spares'}) eq 'HASH') {
                   22607:                 if (keys(%{$changes{'spares'}}) > 0) {
                   22608:                     $savespares = 1;
                   22609:                 }
                   22610:             }
                   22611:         } else {
                   22612:             $savespares = 1;
                   22613:         }
1.371     raeburn  22614:         foreach my $offload ('offloadnow','offloadoth') {
                   22615:             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   22616:                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   22617:                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   22618:                         $changes{$offload} = 1;
                   22619:                         last;
                   22620:                     }
1.261     raeburn  22621:                 }
1.371     raeburn  22622:                 unless ($changes{$offload}) {
                   22623:                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   22624:                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   22625:                             $changes{$offload} = 1;
                   22626:                             last;
                   22627:                         }
1.261     raeburn  22628:                     }
                   22629:                 }
1.371     raeburn  22630:             } else {
                   22631:                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   22632:                      $changes{'offloadnow'} = 1;
                   22633:                 }
                   22634:                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   22635:                     $changes{'offloadoth'} = 1;
                   22636:                 }
1.425     raeburn  22637:             }
1.371     raeburn  22638:         }
                   22639:     } else {
                   22640:         if (@okoffload) {
1.261     raeburn  22641:             $changes{'offloadnow'} = 1;
                   22642:         }
1.371     raeburn  22643:         if (@okoffloadoth) {
                   22644:             $changes{'offloadoth'} = 1;
                   22645:         }
1.145     raeburn  22646:     }
1.147     raeburn  22647:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   22648:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  22649:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22650:                                                  $dom);
                   22651:         if ($putresult eq 'ok') {
                   22652:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   22653:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   22654:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   22655:                 }
                   22656:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   22657:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   22658:                 }
1.261     raeburn  22659:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   22660:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   22661:                 }
1.371     raeburn  22662:                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   22663:                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   22664:                 }
1.137     raeburn  22665:             }
                   22666:             my $cachetime = 24*60*60;
                   22667:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  22668:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  22669:             if (ref($lastactref) eq 'HASH') {
                   22670:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  22671:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  22672:             }
1.147     raeburn  22673:             if (keys(%changes) > 0) {
                   22674:                 my %lt = &usersession_titles();
                   22675:                 $resulttext = &mt('Changes made:').'<ul>';
                   22676:                 foreach my $prefix (@prefixes) {
                   22677:                     if (ref($changes{$prefix}) eq 'HASH') {
                   22678:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   22679:                         if ($prefix eq 'spares') {
                   22680:                             if (ref($changes{$prefix}) eq 'HASH') {
                   22681:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   22682:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  22683:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  22684:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   22685:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  22686:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   22687:                                         foreach my $type (@{$types{$prefix}}) {
                   22688:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   22689:                                                 my $offloadto = &mt('None');
                   22690:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   22691:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   22692:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   22693:                                                     }
1.145     raeburn  22694:                                                 }
1.147     raeburn  22695:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  22696:                                             }
1.137     raeburn  22697:                                         }
                   22698:                                     }
1.147     raeburn  22699:                                     $resulttext .= '</li>';
1.137     raeburn  22700:                                 }
                   22701:                             }
1.147     raeburn  22702:                         } else {
                   22703:                             foreach my $type (@{$types{$prefix}}) {
                   22704:                                 if (defined($changes{$prefix}{$type})) {
1.344     raeburn  22705:                                     my ($newvalue,$notinuse);
1.147     raeburn  22706:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   22707:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   22708:                                             if ($type eq 'version') {
                   22709:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344     raeburn  22710:                                             } else {
                   22711:                                                 if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   22712:                                                     if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   22713:                                                         $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   22714:                                                     }
                   22715:                                                 } else {
                   22716:                                                     $notinuse = 1;
1.147     raeburn  22717:                                                 }
1.145     raeburn  22718:                                             }
                   22719:                                         }
                   22720:                                     }
1.147     raeburn  22721:                                     if ($newvalue eq '') {
                   22722:                                         if ($type eq 'version') {
                   22723:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344     raeburn  22724:                                         } elsif ($notinuse) {
                   22725:                                             $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147     raeburn  22726:                                         } else {
                   22727:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   22728:                                         }
1.145     raeburn  22729:                                     } else {
1.147     raeburn  22730:                                         if ($type eq 'version') {
1.344     raeburn  22731:                                             $newvalue .= ' '.&mt('(or later)');
1.147     raeburn  22732:                                         }
                   22733:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  22734:                                     }
1.137     raeburn  22735:                                 }
                   22736:                             }
                   22737:                         }
1.147     raeburn  22738:                         $resulttext .= '</ul>';
1.137     raeburn  22739:                     }
                   22740:                 }
1.261     raeburn  22741:                 if ($changes{'offloadnow'}) {
                   22742:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   22743:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371     raeburn  22744:                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261     raeburn  22745:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   22746:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   22747:                             }
                   22748:                             $resulttext .= '</ul>';
                   22749:                         } else {
1.371     raeburn  22750:                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   22751:                         }
                   22752:                     } else {
                   22753:                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   22754:                     }
                   22755:                 }
                   22756:                 if ($changes{'offloadoth'}) {
                   22757:                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   22758:                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   22759:                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   22760:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   22761:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   22762:                             }
                   22763:                             $resulttext .= '</ul>';
                   22764:                         } else {
                   22765:                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261     raeburn  22766:                         }
                   22767:                     } else {
1.371     raeburn  22768:                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261     raeburn  22769:                     }
                   22770:                 }
1.147     raeburn  22771:                 $resulttext .= '</ul>';
                   22772:             } else {
                   22773:                 $resulttext = $nochgmsg;
1.137     raeburn  22774:             }
                   22775:         } else {
                   22776:             $resulttext = '<span class="LC_error">'.
                   22777:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   22778:         }
                   22779:     } else {
1.147     raeburn  22780:         $resulttext = $nochgmsg;
1.137     raeburn  22781:     }
                   22782:     return $resulttext;
                   22783: }
                   22784: 
1.275     raeburn  22785: sub modify_ssl {
                   22786:     my ($dom,$lastactref,%domconfig) = @_;
                   22787:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   22788:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   22789:     my @locations = sort(keys(%by_location));
                   22790:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   22791:     my (%defaultshash,%changes);
                   22792:     my $action = 'ssl';
1.293     raeburn  22793:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  22794:     foreach my $prefix (@prefixes) {
                   22795:         $defaultshash{$action}{$prefix} = {};
                   22796:     }
                   22797:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   22798:     my $resulttext;
                   22799:     my %iphost = &Apache::lonnet::get_iphost();
                   22800:     my @reptypes = ('certreq','nocertreq');
                   22801:     my @connecttypes = ('dom','intdom','other');
                   22802:     my %types = (
1.293     raeburn  22803:                   connto      => \@connecttypes,
                   22804:                   connfrom    => \@connecttypes,
                   22805:                   replication => \@reptypes,
1.275     raeburn  22806:                 );
                   22807:     foreach my $prefix (sort(keys(%types))) {
                   22808:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  22809:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  22810:                 my $value = 'yes';
                   22811:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   22812:                     $value = $env{'form.'.$prefix.'_'.$type};
                   22813:                 }
1.335     raeburn  22814:                 if (ref($domconfig{$action}) eq 'HASH') {
                   22815:                     if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   22816:                         if ($domconfig{$action}{$prefix}{$type} ne '') {
                   22817:                             if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   22818:                                 $changes{$prefix}{$type} = 1;
                   22819:                             }
                   22820:                             $defaultshash{$action}{$prefix}{$type} = $value;
                   22821:                         } else {
                   22822:                             $defaultshash{$action}{$prefix}{$type} = $value;
1.275     raeburn  22823:                             $changes{$prefix}{$type} = 1;
                   22824:                         }
                   22825:                     } else {
                   22826:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   22827:                         $changes{$prefix}{$type} = 1;
                   22828:                     }
                   22829:                 } else {
                   22830:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   22831:                     $changes{$prefix}{$type} = 1;
                   22832:                 }
                   22833:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   22834:                     delete($changes{$prefix}{$type});
                   22835:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   22836:                     delete($changes{$prefix}{$type});
                   22837:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   22838:                     delete($changes{$prefix}{$type});
                   22839:                 }
                   22840:             } elsif ($prefix eq 'replication') {
                   22841:                 if (@locations > 0) {
                   22842:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   22843:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   22844:                     my @okvals;
                   22845:                     foreach my $val (@vals) {
                   22846:                         if ($val =~ /:/) {
                   22847:                             my @items = split(/:/,$val);
                   22848:                             foreach my $item (@items) {
                   22849:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   22850:                                     push(@okvals,$item);
                   22851:                                 }
                   22852:                             }
                   22853:                         } else {
                   22854:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   22855:                                 push(@okvals,$val);
                   22856:                             }
                   22857:                         }
                   22858:                     }
                   22859:                     @okvals = sort(@okvals);
                   22860:                     if (ref($domconfig{$action}) eq 'HASH') {
                   22861:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   22862:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   22863:                                 if ($inuse == 0) {
                   22864:                                     $changes{$prefix}{$type} = 1;
                   22865:                                 } else {
                   22866:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22867:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   22868:                                     if (@changed > 0) {
                   22869:                                         $changes{$prefix}{$type} = 1;
                   22870:                                     }
                   22871:                                 }
                   22872:                             } else {
                   22873:                                 if ($inuse == 1) {
                   22874:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22875:                                     $changes{$prefix}{$type} = 1;
                   22876:                                 }
                   22877:                             }
                   22878:                         } else {
                   22879:                             if ($inuse == 1) {
                   22880:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22881:                                 $changes{$prefix}{$type} = 1;
                   22882:                             }
                   22883:                         }
                   22884:                     } else {
                   22885:                         if ($inuse == 1) {
                   22886:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22887:                             $changes{$prefix}{$type} = 1;
                   22888:                         }
                   22889:                     }
                   22890:                 }
                   22891:             }
                   22892:         }
                   22893:     }
1.336     raeburn  22894:     if (keys(%changes)) {
                   22895:         foreach my $prefix (keys(%changes)) {
                   22896:             if (ref($changes{$prefix}) eq 'HASH') {
                   22897:                 if (scalar(keys(%{$changes{$prefix}})) == 0) {
                   22898:                     delete($changes{$prefix});
                   22899:                 }
                   22900:             } else {
                   22901:                 delete($changes{$prefix});
                   22902:             }
                   22903:         }
                   22904:     }
1.275     raeburn  22905:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   22906:     if (keys(%changes) > 0) {
                   22907:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22908:                                                  $dom);
                   22909:         if ($putresult eq 'ok') {
                   22910:             if (ref($defaultshash{$action}) eq 'HASH') {
                   22911:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   22912:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   22913:                 }
1.293     raeburn  22914:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335     raeburn  22915:                     $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293     raeburn  22916:                 }
                   22917:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335     raeburn  22918:                     $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275     raeburn  22919:                 }
                   22920:             }
                   22921:             my $cachetime = 24*60*60;
                   22922:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   22923:             if (ref($lastactref) eq 'HASH') {
                   22924:                 $lastactref->{'domdefaults'} = 1;
                   22925:             }
                   22926:             if (keys(%changes) > 0) {
                   22927:                 my %titles = &ssl_titles();
                   22928:                 $resulttext = &mt('Changes made:').'<ul>';
                   22929:                 foreach my $prefix (@prefixes) {
                   22930:                     if (ref($changes{$prefix}) eq 'HASH') {
                   22931:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   22932:                         foreach my $type (@{$types{$prefix}}) {
                   22933:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  22934:                                 my ($newvalue,$notinuse);
1.275     raeburn  22935:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   22936:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  22937:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  22938:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344     raeburn  22939:                                         } else {
                   22940:                                             if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   22941:                                                 if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   22942:                                                     $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   22943:                                                 }
                   22944:                                             } else {
                   22945:                                                 $notinuse = 1;
1.275     raeburn  22946:                                             }
                   22947:                                         }
                   22948:                                     }
1.344     raeburn  22949:                                     if ($notinuse) {
                   22950:                                         $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                   22951:                                     } elsif ($newvalue eq '') {
1.275     raeburn  22952:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   22953:                                     } else {
                   22954:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   22955:                                     }
                   22956:                                 }
                   22957:                             }
                   22958:                         }
                   22959:                         $resulttext .= '</ul>';
                   22960:                     }
                   22961:                 }
                   22962:             } else {
                   22963:                 $resulttext = $nochgmsg;
                   22964:             }
                   22965:         } else {
                   22966:             $resulttext = '<span class="LC_error">'.
                   22967:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   22968:         }
                   22969:     } else {
                   22970:         $resulttext = $nochgmsg;
                   22971:     }
                   22972:     return $resulttext;
                   22973: }
                   22974: 
1.279     raeburn  22975: sub modify_trust {
                   22976:     my ($dom,$lastactref,%domconfig) = @_;
                   22977:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   22978:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   22979:     my @locations = sort(keys(%by_location));
                   22980:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   22981:     my @types = ('exc','inc');
                   22982:     my (%defaultshash,%changes);
                   22983:     foreach my $prefix (@prefixes) {
                   22984:         $defaultshash{'trust'}{$prefix} = {};
                   22985:     }
                   22986:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   22987:     my $resulttext;
                   22988:     foreach my $prefix (@prefixes) {
                   22989:         foreach my $type (@types) {
                   22990:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   22991:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   22992:             my @okvals;
                   22993:             foreach my $val (@vals) {
                   22994:                 if ($val =~ /:/) {
                   22995:                     my @items = split(/:/,$val);
                   22996:                     foreach my $item (@items) {
                   22997:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   22998:                             push(@okvals,$item);
                   22999:                         }
                   23000:                     }
                   23001:                 } else {
                   23002:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   23003:                         push(@okvals,$val);
                   23004:                     }
                   23005:                 }
                   23006:             }
                   23007:             @okvals = sort(@okvals);
                   23008:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   23009:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   23010:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   23011:                         if ($inuse == 0) {
                   23012:                             $changes{$prefix}{$type} = 1;
                   23013:                         } else {
                   23014:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   23015:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   23016:                             if (@changed > 0) {
                   23017:                                 $changes{$prefix}{$type} = 1;
                   23018:                             }
                   23019:                         }
                   23020:                     } else {
                   23021:                         if ($inuse == 1) {
                   23022:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   23023:                             $changes{$prefix}{$type} = 1;
                   23024:                         }
                   23025:                     }
                   23026:                 } else {
                   23027:                     if ($inuse == 1) {
                   23028:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   23029:                         $changes{$prefix}{$type} = 1;
                   23030:                     }
                   23031:                 }
                   23032:             } else {
                   23033:                 if ($inuse == 1) {
                   23034:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   23035:                     $changes{$prefix}{$type} = 1;
                   23036:                 }
                   23037:             }
                   23038:         }
                   23039:     }
                   23040:     my $nochgmsg = &mt('No changes made to trust settings.');
                   23041:     if (keys(%changes) > 0) {
                   23042:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   23043:                                                  $dom);
                   23044:         if ($putresult eq 'ok') {
                   23045:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   23046:                 foreach my $prefix (@prefixes) {
                   23047:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   23048:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   23049:                     }
                   23050:                 }
                   23051:             }
                   23052:             my $cachetime = 24*60*60;
                   23053:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410     raeburn  23054:             &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279     raeburn  23055:             if (ref($lastactref) eq 'HASH') {
                   23056:                 $lastactref->{'domdefaults'} = 1;
1.410     raeburn  23057:                 $lastactref->{'trust'} = 1;
1.279     raeburn  23058:             }
                   23059:             if (keys(%changes) > 0) {
                   23060:                 my %lt = &trust_titles();
                   23061:                 $resulttext = &mt('Changes made:').'<ul>';
                   23062:                 foreach my $prefix (@prefixes) {
                   23063:                     if (ref($changes{$prefix}) eq 'HASH') {
                   23064:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   23065:                         foreach my $type (@types) {
                   23066:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  23067:                                 my ($newvalue,$notinuse);
1.279     raeburn  23068:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   23069:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   23070:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   23071:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   23072:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   23073:                                             }
1.344     raeburn  23074:                                         } else {
                   23075:                                             $notinuse = 1;
1.279     raeburn  23076:                                         }
                   23077:                                     }
                   23078:                                 }
1.344     raeburn  23079:                                 if ($notinuse) {
                   23080:                                     $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                   23081:                                 } elsif ($newvalue eq '') {
1.279     raeburn  23082:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   23083:                                 } else {
                   23084:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   23085:                                 }
                   23086:                             }
                   23087:                         }
                   23088:                         $resulttext .= '</ul>';
                   23089:                     }
                   23090:                 }
                   23091:                 $resulttext .= '</ul>';
                   23092:             } else {
                   23093:                 $resulttext = $nochgmsg;
                   23094:             }
                   23095:         } else {
                   23096:             $resulttext = '<span class="LC_error">'.
                   23097:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   23098:         }
                   23099:     } else {
                   23100:         $resulttext = $nochgmsg;
                   23101:     }
                   23102:     return $resulttext;
                   23103: }
                   23104: 
1.150     raeburn  23105: sub modify_loadbalancing {
                   23106:     my ($dom,%domconfig) = @_;
                   23107:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   23108:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   23109:     my ($othertitle,$usertypes,$types) =
                   23110:         &Apache::loncommon::sorted_inst_types($dom);
                   23111:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  23112:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  23113:     my @sparestypes = ('primary','default');
                   23114:     my %typetitles = &sparestype_titles();
                   23115:     my $resulttext;
1.342     raeburn  23116:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  23117:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   23118:         %existing = %{$domconfig{'loadbalancing'}};
                   23119:     }
                   23120:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  23121:                               \%currtargets,\%currrules,\%currcookies);
1.171     raeburn  23122:     my ($saveloadbalancing,%defaultshash,%changes);
                   23123:     my ($alltypes,$othertypes,$titles) =
                   23124:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   23125:     my %ruletitles = &offloadtype_text();
                   23126:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   23127:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   23128:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   23129:         if ($balancer eq '') {
                   23130:             next;
                   23131:         }
1.210     raeburn  23132:         if (!exists($servers{$balancer})) {
1.171     raeburn  23133:             if (exists($currbalancer{$balancer})) {
                   23134:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  23135:             }
1.171     raeburn  23136:             next;
                   23137:         }
                   23138:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   23139:             push(@{$changes{'delete'}},$balancer);
                   23140:             next;
                   23141:         }
                   23142:         if (!exists($currbalancer{$balancer})) {
                   23143:             push(@{$changes{'add'}},$balancer);
                   23144:         }
                   23145:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   23146:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   23147:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   23148:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   23149:             $saveloadbalancing = 1;
                   23150:         }
                   23151:         foreach my $sparetype (@sparestypes) {
                   23152:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   23153:             my @offloadto;
                   23154:             foreach my $target (@targets) {
                   23155:                 if (($servers{$target}) && ($target ne $balancer)) {
                   23156:                     if ($sparetype eq 'default') {
                   23157:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   23158:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  23159:                         }
                   23160:                     }
1.171     raeburn  23161:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   23162:                         push(@offloadto,$target);
                   23163:                     }
1.150     raeburn  23164:                 }
                   23165:             }
1.284     raeburn  23166:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   23167:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   23168:                     push(@offloadto,$balancer);
                   23169:                 }
                   23170:             }
                   23171:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  23172:         }
1.342     raeburn  23173:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   23174:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425     raeburn  23175:             if (exists($currbalancer{$balancer})) {
1.342     raeburn  23176:                 unless ($currcookies{$balancer}) {
                   23177:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   23178:                 }
                   23179:             }
                   23180:         } elsif (exists($currbalancer{$balancer})) {
                   23181:             if ($currcookies{$balancer}) {
                   23182:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   23183:             }
                   23184:         }
1.171     raeburn  23185:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  23186:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  23187:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   23188:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  23189:                     if (@targetdiffs > 0) {
1.171     raeburn  23190:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  23191:                     }
1.171     raeburn  23192:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23193:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   23194:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  23195:                     }
                   23196:                 }
                   23197:             }
                   23198:         } else {
1.171     raeburn  23199:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  23200:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  23201:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23202:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   23203:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   23204:                         }
1.150     raeburn  23205:                     }
                   23206:                 }
1.210     raeburn  23207:             }
1.150     raeburn  23208:         }
                   23209:         my $ishomedom;
1.171     raeburn  23210:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   23211:             $ishomedom = 1;
1.150     raeburn  23212:         }
                   23213:         if (ref($alltypes) eq 'ARRAY') {
                   23214:             foreach my $type (@{$alltypes}) {
                   23215:                 my $rule;
1.210     raeburn  23216:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  23217:                          (!$ishomedom)) {
1.171     raeburn  23218:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   23219:                 }
                   23220:                 if ($rule eq 'specific') {
1.255     raeburn  23221:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  23222:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  23223:                         $rule = $specifiedhost;
                   23224:                     }
1.150     raeburn  23225:                 }
1.171     raeburn  23226:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   23227:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   23228:                     if ($rule ne $currrules{$balancer}{$type}) {
                   23229:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  23230:                     }
                   23231:                 } elsif ($rule ne '') {
1.171     raeburn  23232:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  23233:                 }
                   23234:             }
                   23235:         }
1.171     raeburn  23236:     }
                   23237:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   23238:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   23239:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   23240:             $defaultshash{'loadbalancing'} = {};
                   23241:         }
                   23242:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   23243:                                                  \%defaultshash,$dom);
                   23244:         if ($putresult eq 'ok') {
                   23245:             if (keys(%changes) > 0) {
1.252     raeburn  23246:                 my %toupdate;
1.171     raeburn  23247:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   23248:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   23249:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  23250:                         $toupdate{$balancer} = 1;
1.150     raeburn  23251:                     }
1.171     raeburn  23252:                 }
                   23253:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  23254:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  23255:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  23256:                         $toupdate{$balancer} = 1;
1.171     raeburn  23257:                     }
                   23258:                 }
                   23259:                 if (ref($changes{'curr'}) eq 'HASH') {
                   23260:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  23261:                         $toupdate{$balancer} = 1;
1.171     raeburn  23262:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   23263:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   23264:                                 my %offloadstr;
                   23265:                                 foreach my $sparetype (@sparestypes) {
                   23266:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23267:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   23268:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   23269:                                         }
                   23270:                                     }
1.150     raeburn  23271:                                 }
1.171     raeburn  23272:                                 if (keys(%offloadstr) == 0) {
                   23273:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  23274:                                 } else {
1.171     raeburn  23275:                                     my $showoffload;
                   23276:                                     foreach my $sparetype (@sparestypes) {
                   23277:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   23278:                                         if (defined($offloadstr{$sparetype})) {
                   23279:                                             $showoffload .= $offloadstr{$sparetype};
                   23280:                                         } else {
                   23281:                                             $showoffload .= &mt('None');
                   23282:                                         }
                   23283:                                         $showoffload .= ('&nbsp;'x3);
                   23284:                                     }
                   23285:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  23286:                                 }
                   23287:                             }
                   23288:                         }
1.171     raeburn  23289:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   23290:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   23291:                                 foreach my $type (@{$alltypes}) {
                   23292:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   23293:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   23294:                                         my $balancetext;
                   23295:                                         if ($rule eq '') {
                   23296:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  23297:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  23298:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  23299:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  23300:                                                 foreach my $sparetype (@sparestypes) {
                   23301:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23302:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   23303:                                                     }
                   23304:                                                 }
1.253     raeburn  23305:                                                 foreach my $item (@{$alltypes}) {
                   23306:                                                     next if ($item =~  /^_LC_ipchange/);
                   23307:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   23308:                                                     if ($hasrule eq 'homeserver') {
                   23309:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   23310:                                                     } else {
                   23311:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   23312:                                                             if ($servers{$hasrule}) {
                   23313:                                                                 $toupdate{$hasrule} = 1;
                   23314:                                                             }
                   23315:                                                         }
                   23316:                                                     }
                   23317:                                                 }
1.254     raeburn  23318:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   23319:                                                     $balancetext =  $ruletitles{$rule};
                   23320:                                                 } else {
                   23321:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   23322:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   23323:                                                     if ($receiver) {
                   23324:                                                         $toupdate{$receiver};
                   23325:                                                     }
                   23326:                                                 }
                   23327:                                             } else {
                   23328:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  23329:                                             }
1.171     raeburn  23330:                                         } else {
                   23331:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   23332:                                         }
1.210     raeburn  23333:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  23334:                                     }
                   23335:                                 }
                   23336:                             }
                   23337:                         }
1.342     raeburn  23338:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389     raeburn  23339:                             if ($currcookies{$balancer}) {
                   23340:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
                   23341:                                                           $balancer).'</li>';
                   23342:                             } else {
                   23343:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   23344:                                                           $balancer).'</li>';
                   23345:                             }
1.342     raeburn  23346:                         }
1.375     raeburn  23347:                     }
                   23348:                 }
                   23349:                 if (keys(%toupdate)) {
                   23350:                     my %thismachine;
                   23351:                     my $updatedhere;
                   23352:                     my $cachetime = 60*60*24;
                   23353:                     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   23354:                     foreach my $lonhost (keys(%toupdate)) {
                   23355:                         if ($thismachine{$lonhost}) {
                   23356:                             unless ($updatedhere) {
                   23357:                                 &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   23358:                                                               $defaultshash{'loadbalancing'},
                   23359:                                                               $cachetime);
                   23360:                                 $updatedhere = 1;
1.252     raeburn  23361:                             }
1.375     raeburn  23362:                         } else {
                   23363:                             my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   23364:                             &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252     raeburn  23365:                         }
1.150     raeburn  23366:                     }
1.171     raeburn  23367:                 }
                   23368:                 if ($resulttext ne '') {
                   23369:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  23370:                 } else {
                   23371:                     $resulttext = $nochgmsg;
                   23372:                 }
                   23373:             } else {
1.171     raeburn  23374:                 $resulttext = $nochgmsg;
1.150     raeburn  23375:             }
                   23376:         } else {
1.171     raeburn  23377:             $resulttext = '<span class="LC_error">'.
                   23378:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  23379:         }
                   23380:     } else {
1.171     raeburn  23381:         $resulttext = $nochgmsg;
1.150     raeburn  23382:     }
                   23383:     return $resulttext;
                   23384: }
                   23385: 
1.48      raeburn  23386: sub recurse_check {
                   23387:     my ($chkcats,$categories,$depth,$name) = @_;
                   23388:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   23389:         my $chg = 0;
                   23390:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   23391:             my $category = $chkcats->[$depth]{$name}[$j];
                   23392:             my $item;
                   23393:             if ($category eq '') {
                   23394:                 $chg ++;
                   23395:             } else {
                   23396:                 my $deeper = $depth + 1;
                   23397:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   23398:                 if ($chg) {
                   23399:                     $categories->{$item} -= $chg;
                   23400:                 }
                   23401:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   23402:                 $deeper --;
                   23403:             }
                   23404:         }
                   23405:     }
                   23406:     return;
                   23407: }
                   23408: 
                   23409: sub recurse_cat_deletes {
                   23410:     my ($item,$coursecategories,$deletions) = @_;
                   23411:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   23412:     my $subdepth = $depth + 1;
                   23413:     if (ref($coursecategories) eq 'HASH') {
                   23414:         foreach my $subitem (keys(%{$coursecategories})) {
                   23415:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   23416:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   23417:                 delete($coursecategories->{$subitem});
                   23418:                 $deletions->{$subitem} = 1;
                   23419:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  23420:             }
1.48      raeburn  23421:         }
                   23422:     }
                   23423:     return;
                   23424: }
                   23425: 
1.125     raeburn  23426: sub active_dc_picker {
1.191     raeburn  23427:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  23428:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  23429:     my @domcoord = keys(%domcoords);
                   23430:     if (keys(%currhash)) {
                   23431:         foreach my $dc (keys(%currhash)) {
                   23432:             unless (exists($domcoords{$dc})) {
                   23433:                 push(@domcoord,$dc);
                   23434:             }
                   23435:         }
                   23436:     }
                   23437:     @domcoord = sort(@domcoord);
1.210     raeburn  23438:     my $numdcs = scalar(@domcoord);
1.191     raeburn  23439:     my $rows = 0;
                   23440:     my $table;
1.125     raeburn  23441:     if ($numdcs > 1) {
1.191     raeburn  23442:         $table = '<table>';
                   23443:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  23444:             my $rem = $i%($numinrow);
                   23445:             if ($rem == 0) {
                   23446:                 if ($i > 0) {
1.191     raeburn  23447:                     $table .= '</tr>';
1.125     raeburn  23448:                 }
1.191     raeburn  23449:                 $table .= '<tr>';
                   23450:                 $rows ++;
1.125     raeburn  23451:             }
1.191     raeburn  23452:             my $check = '';
                   23453:             if ($inputtype eq 'radio') {
                   23454:                 if (keys(%currhash) == 0) {
                   23455:                     if (!$i) {
                   23456:                         $check = ' checked="checked"';
                   23457:                     }
                   23458:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   23459:                     $check = ' checked="checked"';
                   23460:                 }
                   23461:             } else {
                   23462:                 if (exists($currhash{$domcoord[$i]})) {
                   23463:                     $check = ' checked="checked"';
1.125     raeburn  23464:                 }
                   23465:             }
1.191     raeburn  23466:             if ($i == @domcoord - 1) {
1.125     raeburn  23467:                 my $colsleft = $numinrow - $rem;
                   23468:                 if ($colsleft > 1) {
1.191     raeburn  23469:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  23470:                 } else {
1.191     raeburn  23471:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  23472:                 }
                   23473:             } else {
1.191     raeburn  23474:                 $table .= '<td class="LC_left_item">';
                   23475:             }
                   23476:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   23477:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   23478:             $table .= '<span class="LC_nobreak"><label>'.
                   23479:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   23480:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   23481:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  23482:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  23483:             }
1.219     raeburn  23484:             $table .= '</label></span></td>';
1.191     raeburn  23485:         }
                   23486:         $table .= '</tr></table>';
                   23487:     } elsif ($numdcs == 1) {
1.219     raeburn  23488:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   23489:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  23490:         if ($inputtype eq 'radio') {
1.247     raeburn  23491:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  23492:             if ($user ne $dcname.':'.$dcdom) {
                   23493:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   23494:             }
1.191     raeburn  23495:         } else {
                   23496:             my $check;
                   23497:             if (exists($currhash{$domcoord[0]})) {
                   23498:                 $check = ' checked="checked"';
1.125     raeburn  23499:             }
1.247     raeburn  23500:             $table = '<span class="LC_nobreak"><label>'.
                   23501:                      '<input type="checkbox" name="'.$name.'" '.
                   23502:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  23503:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  23504:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  23505:             }
1.220     raeburn  23506:             $table .= '</label></span>';
1.191     raeburn  23507:             $rows ++;
1.125     raeburn  23508:         }
                   23509:     }
1.191     raeburn  23510:     return ($numdcs,$table,$rows);
1.125     raeburn  23511: }
                   23512: 
1.137     raeburn  23513: sub usersession_titles {
                   23514:     return &Apache::lonlocal::texthash(
                   23515:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   23516:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  23517:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  23518:                version => 'LON-CAPA version requirement',
1.138     raeburn  23519:                excludedomain => 'Allow all, but exclude specific domains',
                   23520:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  23521:                primary => 'Primary (checked first)',
1.154     raeburn  23522:                default => 'Default',
1.137     raeburn  23523:            );
                   23524: }
                   23525: 
1.152     raeburn  23526: sub id_for_thisdom {
                   23527:     my (%servers) = @_;
                   23528:     my %altids;
                   23529:     foreach my $server (keys(%servers)) {
                   23530:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   23531:         if ($serverhome ne $server) {
                   23532:             $altids{$serverhome} = $server;
                   23533:         }
                   23534:     }
                   23535:     return %altids;
                   23536: }
                   23537: 
1.150     raeburn  23538: sub count_servers {
                   23539:     my ($currbalancer,%servers) = @_;
                   23540:     my (@spares,$numspares);
                   23541:     foreach my $lonhost (sort(keys(%servers))) {
                   23542:         next if ($currbalancer eq $lonhost);
                   23543:         push(@spares,$lonhost);
                   23544:     }
                   23545:     if ($currbalancer) {
                   23546:         $numspares = scalar(@spares);
                   23547:     } else {
                   23548:         $numspares = scalar(@spares) - 1;
                   23549:     }
                   23550:     return ($numspares,@spares);
                   23551: }
                   23552: 
                   23553: sub lonbalance_targets_js {
1.171     raeburn  23554:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  23555:     my $select = &mt('Select');
                   23556:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   23557:     if (ref($servers) eq 'HASH') {
                   23558:         $alltargets = join("','",sort(keys(%{$servers})));
                   23559:         my @homedoms;
                   23560:         foreach my $server (sort(keys(%{$servers}))) {
                   23561:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   23562:                 push(@homedoms,'1');
                   23563:             } else {
                   23564:                 push(@homedoms,'0');
                   23565:             }
                   23566:         }
                   23567:         $allishome = join("','",@homedoms);
                   23568:     }
                   23569:     if (ref($types) eq 'ARRAY') {
                   23570:         if (@{$types} > 0) {
                   23571:             @alltypes = @{$types};
                   23572:         }
                   23573:     }
                   23574:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   23575:     $allinsttypes = join("','",@alltypes);
1.342     raeburn  23576:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  23577:     if (ref($settings) eq 'HASH') {
                   23578:         %existing = %{$settings};
                   23579:     }
                   23580:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342     raeburn  23581:                               \%currtargets,\%currrules,\%currcookies);
1.210     raeburn  23582:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  23583:     return <<"END";
                   23584: 
                   23585: <script type="text/javascript">
                   23586: // <![CDATA[
                   23587: 
1.171     raeburn  23588: currBalancers = new Array('$balancers');
                   23589: 
                   23590: function toggleTargets(balnum) {
                   23591:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   23592:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   23593:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   23594:     var prevbalancer = prevhostitem.value;
                   23595:     var baltotal = document.getElementById('loadbalancing_total').value;
                   23596:     prevhostitem.value = balancer;
                   23597:     if (prevbalancer != '') {
                   23598:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   23599:         if (prevIdx != -1) {
                   23600:             currBalancers.splice(prevIdx,1);
                   23601:         }
                   23602:     }
1.150     raeburn  23603:     if (balancer == '') {
1.171     raeburn  23604:         hideSpares(balnum);
1.150     raeburn  23605:     } else {
1.171     raeburn  23606:         var currIdx = currBalancers.indexOf(balancer);
                   23607:         if (currIdx == -1) {
                   23608:             currBalancers.push(balancer);
                   23609:         }
1.150     raeburn  23610:         var homedoms = new Array('$allishome');
1.171     raeburn  23611:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   23612:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  23613:     }
1.171     raeburn  23614:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  23615:     return;
                   23616: }
                   23617: 
1.171     raeburn  23618: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  23619:     var alltargets = new Array('$alltargets');
                   23620:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  23621:     var offloadtypes = new Array('primary','default');
                   23622: 
1.171     raeburn  23623:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   23624:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  23625:  
1.151     raeburn  23626:     for (var i=0; i<offloadtypes.length; i++) {
                   23627:         var count = 0;
                   23628:         for (var j=0; j<alltargets.length; j++) {
                   23629:             if (alltargets[j] != balancer) {
1.171     raeburn  23630:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   23631:                 item.value = alltargets[j];
                   23632:                 item.style.textAlign='left';
                   23633:                 item.style.textFace='normal';
                   23634:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   23635:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   23636:                     item.disabled = '';
                   23637:                 } else {
                   23638:                     item.disabled = 'disabled';
                   23639:                     item.checked = false;
                   23640:                 }
1.151     raeburn  23641:                 count ++;
                   23642:             }
1.150     raeburn  23643:         }
                   23644:     }
1.151     raeburn  23645:     for (var k=0; k<insttypes.length; k++) {
                   23646:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  23647:             if (ishomedom == 1) {
1.171     raeburn  23648:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   23649:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  23650:             } else {
1.171     raeburn  23651:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   23652:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  23653:             }
                   23654:         } else {
1.171     raeburn  23655:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   23656:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  23657:         }
1.151     raeburn  23658:         if ((insttypes[k] != '_LC_external') && 
                   23659:             ((insttypes[k] != '_LC_internetdom') ||
                   23660:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  23661:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   23662:             item.options.length = 0;
                   23663:             item.options[0] = new Option("","",true,true);
1.210     raeburn  23664:             var idx = 0;
1.151     raeburn  23665:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  23666:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   23667:                     idx ++;
                   23668:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  23669:                 }
                   23670:             }
                   23671:         }
                   23672:     }
                   23673:     return;
                   23674: }
                   23675: 
1.171     raeburn  23676: function hideSpares(balnum) {
1.150     raeburn  23677:     var alltargets = new Array('$alltargets');
                   23678:     var insttypes = new Array('$allinsttypes');
                   23679:     var offloadtypes = new Array('primary','default');
                   23680: 
1.171     raeburn  23681:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   23682:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  23683: 
                   23684:     var total = alltargets.length - 1;
                   23685:     for (var i=0; i<offloadtypes; i++) {
                   23686:         for (var j=0; j<total; j++) {
1.171     raeburn  23687:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   23688:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   23689:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  23690:         }
1.150     raeburn  23691:     }
                   23692:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  23693:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   23694:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  23695:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  23696:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   23697:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  23698:         }
                   23699:     }
                   23700:     return;
                   23701: }
                   23702: 
1.171     raeburn  23703: function checkOffloads(item,balnum,type) {
1.150     raeburn  23704:     var alltargets = new Array('$alltargets');
                   23705:     var offloadtypes = new Array('primary','default');
                   23706:     if (item.checked) {
                   23707:         var total = alltargets.length - 1;
                   23708:         var other;
                   23709:         if (type == offloadtypes[0]) {
1.151     raeburn  23710:             other = offloadtypes[1];
1.150     raeburn  23711:         } else {
1.151     raeburn  23712:             other = offloadtypes[0];
1.150     raeburn  23713:         }
                   23714:         for (var i=0; i<total; i++) {
1.171     raeburn  23715:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  23716:             if (server == item.value) {
1.171     raeburn  23717:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   23718:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  23719:                 }
                   23720:             }
                   23721:         }
                   23722:     }
                   23723:     return;
                   23724: }
                   23725: 
1.171     raeburn  23726: function singleServerToggle(balnum,type) {
                   23727:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  23728:     if (offloadtoSelIdx == 0) {
1.171     raeburn  23729:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   23730:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  23731: 
                   23732:     } else {
1.171     raeburn  23733:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   23734:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  23735:     }
                   23736:     return;
                   23737: }
                   23738: 
1.171     raeburn  23739: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  23740:     if (type == '_LC_external') {
1.171     raeburn  23741:         return;
1.150     raeburn  23742:     }
1.171     raeburn  23743:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  23744:     for (var i=0; i<typesRules.length; i++) {
                   23745:         if (formname.elements[typesRules[i]].checked) {
                   23746:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  23747:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   23748:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  23749:             } else {
1.171     raeburn  23750:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   23751:             }
                   23752:         }
                   23753:     }
                   23754:     return;
                   23755: }
                   23756: 
                   23757: function balancerDeleteChange(balnum) {
                   23758:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   23759:     var baltotal = document.getElementById('loadbalancing_total').value;
                   23760:     var addtarget;
                   23761:     var removetarget;
                   23762:     var action = 'delete';
                   23763:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   23764:         var lonhost = hostitem.value;
                   23765:         var currIdx = currBalancers.indexOf(lonhost);
                   23766:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   23767:             if (currIdx != -1) {
                   23768:                 currBalancers.splice(currIdx,1);
                   23769:             }
                   23770:             addtarget = lonhost;
                   23771:         } else {
                   23772:             if (currIdx == -1) {
                   23773:                 currBalancers.push(lonhost);
                   23774:             }
                   23775:             removetarget = lonhost;
                   23776:             action = 'undelete';
                   23777:         }
                   23778:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   23779:     }
                   23780:     return;
                   23781: }
                   23782: 
                   23783: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   23784:     if (baltotal > 1) {
                   23785:         var offloadtypes = new Array('primary','default');
                   23786:         var alltargets = new Array('$alltargets');
                   23787:         var insttypes = new Array('$allinsttypes');
                   23788:         for (var i=0; i<baltotal; i++) {
                   23789:             if (i != balnum) {
                   23790:                 for (var j=0; j<offloadtypes.length; j++) {
                   23791:                     var total = alltargets.length - 1;
                   23792:                     for (var k=0; k<total; k++) {
                   23793:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   23794:                         var server = serveritem.value;
                   23795:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   23796:                             if (server == addtarget) {
                   23797:                                 serveritem.disabled = '';
                   23798:                             }
                   23799:                         }
                   23800:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   23801:                             if (server == removetarget) {
                   23802:                                 serveritem.disabled = 'disabled';
                   23803:                                 serveritem.checked = false;
                   23804:                             }
                   23805:                         }
                   23806:                     }
                   23807:                 }
                   23808:                 for (var j=0; j<insttypes.length; j++) {
                   23809:                     if (insttypes[j] != '_LC_external') {
                   23810:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   23811:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   23812:                             var currSel = singleserver.selectedIndex;
                   23813:                             var currVal = singleserver.options[currSel].value;
                   23814:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   23815:                                 var numoptions = singleserver.options.length;
                   23816:                                 var needsnew = 1;
                   23817:                                 for (var k=0; k<numoptions; k++) {
                   23818:                                     if (singleserver.options[k] == addtarget) {
                   23819:                                         needsnew = 0;
                   23820:                                         break;
                   23821:                                     }
                   23822:                                 }
                   23823:                                 if (needsnew == 1) {
                   23824:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   23825:                                 }
                   23826:                             }
                   23827:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   23828:                                 singleserver.options.length = 0;
                   23829:                                 if ((currVal) && (currVal != removetarget)) {
                   23830:                                     singleserver.options[0] = new Option("","",false,false);
                   23831:                                 } else {
                   23832:                                     singleserver.options[0] = new Option("","",true,true);
                   23833:                                 }
                   23834:                                 var idx = 0;
                   23835:                                 for (var m=0; m<alltargets.length; m++) {
                   23836:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   23837:                                         idx ++;
                   23838:                                         if (currVal == alltargets[m]) {
                   23839:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   23840:                                         } else {
                   23841:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   23842:                                         }
                   23843:                                     }
                   23844:                                 }
                   23845:                             }
                   23846:                         }
                   23847:                     }
                   23848:                 }
1.150     raeburn  23849:             }
                   23850:         }
                   23851:     }
                   23852:     return;
                   23853: }
                   23854: 
1.152     raeburn  23855: // ]]>
                   23856: </script>
                   23857: 
                   23858: END
                   23859: }
                   23860: 
                   23861: sub new_spares_js {
                   23862:     my @sparestypes = ('primary','default');
                   23863:     my $types = join("','",@sparestypes);
                   23864:     my $select = &mt('Select');
                   23865:     return <<"END";
                   23866: 
                   23867: <script type="text/javascript">
                   23868: // <![CDATA[
                   23869: 
                   23870: function updateNewSpares(formname,lonhost) {
                   23871:     var types = new Array('$types');
                   23872:     var include = new Array();
                   23873:     var exclude = new Array();
                   23874:     for (var i=0; i<types.length; i++) {
                   23875:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   23876:         for (var j=0; j<spareboxes.length; j++) {
                   23877:             if (formname.elements[spareboxes[j]].checked) {
                   23878:                 exclude.push(formname.elements[spareboxes[j]].value);
                   23879:             } else {
                   23880:                 include.push(formname.elements[spareboxes[j]].value);
                   23881:             }
                   23882:         }
                   23883:     }
                   23884:     for (var i=0; i<types.length; i++) {
                   23885:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   23886:         var selIdx = newSpare.selectedIndex;
                   23887:         var currnew = newSpare.options[selIdx].value;
                   23888:         var okSpares = new Array();
                   23889:         for (var j=0; j<newSpare.options.length; j++) {
                   23890:             var possible = newSpare.options[j].value;
                   23891:             if (possible != '') {
                   23892:                 if (exclude.indexOf(possible) == -1) {
                   23893:                     okSpares.push(possible);
                   23894:                 } else {
                   23895:                     if (currnew == possible) {
                   23896:                         selIdx = 0;
                   23897:                     }
                   23898:                 }
                   23899:             }
                   23900:         }
                   23901:         for (var k=0; k<include.length; k++) {
                   23902:             if (okSpares.indexOf(include[k]) == -1) {
                   23903:                 okSpares.push(include[k]);
                   23904:             }
                   23905:         }
                   23906:         okSpares.sort();
                   23907:         newSpare.options.length = 0;
                   23908:         if (selIdx == 0) {
                   23909:             newSpare.options[0] = new Option("$select","",true,true);
                   23910:         } else {
                   23911:             newSpare.options[0] = new Option("$select","",false,false);
                   23912:         }
                   23913:         for (var m=0; m<okSpares.length; m++) {
                   23914:             var idx = m+1;
                   23915:             var selThis = 0;
                   23916:             if (selIdx != 0) {
                   23917:                 if (okSpares[m] == currnew) {
                   23918:                     selThis = 1;
                   23919:                 }
                   23920:             }
                   23921:             if (selThis == 1) {
                   23922:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   23923:             } else {
                   23924:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   23925:             }
                   23926:         }
                   23927:     }
                   23928:     return;
                   23929: }
                   23930: 
                   23931: function checkNewSpares(lonhost,type) {
                   23932:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   23933:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
1.372     raeburn  23934:     if (chosen != '') {
1.152     raeburn  23935:         var othertype;
                   23936:         var othernewSpare;
                   23937:         if (type == 'primary') {
                   23938:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   23939:         }
                   23940:         if (type == 'default') {
                   23941:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   23942:         }
                   23943:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   23944:             othernewSpare.selectedIndex = 0;
                   23945:         }
                   23946:     }
                   23947:     return;
                   23948: }
                   23949: 
                   23950: // ]]>
                   23951: </script>
                   23952: 
                   23953: END
                   23954: 
                   23955: }
                   23956: 
                   23957: sub common_domprefs_js {
                   23958:     return <<"END";
                   23959: 
                   23960: <script type="text/javascript">
                   23961: // <![CDATA[
                   23962: 
1.150     raeburn  23963: function getIndicesByName(formname,item) {
1.152     raeburn  23964:     var group = new Array();
1.150     raeburn  23965:     for (var i=0;i<formname.elements.length;i++) {
                   23966:         if (formname.elements[i].name == item) {
1.152     raeburn  23967:             group.push(formname.elements[i].id);
1.150     raeburn  23968:         }
                   23969:     }
1.152     raeburn  23970:     return group;
1.150     raeburn  23971: }
                   23972: 
                   23973: // ]]>
                   23974: </script>
                   23975: 
                   23976: END
1.152     raeburn  23977: 
1.150     raeburn  23978: }
                   23979: 
1.165     raeburn  23980: sub recaptcha_js {
                   23981:     my %lt = &captcha_phrases();
                   23982:     return <<"END";
                   23983: 
                   23984: <script type="text/javascript">
                   23985: // <![CDATA[
                   23986: 
                   23987: function updateCaptcha(caller,context) {
                   23988:     var privitem;
                   23989:     var pubitem;
                   23990:     var privtext;
                   23991:     var pubtext;
1.269     raeburn  23992:     var versionitem;
                   23993:     var versiontext;
1.165     raeburn  23994:     if (document.getElementById(context+'_recaptchapub')) {
                   23995:         pubitem = document.getElementById(context+'_recaptchapub');
                   23996:     } else {
                   23997:         return;
                   23998:     }
                   23999:     if (document.getElementById(context+'_recaptchapriv')) {
                   24000:         privitem = document.getElementById(context+'_recaptchapriv');
                   24001:     } else {
                   24002:         return;
                   24003:     }
                   24004:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   24005:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   24006:     } else {
                   24007:         return;
                   24008:     }
                   24009:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   24010:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   24011:     } else {
                   24012:         return;
                   24013:     }
1.269     raeburn  24014:     if (document.getElementById(context+'_recaptchaversion')) {
                   24015:         versionitem = document.getElementById(context+'_recaptchaversion');
                   24016:     } else {
                   24017:         return;
                   24018:     }
                   24019:     if (document.getElementById(context+'_recaptchavertxt')) {
                   24020:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   24021:     } else {
                   24022:         return;
                   24023:     }
1.165     raeburn  24024:     if (caller.checked) {
                   24025:         if (caller.value == 'recaptcha') {
                   24026:             pubitem.type = 'text';
                   24027:             privitem.type = 'text';
                   24028:             pubitem.size = '40';
                   24029:             privitem.size = '40';
                   24030:             pubtext.innerHTML = "$lt{'pub'}";
                   24031:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  24032:             versionitem.type = 'text';
                   24033:             versionitem.size = '3';
1.289     raeburn  24034:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  24035:         } else {
                   24036:             pubitem.type = 'hidden';
                   24037:             privitem.type = 'hidden';
1.269     raeburn  24038:             versionitem.type = 'hidden';
1.165     raeburn  24039:             pubtext.innerHTML = '';
                   24040:             privtext.innerHTML = '';
1.269     raeburn  24041:             versiontext.innerHTML = '';
1.165     raeburn  24042:         }
                   24043:     }
                   24044:     return;
                   24045: }
                   24046: 
                   24047: // ]]>
                   24048: </script>
                   24049: 
                   24050: END
                   24051: 
                   24052: }
                   24053: 
1.236     raeburn  24054: sub toggle_display_js {
1.192     raeburn  24055:     return <<"END";
                   24056: 
                   24057: <script type="text/javascript">
                   24058: // <![CDATA[
                   24059: 
1.236     raeburn  24060: function toggleDisplay(domForm,caller) {
                   24061:     if (document.getElementById(caller)) {
                   24062:         var divitem = document.getElementById(caller);
                   24063:         var optionsElement = domForm.coursecredits;
1.264     raeburn  24064:         var checkval = 1;
                   24065:         var dispval = 'block';
1.303     raeburn  24066:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  24067:         if (caller == 'emailoptions') {
1.372     raeburn  24068:             optionsElement = domForm.cancreate_email;
1.236     raeburn  24069:         }
1.257     raeburn  24070:         if (caller == 'studentsubmission') {
                   24071:             optionsElement = domForm.postsubmit;
                   24072:         }
1.264     raeburn  24073:         if (caller == 'cloneinstcode') {
                   24074:             optionsElement = domForm.canclone;
                   24075:             checkval = 'instcode';
                   24076:         }
1.303     raeburn  24077:         if (selfcreateRegExp.test(caller)) {
                   24078:             optionsElement = domForm.elements[caller];
                   24079:             checkval = 'other';
                   24080:             dispval = 'inline'
                   24081:         }
1.236     raeburn  24082:         if (optionsElement.length) {
1.192     raeburn  24083:             var currval;
1.236     raeburn  24084:             for (var i=0; i<optionsElement.length; i++) {
                   24085:                 if (optionsElement[i].checked) {
                   24086:                    currval = optionsElement[i].value;
1.192     raeburn  24087:                 }
                   24088:             }
1.264     raeburn  24089:             if (currval == checkval) {
                   24090:                 divitem.style.display = dispval;
1.192     raeburn  24091:             } else {
1.236     raeburn  24092:                 divitem.style.display = 'none';
1.192     raeburn  24093:             }
                   24094:         }
                   24095:     }
                   24096:     return;
                   24097: }
                   24098: 
                   24099: // ]]>
                   24100: </script>
                   24101: 
                   24102: END
                   24103: 
                   24104: }
                   24105: 
1.165     raeburn  24106: sub captcha_phrases {
                   24107:     return &Apache::lonlocal::texthash (
                   24108:                  priv => 'Private key',
                   24109:                  pub  => 'Public key',
                   24110:                  original  => 'original (CAPTCHA)',
                   24111:                  recaptcha => 'successor (ReCAPTCHA)',
                   24112:                  notused   => 'unused',
1.289     raeburn  24113:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  24114:     );
                   24115: }
                   24116: 
1.205     raeburn  24117: sub devalidate_remote_domconfs {
1.212     raeburn  24118:     my ($dom,$cachekeys) = @_;
                   24119:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  24120:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   24121:     my %thismachine;
                   24122:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355     raeburn  24123:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394     raeburn  24124:                       'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410     raeburn  24125:                       'ipaccess','trust');
1.386     raeburn  24126:     my %cache_by_lonhost;
                   24127:     if (exists($cachekeys->{'samllanding'})) {
                   24128:         if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
                   24129:             my %landing = %{$cachekeys->{'samllanding'}};
                   24130:             my %domservers = &Apache::lonnet::get_servers($dom);
                   24131:             if (keys(%domservers)) {
                   24132:                 foreach my $server (keys(%domservers)) {
                   24133:                     my @cached;
                   24134:                     next if ($thismachine{$server});
                   24135:                     if ($landing{$server}) {
                   24136:                         push(@cached,&escape('samllanding').':'.&escape($server));
                   24137:                     }
                   24138:                     if (@cached) {
                   24139:                         $cache_by_lonhost{$server} = \@cached;
                   24140:                     }
                   24141:                 }
                   24142:             }
                   24143:         }
                   24144:     }
1.260     raeburn  24145:     if (keys(%servers)) {
1.205     raeburn  24146:         foreach my $server (keys(%servers)) {
                   24147:             next if ($thismachine{$server});
1.212     raeburn  24148:             my @cached;
                   24149:             foreach my $name (@posscached) {
                   24150:                 if ($cachekeys->{$name}) {
1.388     raeburn  24151:                     if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386     raeburn  24152:                         if (ref($cachekeys->{$name}) eq 'HASH') {
1.373     raeburn  24153:                             foreach my $key (keys(%{$cachekeys->{$name}})) {
                   24154:                                 push(@cached,&escape($name).':'.&escape($key));
                   24155:                             }
                   24156:                         }
                   24157:                     } else {
                   24158:                         push(@cached,&escape($name).':'.&escape($dom));
                   24159:                     }
1.212     raeburn  24160:                 }
                   24161:             }
1.386     raeburn  24162:             if ((exists($cache_by_lonhost{$server})) &&
                   24163:                 (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
                   24164:                 push(@cached,@{$cache_by_lonhost{$server}});
                   24165:             }
1.212     raeburn  24166:             if (@cached) {
                   24167:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   24168:             }
1.205     raeburn  24169:         }
                   24170:     }
                   24171:     return;
                   24172: }
                   24173: 
1.3       raeburn  24174: 1;

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