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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.420   ! raeburn     4: # $Id: domainprefs.pm,v 1.419 2023/02/14 21:44:15 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.197     raeburn    98: used by course owners to request creation of a course, and to display/store
1.223     bisitz     99: default quota sizes for Authoring Spaces.
1.101     raeburn   100: 
                    101: Outputs: 1
                    102: 
                    103: $datatable  - HTML containing form elements which allow settings to be changed. 
                    104: 
                    105: In the case of course requests, radio buttons are displayed for each institutional
                    106: affiliate type (and also default, and _LC_adv) for each of the course types 
1.325     raeburn   107: (official, unofficial, community, textbook, placement, and lti).  
1.271     raeburn   108: In each case the radio buttons allow the selection of one of four values:  
1.101     raeburn   109: 
1.104     raeburn   110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   111: which have the following effects:
                    112: 
                    113: 0
                    114: 
                    115: =over
                    116: 
                    117: - course requests are not allowed for this course types/affiliation
                    118: 
                    119: =back
                    120: 
1.104     raeburn   121: approval 
1.101     raeburn   122: 
                    123: =over 
                    124: 
                    125: - course requests must be approved by a Doman Coordinator in the 
                    126: course's domain
                    127: 
                    128: =back
                    129: 
                    130: validate 
                    131: 
                    132: =over
                    133: 
                    134: - an institutional validation (e.g., check requestor is instructor
                    135: of record) needs to be passed before the course will be created.  The required
                    136: validation is in localenroll.pm on the primary library server for the course 
                    137: domain.
                    138: 
                    139: =back
                    140: 
                    141: autolimit 
                    142: 
                    143: =over
                    144:  
1.143     raeburn   145: - course requests will be processed automatically up to a limit of
1.101     raeburn   146: N requests for the course type for the particular requestor.
                    147: If N is undefined, there is no limit to the number of course requests
                    148: which a course owner may submit and have processed automatically. 
                    149: 
                    150: =back
                    151: 
                    152: =item modify_quotas() 
                    153: 
                    154: =back
                    155: 
                    156: =cut
                    157: 
1.1       raeburn   158: package Apache::domainprefs;
                    159: 
                    160: use strict;
                    161: use Apache::Constants qw(:common :http);
                    162: use Apache::lonnet;
                    163: use Apache::loncommon();
                    164: use Apache::lonhtmlcommon();
                    165: use Apache::lonlocal;
1.43      raeburn   166: use Apache::lonmsg();
1.91      raeburn   167: use Apache::lonconfigsettings;
1.232     raeburn   168: use Apache::lonuserutils();
1.235     raeburn   169: use Apache::loncoursequeueadmin();
1.419     raeburn   170: use Apache::courseprefs();
1.69      raeburn   171: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   172: use LONCAPA::Enrollment;
1.81      raeburn   173: use LONCAPA::lonauthcgi();
1.275     raeburn   174: use LONCAPA::SSL;
1.9       raeburn   175: use File::Copy;
1.43      raeburn   176: use Locale::Language;
1.62      raeburn   177: use DateTime::TimeZone;
1.68      raeburn   178: use DateTime::Locale;
1.267     raeburn   179: use Time::HiRes qw( sleep );
1.373     raeburn   180: use Net::CIDR;
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.405     raeburn   224:                 'ltitools','ssl','trust','lti','ltisec','privacy','passwords',
1.394     raeburn   225:                 'proctoring','wafproxy','ipaccess'],$dom);
1.320     raeburn   226:     my %encconfig =
1.405     raeburn   227:         &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.297     raeburn   228:     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    229:         if (ref($encconfig{'ltitools'}) eq 'HASH') {
                    230:             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320     raeburn   231:                 if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
                    232:                     (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297     raeburn   233:                     foreach my $item ('key','secret') {
                    234:                         $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
                    235:                     }
                    236:                 }
                    237:             }
                    238:         }
                    239:     }
1.320     raeburn   240:     if (ref($domconfig{'lti'}) eq 'HASH') {
                    241:         if (ref($encconfig{'lti'}) eq 'HASH') {
                    242:             foreach my $id (keys(%{$domconfig{'lti'}})) {
                    243:                 if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
                    244:                     (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
                    245:                     foreach my $item ('key','secret') {
                    246:                         $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
                    247:                     }
                    248:                 }
                    249:             }
                    250:         }
                    251:     }
1.405     raeburn   252:     if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406     raeburn   253:         if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405     raeburn   254:             if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406     raeburn   255:                 foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
                    256:                     unless ($id =~ /^\d+$/) {
                    257:                         delete($domconfig{'ltisec'}{'linkprot'}{$id});
                    258:                     }
                    259:                     if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405     raeburn   260:                         (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
                    261:                         foreach my $item ('key','secret') {
1.406     raeburn   262:                             $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405     raeburn   263:                         }
                    264:                     }
                    265:                 }
                    266:             }
                    267:         }
                    268:     }
1.372     raeburn   269:     if (ref($domconfig{'proctoring'}) eq 'HASH') {
                    270:         if (ref($encconfig{'proctoring'}) eq 'HASH') {
                    271:             foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
                    272:                 if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
                    273:                     (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
                    274:                     foreach my $item ('key','secret') {
                    275:                         $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
                    276:                     }
                    277:                 }
                    278:             }
                    279:         }
                    280:     }
1.394     raeburn   281:     my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
                    282:                        'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373     raeburn   283:                        'contacts','privacy','usercreation','selfcreation',
1.374     raeburn   284:                        'usermodification','scantron','requestcourses','requestauthor',
1.373     raeburn   285:                        'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372     raeburn   286:                        'ltitools','proctoring','selfenrollment','usersessions','ssl',
                    287:                        'trust','lti');
1.171     raeburn   288:     my %existing;
                    289:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    290:         %existing = %{$domconfig{'loadbalancing'}};
                    291:     }
                    292:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   293:         push(@prefs_order,'loadbalancing');
                    294:     }
1.30      raeburn   295:     my %prefs = (
                    296:         'rolecolors' =>
                    297:                    { text => 'Default color schemes',
1.67      raeburn   298:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   299:                      header => [{col1 => 'Student Settings',
                    300:                                  col2 => '',},
                    301:                                 {col1 => 'Coordinator Settings',
                    302:                                  col2 => '',},
                    303:                                 {col1 => 'Author Settings',
                    304:                                  col2 => '',},
                    305:                                 {col1 => 'Administrator Settings',
                    306:                                  col2 => '',}],
1.230     raeburn   307:                       print => \&print_rolecolors,
                    308:                       modify => \&modify_rolecolors,
1.30      raeburn   309:                     },
1.110     raeburn   310:         'login' =>
1.30      raeburn   311:                     { text => 'Log-in page options',
1.67      raeburn   312:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   313:                       header => [{col1 => 'Log-in Page Items',
                    314:                                   col2 => '',},
                    315:                                  {col1 => 'Log-in Help',
1.256     raeburn   316:                                   col2 => 'Value'},
                    317:                                  {col1 => 'Custom HTML in document head',
1.386     raeburn   318:                                   col2 => 'Value'},
                    319:                                  {col1 => 'SSO',
                    320:                                   col2 => 'Dual login: SSO and non-SSO options'},
                    321:                                 ],
1.230     raeburn   322:                       print => \&print_login,
                    323:                       modify => \&modify_login,
1.30      raeburn   324:                     },
1.43      raeburn   325:         'defaults' => 
1.236     raeburn   326:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   327:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   328:                       header => [{col1 => 'Setting',
1.236     raeburn   329:                                   col2 => 'Value'},
                    330:                                  {col1 => 'Institutional user types',
1.409     raeburn   331:                                   col2 => 'Name displayed'},
                    332:                                  {col1 => 'Mapping for missing usernames via standard log-in',
                    333:                                   col2 => 'Rules in use'}],
1.230     raeburn   334:                       print => \&print_defaults,
                    335:                       modify => \&modify_defaults,
1.43      raeburn   336:                     },
1.381     raeburn   337:         'wafproxy' =>
                    338:                     { text => 'Web Application Firewall/Reverse Proxy',
1.373     raeburn   339:                       help => 'Domain_Configuration_WAF_Proxy',
1.381     raeburn   340:                       header => [{col1 => 'Domain(s)',
                    341:                                   col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373     raeburn   342:                                  },
1.381     raeburn   343:                                  {col1 => 'Domain(s)',
                    344:                                   col2 => 'WAF Configuration',}],
1.373     raeburn   345:                       print => \&print_wafproxy,
1.381     raeburn   346:                       modify => \&modify_wafproxy,
1.373     raeburn   347:                     },
1.354     raeburn   348:         'passwords' =>
                    349:                     { text => 'Passwords (Internal authentication)',
                    350:                       help => 'Domain_Configuration_Passwords',
                    351:                       header => [{col1 => 'Resetting Forgotten Password',
                    352:                                   col2 => 'Settings'},
                    353:                                  {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                    354:                                   col2 => 'Settings'},
                    355:                                  {col1 => 'Rules for LON-CAPA Passwords',
                    356:                                   col2 => 'Settings'},
                    357:                                  {col1 => 'Course Owner Changing Student Passwords',
                    358:                                   col2 => 'Settings'}],
                    359:                       print => \&print_passwords,
                    360:                       modify => \&modify_passwords,
                    361:                     },
1.30      raeburn   362:         'quotas' => 
1.413     raeburn   363:                     { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67      raeburn   364:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   365:                       header => [{col1 => 'User affiliation',
1.72      raeburn   366:                                   col2 => 'Available tools',
1.213     raeburn   367:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230     raeburn   368:                       print => \&print_quotas,
                    369:                       modify => \&modify_quotas,
1.30      raeburn   370:                     },
                    371:         'autoenroll' =>
                    372:                    { text => 'Auto-enrollment settings',
1.67      raeburn   373:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   374:                      header => [{col1 => 'Configuration setting',
                    375:                                  col2 => 'Value(s)'}],
1.230     raeburn   376:                      print => \&print_autoenroll,
                    377:                      modify => \&modify_autoenroll,
1.30      raeburn   378:                    },
                    379:         'autoupdate' => 
                    380:                    { text => 'Auto-update settings',
1.67      raeburn   381:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   382:                      header => [{col1 => 'Setting',
                    383:                                  col2 => 'Value',},
1.131     raeburn   384:                                 {col1 => 'Setting',
                    385:                                  col2 => 'Affiliation'},
1.43      raeburn   386:                                 {col1 => 'User population',
1.227     bisitz    387:                                  col2 => 'Updatable user data'}],
1.230     raeburn   388:                      print => \&print_autoupdate,
                    389:                      modify => \&modify_autoupdate,
1.30      raeburn   390:                   },
1.125     raeburn   391:         'autocreate' => 
                    392:                   { text => 'Auto-course creation settings',
                    393:                      help => 'Domain_Configuration_Auto_Creation',
                    394:                      header => [{col1 => 'Configuration Setting',
                    395:                                  col2 => 'Value',}],
1.230     raeburn   396:                      print => \&print_autocreate,
                    397:                      modify => \&modify_autocreate,
1.125     raeburn   398:                   },
1.30      raeburn   399:         'directorysrch' => 
1.277     raeburn   400:                   { text => 'Directory searches',
1.67      raeburn   401:                     help => 'Domain_Configuration_InstDirectory_Search',
1.277     raeburn   402:                     header => [{col1 => 'Institutional Directory Setting',
                    403:                                 col2 => 'Value',},
                    404:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   405:                                 col2 => 'Value',}],
1.230     raeburn   406:                     print => \&print_directorysrch,
                    407:                     modify => \&modify_directorysrch,
1.30      raeburn   408:                   },
                    409:         'contacts' =>
1.286     raeburn   410:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   411:                     help => 'Domain_Configuration_Contact_Info',
1.286     raeburn   412:                     header => [{col1 => 'Default e-mail addresses',
                    413:                                 col2 => 'Value',},
                    414:                                {col1 => 'Recipient(s) for notifications',
                    415:                                 col2 => 'Value',},
1.340     raeburn   416:                                {col1 => 'Nightly status check e-mail',
                    417:                                 col2 => 'Settings',},
1.286     raeburn   418:                                {col1 => 'Ask helpdesk form settings',
                    419:                                 col2 => 'Value',},],
1.230     raeburn   420:                     print => \&print_contacts,
                    421:                     modify => \&modify_contacts,
1.30      raeburn   422:                   },
                    423:         'usercreation' => 
                    424:                   { text => 'User creation',
1.67      raeburn   425:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   426:                     header => [{col1 => 'Format rule type',
                    427:                                 col2 => 'Format rules in force'},
1.34      raeburn   428:                                {col1 => 'User account creation',
                    429:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   430:                                {col1 => 'Context',
1.43      raeburn   431:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   432:                     print => \&print_usercreation,
                    433:                     modify => \&modify_usercreation,
1.30      raeburn   434:                   },
1.224     raeburn   435:         'selfcreation' => 
                    436:                   { text => 'Users self-creating accounts',
                    437:                     help => 'Domain_Configuration_Self_Creation', 
                    438:                     header => [{col1 => 'Self-creation with institutional username',
                    439:                                 col2 => 'Enabled?'},
                    440:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    441:                                 col2 => 'Information user can enter'},
1.303     raeburn   442:                                {col1 => 'Self-creation with e-mail verification',
1.224     raeburn   443:                                 col2 => 'Settings'}],
1.230     raeburn   444:                     print => \&print_selfcreation,
                    445:                     modify => \&modify_selfcreation,
1.224     raeburn   446:                   },
1.69      raeburn   447:         'usermodification' =>
1.33      raeburn   448:                   { text => 'User modification',
1.67      raeburn   449:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   450:                     header => [{col1 => 'Target user has role',
1.227     bisitz    451:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   452:                                {col1 => 'Target user has role',
1.227     bisitz    453:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   454:                     print => \&print_usermodification,
                    455:                     modify => \&modify_usermodification,
1.33      raeburn   456:                   },
1.69      raeburn   457:         'scantron' =>
1.346     raeburn   458:                   { text => 'Bubblesheet format',
1.67      raeburn   459:                     help => 'Domain_Configuration_Scantron_Format',
1.346     raeburn   460:                     header => [ {col1 => 'Bubblesheet format file',
                    461:                                  col2 => ''},
                    462:                                 {col1 => 'Bubblesheet data upload formats',
                    463:                                  col2 => 'Settings'}],
1.230     raeburn   464:                     print => \&print_scantron,
                    465:                     modify => \&modify_scantron,
1.46      raeburn   466:                   },
1.86      raeburn   467:         'requestcourses' => 
                    468:                  {text => 'Request creation of courses',
                    469:                   help => 'Domain_Configuration_Request_Courses',
                    470:                   header => [{col1 => 'User affiliation',
1.102     raeburn   471:                               col2 => 'Availability/Processing of requests',},
                    472:                              {col1 => 'Setting',
1.216     raeburn   473:                               col2 => 'Value'},
                    474:                              {col1 => 'Available textbooks',
1.235     raeburn   475:                               col2 => ''},
1.242     raeburn   476:                              {col1 => 'Available templates',
                    477:                               col2 => ''},
1.235     raeburn   478:                              {col1 => 'Validation (not official courses)',
                    479:                               col2 => 'Value'},],
1.230     raeburn   480:                   print => \&print_quotas,
                    481:                   modify => \&modify_quotas,
1.86      raeburn   482:                  },
1.163     raeburn   483:         'requestauthor' =>
1.223     bisitz    484:                  {text => 'Request Authoring Space',
1.163     raeburn   485:                   help => 'Domain_Configuration_Request_Author',
                    486:                   header => [{col1 => 'User affiliation',
                    487:                               col2 => 'Availability/Processing of requests',},
                    488:                              {col1 => 'Setting',
                    489:                               col2 => 'Value'}],
1.230     raeburn   490:                   print => \&print_quotas,
                    491:                   modify => \&modify_quotas,
1.163     raeburn   492:                  },
1.69      raeburn   493:         'coursecategories' =>
1.120     raeburn   494:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   495:                     help => 'Domain_Configuration_Cataloging_Courses',
1.238     raeburn   496:                     header => [{col1 => 'Catalog type/availability',
                    497:                                 col2 => '',},
                    498:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   499:                                 col2 => '',},
                    500:                                {col1 => 'Categories',
                    501:                                 col2 => '',
                    502:                                }],
1.230     raeburn   503:                     print => \&print_coursecategories,
                    504:                     modify => \&modify_coursecategories,
1.69      raeburn   505:                   },
                    506:         'serverstatuses' =>
1.77      raeburn   507:                  {text   => 'Access to server status pages',
1.69      raeburn   508:                   help   => 'Domain_Configuration_Server_Status',
                    509:                   header => [{col1 => 'Status Page',
                    510:                               col2 => 'Other named users',
                    511:                               col3 => 'Specific IPs',
                    512:                             }],
1.230     raeburn   513:                   print => \&print_serverstatuses,
                    514:                   modify => \&modify_serverstatuses,
1.69      raeburn   515:                  },
1.118     jms       516:         'helpsettings' =>
1.282     raeburn   517:                  {text   => 'Support settings',
1.118     jms       518:                   help   => 'Domain_Configuration_Help_Settings',
1.282     raeburn   519:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    520:                               col2 => 'Value'},
                    521:                              {col1 => 'Helpdesk Roles',
                    522:                               col2 => 'Settings'},],
1.230     raeburn   523:                   print  => \&print_helpsettings,
                    524:                   modify => \&modify_helpsettings,
1.118     jms       525:                  },
1.121     raeburn   526:         'coursedefaults' => 
                    527:                  {text => 'Course/Community defaults',
                    528:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   529:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    530:                               col2 => 'Value',},
                    531:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    532:                               col2 => 'Value',},],
1.230     raeburn   533:                   print => \&print_coursedefaults,
                    534:                   modify => \&modify_coursedefaults,
1.121     raeburn   535:                  },
1.231     raeburn   536:         'selfenrollment' => 
                    537:                  {text   => 'Self-enrollment in Course/Community',
                    538:                   help   => 'Domain_Configuration_Selfenrollment',
                    539:                   header => [{col1 => 'Configuration Rights',
                    540:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    541:                              {col1 => 'Defaults',
                    542:                               col2 => 'Value'},
                    543:                              {col1 => 'Self-enrollment validation (optional)',
                    544:                               col2 => 'Value'},],
                    545:                   print => \&print_selfenrollment,
                    546:                   modify => \&modify_selfenrollment,
                    547:                  },
1.120     raeburn   548:         'privacy' => 
1.357     raeburn   549:                  {text   => 'Availability of User Information',
1.120     raeburn   550:                   help   => 'Domain_Configuration_User_Privacy',
1.357     raeburn   551:                   header => [{col1 => 'Role assigned in different domain',
                    552:                               col2 => 'Approval options'},
                    553:                              {col1 => 'Role assigned in different domain to user of type',
                    554:                               col2 => 'User information available in that domain'},
                    555:                              {col1 => "Role assigned in user's domain",
                    556:                               col2 => 'Information viewable by privileged user'},
                    557:                              {col1 => "Role assigned in user's domain",
                    558:                               col2 => 'Information viewable by unprivileged user'}],
1.230     raeburn   559:                   print => \&print_privacy,
                    560:                   modify => \&modify_privacy,
1.120     raeburn   561:                  },
1.141     raeburn   562:         'usersessions' =>
1.145     raeburn   563:                  {text  => 'User session hosting/offloading',
1.137     raeburn   564:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   565:                   header => [{col1 => 'Domain server',
                    566:                               col2 => 'Servers to offload sessions to when busy'},
                    567:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   568:                               col2 => 'Rules'},
                    569:                              {col1 => "Hosting domain's own users elsewhere",
                    570:                               col2 => 'Rules'}],
1.230     raeburn   571:                   print => \&print_usersessions,
                    572:                   modify => \&modify_usersessions,
1.137     raeburn   573:                  },
1.279     raeburn   574:         'loadbalancing' =>
1.185     raeburn   575:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   576:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   577:                   header => [{col1 => 'Balancers',
1.150     raeburn   578:                               col2 => 'Default destinations',
1.183     bisitz    579:                               col3 => 'User affiliation',
1.150     raeburn   580:                               col4 => 'Overrides'},
                    581:                             ],
1.230     raeburn   582:                   print => \&print_loadbalancing,
                    583:                   modify => \&modify_loadbalancing,
1.150     raeburn   584:                  },
1.279     raeburn   585:         'ltitools' => 
1.267     raeburn   586:                  {text => 'External Tools (LTI)',
1.296     raeburn   587:                   help => 'Domain_Configuration_LTI_Tools',
1.267     raeburn   588:                   header => [{col1 => 'Setting',
                    589:                               col2 => 'Value',}],
                    590:                   print => \&print_ltitools,
                    591:                   modify => \&modify_ltitools,
                    592:                  },
1.372     raeburn   593:         'proctoring' =>
                    594:                  {text => 'Remote Proctoring Integration',
                    595:                   help => 'Domain_Configuration_Proctoring',
                    596:                   header => [{col1 => 'Name',
                    597:                               col2 => 'Configuration'}],
                    598:                   print => \&print_proctoring,
                    599:                   modify => \&modify_proctoring,
                    600:                  },
1.279     raeburn   601:         'ssl' =>
1.275     raeburn   602:                  {text  => 'LON-CAPA Network (SSL)',
                    603:                   help  => 'Domain_Configuration_Network_SSL',
                    604:                   header => [{col1 => 'Server',
                    605:                               col2 => 'Certificate Status'},
                    606:                              {col1 => 'Connections to other servers',
                    607:                               col2 => 'Rules'},
1.293     raeburn   608:                              {col1 => 'Connections from other servers',
                    609:                               col2 => 'Rules'},
1.275     raeburn   610:                              {col1 => "Replicating domain's published content",
                    611:                               col2 => 'Rules'}],
                    612:                   print => \&print_ssl,
                    613:                   modify => \&modify_ssl,
                    614:                  },
1.279     raeburn   615:         'trust' =>
                    616:                  {text   => 'Trust Settings',
                    617:                   help   => 'Domain_Configuration_Trust',
                    618:                   header => [{col1 => "Access to this domain's content by others",
                    619:                               col2 => 'Rules'},
                    620:                              {col1 => "Access to other domain's content by this domain",
                    621:                               col2 => 'Rules'},
                    622:                              {col1 => "Enrollment in this domain's courses by others",
                    623:                               col2 => 'Rules',},
                    624:                              {col1 => "Co-author roles in this domain for others",
                    625:                               col2 => 'Rules',},
                    626:                              {col1 => "Co-author roles for this domain's users elsewhere",
                    627:                               col2 => 'Rules',},
                    628:                              {col1 => "Domain roles in this domain assignable to others",
                    629:                               col2 => 'Rules'},
                    630:                              {col1 => "Course catalog for this domain displayed elsewhere",
                    631:                               col2 => 'Rules'},
                    632:                              {col1 => "Requests for creation of courses in this domain by others",
                    633:                               col2 => 'Rules'},
                    634:                              {col1 => "Users in other domains can send messages to this domain",
                    635:                               col2 => 'Rules'},],
                    636:                   print => \&print_trust,
                    637:                   modify => \&modify_trust,
                    638:                  },
1.320     raeburn   639:           'lti' =>
1.405     raeburn   640:                  {text => 'LTI Link Protection and LTI Consumers',
1.320     raeburn   641:                   help => 'Domain_Configuration_LTI_Provider',
1.405     raeburn   642:                   header => [{col1 => 'Encryption of shared secrets',
                    643:                               col2 => 'Settings'},
                    644:                              {col1 => 'Rules for shared secrets', 
                    645:                               col2 => 'Settings'},
1.406     raeburn   646:                              {col1 => 'Link Protectors',
1.405     raeburn   647:                               col2 => 'Settings'},
                    648:                              {col1 => 'Consumers',
                    649:                               col2 => 'Settings'},],
1.320     raeburn   650:                   print => \&print_lti,
                    651:                   modify => \&modify_lti,
                    652:                  },
1.394     raeburn   653:            'ipaccess' =>
                    654:                        {text => 'IP-based access control',
                    655:                         help => 'Domain_Configuration_IP_Access',
                    656:                         header => [{col1 => 'Setting',
                    657:                                     col2 => 'Value'},],
                    658:                         print  => \&print_ipaccess,
                    659:                         modify => \&modify_ipaccess,
                    660:                        },
1.3       raeburn   661:     );
1.110     raeburn   662:     if (keys(%servers) > 1) {
                    663:         $prefs{'login'}  = { text   => 'Log-in page options',
                    664:                              help   => 'Domain_Configuration_Login_Page',
                    665:                             header => [{col1 => 'Log-in Service',
                    666:                                         col2 => 'Server Setting',},
                    667:                                        {col1 => 'Log-in Page Items',
1.405     raeburn   668:                                         col2 => 'Settings'},
1.168     raeburn   669:                                        {col1 => 'Log-in Help',
1.256     raeburn   670:                                         col2 => 'Value'},
                    671:                                        {col1 => 'Custom HTML in document head',
1.386     raeburn   672:                                         col2 => 'Value'},
                    673:                                        {col1 => 'SSO',
                    674:                                         col2 => 'Dual login: SSO and non-SSO options'},
                    675:                                       ],
1.230     raeburn   676:                             print => \&print_login,
                    677:                             modify => \&modify_login,
1.110     raeburn   678:                            };
                    679:     }
1.174     foxr      680: 
1.6       raeburn   681:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   682:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   683:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   684:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   685:       text=>"Settings to display/modify"});
1.9       raeburn   686:     my $confname = $dom.'-domainconfig';
1.174     foxr      687: 
1.3       raeburn   688:     if ($phase eq 'process') {
1.212     raeburn   689:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    690:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   691:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   692:             $r->rflush();
1.212     raeburn   693:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   694:         }
1.30      raeburn   695:     } elsif ($phase eq 'display') {
1.192     raeburn   696:         my $js = &recaptcha_js().
1.236     raeburn   697:                  &toggle_display_js();
1.171     raeburn   698:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   699:             my ($othertitle,$usertypes,$types) =
                    700:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   701:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    702:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   703:                    &new_spares_js().
                    704:                    &common_domprefs_js().
                    705:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   706:         }
1.216     raeburn   707:         if (grep(/^requestcourses$/,@actions)) {
                    708:             my $javascript_validations;
                    709:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    710:             $js .= <<END;
                    711: <script type="text/javascript">
                    712: $javascript_validations
                    713: </script>
                    714: $coursebrowserjs
                    715: END
1.394     raeburn   716:         } elsif (grep(/^ipaccess$/,@actions)) {
                    717:             $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216     raeburn   718:         }
1.305     raeburn   719:         if (grep(/^selfcreation$/,@actions)) {
                    720:             $js .= &selfcreate_javascript();
                    721:         }
1.286     raeburn   722:         if (grep(/^contacts$/,@actions)) {
                    723:             $js .= &contacts_javascript();
                    724:         }
1.346     raeburn   725:         if (grep(/^scantron$/,@actions)) {
                    726:             $js .= &scantron_javascript();
                    727:         }
1.150     raeburn   728:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   729:     } else {
1.180     raeburn   730: # check if domconfig user exists for the domain.
                    731:         my $servadm = $r->dir_config('lonAdmEMail');
                    732:         my ($configuserok,$author_ok,$switchserver) =
                    733:             &config_check($dom,$confname,$servadm);
                    734:         unless ($configuserok eq 'ok') {
1.181     raeburn   735:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    736:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   737:                           $confname).
1.181     raeburn   738:                       '<br />'
                    739:             );
1.180     raeburn   740:             if ($switchserver) {
1.181     raeburn   741:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    742:                           '<br />'.
                    743:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    744:                           '<br />'.
                    745:                           &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).
                    746:                           '<br />'.
                    747:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    748:                 );
                    749:             } else {
                    750:                 $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.').
                    751:                           '<br />'.
                    752:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    753:                 );
1.180     raeburn   754:             }
                    755:             $r->print(&Apache::loncommon::end_page());
                    756:             return OK;
                    757:         }
1.21      raeburn   758:         if (keys(%domconfig) == 0) {
                    759:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   760:             my @ids=&Apache::lonnet::current_machine_ids();
                    761:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   762:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   763:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   764:                 my $custom_img_count = 0;
                    765:                 foreach my $img (@loginimages) {
                    766:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    767:                         $custom_img_count ++;
                    768:                     }
                    769:                 }
                    770:                 foreach my $role (@roles) {
                    771:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    772:                         $custom_img_count ++;
                    773:                     }
                    774:                 }
                    775:                 if ($custom_img_count > 0) {
1.94      raeburn   776:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   777:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   778:                     $r->print(
                    779:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    780:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    781:     &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 />'.
                    782:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    783:                     if ($switch_server) {
1.30      raeburn   784:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   785:                     }
1.91      raeburn   786:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   787:                     return OK;
                    788:                 }
                    789:             }
                    790:         }
1.91      raeburn   791:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   792:     }
                    793:     return OK;
                    794: }
                    795: 
                    796: sub process_changes {
1.205     raeburn   797:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   798:     my %domconfig;
                    799:     if (ref($values) eq 'HASH') {
                    800:         %domconfig = %{$values};
                    801:     }
1.3       raeburn   802:     my $output;
                    803:     if ($action eq 'login') {
1.205     raeburn   804:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   805:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   806:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   807:                                      $lastactref,%domconfig);
1.3       raeburn   808:     } elsif ($action eq 'quotas') {
1.216     raeburn   809:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   810:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   811:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   812:     } elsif ($action eq 'autoupdate') {
                    813:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   814:     } elsif ($action eq 'autocreate') {
                    815:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   816:     } elsif ($action eq 'directorysrch') {
1.295     raeburn   817:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   818:     } elsif ($action eq 'usercreation') {
1.28      raeburn   819:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   820:     } elsif ($action eq 'selfcreation') {
1.305     raeburn   821:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   822:     } elsif ($action eq 'usermodification') {
                    823:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   824:     } elsif ($action eq 'contacts') {
1.205     raeburn   825:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   826:     } elsif ($action eq 'defaults') {
1.212     raeburn   827:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   828:     } elsif ($action eq 'scantron') {
1.205     raeburn   829:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   830:     } elsif ($action eq 'coursecategories') {
1.239     raeburn   831:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   832:     } elsif ($action eq 'serverstatuses') {
                    833:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   834:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   835:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   836:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   837:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       838:     } elsif ($action eq 'helpsettings') {
1.285     raeburn   839:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121     raeburn   840:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   841:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   842:     } elsif ($action eq 'selfenrollment') {
                    843:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   844:     } elsif ($action eq 'usersessions') {
1.212     raeburn   845:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   846:     } elsif ($action eq 'loadbalancing') {
                    847:         $output = &modify_loadbalancing($dom,%domconfig);
1.267     raeburn   848:     } elsif ($action eq 'ltitools') {
                    849:         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372     raeburn   850:     } elsif ($action eq 'proctoring') {
                    851:         $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275     raeburn   852:     } elsif ($action eq 'ssl') {
                    853:         $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279     raeburn   854:     } elsif ($action eq 'trust') {
                    855:         $output = &modify_trust($dom,$lastactref,%domconfig);
1.320     raeburn   856:     } elsif ($action eq 'lti') {
                    857:         $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357     raeburn   858:     } elsif ($action eq 'privacy') {
                    859:         $output = &modify_privacy($dom,%domconfig);
1.354     raeburn   860:     } elsif ($action eq 'passwords') {
                    861:         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373     raeburn   862:     } elsif ($action eq 'wafproxy') {
                    863:         $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394     raeburn   864:     } elsif ($action eq 'ipaccess') {
                    865:         $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3       raeburn   866:     }
                    867:     return $output;
                    868: }
                    869: 
                    870: sub print_config_box {
1.9       raeburn   871:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   872:     my $rowtotal = 0;
1.49      raeburn   873:     my $output;
                    874:     if ($action eq 'coursecategories') {
                    875:         $output = &coursecategories_javascript($settings);
1.236     raeburn   876:     } elsif ($action eq 'defaults') {
                    877:         $output = &defaults_javascript($settings); 
1.354     raeburn   878:     } elsif ($action eq 'passwords') {
1.405     raeburn   879:         $output = &passwords_javascript($action);
1.282     raeburn   880:     } elsif ($action eq 'helpsettings') {
                    881:         my (%privs,%levelscurrent);
                    882:         my %full=();
                    883:         my %levels=(
                    884:                      course => {},
                    885:                      domain => {},
                    886:                      system => {},
                    887:                    );
                    888:         my $context = 'domain';
                    889:         my $crstype = 'Course';
                    890:         my $formname = 'display';
                    891:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    892:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    893:         $output =
                    894:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, 
                    895:                                                       \@templateroles);
1.334     raeburn   896:     } elsif ($action eq 'ltitools') {
                    897:         $output .= &ltitools_javascript($settings);
                    898:     } elsif ($action eq 'lti') {
1.405     raeburn   899:         $output .= &passwords_javascript('secrets')."\n".
                    900:                    &lti_javascript($dom,$settings);
1.372     raeburn   901:     } elsif ($action eq 'proctoring') {
                    902:         $output .= &proctoring_javascript($settings);
1.381     raeburn   903:     } elsif ($action eq 'wafproxy') {
                    904:         $output .= &wafproxy_javascript($dom);
1.385     raeburn   905:     } elsif ($action eq 'autoupdate') {
                    906:         $output .= &autoupdate_javascript();
1.399     raeburn   907:     } elsif ($action eq 'autoenroll') {
                    908:         $output .= &autoenroll_javascript();
1.386     raeburn   909:     } elsif ($action eq 'login') {
                    910:         $output .= &saml_javascript();
1.394     raeburn   911:     } elsif ($action eq 'ipaccess') {
                    912:         $output .= &ipaccess_javascript($settings);
1.91      raeburn   913:     }
1.236     raeburn   914:     $output .=
1.30      raeburn   915:          '<table class="LC_nested_outer">
1.3       raeburn   916:           <tr>
1.306     raeburn   917:            <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66      raeburn   918:            &mt($item->{text}).'&nbsp;'.
                    919:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    920:           '</tr>';
1.30      raeburn   921:     $rowtotal ++;
1.110     raeburn   922:     my $numheaders = 1;
                    923:     if (ref($item->{'header'}) eq 'ARRAY') {
                    924:         $numheaders = scalar(@{$item->{'header'}});
                    925:     }
                    926:     if ($numheaders > 1) {
1.64      raeburn   927:         my $colspan = '';
1.145     raeburn   928:         my $rightcolspan = '';
1.369     raeburn   929:         my $leftnobr = '';
1.238     raeburn   930:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   931:             ($action eq 'directorysrch') ||
1.386     raeburn   932:             (($action eq 'login') && ($numheaders < 5))) {
1.64      raeburn   933:             $colspan = ' colspan="2"';
                    934:         }
1.145     raeburn   935:         if ($action eq 'usersessions') {
                    936:             $rightcolspan = ' colspan="3"'; 
                    937:         }
1.369     raeburn   938:         if ($action eq 'passwords') {
                    939:             $leftnobr = ' LC_nobreak';
                    940:         }
1.30      raeburn   941:         $output .= '
1.3       raeburn   942:           <tr>
                    943:            <td>
                    944:             <table class="LC_nested">
                    945:              <tr class="LC_info_row">
1.369     raeburn   946:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   947:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   948:              </tr>';
1.69      raeburn   949:         $rowtotal ++;
1.230     raeburn   950:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   951:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   952:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286     raeburn   953:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.405     raeburn   954:             ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') || ($action eq 'lti')) {
1.230     raeburn   955:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354     raeburn   956:         } elsif ($action eq 'passwords') {
                    957:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   958:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   959:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346     raeburn   960:         } elsif ($action eq 'scantron') {
                    961:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   962:         } elsif ($action eq 'login') {
1.386     raeburn   963:             if ($numheaders == 5) {
1.168     raeburn   964:                 $colspan = ' colspan="2"';
                    965:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    966:             } else {
                    967:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    968:             }
1.230     raeburn   969:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   970:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       971:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   972:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   973:         }
1.30      raeburn   974:         $output .= '
1.6       raeburn   975:            </table>
                    976:           </td>
                    977:          </tr>
                    978:          <tr>
                    979:            <td>
                    980:             <table class="LC_nested">
                    981:              <tr class="LC_info_row">
1.230     raeburn   982:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    983:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   984:              </tr>';
                    985:             $rowtotal ++;
1.230     raeburn   986:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    987:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn   988:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.409     raeburn   989:             ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.405     raeburn   990:             ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti')) {
1.238     raeburn   991:             if ($action eq 'coursecategories') {
                    992:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    993:                 $colspan = ' colspan="2"';
1.279     raeburn   994:             } elsif ($action eq 'trust') {
                    995:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354     raeburn   996:             } elsif ($action eq 'passwords') {
                    997:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238     raeburn   998:             } else {
                    999:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                   1000:             }
1.279     raeburn  1001:             if ($action eq 'trust') {
                   1002:                 $output .= '
                   1003:             </table>
                   1004:           </td>
                   1005:          </tr>';
                   1006:                 my @trusthdrs = qw(2 3 4 5 6 7);
                   1007:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                   1008:                 for (my $i=0; $i<@trusthdrs; $i++) {
                   1009:                     $output .= '
                   1010:          <tr>
                   1011:            <td>
                   1012:             <table class="LC_nested">
                   1013:              <tr class="LC_info_row">
                   1014:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                   1015:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                   1016:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                   1017:             </table>
                   1018:           </td>
                   1019:          </tr>';
                   1020:                 }
                   1021:                 $output .= '
                   1022:          <tr>
                   1023:            <td>
                   1024:             <table class="LC_nested">
                   1025:              <tr class="LC_info_row">
                   1026:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                   1027:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                   1028:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1029:             } else {
                   1030:                 $output .= '
1.63      raeburn  1031:            </table>
                   1032:           </td>
                   1033:          </tr>
                   1034:          <tr>
                   1035:            <td>
                   1036:             <table class="LC_nested">
                   1037:              <tr class="LC_info_row">
                   1038:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn  1039:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn  1040:              </tr>'."\n";
1.279     raeburn  1041:                 if ($action eq 'coursecategories') {
                   1042:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405     raeburn  1043:                 } elsif (($action eq 'contacts') || ($action eq 'privacy') || 
                   1044:                          ($action eq 'passwords') || ($action eq 'lti')) {
1.354     raeburn  1045:                     if ($action eq 'passwords') {
                   1046:                         $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                   1047:                     } else {
                   1048:                         $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                   1049:                     }
                   1050:                     $output .= '
1.340     raeburn  1051:              </tr>
                   1052:             </table>
                   1053:            </td>
                   1054:           </tr>
                   1055:           <tr>
                   1056:            <td>
                   1057:             <table class="LC_nested">
                   1058:              <tr class="LC_info_row">
1.369     raeburn  1059:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354     raeburn  1060:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
                   1061:                     if ($action eq 'passwords') {
                   1062:                         $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                   1063:                     } else {
                   1064:                         $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1065:                     }
                   1066:                     $output .= '
1.340     raeburn  1067:             </table>
                   1068:           </td>
                   1069:          </tr>
                   1070:          <tr>';
1.279     raeburn  1071:                 } else {
                   1072:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1073:                 }
1.238     raeburn  1074:             }
1.63      raeburn  1075:             $rowtotal ++;
1.236     raeburn  1076:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409     raeburn  1077:                  ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
                   1078:                  ($action eq 'wafproxy')) {
1.230     raeburn  1079:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346     raeburn  1080:         } elsif ($action eq 'scantron') {
                   1081:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293     raeburn  1082:         } elsif ($action eq 'ssl') {
                   1083:             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
                   1084:             </table>
                   1085:           </td>
                   1086:          </tr>
                   1087:          <tr>
                   1088:            <td>
                   1089:             <table class="LC_nested">
                   1090:              <tr class="LC_info_row">
                   1091:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1092:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                   1093:                            $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
                   1094:             </table>
                   1095:           </td>
                   1096:          </tr>
                   1097:          <tr>
                   1098:            <td>
                   1099:             <table class="LC_nested">
                   1100:              <tr class="LC_info_row">
                   1101:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1102:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                   1103:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn  1104:         } elsif ($action eq 'login') {
1.386     raeburn  1105:             if ($numheaders == 5) {
1.168     raeburn  1106:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1107:            </table>
                   1108:           </td>
                   1109:          </tr>
                   1110:          <tr>
                   1111:            <td>
                   1112:             <table class="LC_nested">
                   1113:              <tr class="LC_info_row">
                   1114:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn  1115:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn  1116:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1117:                 $rowtotal ++;
                   1118:             } else {
                   1119:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1120:             }
1.256     raeburn  1121:             $output .= '
                   1122:            </table>
                   1123:           </td>
                   1124:          </tr>
                   1125:          <tr>
                   1126:            <td>
                   1127:             <table class="LC_nested">
                   1128:              <tr class="LC_info_row">';
1.386     raeburn  1129:             if ($numheaders == 5) {
1.256     raeburn  1130:                 $output .= '
                   1131:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1132:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1133:              </tr>';
                   1134:             } else {
                   1135:                 $output .= '
                   1136:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1137:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                   1138:              </tr>';
                   1139:             }
                   1140:             $rowtotal ++;
1.386     raeburn  1141:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1142:            </table>
                   1143:           </td>
                   1144:          </tr>
                   1145:          <tr>
                   1146:            <td>
                   1147:             <table class="LC_nested">
                   1148:              <tr class="LC_info_row">';
                   1149:             if ($numheaders == 5) {
                   1150:                 $output .= '
                   1151:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1152:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
                   1153:              </tr>';
                   1154:             } else {
                   1155:                 $output .= '
                   1156:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1157:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1158:              </tr>';
                   1159:             }
                   1160:             $rowtotal ++;
                   1161:             $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn  1162:         } elsif ($action eq 'requestcourses') {
1.247     raeburn  1163:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                   1164:             $rowtotal ++;
                   1165:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn  1166:            </table>
                   1167:           </td>
                   1168:          </tr>
                   1169:          <tr>
                   1170:            <td>
                   1171:             <table class="LC_nested">
                   1172:              <tr class="LC_info_row">
                   1173:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1174:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn  1175:                        &textbookcourses_javascript($settings).
                   1176:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                   1177:             </table>
                   1178:            </td>
                   1179:           </tr>
                   1180:          <tr>
                   1181:            <td>
                   1182:             <table class="LC_nested">
                   1183:              <tr class="LC_info_row">
                   1184:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1185:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                   1186:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn  1187:             </table>
                   1188:            </td>
                   1189:           </tr>
                   1190:           <tr>
                   1191:            <td>
                   1192:             <table class="LC_nested">
                   1193:              <tr class="LC_info_row">
1.306     raeburn  1194:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1195:               <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn  1196:              </tr>'.
                   1197:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn  1198:         } elsif ($action eq 'requestauthor') {
                   1199:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn  1200:             $rowtotal ++;
1.122     jms      1201:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1202:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn  1203:            </table>
                   1204:           </td>
                   1205:          </tr>
                   1206:          <tr>
                   1207:            <td>
                   1208:             <table class="LC_nested">
                   1209:              <tr class="LC_info_row">
1.306     raeburn  1210:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69      raeburn  1211:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306     raeburn  1212:               <td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1213:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1214:              </tr>'.
1.30      raeburn  1215:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1216:            </table>
                   1217:           </td>
                   1218:          </tr>
                   1219:          <tr>
                   1220:            <td>
                   1221:             <table class="LC_nested">
                   1222:              <tr class="LC_info_row">
1.59      bisitz   1223:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1224:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1225:              </tr>'.
1.30      raeburn  1226:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1227:             $rowtotal += 2;
1.6       raeburn  1228:         }
1.3       raeburn  1229:     } else {
1.30      raeburn  1230:         $output .= '
1.3       raeburn  1231:           <tr>
                   1232:            <td>
                   1233:             <table class="LC_nested">
1.30      raeburn  1234:              <tr class="LC_info_row">';
1.277     raeburn  1235:         if ($action eq 'login') {
1.30      raeburn  1236:             $output .= '  
1.59      bisitz   1237:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1238:         } elsif ($action eq 'serverstatuses') {
                   1239:             $output .= '
1.306     raeburn  1240:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69      raeburn  1241:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1242: 
1.6       raeburn  1243:         } else {
1.30      raeburn  1244:             $output .= '
1.306     raeburn  1245:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1246:         }
1.72      raeburn  1247:         if (defined($item->{'header'}->[0]->{'col3'})) {
1.306     raeburn  1248:             $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72      raeburn  1249:                        &mt($item->{'header'}->[0]->{'col2'});
                   1250:             if ($action eq 'serverstatuses') {
                   1251:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1252:             } 
1.69      raeburn  1253:         } else {
1.306     raeburn  1254:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1255:                        &mt($item->{'header'}->[0]->{'col2'});
                   1256:         }
                   1257:         $output .= '</td>';
                   1258:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1259:             if (defined($item->{'header'}->[0]->{'col4'})) {
1.306     raeburn  1260:                 $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150     raeburn  1261:                             &mt($item->{'header'}->[0]->{'col3'});
                   1262:             } else {
1.306     raeburn  1263:                 $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1264:                            &mt($item->{'header'}->[0]->{'col3'});
                   1265:             }
1.69      raeburn  1266:             if ($action eq 'serverstatuses') {
                   1267:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1268:             }
                   1269:             $output .= '</td>';
1.6       raeburn  1270:         }
1.150     raeburn  1271:         if ($item->{'header'}->[0]->{'col4'}) {
1.306     raeburn  1272:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1273:                        &mt($item->{'header'}->[0]->{'col4'});
                   1274:         }
1.69      raeburn  1275:         $output .= '</tr>';
1.48      raeburn  1276:         $rowtotal ++;
1.168     raeburn  1277:         if ($action eq 'quotas') {
1.86      raeburn  1278:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1279:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.286     raeburn  1280:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
1.405     raeburn  1281:                  ($action eq 'ltitools') || ($action eq 'proctoring') ||
                   1282:                  ($action eq 'ipaccess')) {
1.230     raeburn  1283:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1284:         }
1.3       raeburn  1285:     }
1.30      raeburn  1286:     $output .= '
1.3       raeburn  1287:    </table>
                   1288:   </td>
                   1289:  </tr>
1.30      raeburn  1290: </table><br />';
                   1291:     return ($output,$rowtotal);
1.1       raeburn  1292: }
                   1293: 
1.3       raeburn  1294: sub print_login {
1.168     raeburn  1295:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386     raeburn  1296:     my ($css_class,$datatable,$switchserver,%lt);
1.6       raeburn  1297:     my %choices = &login_choices();
1.386     raeburn  1298:     if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
                   1299:         %lt = &login_file_options();
                   1300:         $switchserver = &check_switchserver($dom,$confname);
                   1301:     }
1.168     raeburn  1302:     if ($caller eq 'service') {
1.149     raeburn  1303:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1304:         my $choice = $choices{'disallowlogin'};
                   1305:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1306:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306     raeburn  1307:                       '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1308:                       '<th>'.$choices{'server'}.'</th>'.
                   1309:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1310:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1311:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1312:         my %disallowed;
                   1313:         if (ref($settings) eq 'HASH') {
                   1314:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1315:                %disallowed = %{$settings->{'loginvia'}};
                   1316:             }
                   1317:         }
                   1318:         foreach my $lonhost (sort(keys(%servers))) {
                   1319:             my $direct = 'selected="selected"';
1.128     raeburn  1320:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1321:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1322:                     $direct = '';
                   1323:                 }
1.110     raeburn  1324:             }
1.115     raeburn  1325:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1326:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1327:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1328:                           '</option>';
1.184     raeburn  1329:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1330:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1331:                 my $selected = '';
1.128     raeburn  1332:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1333:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1334:                         $selected = 'selected="selected"';
                   1335:                     }
1.110     raeburn  1336:                 }
                   1337:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1338:                               $servers{$hostid}.'</option>';
                   1339:             }
1.128     raeburn  1340:             $datatable .= '</select></td>'.
                   1341:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1342:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1343:                 my $pathname = $path;
                   1344:                 if ($path eq 'custom') {
                   1345:                     $pathname = &mt('Custom Path').' ->';
                   1346:                 }
                   1347:                 my $selected = '';
                   1348:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1349:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1350:                         $selected = 'selected="selected"';
                   1351:                     }
                   1352:                 } elsif ($path eq '') {
                   1353:                     $selected = 'selected="selected"';
                   1354:                 }
                   1355:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1356:             }
                   1357:             $datatable .= '</select></td>';
                   1358:             my ($custom,$exempt);
                   1359:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1360:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1361:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1362:             }
                   1363:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1364:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1365:                           '</tr>';
1.110     raeburn  1366:         }
                   1367:         $datatable .= '</table></td></tr>';
                   1368:         return $datatable;
1.168     raeburn  1369:     } elsif ($caller eq 'page') {
                   1370:         my %defaultchecked = ( 
                   1371:                                'coursecatalog' => 'on',
1.188     raeburn  1372:                                'helpdesk'      => 'on',
1.168     raeburn  1373:                                'adminmail'     => 'off',
                   1374:                                'newuser'       => 'off',
                   1375:                              );
1.188     raeburn  1376:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1377:         my (%checkedon,%checkedoff);
1.42      raeburn  1378:         foreach my $item (@toggles) {
1.168     raeburn  1379:             if ($defaultchecked{$item} eq 'on') { 
                   1380:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1381:                 $checkedoff{$item} = ' ';
1.168     raeburn  1382:             } elsif ($defaultchecked{$item} eq 'off') {
                   1383:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1384:                 $checkedon{$item} = ' ';
                   1385:             }
1.1       raeburn  1386:         }
1.168     raeburn  1387:         my @images = ('img','logo','domlogo','login');
1.402     raeburn  1388:         my @alttext = ('img','logo','domlogo');
1.168     raeburn  1389:         my @logintext = ('textcol','bgcol');
                   1390:         my @bgs = ('pgbg','mainbg','sidebg');
                   1391:         my @links = ('link','alink','vlink');
                   1392:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1393:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1394:         my (%is_custom,%designs);
                   1395:         my %defaults = (
                   1396:                        font => $defaultdesign{'login.font'},
                   1397:                        );
1.6       raeburn  1398:         foreach my $item (@images) {
1.168     raeburn  1399:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1400:             $defaults{'showlogo'}{$item} = 1;
                   1401:         }
                   1402:         foreach my $item (@bgs) {
                   1403:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1404:         }
1.41      raeburn  1405:         foreach my $item (@logintext) {
1.168     raeburn  1406:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1407:         }
1.168     raeburn  1408:         foreach my $item (@links) {
                   1409:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1410:         }
1.168     raeburn  1411:         if (ref($settings) eq 'HASH') {
                   1412:             foreach my $item (@toggles) {
                   1413:                 if ($settings->{$item} eq '1') {
                   1414:                     $checkedon{$item} =  ' checked="checked" ';
                   1415:                     $checkedoff{$item} = ' ';
                   1416:                 } elsif ($settings->{$item} eq '0') {
                   1417:                     $checkedoff{$item} =  ' checked="checked" ';
                   1418:                     $checkedon{$item} = ' ';
                   1419:                 }
                   1420:             }
                   1421:             foreach my $item (@images) {
                   1422:                 if (defined($settings->{$item})) {
                   1423:                     $designs{$item} = $settings->{$item};
                   1424:                     $is_custom{$item} = 1;
                   1425:                 }
                   1426:                 if (defined($settings->{'showlogo'}{$item})) {
                   1427:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1428:                 }
                   1429:             }
1.402     raeburn  1430:             foreach my $item (@alttext) {
                   1431:                 if (ref($settings->{'alttext'}) eq 'HASH') {
                   1432:                     if ($settings->{'alttext'}->{$item} ne '') {
                   1433:                         $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
                   1434:                     }
                   1435:                 }
                   1436:             }
1.168     raeburn  1437:             foreach my $item (@logintext) {
                   1438:                 if ($settings->{$item} ne '') {
                   1439:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1440:                     $is_custom{$item} = 1;
                   1441:                 }
                   1442:             }
                   1443:             if ($settings->{'font'} ne '') {
                   1444:                 $designs{'font'} = $settings->{'font'};
                   1445:                 $is_custom{'font'} = 1;
                   1446:             }
                   1447:             foreach my $item (@bgs) {
                   1448:                 if ($settings->{$item} ne '') {
                   1449:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1450:                     $is_custom{$item} = 1;
                   1451:                 }
                   1452:             }
                   1453:             foreach my $item (@links) {
                   1454:                 if ($settings->{$item} ne '') {
                   1455:                     $designs{'links'}{$item} = $settings->{$item};
                   1456:                     $is_custom{$item} = 1;
                   1457:                 }
                   1458:             }
                   1459:         } else {
                   1460:             if ($designhash{$dom.'.login.font'} ne '') {
                   1461:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1462:                 $is_custom{'font'} = 1;
                   1463:             }
                   1464:             foreach my $item (@images) {
                   1465:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1466:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1467:                     $is_custom{$item} = 1;
                   1468:                 }
                   1469:             }
                   1470:             foreach my $item (@bgs) {
                   1471:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1472:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1473:                     $is_custom{$item} = 1;
                   1474:                 }
1.6       raeburn  1475:             }
1.168     raeburn  1476:             foreach my $item (@links) {
                   1477:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1478:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1479:                     $is_custom{$item} = 1;
                   1480:                 }
1.6       raeburn  1481:             }
                   1482:         }
1.168     raeburn  1483:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1484:                                                       logo => 'Institution Logo',
                   1485:                                                       domlogo => 'Domain Logo',
                   1486:                                                       login => 'Login box');
                   1487:         my $itemcount = 1;
                   1488:         foreach my $item (@toggles) {
                   1489:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1490:             $datatable .=  
                   1491:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1492:                 '</td><td>'.
                   1493:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1494:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1495:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1496:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1497:                 '</tr>';
                   1498:             $itemcount ++;
1.6       raeburn  1499:         }
1.168     raeburn  1500:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1501:         $datatable .= '</tr></table></td></tr>';
                   1502:     } elsif ($caller eq 'help') {
1.386     raeburn  1503:         my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168     raeburn  1504:         my $itemcount = 1;
                   1505:         $defaulturl = '/adm/loginproblems.html';
                   1506:         $defaulttype = 'default';
                   1507:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1508:         my @currlangs;
                   1509:         if (ref($settings) eq 'HASH') {
                   1510:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1511:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1512:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1513:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1514:                     $type{$key} = 'custom';
                   1515:                     unless ($key eq 'nolang') {
                   1516:                         push(@currlangs,$key);
                   1517:                     }
                   1518:                 }
                   1519:             } elsif ($settings->{'helpurl'} ne '') {
                   1520:                 $type{'nolang'} = 'custom';
                   1521:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1522:             }
                   1523:         }
1.168     raeburn  1524:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1525:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1526:             $datatable .= '<tr'.$css_class.'>';
                   1527:             if ($url{$lang} eq '') {
                   1528:                 $url{$lang} = $defaulturl;
                   1529:             }
                   1530:             if ($type{$lang} eq '') {
                   1531:                 $type{$lang} = $defaulttype;
                   1532:             }
                   1533:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1534:             if ($lang eq 'nolang') {
                   1535:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1536:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1537:             } else {
                   1538:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1539:                                   $langchoices{$lang},
                   1540:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1541:             }
                   1542:             $datatable .= '</span></td>'."\n".
                   1543:                           '<td class="LC_left_item">';
                   1544:             if ($type{$lang} eq 'custom') {
                   1545:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1546:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1547:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1548:             } else {
                   1549:                 $datatable .= $lt{'upl'};
                   1550:             }
                   1551:             $datatable .='<br />';
                   1552:             if ($switchserver) {
                   1553:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1554:             } else {
                   1555:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1556:             }
1.168     raeburn  1557:             $datatable .= '</td></tr>';
                   1558:             $itemcount ++;
1.6       raeburn  1559:         }
1.168     raeburn  1560:         my @addlangs;
                   1561:         foreach my $lang (sort(keys(%langchoices))) {
                   1562:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1563:             push(@addlangs,$lang);
                   1564:         }
                   1565:         if (@addlangs > 0) {
                   1566:             my %toadd;
                   1567:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1568:             $toadd{''} = &mt('Select');
                   1569:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1570:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1571:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1572:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1573:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1574:             if ($switchserver) {
                   1575:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1576:             } else {
                   1577:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1578:             }
1.168     raeburn  1579:             $datatable .= '</td></tr>';
1.169     raeburn  1580:             $itemcount ++;
1.6       raeburn  1581:         }
1.169     raeburn  1582:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1583:     } elsif ($caller eq 'headtag') {
                   1584:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1585:         my $choice = $choices{'headtag'};
                   1586:         $css_class = ' class="LC_odd_row"';
                   1587:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1588:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1589:                       '<th>'.$choices{'current'}.'</th>'.
                   1590:                       '<th>'.$choices{'action'}.'</th>'.
                   1591:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1592:         my (%currurls,%currexempt);
                   1593:         if (ref($settings) eq 'HASH') {
                   1594:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1595:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1596:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1597:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1598:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1599:                     }
                   1600:                 }
                   1601:             }
                   1602:         }
                   1603:         foreach my $lonhost (sort(keys(%domservers))) {
                   1604:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1605:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1606:             if ($currurls{$lonhost}) {
                   1607:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1608:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1609:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1610:                               '">'.$lt{'curr'}.'</a></td>'.
                   1611:                               '<td><span class="LC_nobreak"><label>'.
                   1612:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1613:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1614:             } else {
                   1615:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1616:             }
                   1617:             $datatable .='<br />';
                   1618:             if ($switchserver) {
                   1619:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1620:             } else {
                   1621:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1622:             }
1.330     raeburn  1623:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256     raeburn  1624:         }
                   1625:         $datatable .= '</table></td></tr>';
1.386     raeburn  1626:     } elsif ($caller eq 'saml') {
                   1627:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1628:         $datatable .= '<tr><td colspan="3" style="text-align: left">'.
                   1629:                       '<table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1630:                       '<th>'.$choices{'samllanding'}.'</th>'.
                   1631:                       '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412     raeburn  1632:         my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386     raeburn  1633:         foreach my $lonhost (keys(%domservers)) {
                   1634:             $samlurl{$lonhost} = '/adm/sso';
                   1635:             $styleon{$lonhost} = 'display:none';
                   1636:             $styleoff{$lonhost} = '';
                   1637:         }
1.411     raeburn  1638:         if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386     raeburn  1639:             foreach my $lonhost (keys(%{$settings->{'saml'}})) {
                   1640:                 if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
                   1641:                     $saml{$lonhost} = 1;
                   1642:                     $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
                   1643:                     $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
                   1644:                     $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                   1645:                     $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                   1646:                     $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412     raeburn  1647:                     $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386     raeburn  1648:                     $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                   1649:                     $styleon{$lonhost} = '';
                   1650:                     $styleoff{$lonhost} = 'display:none';
                   1651:                 } else {
                   1652:                     $styleon{$lonhost} = 'display:none';
                   1653:                     $styleoff{$lonhost} = '';
                   1654:                 }
                   1655:             }
                   1656:         }
                   1657:         my $itemcount = 1;
                   1658:         foreach my $lonhost (sort(keys(%domservers))) {
                   1659:             my $samlon = ' ';
                   1660:             my $samloff = ' checked="checked" ';
                   1661:             if ($saml{$lonhost}) {
                   1662:                 $samlon = $samloff;
                   1663:                 $samloff = ' ';
                   1664:             }
1.412     raeburn  1665:             my $samlwinon = '';
                   1666:             my $samlwinoff = ' checked="checked"';
                   1667:             if ($samlwindow{$lonhost}) {
                   1668:                 $samlwinon = $samlwinoff;
                   1669:                 $samlwinoff = '';
                   1670:             }
1.386     raeburn  1671:             my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1672:             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
                   1673:                           '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
                   1674:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
                   1675:                           &mt('No').'</label>'.('&nbsp;'x2).
                   1676:                           '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
                   1677:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
                   1678:                           &mt('Yes').'</label></span></td>'.
                   1679:                           '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412     raeburn  1680:                           '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386     raeburn  1681:                           '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412     raeburn  1682:                           '<th>'.&mt('Alt Text').'</th></tr>'.
                   1683:                           '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386     raeburn  1684:                           $samltext{$lonhost}.'" /></td><td>';
                   1685:             if ($samlimg{$lonhost}) {
                   1686:                 $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
                   1687:                               '<span class="LC_nobreak"><label>'.
                   1688:                               '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
                   1689:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1690:             } else {
                   1691:                 $datatable .= $lt{'upl'};
                   1692:             }
                   1693:             $datatable .='<br />';
                   1694:             if ($switchserver) {
                   1695:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1696:             } else {
                   1697:                 $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
                   1698:             }
                   1699:             $datatable .= '</td>'.
1.412     raeburn  1700:                           '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
                   1701:                           'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
                   1702:                           '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
                   1703:                           '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
                   1704:                           '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
                   1705:                           '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
                   1706:                           '<tr'.$css_class.'>'.
                   1707:                           '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386     raeburn  1708:                           'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412     raeburn  1709:                           '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386     raeburn  1710:                           $samltitle{$lonhost}.'</textarea></td>'.
1.412     raeburn  1711:                           '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
                   1712:                           &mt('No').'</label>'.('&nbsp;'x2).'<label><input type="radio" '.
                   1713:                           'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
                   1714:                           '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386     raeburn  1715:                           'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                   1716:                           '</table></td>'.
                   1717:                           '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%">&nbsp;</td></tr>';
                   1718:            $itemcount ++;
                   1719:         }
                   1720:         $datatable .= '</table></td></tr>';
1.1       raeburn  1721:     }
1.6       raeburn  1722:     return $datatable;
                   1723: }
                   1724: 
                   1725: sub login_choices {
                   1726:     my %choices =
                   1727:         &Apache::lonlocal::texthash (
1.116     bisitz   1728:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1729:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1730:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1731:             disallowlogin => "Login page requests redirected",
                   1732:             hostid        => "Server",
1.128     raeburn  1733:             server        => "Redirect to:",
                   1734:             serverpath    => "Path",
                   1735:             custompath    => "Custom", 
                   1736:             exempt        => "Exempt IP(s)",
1.110     raeburn  1737:             directlogin   => "No redirect",
                   1738:             newuser       => "Link to create a user account",
                   1739:             img           => "Header",
                   1740:             logo          => "Main Logo",
                   1741:             domlogo       => "Domain Logo",
                   1742:             login         => "Log-in Header", 
                   1743:             textcol       => "Text color",
                   1744:             bgcol         => "Box color",
                   1745:             bgs           => "Background colors",
                   1746:             links         => "Link colors",
                   1747:             font          => "Font color",
                   1748:             pgbg          => "Header",
                   1749:             mainbg        => "Page",
                   1750:             sidebg        => "Login box",
                   1751:             link          => "Link",
                   1752:             alink         => "Active link",
                   1753:             vlink         => "Visited link",
1.256     raeburn  1754:             headtag       => "Custom markup",
                   1755:             action        => "Action",
                   1756:             current       => "Current",
1.386     raeburn  1757:             samllanding   => "Dual login?",
                   1758:             samloptions   => "Options",
1.402     raeburn  1759:             alttext       => "Alt text",
1.6       raeburn  1760:         );
                   1761:     return %choices;
                   1762: }
                   1763: 
1.386     raeburn  1764: sub login_file_options {
                   1765:       return &Apache::lonlocal::texthash(
                   1766:                                            del     => 'Delete?',
                   1767:                                            rep     => 'Replace:',
                   1768:                                            upl     => 'Upload:',
                   1769:                                            curr    => 'View contents',
                   1770:                                            default => 'Default',
                   1771:                                            custom  => 'Custom',
                   1772:                                            none    => 'None',
                   1773:       );
                   1774: }
                   1775: 
1.394     raeburn  1776: sub print_ipaccess {
                   1777:     my ($dom,$settings,$rowtotal) = @_;
                   1778:     my $css_class;
                   1779:     my $itemcount = 0;
                   1780:     my $datatable;
                   1781:     my %ordered;
                   1782:     if (ref($settings) eq 'HASH') {
                   1783:         foreach my $item (keys(%{$settings})) {
                   1784:             if (ref($settings->{$item}) eq 'HASH') {
                   1785:                 my $num = $settings->{$item}{'order'};
                   1786:                 if ($num eq '') {
                   1787:                     $num = scalar(keys(%{$settings}));
                   1788:                 }
                   1789:                 $ordered{$num} = $item;
                   1790:             }
                   1791:         }
                   1792:     }
                   1793:     my $maxnum = scalar(keys(%ordered));
                   1794:     if (keys(%ordered)) {
                   1795:         my @items = sort { $a <=> $b } keys(%ordered);
                   1796:         for (my $i=0; $i<@items; $i++) {
                   1797:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1798:             my $item = $ordered{$items[$i]};
                   1799:             my ($name,$ipranges,%commblocks,%courses);
                   1800:             if (ref($settings->{$item}) eq 'HASH') {
                   1801:                 $name = $settings->{$item}->{'name'};
                   1802:                 $ipranges = $settings->{$item}->{'ip'};
                   1803:                 if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
                   1804:                     %commblocks = %{$settings->{$item}->{'commblocks'}};
                   1805:                 }
                   1806:                 if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
                   1807:                     %courses = %{$settings->{$item}->{'courses'}};
                   1808:                 }
                   1809:             }
                   1810:             my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
                   1811:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   1812:                          .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
                   1813:             for (my $k=0; $k<=$maxnum; $k++) {
                   1814:                 my $vpos = $k+1;
                   1815:                 my $selstr;
                   1816:                 if ($k == $i) {
                   1817:                     $selstr = ' selected="selected" ';
                   1818:                 }
                   1819:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1820:             }
                   1821:             $datatable .= '</select>'.('&nbsp;'x2).
                   1822:                 '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
                   1823:                 &mt('Delete?').'</label></span></td>'.
                   1824:                 '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
                   1825:                 &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
                   1826:                 '</td></tr>';
                   1827:             $itemcount ++;
                   1828:         }
                   1829:     }
                   1830:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1831:     my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
                   1832:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   1833:                   '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
                   1834:                   '<select name="ipaccess_pos_add"'.$chgstr.'>';
                   1835:     for (my $k=0; $k<$maxnum+1; $k++) {
                   1836:         my $vpos = $k+1;
                   1837:         my $selstr;
                   1838:         if ($k == $maxnum) {
                   1839:             $selstr = ' selected="selected" ';
                   1840:         }
                   1841:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1842:     }
                   1843:     $datatable .= '</select>&nbsp;'."\n".
                   1844:                   '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   1845:                   '<td colspan="2">'.
                   1846:                   &ipaccess_options('add',$itemcount,$dom).
                   1847:                   '</td>'."\n".
                   1848:                   '</tr>'."\n";
                   1849:     $$rowtotal ++;
                   1850:     return $datatable;
                   1851: }
                   1852: 
                   1853: sub ipaccess_options {
                   1854:     my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
                   1855:     my (%currblocks,%currcourses,$output);
                   1856:     if (ref($blocksref) eq 'HASH') {
                   1857:         %currblocks = %{$blocksref};
                   1858:     }
                   1859:     if (ref($coursesref) eq 'HASH') {
                   1860:         %currcourses = %{$coursesref};
                   1861:     }
                   1862:     $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
                   1863:               '<span class="LC_nobreak">'.&mt('Name').':&nbsp;'.
                   1864:               '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
                   1865:               '</span></fieldset>'.
                   1866:               '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
                   1867:               &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   1868:               &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
                   1869:               '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
                   1870:               $ipranges.'</textarea></fieldset>'.
                   1871:               '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
                   1872:               &blocker_checkboxes($num,$blocksref).'</fieldset>'.
                   1873:               '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
                   1874:               '<table>';
                   1875:     foreach my $cid (sort(keys(%currcourses))) {
                   1876:         my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   1877:         $output .= '<tr><td><span class="LC_nobreak">'.
                   1878:                    '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
                   1879:                    &mt('Delete?').'&nbsp;<span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
                   1880:                    ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
                   1881:     }
                   1882:     $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').':&nbsp;'.
                   1883:                '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
                   1884:                 &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
                   1885:                '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
                   1886:                '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
                   1887:                '</span></td></tr></table>'."\n".
                   1888:                '</fieldset>';
                   1889:     return $output;
                   1890: }
                   1891: 
                   1892: sub blocker_checkboxes {
                   1893:     my ($num,$blocks) = @_;
                   1894:     my ($typeorder,$types) = &commblocktype_text();
                   1895:     my $numinrow = 6;
                   1896:     my $output = '<table>';
                   1897:     for (my $i=0; $i<@{$typeorder}; $i++) {
                   1898:         my $block = $typeorder->[$i];
                   1899:         my $blockstatus;
                   1900:         if (ref($blocks) eq 'HASH') {
                   1901:             if ($blocks->{$block} eq 'on') {
                   1902:                 $blockstatus = 'checked="checked"';
                   1903:             }
                   1904:         }
                   1905:         my $rem = $i%($numinrow);
                   1906:         if ($rem == 0) {
                   1907:             if ($i > 0) {
                   1908:                 $output .= '</tr>';
                   1909:             }
                   1910:             $output .= '<tr>';
                   1911:         }
                   1912:         if ($i == scalar(@{$typeorder})-1) {
                   1913:             my $colsleft = $numinrow-$rem;
                   1914:             if ($colsleft > 1) {
                   1915:                 $output .= '<td colspan="'.$colsleft.'">';
                   1916:             } else {
                   1917:                 $output .= '<td>';
                   1918:             }
                   1919:         } else {
                   1920:             $output .= '<td>';
                   1921:         }
                   1922:         my $item = 'ipaccess_block_'.$num;
                   1923:         if ($blockstatus) {
                   1924:             $blockstatus = ' '.$blockstatus;
                   1925:         }
                   1926:         $output .= '<span class="LC_nobreak"><label>'."\n".
                   1927:                    '<input type="checkbox" name="'.$item.'"'.
                   1928:                    $blockstatus.' value="'.$block.'"'.' />'.
                   1929:                    $types->{$block}.'</label></span>'."\n".
                   1930:                    '<br /></td>';
                   1931:     }
                   1932:     $output .= '</tr></table>';
                   1933:     return $output;
                   1934: }
                   1935: 
                   1936: sub commblocktype_text {
                   1937:     my %types = &Apache::lonlocal::texthash(
                   1938:         'com' => 'Messaging',
                   1939:         'chat' => 'Chat Room',
                   1940:         'boards' => 'Discussion',
                   1941:         'port' => 'Portfolio',
                   1942:         'groups' => 'Groups',
                   1943:         'blogs' => 'Blogs',
                   1944:         'about' => 'User Information',
                   1945:         'printout' => 'Printouts',
                   1946:         'passwd' => 'Change Password',
                   1947:         'grades' => 'Gradebook',
1.397     raeburn  1948:         'search' => 'Course search',
                   1949:         'wishlist' => 'Stored links',
                   1950:         'annotate' => 'Annotations',
1.394     raeburn  1951:     );
1.397     raeburn  1952:     my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394     raeburn  1953:     return ($typeorder,\%types);
                   1954: }
                   1955: 
1.6       raeburn  1956: sub print_rolecolors {
1.30      raeburn  1957:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1958:     my %choices = &color_font_choices();
                   1959:     my @bgs = ('pgbg','tabbg','sidebg');
                   1960:     my @links = ('link','alink','vlink');
                   1961:     my @images = ('img');
                   1962:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1963:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1964:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1965:     my (%is_custom,%designs);
1.200     raeburn  1966:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1967:     if (ref($settings) eq 'HASH') {
                   1968:         if (ref($settings->{$role}) eq 'HASH') {
                   1969:             if ($settings->{$role}->{'img'} ne '') {
                   1970:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1971:                 $is_custom{'img'} = 1;
                   1972:             }
                   1973:             if ($settings->{$role}->{'font'} ne '') {
                   1974:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1975:                 $is_custom{'font'} = 1;
                   1976:             }
1.97      tempelho 1977:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1978:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1979:                 $is_custom{'fontmenu'} = 1;
                   1980:             }
1.6       raeburn  1981:             foreach my $item (@bgs) {
                   1982:                 if ($settings->{$role}->{$item} ne '') {
                   1983:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1984:                     $is_custom{$item} = 1;
                   1985:                 }
                   1986:             }
                   1987:             foreach my $item (@links) {
                   1988:                 if ($settings->{$role}->{$item} ne '') {
                   1989:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1990:                     $is_custom{$item} = 1;
                   1991:                 }
                   1992:             }
                   1993:         }
                   1994:     } else {
                   1995:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1996:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1997:             $is_custom{'img'} = 1;
                   1998:         }
1.97      tempelho 1999:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   2000:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   2001:             $is_custom{'fontmenu'} = 1; 
                   2002:         }
1.6       raeburn  2003:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   2004:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   2005:             $is_custom{'font'} = 1;
                   2006:         }
                   2007:         foreach my $item (@bgs) {
                   2008:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   2009:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   2010:                 $is_custom{$item} = 1;
                   2011:             
                   2012:             }
                   2013:         }
                   2014:         foreach my $item (@links) {
                   2015:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   2016:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   2017:                 $is_custom{$item} = 1;
                   2018:             }
                   2019:         }
                   2020:     }
                   2021:     my $itemcount = 1;
1.30      raeburn  2022:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  2023:     $datatable .= '</tr></table></td></tr>';
                   2024:     return $datatable;
                   2025: }
                   2026: 
1.200     raeburn  2027: sub role_defaults {
                   2028:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  2029:     my %defaults;
                   2030:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  2031:         return %defaults;
                   2032:     }
                   2033:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   2034:     if ($role eq 'login') {
                   2035:         %defaults = (
                   2036:                        font => $defaultdesign{$role.'.font'},
                   2037:                     );
                   2038:         if (ref($logintext) eq 'ARRAY') {
                   2039:             foreach my $item (@{$logintext}) {
                   2040:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   2041:             }
                   2042:         }
                   2043:         foreach my $item (@{$images}) {
                   2044:             $defaults{'showlogo'}{$item} = 1;
                   2045:         }
                   2046:     } else {
                   2047:         %defaults = (
                   2048:                        img => $defaultdesign{$role.'.img'},
                   2049:                        font => $defaultdesign{$role.'.font'},
                   2050:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   2051:                     );
                   2052:     }
                   2053:     foreach my $item (@{$bgs}) {
                   2054:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   2055:     }
                   2056:     foreach my $item (@{$links}) {
                   2057:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   2058:     }
                   2059:     foreach my $item (@{$images}) {
                   2060:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   2061:     }
                   2062:     return %defaults;
                   2063: }
                   2064: 
1.6       raeburn  2065: sub display_color_options {
1.9       raeburn  2066:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   2067:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  2068:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  2069:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  2070:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  2071:         '<td>'.$choices->{'font'}.'</td>';
                   2072:     if (!$is_custom->{'font'}) {
1.329     raeburn  2073:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  2074:     } else {
                   2075:         $datatable .= '<td>&nbsp;</td>';
                   2076:     }
1.174     foxr     2077:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   2078: 
1.8       raeburn  2079:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2080:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  2081:                   ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2082:                   '&nbsp;</span></td></tr>';
1.107     raeburn  2083:     unless ($role eq 'login') { 
                   2084:         $datatable .= '<tr'.$css_class.'>'.
                   2085:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   2086:         if (!$is_custom->{'fontmenu'}) {
1.329     raeburn  2087:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  2088:         } else {
                   2089:             $datatable .= '<td>&nbsp;</td>';
                   2090:         }
1.202     raeburn  2091: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     2092: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  2093:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2094:                       '<input class="colorchooser" type="text" size="10" name="'
                   2095: 		      .$role.'_fontmenu"'.
                   2096:                       ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2097:                       '&nbsp;</span></td></tr>';
1.97      tempelho 2098:     }
1.9       raeburn  2099:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  2100:     foreach my $img (@{$images}) {
1.18      albertel 2101: 	$itemcount ++;
1.6       raeburn  2102:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  2103:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  2104:                       '<td>'.$choices->{$img};
1.402     raeburn  2105:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70      raeburn  2106:         if ($role eq 'login') {
                   2107:             if ($img eq 'login') {
                   2108:                 $login_hdr_pick =
1.135     bisitz   2109:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  2110:                 $logincolors =
                   2111:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  2112:                                        $designs,$defaults);
1.402     raeburn  2113:             } else {
                   2114:                 if ($img ne 'domlogo') {
                   2115:                     $datatable.= &logo_display_options($img,$defaults,$designs);
                   2116:                 }
                   2117:                 if (ref($designs->{'alttext'}) eq 'HASH') {
                   2118:                     $alttext = $designs->{'alttext'}{$img};
                   2119:                 }
1.70      raeburn  2120:             }
                   2121:         }
                   2122:         $datatable .= '</td>';
1.6       raeburn  2123:         if ($designs->{$img} ne '') {
                   2124:             $imgfile = $designs->{$img};
1.18      albertel 2125: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  2126:         } else {
                   2127:             $imgfile = $defaults->{$img};
                   2128:         }
                   2129:         if ($imgfile) {
1.9       raeburn  2130:             my ($showfile,$fullsize);
                   2131:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  2132:                 my $urldir = $1;
                   2133:                 my $filename = $2;
                   2134:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   2135:                 if (@info) {
                   2136:                     my $thumbfile = 'tn-'.$filename;
                   2137:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   2138:                     if (@thumb) {
                   2139:                         $showfile = $urldir.'/'.$thumbfile;
                   2140:                     } else {
                   2141:                         $showfile = $imgfile;
                   2142:                     }
                   2143:                 } else {
                   2144:                     $showfile = '';
                   2145:                 }
                   2146:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  2147:                 $showfile = $imgfile;
1.6       raeburn  2148:                 my $imgdir = $1;
                   2149:                 my $filename = $2;
1.159     raeburn  2150:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  2151:                     $showfile = "/$imgdir/tn-".$filename;
                   2152:                 } else {
1.159     raeburn  2153:                     my $input = $londocroot.$imgfile;
                   2154:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  2155:                     if (!-e $output) {
1.9       raeburn  2156:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  2157:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   2158:                         if ($fullwidth ne '' && $fullheight ne '') {
                   2159:                             if ($fullwidth > $width && $fullheight > $height) { 
                   2160:                                 my $size = $width.'x'.$height;
1.316     raeburn  2161:                                 my @args = ('convert','-sample',$size,$input,$output);
                   2162:                                 system({$args[0]} @args);
1.159     raeburn  2163:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  2164:                             }
                   2165:                         }
1.6       raeburn  2166:                     }
                   2167:                 }
1.16      raeburn  2168:             }
1.6       raeburn  2169:             if ($showfile) {
1.40      raeburn  2170:                 if ($showfile =~ m{^/(adm|res)/}) {
                   2171:                     if ($showfile =~ m{^/res/}) {
                   2172:                         my $local_showfile =
                   2173:                             &Apache::lonnet::filelocation('',$showfile);
                   2174:                         &Apache::lonnet::repcopy($local_showfile);
                   2175:                     }
                   2176:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   2177:                 }
                   2178:                 if ($imgfile) {
                   2179:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   2180:                         if ($imgfile =~ m{^/res/}) {
                   2181:                             my $local_imgfile =
                   2182:                                 &Apache::lonnet::filelocation('',$imgfile);
                   2183:                             &Apache::lonnet::repcopy($local_imgfile);
                   2184:                         }
                   2185:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   2186:                     } else {
                   2187:                         $fullsize = $imgfile;
                   2188:                     }
                   2189:                 }
1.41      raeburn  2190:                 $datatable .= '<td>';
                   2191:                 if ($img eq 'login') {
1.135     bisitz   2192:                     $datatable .= $login_hdr_pick;
                   2193:                 } 
1.41      raeburn  2194:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   2195:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  2196:             } else {
1.201     raeburn  2197:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2198:                               &mt('Upload:').'<br />';
1.6       raeburn  2199:             }
                   2200:         } else {
1.201     raeburn  2201:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2202:                           &mt('Upload:').'<br />';
1.6       raeburn  2203:         }
1.9       raeburn  2204:         if ($switchserver) {
                   2205:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2206:         } else {
1.135     bisitz   2207:             if ($img ne 'login') { # suppress file selection for Log-in header
                   2208:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   2209:             }
1.9       raeburn  2210:         }
1.402     raeburn  2211:         if (($role eq 'login') && ($img ne 'login')) {
                   2212:             $datatable .= ('&nbsp;' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
                   2213:                           '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
                   2214:                           '</label></span>';
                   2215:         }
1.9       raeburn  2216:         $datatable .= '</td></tr>';
1.6       raeburn  2217:     }
                   2218:     $itemcount ++;
                   2219:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2220:     $datatable .= '<tr'.$css_class.'>'.
                   2221:                   '<td>'.$choices->{'bgs'}.'</td>';
                   2222:     my $bgs_def;
                   2223:     foreach my $item (@{$bgs}) {
                   2224:         if (!$is_custom->{$item}) {
1.329     raeburn  2225:             $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  2226:         }
                   2227:     }
                   2228:     if ($bgs_def) {
1.8       raeburn  2229:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  2230:     } else {
                   2231:         $datatable .= '<td>&nbsp;</td>';
                   2232:     }
                   2233:     $datatable .= '<td class="LC_right_item">'.
                   2234:                   '<table border="0"><tr>';
1.174     foxr     2235: 
1.6       raeburn  2236:     foreach my $item (@{$bgs}) {
1.306     raeburn  2237:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     2238: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  2239:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     2240:             $datatable .= '&nbsp;';
1.6       raeburn  2241:         }
1.174     foxr     2242:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  2243:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  2244:     }
                   2245:     $datatable .= '</tr></table></td></tr>';
                   2246:     $itemcount ++;
                   2247:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2248:     $datatable .= '<tr'.$css_class.'>'.
                   2249:                   '<td>'.$choices->{'links'}.'</td>';
                   2250:     my $links_def;
                   2251:     foreach my $item (@{$links}) {
                   2252:         if (!$is_custom->{$item}) {
1.329     raeburn  2253:             $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  2254:         }
                   2255:     }
                   2256:     if ($links_def) {
1.8       raeburn  2257:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  2258:     } else {
                   2259:         $datatable .= '<td>&nbsp;</td>';
                   2260:     }
                   2261:     $datatable .= '<td class="LC_right_item">'.
                   2262:                   '<table border="0"><tr>';
                   2263:     foreach my $item (@{$links}) {
1.234     raeburn  2264: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  2265:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  2266:         if ($designs->{'links'}{$item}) {
1.174     foxr     2267:             $datatable.='&nbsp;';
1.6       raeburn  2268:         }
1.174     foxr     2269:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  2270:                       '" /></td>';
                   2271:     }
1.30      raeburn  2272:     $$rowtotal += $itemcount;
1.3       raeburn  2273:     return $datatable;
                   2274: }
                   2275: 
1.70      raeburn  2276: sub logo_display_options {
                   2277:     my ($img,$defaults,$designs) = @_;
                   2278:     my $checkedon;
                   2279:     if (ref($defaults) eq 'HASH') {
                   2280:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   2281:             if ($defaults->{'showlogo'}{$img}) {
                   2282:                 $checkedon = 'checked="checked" ';     
                   2283:             }
                   2284:         } 
                   2285:     }
                   2286:     if (ref($designs) eq 'HASH') {
                   2287:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   2288:             if (defined($designs->{'showlogo'}{$img})) {
                   2289:                 if ($designs->{'showlogo'}{$img} == 0) {
                   2290:                     $checkedon = '';
                   2291:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   2292:                     $checkedon = 'checked="checked" ';
                   2293:                 }
                   2294:             }
                   2295:         }
                   2296:     }
                   2297:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   2298:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   2299:            &mt('show').'</label>'."\n";
                   2300: }
                   2301: 
1.41      raeburn  2302: sub login_header_options  {
1.135     bisitz   2303:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   2304:     my $output = '';
1.41      raeburn  2305:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   2306:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  2307:         if (!$is_custom->{'textcol'}) {
                   2308:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   2309:                        '&nbsp;&nbsp;&nbsp;';
                   2310:         }
                   2311:         if (!$is_custom->{'bgcol'}) {
                   2312:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   2313:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   2314:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   2315:         }
                   2316:         $output .= '<br />';
                   2317:     }
                   2318:     $output .='<br />';
                   2319:     return $output;
                   2320: }
                   2321: 
                   2322: sub login_text_colors {
1.201     raeburn  2323:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  2324:     my $color_menu = '<table border="0"><tr>';
                   2325:     foreach my $item (@{$logintext}) {
1.306     raeburn  2326:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  2327:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   2328:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   2329:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  2330:     }
                   2331:     $color_menu .= '</tr></table><br />';
                   2332:     return $color_menu;
                   2333: }
                   2334: 
                   2335: sub image_changes {
                   2336:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   2337:     my $output;
1.135     bisitz   2338:     if ($img eq 'login') {
1.331     raeburn  2339:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   2340:     } elsif (!$is_custom) {
1.70      raeburn  2341:         if ($img ne 'domlogo') {
1.331     raeburn  2342:             $output = &mt('Default image:').'<br />';
1.41      raeburn  2343:         } else {
1.331     raeburn  2344:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  2345:         }
                   2346:     }
1.331     raeburn  2347:     if ($img ne 'login') {
1.135     bisitz   2348:         if ($img_import) {
                   2349:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   2350:         }
                   2351:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   2352:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   2353:         if ($is_custom) {
                   2354:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   2355:                        '<input type="checkbox" name="'.
                   2356:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   2357:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   2358:         } else {
1.306     raeburn  2359:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   2360:         }
1.41      raeburn  2361:     }
                   2362:     return $output;
                   2363: }
                   2364: 
1.3       raeburn  2365: sub print_quotas {
1.86      raeburn  2366:     my ($dom,$settings,$rowtotal,$action) = @_;
                   2367:     my $context;
                   2368:     if ($action eq 'quotas') {
                   2369:         $context = 'tools';
                   2370:     } else {
                   2371:         $context = $action;
                   2372:     }
1.197     raeburn  2373:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  2374:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  2375:     my $typecount = 0;
1.101     raeburn  2376:     my ($css_class,%titles);
1.86      raeburn  2377:     if ($context eq 'requestcourses') {
1.325     raeburn  2378:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  2379:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  2380:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   2381:         %titles = &courserequest_titles();
1.163     raeburn  2382:     } elsif ($context eq 'requestauthor') {
                   2383:         @usertools = ('author');
                   2384:         @options = ('norequest','approval','automatic');
1.210     raeburn  2385:         %titles = &authorrequest_titles();
1.86      raeburn  2386:     } else {
1.413     raeburn  2387:         @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101     raeburn  2388:         %titles = &tool_titles();
1.86      raeburn  2389:     }
1.26      raeburn  2390:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  2391:         foreach my $type (@{$types}) {
1.197     raeburn  2392:             my ($currdefquota,$currauthorquota);
1.163     raeburn  2393:             unless (($context eq 'requestcourses') ||
                   2394:                     ($context eq 'requestauthor')) {
1.86      raeburn  2395:                 if (ref($settings) eq 'HASH') {
                   2396:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  2397:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  2398:                     } else {
                   2399:                         $currdefquota = $settings->{$type};
                   2400:                     }
1.197     raeburn  2401:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   2402:                         $currauthorquota = $settings->{authorquota}->{$type};
                   2403:                     }
1.78      raeburn  2404:                 }
1.72      raeburn  2405:             }
1.3       raeburn  2406:             if (defined($usertypes->{$type})) {
                   2407:                 $typecount ++;
                   2408:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  2409:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  2410:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  2411:                               '<td class="LC_left_item">';
1.101     raeburn  2412:                 if ($context eq 'requestcourses') {
                   2413:                     $datatable .= '<table><tr>';
                   2414:                 }
                   2415:                 my %cell;  
1.72      raeburn  2416:                 foreach my $item (@usertools) {
1.101     raeburn  2417:                     if ($context eq 'requestcourses') {
                   2418:                         my ($curroption,$currlimit);
                   2419:                         if (ref($settings) eq 'HASH') {
                   2420:                             if (ref($settings->{$item}) eq 'HASH') {
                   2421:                                 $curroption = $settings->{$item}->{$type};
                   2422:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2423:                                     $currlimit = $1; 
                   2424:                                 }
                   2425:                             }
                   2426:                         }
                   2427:                         if (!$curroption) {
                   2428:                             $curroption = 'norequest';
                   2429:                         }
                   2430:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2431:                         foreach my $option (@options) {
                   2432:                             my $val = $option;
                   2433:                             if ($option eq 'norequest') {
                   2434:                                 $val = 0;  
                   2435:                             }
                   2436:                             if ($option eq 'validate') {
                   2437:                                 my $canvalidate = 0;
                   2438:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2439:                                     if ($validations{$item}{$type}) {
                   2440:                                         $canvalidate = 1;
                   2441:                                     }
                   2442:                                 }
                   2443:                                 next if (!$canvalidate);
                   2444:                             }
                   2445:                             my $checked = '';
                   2446:                             if ($option eq $curroption) {
                   2447:                                 $checked = ' checked="checked"';
                   2448:                             } elsif ($option eq 'autolimit') {
                   2449:                                 if ($curroption =~ /^autolimit/) {
                   2450:                                     $checked = ' checked="checked"';
                   2451:                                 }                       
                   2452:                             } 
                   2453:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2454:                                   '<input type="radio" name="crsreq_'.$item.
                   2455:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2456:                                   $titles{$option}.'</label>';
1.101     raeburn  2457:                             if ($option eq 'autolimit') {
1.127     raeburn  2458:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2459:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2460:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2461:                             }
1.127     raeburn  2462:                             $cell{$item} .= '</span> ';
1.103     raeburn  2463:                             if ($option eq 'autolimit') {
1.127     raeburn  2464:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2465:                             }
1.101     raeburn  2466:                         }
1.163     raeburn  2467:                     } elsif ($context eq 'requestauthor') {
                   2468:                         my $curroption;
                   2469:                         if (ref($settings) eq 'HASH') {
                   2470:                             $curroption = $settings->{$type};
                   2471:                         }
                   2472:                         if (!$curroption) {
                   2473:                             $curroption = 'norequest';
                   2474:                         }
                   2475:                         foreach my $option (@options) {
                   2476:                             my $val = $option;
                   2477:                             if ($option eq 'norequest') {
                   2478:                                 $val = 0;
                   2479:                             }
                   2480:                             my $checked = '';
                   2481:                             if ($option eq $curroption) {
                   2482:                                 $checked = ' checked="checked"';
                   2483:                             }
                   2484:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2485:                                   '<input type="radio" name="authorreq_'.$type.
                   2486:                                   '" value="'.$val.'"'.$checked.' />'.
                   2487:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2488:                         }
1.101     raeburn  2489:                     } else {
                   2490:                         my $checked = 'checked="checked" ';
1.413     raeburn  2491:                         if ($item eq 'timezone') {
                   2492:                             $checked = '';
                   2493:                         }
1.101     raeburn  2494:                         if (ref($settings) eq 'HASH') {
                   2495:                             if (ref($settings->{$item}) eq 'HASH') {
1.413     raeburn  2496:                                 if (!$settings->{$item}->{$type}) {
1.101     raeburn  2497:                                     $checked = '';
                   2498:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2499:                                     $checked =  'checked="checked" ';
                   2500:                                 }
1.78      raeburn  2501:                             }
1.72      raeburn  2502:                         }
1.101     raeburn  2503:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2504:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2505:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2506:                                       '</label></span>&nbsp; ';
1.72      raeburn  2507:                     }
1.101     raeburn  2508:                 }
                   2509:                 if ($context eq 'requestcourses') {
                   2510:                     $datatable .= '</tr><tr>';
                   2511:                     foreach my $item (@usertools) {
1.106     raeburn  2512:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2513:                     }
                   2514:                     $datatable .= '</tr></table>';
1.72      raeburn  2515:                 }
1.86      raeburn  2516:                 $datatable .= '</td>';
1.163     raeburn  2517:                 unless (($context eq 'requestcourses') ||
                   2518:                         ($context eq 'requestauthor')) {
1.86      raeburn  2519:                     $datatable .= 
1.197     raeburn  2520:                               '<td class="LC_right_item">'.
                   2521:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2522:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2523:                               '" value="'.$currdefquota.
1.197     raeburn  2524:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2525:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2526:                               '<input type="text" name="authorquota_'.$type.
                   2527:                               '" value="'.$currauthorquota.
                   2528:                               '" size="5" /></span></td>';
1.86      raeburn  2529:                 }
                   2530:                 $datatable .= '</tr>';
1.3       raeburn  2531:             }
                   2532:         }
                   2533:     }
1.163     raeburn  2534:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2535:         $defaultquota = '20';
1.197     raeburn  2536:         $authorquota = '500';
1.86      raeburn  2537:         if (ref($settings) eq 'HASH') {
                   2538:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2539:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2540:             } elsif (defined($settings->{'default'})) {
                   2541:                 $defaultquota = $settings->{'default'};
                   2542:             }
1.197     raeburn  2543:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2544:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2545:             }
1.3       raeburn  2546:         }
                   2547:     }
                   2548:     $typecount ++;
                   2549:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2550:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2551:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2552:                   '<td class="LC_left_item">';
1.101     raeburn  2553:     if ($context eq 'requestcourses') {
                   2554:         $datatable .= '<table><tr>';
                   2555:     }
                   2556:     my %defcell;
1.72      raeburn  2557:     foreach my $item (@usertools) {
1.101     raeburn  2558:         if ($context eq 'requestcourses') {
                   2559:             my ($curroption,$currlimit);
                   2560:             if (ref($settings) eq 'HASH') {
                   2561:                 if (ref($settings->{$item}) eq 'HASH') {
                   2562:                     $curroption = $settings->{$item}->{'default'};
                   2563:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2564:                         $currlimit = $1;
                   2565:                     }
                   2566:                 }
                   2567:             }
                   2568:             if (!$curroption) {
                   2569:                 $curroption = 'norequest';
                   2570:             }
                   2571:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2572:             foreach my $option (@options) {
                   2573:                 my $val = $option;
                   2574:                 if ($option eq 'norequest') {
                   2575:                     $val = 0;
                   2576:                 }
                   2577:                 if ($option eq 'validate') {
                   2578:                     my $canvalidate = 0;
                   2579:                     if (ref($validations{$item}) eq 'HASH') {
                   2580:                         if ($validations{$item}{'default'}) {
                   2581:                             $canvalidate = 1;
                   2582:                         }
                   2583:                     }
                   2584:                     next if (!$canvalidate);
                   2585:                 }
                   2586:                 my $checked = '';
                   2587:                 if ($option eq $curroption) {
                   2588:                     $checked = ' checked="checked"';
                   2589:                 } elsif ($option eq 'autolimit') {
                   2590:                     if ($curroption =~ /^autolimit/) {
                   2591:                         $checked = ' checked="checked"';
                   2592:                     }
                   2593:                 }
                   2594:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2595:                                   '<input type="radio" name="crsreq_'.$item.
                   2596:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2597:                                   $titles{$option}.'</label>';
                   2598:                 if ($option eq 'autolimit') {
1.127     raeburn  2599:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2600:                                        $item.'_limit_default" size="1" '.
                   2601:                                        'value="'.$currlimit.'" />';
                   2602:                 }
1.127     raeburn  2603:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2604:                 if ($option eq 'autolimit') {
1.127     raeburn  2605:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2606:                 }
1.101     raeburn  2607:             }
1.163     raeburn  2608:         } elsif ($context eq 'requestauthor') {
                   2609:             my $curroption;
                   2610:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2611:                 $curroption = $settings->{'default'};
1.163     raeburn  2612:             }
                   2613:             if (!$curroption) {
                   2614:                 $curroption = 'norequest';
                   2615:             }
                   2616:             foreach my $option (@options) {
                   2617:                 my $val = $option;
                   2618:                 if ($option eq 'norequest') {
                   2619:                     $val = 0;
                   2620:                 }
                   2621:                 my $checked = '';
                   2622:                 if ($option eq $curroption) {
                   2623:                     $checked = ' checked="checked"';
                   2624:                 }
                   2625:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2626:                               '<input type="radio" name="authorreq_default"'.
                   2627:                               ' value="'.$val.'"'.$checked.' />'.
                   2628:                               $titles{$option}.'</label></span>&nbsp; ';
                   2629:             }
1.101     raeburn  2630:         } else {
                   2631:             my $checked = 'checked="checked" ';
                   2632:             if (ref($settings) eq 'HASH') {
                   2633:                 if (ref($settings->{$item}) eq 'HASH') {
                   2634:                     if ($settings->{$item}->{'default'} == 0) {
                   2635:                         $checked = '';
                   2636:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2637:                         $checked = 'checked="checked" ';
                   2638:                     }
1.78      raeburn  2639:                 }
1.72      raeburn  2640:             }
1.101     raeburn  2641:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2642:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2643:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2644:                           '</label></span>&nbsp; ';
                   2645:         }
                   2646:     }
                   2647:     if ($context eq 'requestcourses') {
                   2648:         $datatable .= '</tr><tr>';
                   2649:         foreach my $item (@usertools) {
1.106     raeburn  2650:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2651:         }
1.101     raeburn  2652:         $datatable .= '</tr></table>';
1.72      raeburn  2653:     }
1.86      raeburn  2654:     $datatable .= '</td>';
1.163     raeburn  2655:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2656:         $datatable .= '<td class="LC_right_item">'.
                   2657:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2658:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2659:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2660:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2661:                       '<input type="text" name="authorquota" value="'.
                   2662:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2663:     }
                   2664:     $datatable .= '</tr>';
1.72      raeburn  2665:     $typecount ++;
                   2666:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2667:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2668:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2669:     if ($context eq 'requestcourses') {
1.109     raeburn  2670:         $datatable .= &mt('(overrides affiliation, if set)').
                   2671:                       '</td>'.
                   2672:                       '<td class="LC_left_item">'.
                   2673:                       '<table><tr>';
1.101     raeburn  2674:     } else {
1.109     raeburn  2675:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2676:                       '</td>'.
                   2677:                       '<td class="LC_left_item" colspan="2">'.
                   2678:                       '<br />';
1.101     raeburn  2679:     }
                   2680:     my %advcell;
1.72      raeburn  2681:     foreach my $item (@usertools) {
1.101     raeburn  2682:         if ($context eq 'requestcourses') {
                   2683:             my ($curroption,$currlimit);
                   2684:             if (ref($settings) eq 'HASH') {
                   2685:                 if (ref($settings->{$item}) eq 'HASH') {
                   2686:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2687:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2688:                         $currlimit = $1;
                   2689:                     }
                   2690:                 }
                   2691:             }
                   2692:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2693:             my $checked = '';
                   2694:             if ($curroption eq '') {
                   2695:                 $checked = ' checked="checked"';
                   2696:             }
                   2697:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2698:                                '<input type="radio" name="crsreq_'.$item.
                   2699:                                '__LC_adv" value=""'.$checked.' />'.
                   2700:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2701:             foreach my $option (@options) {
                   2702:                 my $val = $option;
                   2703:                 if ($option eq 'norequest') {
                   2704:                     $val = 0;
                   2705:                 }
                   2706:                 if ($option eq 'validate') {
                   2707:                     my $canvalidate = 0;
                   2708:                     if (ref($validations{$item}) eq 'HASH') {
                   2709:                         if ($validations{$item}{'_LC_adv'}) {
                   2710:                             $canvalidate = 1;
                   2711:                         }
                   2712:                     }
                   2713:                     next if (!$canvalidate);
                   2714:                 }
                   2715:                 my $checked = '';
1.104     raeburn  2716:                 if ($val eq $curroption) {
1.101     raeburn  2717:                     $checked = ' checked="checked"';
                   2718:                 } elsif ($option eq 'autolimit') {
                   2719:                     if ($curroption =~ /^autolimit/) {
                   2720:                         $checked = ' checked="checked"';
                   2721:                     }
                   2722:                 }
                   2723:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2724:                                   '<input type="radio" name="crsreq_'.$item.
                   2725:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2726:                                   $titles{$option}.'</label>';
                   2727:                 if ($option eq 'autolimit') {
1.127     raeburn  2728:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2729:                                        $item.'_limit__LC_adv" size="1" '.
                   2730:                                        'value="'.$currlimit.'" />';
                   2731:                 }
1.127     raeburn  2732:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2733:                 if ($option eq 'autolimit') {
1.127     raeburn  2734:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2735:                 }
1.101     raeburn  2736:             }
1.163     raeburn  2737:         } elsif ($context eq 'requestauthor') {
                   2738:             my $curroption;
                   2739:             if (ref($settings) eq 'HASH') {
                   2740:                 $curroption = $settings->{'_LC_adv'};
                   2741:             }
                   2742:             my $checked = '';
                   2743:             if ($curroption eq '') {
                   2744:                 $checked = ' checked="checked"';
                   2745:             }
                   2746:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2747:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2748:                           ' value=""'.$checked.' />'.
                   2749:                           &mt('No override set').'</label></span>&nbsp; ';
                   2750:             foreach my $option (@options) {
                   2751:                 my $val = $option;
                   2752:                 if ($option eq 'norequest') {
                   2753:                     $val = 0;
                   2754:                 }
                   2755:                 my $checked = '';
                   2756:                 if ($val eq $curroption) {
                   2757:                     $checked = ' checked="checked"';
                   2758:                 }
                   2759:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2760:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2761:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2762:                               $titles{$option}.'</label></span>&nbsp; ';
                   2763:             }
1.101     raeburn  2764:         } else {
                   2765:             my $checked = 'checked="checked" ';
                   2766:             if (ref($settings) eq 'HASH') {
                   2767:                 if (ref($settings->{$item}) eq 'HASH') {
                   2768:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2769:                         $checked = '';
                   2770:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2771:                         $checked = 'checked="checked" ';
                   2772:                     }
1.79      raeburn  2773:                 }
1.72      raeburn  2774:             }
1.101     raeburn  2775:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2776:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2777:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2778:                           '</label></span>&nbsp; ';
                   2779:         }
                   2780:     }
                   2781:     if ($context eq 'requestcourses') {
                   2782:         $datatable .= '</tr><tr>';
                   2783:         foreach my $item (@usertools) {
1.106     raeburn  2784:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2785:         }
1.101     raeburn  2786:         $datatable .= '</tr></table>';
1.72      raeburn  2787:     }
1.98      raeburn  2788:     $datatable .= '</td></tr>';
1.30      raeburn  2789:     $$rowtotal += $typecount;
1.3       raeburn  2790:     return $datatable;
                   2791: }
                   2792: 
1.163     raeburn  2793: sub print_requestmail {
1.305     raeburn  2794:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2795:     my ($now,$datatable,%currapp);
1.102     raeburn  2796:     $now = time;
                   2797:     if (ref($settings) eq 'HASH') {
                   2798:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2799:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2800:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2801:             }
                   2802:         }
                   2803:     }
1.191     raeburn  2804:     my $numinrow = 2;
1.224     raeburn  2805:     my $css_class;
1.305     raeburn  2806:     if ($$rowtotal%2) {
                   2807:         $css_class = 'LC_odd_row';
                   2808:     }
                   2809:     if ($customcss) {
                   2810:         $css_class .= " $customcss";
                   2811:     }
                   2812:     $css_class =~ s/^\s+//;
                   2813:     if ($css_class) {
                   2814:         $css_class = ' class="'.$css_class.'"';
                   2815:     }
                   2816:     if ($rowstyle) {
                   2817:         $css_class .= ' style="'.$rowstyle.'"';
                   2818:     }
1.163     raeburn  2819:     my $text;
                   2820:     if ($action eq 'requestcourses') {
                   2821:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2822:     } elsif ($action eq 'requestauthor') {
                   2823:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2824:     } else {
1.224     raeburn  2825:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2826:     }
1.224     raeburn  2827:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2828:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2829:                  ' <td class="LC_left_item">';
1.191     raeburn  2830:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2831:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2832:     if ($numdc > 0) {
                   2833:         $datatable .= $table;
1.102     raeburn  2834:     } else {
                   2835:         $datatable .= &mt('There are no active Domain Coordinators');
                   2836:     }
                   2837:     $datatable .='</td></tr>';
                   2838:     return $datatable;
                   2839: }
                   2840: 
1.216     raeburn  2841: sub print_studentcode {
                   2842:     my ($settings,$rowtotal) = @_;
                   2843:     my $rownum = 0; 
1.218     raeburn  2844:     my ($output,%current);
1.325     raeburn  2845:     my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248     raeburn  2846:     if (ref($settings) eq 'HASH') {
                   2847:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2848:             foreach my $type (@crstypes) {
                   2849:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2850:             }
1.218     raeburn  2851:         }
                   2852:     }
                   2853:     $output .= '<tr>'.
                   2854:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2855:                '<td class="LC_left_item">';
                   2856:     foreach my $type (@crstypes) {
                   2857:         my $check = ' ';
                   2858:         if ($current{$type}) {
                   2859:             $check = ' checked="checked" ';
                   2860:         }
                   2861:         $output .= '<span class="LC_nobreak"><label>'.
                   2862:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2863:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2864:     }
                   2865:     $output .= '</td></tr>';
                   2866:     $$rowtotal ++;
                   2867:     return $output;
1.216     raeburn  2868: }
                   2869: 
                   2870: sub print_textbookcourses {
1.242     raeburn  2871:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2872:     my $rownum = 0;
                   2873:     my $css_class;
                   2874:     my $itemcount = 1;
                   2875:     my $maxnum = 0;
                   2876:     my $bookshash;
                   2877:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2878:         $bookshash = $settings->{$type};
1.216     raeburn  2879:     }
                   2880:     my %ordered;
                   2881:     if (ref($bookshash) eq 'HASH') {
                   2882:         foreach my $item (keys(%{$bookshash})) {
                   2883:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2884:                 my $num = $bookshash->{$item}{'order'};
                   2885:                 $ordered{$num} = $item;
                   2886:             }
                   2887:         }
                   2888:     }
                   2889:     my $confname = $dom.'-domainconfig';
                   2890:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2891:     my $maxnum = scalar(keys(%ordered));
                   2892:     my $datatable;
1.216     raeburn  2893:     if (keys(%ordered)) {
                   2894:         my @items = sort { $a <=> $b } keys(%ordered);
                   2895:         for (my $i=0; $i<@items; $i++) {
                   2896:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2897:             my $key = $ordered{$items[$i]};
                   2898:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2899:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2900:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2901:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2902:                 $subject = $bookshash->{$key}->{'subject'};
                   2903:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2904:                 if ($type eq 'textbooks') {
1.243     raeburn  2905:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2906:                     $author = $bookshash->{$key}->{'author'};
                   2907:                     $image = $bookshash->{$key}->{'image'};
                   2908:                     if ($image ne '') {
                   2909:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2910:                         my $imagethumb = "$path/tn-".$imagefile;
                   2911:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2912:                     }
1.216     raeburn  2913:                 }
                   2914:             }
1.242     raeburn  2915:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2916:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2917:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2918:             for (my $k=0; $k<=$maxnum; $k++) {
                   2919:                 my $vpos = $k+1;
                   2920:                 my $selstr;
                   2921:                 if ($k == $i) {
                   2922:                     $selstr = ' selected="selected" ';
                   2923:                 }
                   2924:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2925:             }
                   2926:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2927:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2928:                 &mt('Delete?').'</label></span></td>'.
                   2929:                 '<td colspan="2">'.
1.242     raeburn  2930:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2931:                 ('&nbsp;'x2).
1.242     raeburn  2932:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2933:             if ($type eq 'textbooks') {
                   2934:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2935:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2936:                               ('&nbsp;'x2).
1.242     raeburn  2937:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2938:                               ('&nbsp;'x2).
                   2939:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2940:                 if ($image) {
1.267     raeburn  2941:                     $datatable .= $imgsrc.
1.242     raeburn  2942:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2943:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2944:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2945:                 }
                   2946:                 if ($switchserver) {
                   2947:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2948:                 } else {
                   2949:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2950:                 }
1.216     raeburn  2951:             }
1.242     raeburn  2952:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2953:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2954:                           $coursetitle.'</span></td></tr>'."\n";
                   2955:             $itemcount ++;
                   2956:         }
                   2957:     }
                   2958:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2959:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2960:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2961:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2962:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2963:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2964:         my $vpos = $k+1;
                   2965:         my $selstr;
                   2966:         if ($k == $maxnum) {
                   2967:             $selstr = ' selected="selected" ';
                   2968:         }
                   2969:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2970:     }
                   2971:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  2972:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216     raeburn  2973:                   '<td colspan="2">'.
1.242     raeburn  2974:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2975:                   ('&nbsp;'x2).
1.242     raeburn  2976:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2977:                   ('&nbsp;'x2);
                   2978:     if ($type eq 'textbooks') {
1.243     raeburn  2979:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2980:                       ('&nbsp;'x2).
                   2981:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2982:                       ('&nbsp;'x2).
                   2983:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2984:         if ($switchserver) {
                   2985:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2986:         } else {
                   2987:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2988:         }
1.334     raeburn  2989:         $datatable .= '</span>'."\n";
1.216     raeburn  2990:     }
1.334     raeburn  2991:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2992:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2993:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2994:                   &Apache::loncommon::selectcourse_link
1.334     raeburn  2995:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216     raeburn  2996:                   '</span></td>'."\n".
                   2997:                   '</tr>'."\n";
                   2998:     $itemcount ++;
                   2999:     return $datatable;
                   3000: }
                   3001: 
1.217     raeburn  3002: sub textbookcourses_javascript {
1.242     raeburn  3003:     my ($settings) = @_;
                   3004:     return unless(ref($settings) eq 'HASH');
                   3005:     my (%ordered,%total,%jstext);
                   3006:     foreach my $type ('textbooks','templates') {
                   3007:         $total{$type} = 0;
                   3008:         if (ref($settings->{$type}) eq 'HASH') {
                   3009:             foreach my $item (keys(%{$settings->{$type}})) {
                   3010:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   3011:                     my $num = $settings->{$type}->{$item}{'order'};
                   3012:                     $ordered{$type}{$num} = $item;
                   3013:                 }
                   3014:             }
                   3015:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   3016:         }
                   3017:         my @jsarray = ();
                   3018:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   3019:             push(@jsarray,$ordered{$type}{$item});
                   3020:         }
                   3021:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  3022:     }
                   3023:     return <<"ENDSCRIPT";
                   3024: <script type="text/javascript">
                   3025: // <![CDATA[
1.242     raeburn  3026: function reorderBooks(form,item,caller) {
1.217     raeburn  3027:     var changedVal;
1.242     raeburn  3028: $jstext{'textbooks'};
                   3029: $jstext{'templates'};
                   3030:     var newpos;
                   3031:     var maxh;
                   3032:     if (caller == 'textbooks') {  
                   3033:         newpos = 'textbooks_addbook_pos';
                   3034:         maxh = 1 + $total{'textbooks'};
                   3035:     } else {
                   3036:         newpos = 'templates_addbook_pos';
                   3037:         maxh = 1 + $total{'templates'};
                   3038:     }
1.217     raeburn  3039:     var current = new Array;
                   3040:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3041:     if (item == newpos) {
                   3042:         changedVal = newitemVal;
                   3043:     } else {
                   3044:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3045:         current[newitemVal] = newpos;
                   3046:     }
1.242     raeburn  3047:     if (caller == 'textbooks') {
                   3048:         for (var i=0; i<textbooks.length; i++) {
                   3049:             var elementName = 'textbooks_'+textbooks[i];
                   3050:             if (elementName != item) {
                   3051:                 if (form.elements[elementName]) {
                   3052:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3053:                     current[currVal] = elementName;
                   3054:                 }
                   3055:             }
                   3056:         }
                   3057:     }
                   3058:     if (caller == 'templates') {
                   3059:         for (var i=0; i<templates.length; i++) {
                   3060:             var elementName = 'templates_'+templates[i];
                   3061:             if (elementName != item) {
                   3062:                 if (form.elements[elementName]) {
                   3063:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3064:                     current[currVal] = elementName;
                   3065:                 }
1.217     raeburn  3066:             }
                   3067:         }
                   3068:     }
                   3069:     var oldVal;
                   3070:     for (var j=0; j<maxh; j++) {
                   3071:         if (current[j] == undefined) {
                   3072:             oldVal = j;
                   3073:         }
                   3074:     }
                   3075:     if (oldVal < changedVal) {
                   3076:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3077:            var elementName = current[k];
                   3078:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3079:         }
                   3080:     } else {
                   3081:         for (var k=changedVal; k<oldVal; k++) {
                   3082:             var elementName = current[k];
                   3083:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3084:         }
                   3085:     }
                   3086:     return;
                   3087: }
                   3088: 
                   3089: // ]]>
                   3090: </script>
                   3091: 
                   3092: ENDSCRIPT
                   3093: }
                   3094: 
1.267     raeburn  3095: sub ltitools_javascript {
                   3096:     my ($settings) = @_;
1.319     raeburn  3097:     my $togglejs = &ltitools_toggle_js();
                   3098:     unless (ref($settings) eq 'HASH') {
                   3099:         return $togglejs;
                   3100:     }
1.267     raeburn  3101:     my (%ordered,$total,%jstext);
                   3102:     $total = 0;
                   3103:     foreach my $item (keys(%{$settings})) {
                   3104:         if (ref($settings->{$item}) eq 'HASH') {
                   3105:             my $num = $settings->{$item}{'order'};
                   3106:             $ordered{$num} = $item;
                   3107:         }
                   3108:     }
                   3109:     $total = scalar(keys(%{$settings}));
                   3110:     my @jsarray = ();
                   3111:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3112:         push(@jsarray,$ordered{$item});
                   3113:     }
                   3114:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3115:     return <<"ENDSCRIPT";
                   3116: <script type="text/javascript">
                   3117: // <![CDATA[
1.319     raeburn  3118: function reorderLTITools(form,item) {
1.267     raeburn  3119:     var changedVal;
                   3120: $jstext
                   3121:     var newpos = 'ltitools_add_pos';
                   3122:     var maxh = 1 + $total;
                   3123:     var current = new Array;
                   3124:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3125:     if (item == newpos) {
                   3126:         changedVal = newitemVal;
                   3127:     } else {
                   3128:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3129:         current[newitemVal] = newpos;
                   3130:     }
                   3131:     for (var i=0; i<ltitools.length; i++) {
                   3132:         var elementName = 'ltitools_'+ltitools[i];
                   3133:         if (elementName != item) {
                   3134:             if (form.elements[elementName]) {
                   3135:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3136:                 current[currVal] = elementName;
                   3137:             }
                   3138:         }
                   3139:     }
                   3140:     var oldVal;
                   3141:     for (var j=0; j<maxh; j++) {
                   3142:         if (current[j] == undefined) {
                   3143:             oldVal = j;
                   3144:         }
                   3145:     }
                   3146:     if (oldVal < changedVal) {
                   3147:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3148:            var elementName = current[k];
                   3149:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3150:         }
                   3151:     } else {
                   3152:         for (var k=changedVal; k<oldVal; k++) {
                   3153:             var elementName = current[k];
                   3154:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3155:         }
                   3156:     }
                   3157:     return;
                   3158: }
                   3159: 
                   3160: // ]]>
                   3161: </script>
                   3162: 
1.319     raeburn  3163: $togglejs
                   3164: 
                   3165: ENDSCRIPT
                   3166: }
                   3167: 
                   3168: sub ltitools_toggle_js {
                   3169:     return <<"ENDSCRIPT";
                   3170: <script type="text/javascript">
                   3171: // <![CDATA[
                   3172: 
                   3173: function toggleLTITools(form,setting,item) {
                   3174:     var radioname = '';
                   3175:     var divid = '';
                   3176:     if ((setting == 'passback') || (setting == 'roster')) {
                   3177:         radioname = 'ltitools_'+setting+'_'+item;
                   3178:         divid = 'ltitools_'+setting+'time_'+item;
                   3179:         var num = form.elements[radioname].length;
                   3180:         if (num) {
                   3181:             var setvis = '';
                   3182:             for (var i=0; i<num; i++) {
                   3183:                 if (form.elements[radioname][i].checked) {
                   3184:                     if (form.elements[radioname][i].value == '1') {
                   3185:                         if (document.getElementById(divid)) {
                   3186:                             document.getElementById(divid).style.display = 'inline-block';
                   3187:                         }
                   3188:                         setvis = 1;
                   3189:                     }
                   3190:                     break;
                   3191:                 }
                   3192:             }
                   3193:         }
                   3194:         if (!setvis) {
                   3195:             if (document.getElementById(divid)) {
                   3196:                 document.getElementById(divid).style.display = 'none';
                   3197:             }
                   3198:         }
                   3199:     }
1.324     raeburn  3200:     if (setting == 'user') {
                   3201:         divid = 'ltitools_'+setting+'_div_'+item;
                   3202:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   3203:         if (document.getElementById(divid)) {
                   3204:             if (document.getElementById(checkid)) {
                   3205:                 if (document.getElementById(checkid).checked) {
                   3206:                     document.getElementById(divid).style.display = 'inline-block';
                   3207:                 } else {
                   3208:                     document.getElementById(divid).style.display = 'none';
                   3209:                 }
                   3210:             }
                   3211:         }
                   3212:     }
1.319     raeburn  3213:     return;
                   3214: }
                   3215: // ]]>
                   3216: </script>
                   3217: 
1.267     raeburn  3218: ENDSCRIPT
                   3219: }
                   3220: 
1.381     raeburn  3221: sub wafproxy_javascript {
                   3222:     my ($dom) = @_;
                   3223:     return <<"ENDSCRIPT";
                   3224: <script type="text/javascript">
                   3225: // <![CDATA[
                   3226: function updateWAF() {
                   3227:     if (document.getElementById('wafproxy_remoteip')) {
                   3228:         var wafremote = 0;
                   3229:         if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
                   3230:             wafremote = 1;
                   3231:         }
                   3232:         var fields = new Array('header','trust');
                   3233:         for (var i=0; i<fields.length; i++) {
                   3234:             if (document.getElementById('wafproxy_'+fields[i])) {
                   3235:                 if (wafremote == 1) {
                   3236:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
                   3237:                 }
                   3238:                 else {
                   3239:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
                   3240:                 }
                   3241:             }
                   3242:         }
                   3243:         if (document.getElementById('wafproxyranges_$dom')) {
                   3244:             if (wafremote == 1) {
                   3245:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3246:             } else {
                   3247:                 for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3248:                     if (document.display.wafproxy_vpnaccess[i].checked) {
                   3249:                         if (document.display.wafproxy_vpnaccess[i].value == 0) {
                   3250:                             document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3251:                         }
                   3252:                     }
                   3253:                 }
                   3254:             }
                   3255:         }
                   3256:     }
                   3257:     return;
                   3258: }
                   3259: 
                   3260: function checkWAF() {
                   3261:     if (document.getElementById('wafproxy_remoteip')) {
                   3262:         var wafvpn = 0;
                   3263:         for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3264:             if (document.display.wafproxy_vpnaccess[i].checked) {
                   3265:                 if (document.display.wafproxy_vpnaccess[i].value == 1) {
                   3266:                     wafvpn = 1;
                   3267:                 }
                   3268:                 break;
                   3269:             }
                   3270:         }
                   3271:         var vpn = new Array('vpnint','vpnext');
                   3272:         for (var i=0; i<vpn.length; i++) {
                   3273:             if (document.getElementById('wafproxy_show_'+vpn[i])) {
                   3274:                 if (wafvpn == 1) {
                   3275:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
                   3276:                 }
                   3277:                 else {
                   3278:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
                   3279:                 }
                   3280:             }
                   3281:         }
                   3282:         if (document.getElementById('wafproxyranges_$dom')) {
                   3283:             if (wafvpn == 1) {
                   3284:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3285:             }
                   3286:             else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
                   3287:                 document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3288:             }
                   3289:         }
                   3290:     }
                   3291:     return;
                   3292: }
                   3293: 
                   3294: function toggleWAF() {
                   3295:     if (document.getElementById('wafproxy_table')) {
                   3296:         var wafproxy = 0;
                   3297:         for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
                   3298:              if (document.display.wafproxy_${dom}[i].checked) {
                   3299:                  if (document.display.wafproxy_${dom}[i].value == 1) {
                   3300:                      wafproxy = 1;
                   3301:                      break;
                   3302:                 }
                   3303:             }
                   3304:         }
                   3305:         if (wafproxy == 1) {
                   3306:             document.getElementById('wafproxy_table').style.display='inline';
                   3307:         }
                   3308:         else {
                   3309:            document.getElementById('wafproxy_table').style.display='none';
                   3310:         }
                   3311:         if (document.getElementById('wafproxyrow_${dom}')) {
                   3312:             if (wafproxy == 1) {
                   3313:                 document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
                   3314:             }
                   3315:             else {
                   3316:                 document.getElementById('wafproxyrow_${dom}').style.display = 'none';
                   3317:             }
                   3318:         }
                   3319:         if (document.getElementById('nowafproxyrow_$dom')) {
                   3320:             if (wafproxy == 1) {
                   3321:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
                   3322:             }
                   3323:             else {
                   3324:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
                   3325:             }
                   3326:         }
                   3327:     }
                   3328:     return;
                   3329: }
                   3330: // ]]>
                   3331: </script>
                   3332: 
                   3333: ENDSCRIPT
                   3334: }
                   3335: 
1.372     raeburn  3336: sub proctoring_javascript {
                   3337:     my ($settings) = @_;
                   3338:     my (%ordered,$total,%jstext);
                   3339:     $total = 0;
                   3340:     if (ref($settings) eq 'HASH') {
                   3341:         foreach my $item (keys(%{$settings})) {
                   3342:             if (ref($settings->{$item}) eq 'HASH') {
                   3343:                 my $num = $settings->{$item}{'order'};
                   3344:                 $ordered{$num} = $item;
                   3345:             }
                   3346:         }
                   3347:         $total = scalar(keys(%{$settings}));
                   3348:     } else {
                   3349:         %ordered = (
                   3350:                        0 => 'proctorio',
                   3351:                        1 => 'examity',
                   3352:                    );
                   3353:         $total = 2; 
                   3354:     }
                   3355:     my @jsarray = ();
                   3356:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3357:         push(@jsarray,$ordered{$item});
                   3358:     }
                   3359:     my $jstext = '    var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3360:     return <<"ENDSCRIPT";
                   3361: <script type="text/javascript">
                   3362: // <![CDATA[
                   3363: function reorderProctoring(form,item) {
                   3364:     var changedVal;
                   3365: $jstext
                   3366:     var maxh = $total;
                   3367:     var current = new Array;
                   3368:     var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3369:     for (var i=0; i<proctors.length; i++) {
                   3370:         var elementName = 'proctoring_pos_'+proctors[i];
                   3371:         if (elementName != item) {
                   3372:             if (form.elements[elementName]) {
                   3373:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3374:                 current[currVal] = elementName;
                   3375:             }
                   3376:         }
                   3377:     }
                   3378:     var oldVal;
                   3379:     for (var j=0; j<maxh; j++) {
                   3380:         if (current[j] == undefined) {
                   3381:             oldVal = j;
                   3382:         }
                   3383:     }
                   3384:     if (oldVal < changedVal) {
                   3385:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3386:            var elementName = current[k];
                   3387:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3388:         }
                   3389:     } else {
                   3390:         for (var k=changedVal; k<oldVal; k++) {
                   3391:             var elementName = current[k];
                   3392:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3393:         }
                   3394:     }
                   3395:     return;
                   3396: }
                   3397: 
                   3398: function toggleProctoring(form,item) {
                   3399:     var fieldsets = document.getElementsByClassName('proctoring_'+item);
                   3400:     if (fieldsets.length) {
                   3401:         var radioname = 'proctoring_available_'+item;
                   3402:         var num = form.elements[radioname].length;
                   3403:         if (num) {
                   3404:             var setvis = '';
                   3405:             for (var i=0; i<num; i++) {
                   3406:                 if (form.elements[radioname][i].checked) {
                   3407:                     if (form.elements[radioname][i].value == '1') {
                   3408:                        setvis = 1;
                   3409:                        break;
                   3410:                     }
                   3411:                 }
                   3412:             }
                   3413:             for (var j=0; j<fieldsets.length; j++) {
                   3414:                 if (setvis) {
                   3415:                     fieldsets[j].style.display = 'block';
                   3416:                 } else {
                   3417:                     fieldsets[j].style.display = 'none';
                   3418:                 }
                   3419:             }
                   3420:         }
                   3421:     }
                   3422:     return;
                   3423: }
                   3424: 
                   3425: // ]]>
                   3426: </script>
                   3427: 
                   3428: ENDSCRIPT
                   3429: }
                   3430: 
                   3431: 
1.320     raeburn  3432: sub lti_javascript {
1.405     raeburn  3433:     my ($dom,$settings) = @_;
                   3434:     my $togglejs = &lti_toggle_js($dom);
1.419     raeburn  3435:     my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320     raeburn  3436:     unless (ref($settings) eq 'HASH') {
1.419     raeburn  3437:         return $togglejs.'
                   3438: <script type="text/javascript">
                   3439: // <![CDATA[
                   3440: 
                   3441: '.$linkprot_js.'
                   3442: 
                   3443: // ]]>
                   3444: </script>
                   3445: ';
1.320     raeburn  3446:     }
                   3447:     my (%ordered,$total,%jstext);
1.390     raeburn  3448:     $total = scalar(keys(%{$settings}));
1.320     raeburn  3449:     foreach my $item (keys(%{$settings})) {
                   3450:         if (ref($settings->{$item}) eq 'HASH') {
                   3451:             my $num = $settings->{$item}{'order'};
1.390     raeburn  3452:             if ($num eq '') {
                   3453:                 $num = $total - 1;
                   3454:             }
1.320     raeburn  3455:             $ordered{$num} = $item;
                   3456:         }
                   3457:     }
                   3458:     my @jsarray = ();
                   3459:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3460:         push(@jsarray,$ordered{$item});
                   3461:     }
                   3462:     my $jstext = '    var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3463:     return <<"ENDSCRIPT";
                   3464: <script type="text/javascript">
                   3465: // <![CDATA[
                   3466: function reorderLTI(form,item) {
                   3467:     var changedVal;
                   3468: $jstext
                   3469:     var newpos = 'lti_pos_add';
                   3470:     var maxh = 1 + $total;
                   3471:     var current = new Array;
                   3472:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3473:     if (item == newpos) {
                   3474:         changedVal = newitemVal;
                   3475:     } else {
                   3476:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3477:         current[newitemVal] = newpos;
                   3478:     }
                   3479:     for (var i=0; i<lti.length; i++) {
                   3480:         var elementName = 'lti_pos_'+lti[i];
                   3481:         if (elementName != item) {
                   3482:             if (form.elements[elementName]) {
                   3483:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3484:                 current[currVal] = elementName;
                   3485:             }
                   3486:         }
                   3487:     }
                   3488:     var oldVal;
                   3489:     for (var j=0; j<maxh; j++) {
                   3490:         if (current[j] == undefined) {
                   3491:             oldVal = j;
                   3492:         }
                   3493:     }
                   3494:     if (oldVal < changedVal) {
                   3495:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3496:            var elementName = current[k];
                   3497:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3498:         }
                   3499:     } else {
                   3500:         for (var k=changedVal; k<oldVal; k++) {
                   3501:             var elementName = current[k];
                   3502:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3503:         }
                   3504:     }
                   3505:     return;
                   3506: }
1.406     raeburn  3507: 
                   3508: $linkprot_js
                   3509: 
1.320     raeburn  3510: // ]]>
                   3511: </script>
                   3512: 
                   3513: $togglejs
                   3514: 
                   3515: ENDSCRIPT
                   3516: }
                   3517: 
                   3518: sub lti_toggle_js {
1.405     raeburn  3519:     my ($dom) = @_;
1.325     raeburn  3520:     my %lcauthparmtext = &Apache::lonlocal::texthash (
                   3521:                             localauth => 'Local auth argument',
                   3522:                             krb       => 'Kerberos domain',
                   3523:                          );
1.391     raeburn  3524:     my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
                   3525:     &js_escape(\$crsincalert);
1.405     raeburn  3526:     my %servers = &Apache::lonnet::get_servers($dom,'library');
                   3527:     my $primary = &Apache::lonnet::domain($dom,'primary');
                   3528:     my $course_servers = "'".join("','",keys(%servers))."'";
                   3529: 
1.320     raeburn  3530:     return <<"ENDSCRIPT";
                   3531: <script type="text/javascript">
                   3532: // <![CDATA[
                   3533: 
                   3534: function toggleLTI(form,setting,item) {
1.391     raeburn  3535:     if ((setting == 'requser') || (setting == 'crsinc')) {
                   3536:         var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
                   3537:         var setvis = '';
                   3538:         var radioname = 'lti_requser_'+item;
                   3539:         var num = form.elements[radioname].length;
                   3540:         if (num) {
                   3541:             for (var i=0; i<num; i++) {
                   3542:                 if (form.elements[radioname][i].checked) {
                   3543:                     if (form.elements[radioname][i].value == '1') {
                   3544:                         setvis = 1;
                   3545:                         break;
                   3546:                     }
                   3547:                 }
                   3548:             }
                   3549:         }
                   3550:         if (usrfieldsets.length) {
                   3551:             for (var j=0; j<usrfieldsets.length; j++) {
                   3552:                 if (setvis) {
                   3553:                     usrfieldsets[j].style.display = 'block';
                   3554:                 } else {
                   3555:                     usrfieldsets[j].style.display = 'none';
                   3556:                 }
                   3557:             }
                   3558:         }
                   3559:         var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
                   3560:         if (crsfieldsets.length) {
                   3561:             radioname = 'lti_crsinc_'+item;
1.345     raeburn  3562:             var num = form.elements[radioname].length;
                   3563:             if (num) {
1.391     raeburn  3564:                 var crsvis = '';
1.345     raeburn  3565:                 for (var i=0; i<num; i++) {
                   3566:                     if (form.elements[radioname][i].checked) {
                   3567:                         if (form.elements[radioname][i].value == '1') {
1.391     raeburn  3568:                             if (setvis == '') {
                   3569:                                 if (setting == 'crsinc'){
                   3570:                                     alert("$crsincalert");
                   3571:                                     form.elements[radioname][0].checked = true;
                   3572:                                 }
                   3573:                             } else {
                   3574:                                 crsvis = 1;
                   3575:                             }
                   3576:                             break;
1.345     raeburn  3577:                         }
                   3578:                     }
                   3579:                 }
1.391     raeburn  3580:                 setvis = crsvis;
                   3581:             }
                   3582:             for (var j=0; j<crsfieldsets.length; j++) {
                   3583:                 if (setvis) {
                   3584:                     crsfieldsets[j].style.display = 'block';
                   3585:                 } else {
                   3586:                     crsfieldsets[j].style.display = 'none';
1.345     raeburn  3587:                 }
                   3588:             }
                   3589:         }
1.363     raeburn  3590:     } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320     raeburn  3591:         var radioname = '';
                   3592:         var divid = '';
                   3593:         if (setting == 'user') {
                   3594:             radioname = 'lti_mapuser_'+item;
                   3595:             divid = 'lti_userfield_'+item;
1.343     raeburn  3596:         } else if (setting == 'crs') {
1.320     raeburn  3597:             radioname = 'lti_mapcrs_'+item;
                   3598:             divid = 'lti_crsfield_'+item;
1.363     raeburn  3599:         } else if (setting == 'callback') {
                   3600:             radioname = 'lti_callback_'+item;
                   3601:             divid = 'lti_callbackfield_'+item;
1.337     raeburn  3602:         } else {
1.351     raeburn  3603:             radioname = 'lti_passback_'+item;
1.337     raeburn  3604:             divid =  'lti_passback_'+item;
1.320     raeburn  3605:         }
                   3606:         var num = form.elements[radioname].length;
                   3607:         if (num) {
                   3608:             var setvis = '';
                   3609:             for (var i=0; i<num; i++) {
                   3610:                if (form.elements[radioname][i].checked) {
1.363     raeburn  3611:                    if ((setting == 'passback') || (setting == 'callback')) {
1.337     raeburn  3612:                        if (form.elements[radioname][i].value == '1') {
                   3613:                            if (document.getElementById(divid)) {
                   3614:                                document.getElementById(divid).style.display = 'inline-block';
                   3615:                            }
                   3616:                            setvis = 1;
                   3617:                            break;
                   3618:                        }
                   3619:                    } else {
                   3620:                        if (form.elements[radioname][i].value == 'other') {
                   3621:                            if (document.getElementById(divid)) {
                   3622:                                document.getElementById(divid).style.display = 'inline-block';
                   3623:                            }
                   3624:                            setvis = 1;
                   3625:                            break;
1.320     raeburn  3626:                        }
                   3627:                    }
                   3628:                } 
                   3629:             }
                   3630:             if (!setvis) {
                   3631:                 if (document.getElementById(divid)) {
                   3632:                     document.getElementById(divid).style.display = 'none';
                   3633:                 }
                   3634:             }
                   3635:         }
                   3636:     } else if ((setting == 'sec') || (setting == 'secsrc')) {
                   3637:         var numsec = form.elements['lti_crssec_'+item].length;
                   3638:         if (numsec) {
                   3639:             var setvis = '';
                   3640:             for (var i=0; i<numsec; i++) {
                   3641:                 if (form.elements['lti_crssec_'+item][i].checked) {
                   3642:                     if (form.elements['lti_crssec_'+item][i].value == '1') {
                   3643:                         if (document.getElementById('lti_crssecfield_'+item)) {
                   3644:                             document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
                   3645:                             setvis = 1;
                   3646:                             var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
                   3647:                             if (numsrcsec) {
                   3648:                                 var setsrcvis = '';
                   3649:                                 for (var j=0; j<numsrcsec; j++) {
                   3650:                                     if (form.elements['lti_crssecsrc_'+item][j].checked) {
                   3651:                                         if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
                   3652:                                             if (document.getElementById('lti_secsrcfield_'+item)) {
                   3653:                                                 document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
                   3654:                                                 setsrcvis = 1;
                   3655:                                             }
                   3656:                                         }
                   3657:                                     }
                   3658:                                 }
                   3659:                                 if (!setsrcvis) {
                   3660:                                     if (document.getElementById('lti_secsrcfield_'+item)) {
                   3661:                                         document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3662:                                     }
                   3663:                                 }
                   3664:                             }
                   3665:                         }
                   3666:                     }
                   3667:                 }
                   3668:             }
                   3669:             if (!setvis) {
                   3670:                 if (document.getElementById('lti_crssecfield_'+item)) {
                   3671:                     document.getElementById('lti_crssecfield_'+item).style.display = 'none';
                   3672:                 }
                   3673:                 if (document.getElementById('lti_secsrcfield_'+item)) {
                   3674:                     document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3675:                 }
                   3676:             }
                   3677:         }
1.325     raeburn  3678:     } else if (setting == 'lcauth') {
                   3679:         var numauth = form.elements['lti_lcauth_'+item].length;
                   3680:         if (numauth) {
                   3681:             for (var i=0; i<numauth; i++) {
                   3682:                 if (form.elements['lti_lcauth_'+item][i].checked) {
                   3683:                     if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                   3684:                         if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                   3685:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                   3686:                         } else {
                   3687:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                   3688:                             if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                   3689:                                 if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                   3690:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                   3691:                                 } else {
                   3692:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                   3693:                                 }
                   3694:                             }
                   3695:                         }
                   3696:                     }
                   3697:                 }
                   3698:             }
                   3699:         }
1.326     raeburn  3700:     } else if (setting == 'lcmenu') {
                   3701:         var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
                   3702:         var divid = 'lti_menufield_'+item;
                   3703:         var setvis = '';
                   3704:         for (var i=0; i<menus.length; i++) {
                   3705:             var radioname = menus[i];  
                   3706:             var num = form.elements[radioname].length;
                   3707:             if (num) {
                   3708:                 for (var j=0; j<num; j++) {
                   3709:                     if (form.elements[radioname][j].checked) {
                   3710:                         if (form.elements[radioname][j].value == '1') {
                   3711:                             if (document.getElementById(divid)) {
                   3712:                                 document.getElementById(divid).style.display = 'inline-block';
                   3713:                             }
                   3714:                             setvis = 1;
                   3715:                             break;
                   3716:                         }
                   3717:                     }
                   3718:                 }
                   3719:             }
                   3720:             if (setvis == 1) {
                   3721:                 break;
                   3722:             }
                   3723:         }
                   3724:         if (!setvis) {
                   3725:             if (document.getElementById(divid)) {
                   3726:                 document.getElementById(divid).style.display = 'none';
                   3727:             }
                   3728:         }
1.320     raeburn  3729:     }
                   3730:     return;
                   3731: }
1.405     raeburn  3732: 
                   3733: function toggleLTIEncKey(form) {
                   3734:     var shownhosts = new Array();
                   3735:     var hiddenhosts = new Array();
                   3736:     var forcourse = new Array($course_servers);
                   3737:     var fromdomain = '$primary';
                   3738:     var crsradio = form.elements['ltisec_crslinkprot'];
                   3739:     if (crsradio.length) {
                   3740:         for (var i=0; i<crsradio.length; i++) {
                   3741:             if (crsradio[i].checked) {
                   3742:                 if (crsradio[i].value == 1) {
                   3743:                     if (forcourse.length > 0) {
                   3744:                         for (var j=0; j<forcourse.length; j++) {
                   3745:                             if (!shownhosts.includes(forcourse[j])) {
                   3746:                                 shownhosts.push(forcourse[j]);
                   3747:                             }
                   3748:                         }
                   3749:                     }
                   3750:                 } else {
                   3751:                     if (forcourse.length > 0) {
                   3752:                         for (var j=0; j<forcourse.length; j++) {
                   3753:                             if (!hiddenhosts.includes(forcourse[j])) { 
                   3754:                                 hiddenhosts.push(forcourse[j]);
                   3755:                             }
                   3756:                         }
                   3757:                     } 
                   3758:                 }
                   3759:             }
                   3760:         }
                   3761:     }
                   3762:     var domradio = form.elements['ltisec_domlinkprot'];
                   3763:     if (domradio.length) {
                   3764:         for (var i=0; i<domradio.length; i++) {
                   3765:             if (domradio[i].checked) {
                   3766:                 if (domradio[i].value == 1) {
                   3767:                     if (!shownhosts.includes(fromdomain)) { 
                   3768:                         shownhosts.push(fromdomain);
                   3769:                     }
                   3770:                 } else {
                   3771:                     if (!hiddenhosts.includes(fromdomain)) {
                   3772:                         hiddenhosts.push(fromdomain);
                   3773:                     }
                   3774:                 }
                   3775:             }
                   3776:         }
                   3777:     }
                   3778:     var consumersradio = form.elements['ltisec_consumers'];
                   3779:     if (consumersradio.length) {
                   3780:         for (var i=0; i<consumersradio.length; i++) {
                   3781:             if (consumersradio[i].checked) {
                   3782:                 if (consumersradio[i].value == 1) {
                   3783:                     if (!shownhosts.includes(fromdomain)) {     
                   3784:                         shownhosts.push(fromdomain);
                   3785:                     }
                   3786:                 } else {
                   3787:                     if (!hiddenhosts.includes(fromdomain)) {
                   3788:                         hiddenhosts.push(fromdomain);
                   3789:                     }
                   3790:                 }
                   3791:             }
                   3792:         }
                   3793:     }
                   3794:     if (shownhosts.length > 0) {
                   3795:         for (var i=0; i<shownhosts.length; i++) {
                   3796:             if (document.getElementById('ltisec_info_'+shownhosts[i])) {
                   3797:                 document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';                 
                   3798:             }
                   3799:         }
                   3800:         if (document.getElementById('ltisec_noprivkey')) {
                   3801:             document.getElementById('ltisec_noprivkey').style.display = 'none';
                   3802:         }
                   3803:     } else {
                   3804:         if (document.getElementById('ltisec_noprivkey')) {
                   3805:             document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
                   3806:         }
                   3807:     }
                   3808:     if (hiddenhosts.length > 0) {
                   3809:         for (var i=0; i<hiddenhosts.length; i++) {
                   3810:             if (!shownhosts.includes(hiddenhosts[i])) {
                   3811:                 if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
                   3812:                     document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
                   3813:                 }
                   3814:             }
                   3815:         }
                   3816:     }
                   3817:     return;
                   3818: }
                   3819: 
                   3820: function togglePrivKey(form,hostid) {
                   3821:     var radioname = '';
                   3822:     var currdivid = '';
                   3823:     var newdivid = '';
                   3824:     if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
                   3825:         (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
                   3826:         currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
                   3827:         newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
                   3828:         radioname = form.elements['ltisec_changeprivkey_'+hostid];
                   3829:         if (radioname) {
                   3830:             if (radioname.length > 0) {
                   3831:                 var setvis;
                   3832:                 for (var i=0; i<radioname.length; i++) {
                   3833:                     if (radioname[i].checked == true) {
                   3834:                         if (radioname[i].value == 1) {
                   3835:                             newdivid.style.display = 'inline-block';
                   3836:                             currdivid.style.display = 'none';
                   3837:                             setvis = 1;
                   3838:                         }
                   3839:                         break;
                   3840:                     }
                   3841:                 }
                   3842:                 if (!setvis) {
                   3843:                     newdivid.style.display = 'none';
                   3844:                     currdivid.style.display = 'inline-block';
                   3845:                 }
                   3846:             }
                   3847:         }
                   3848:     }
                   3849: }
                   3850: 
1.320     raeburn  3851: // ]]>
                   3852: </script>
                   3853: 
                   3854: ENDSCRIPT
                   3855: }
                   3856: 
1.385     raeburn  3857: sub autoupdate_javascript {
                   3858:     return <<"ENDSCRIPT";
                   3859: <script type="text/javascript">
                   3860: // <![CDATA[
                   3861: function toggleLastActiveDays(form) {
                   3862:     var radioname = 'lastactive';
                   3863:     var divid = 'lastactive_div';
                   3864:     var num = form.elements[radioname].length;
                   3865:     if (num) {
                   3866:         var setvis = '';
                   3867:         for (var i=0; i<num; i++) {
                   3868:             if (form.elements[radioname][i].checked) {
                   3869:                 if (form.elements[radioname][i].value == '1') {
                   3870:                     if (document.getElementById(divid)) {
                   3871:                         document.getElementById(divid).style.display = 'inline-block';
                   3872:                     }
                   3873:                     setvis = 1;
                   3874:                 }
                   3875:                 break;
                   3876:             }
                   3877:         }
                   3878:         if (!setvis) {
                   3879:             if (document.getElementById(divid)) {
                   3880:                 document.getElementById(divid).style.display = 'none';
                   3881:             }
                   3882:         }
                   3883:     }
                   3884:     return;
                   3885: }
                   3886: // ]]>
                   3887: </script>
                   3888: 
                   3889: ENDSCRIPT
                   3890: }
                   3891: 
1.399     raeburn  3892: sub autoenroll_javascript {
                   3893:     return <<"ENDSCRIPT";
                   3894: <script type="text/javascript">
                   3895: // <![CDATA[
                   3896: function toggleFailsafe(form) {
                   3897:     var radioname = 'autoenroll_failsafe';
                   3898:     var divid = 'autoenroll_failsafe_div';
                   3899:     var num = form.elements[radioname].length;
                   3900:     if (num) {
                   3901:         var setvis = '';
                   3902:         for (var i=0; i<num; i++) {
                   3903:             if (form.elements[radioname][i].checked) {
                   3904:                 if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
                   3905:                     if (document.getElementById(divid)) {
                   3906:                         document.getElementById(divid).style.display = 'inline-block';
                   3907:                     }
                   3908:                     setvis = 1;
                   3909:                 }
                   3910:                 break;
                   3911:             }
                   3912:         }
                   3913:         if (!setvis) {
                   3914:             if (document.getElementById(divid)) {
                   3915:                 document.getElementById(divid).style.display = 'none';
                   3916:             }
                   3917:         }
                   3918:     }
                   3919:     return;
                   3920: }
                   3921: // ]]>
                   3922: </script>
                   3923: 
                   3924: ENDSCRIPT
                   3925: }
                   3926: 
1.386     raeburn  3927: sub saml_javascript {
                   3928:     return <<"ENDSCRIPT";
                   3929: <script type="text/javascript">
                   3930: // <![CDATA[
                   3931: function toggleSamlOptions(form,hostid) { 
                   3932:     var radioname = 'saml_'+hostid;
                   3933:     var tablecellon = 'samloptionson_'+hostid;
                   3934:     var tablecelloff = 'samloptionsoff_'+hostid;
                   3935:     var num = form.elements[radioname].length;
                   3936:     if (num) {
                   3937:         var setvis = ''; 
                   3938:         for (var i=0; i<num; i++) {
                   3939:             if (form.elements[radioname][i].checked) {
                   3940:                 if (form.elements[radioname][i].value == '1') { 
                   3941:                     if (document.getElementById(tablecellon)) {
                   3942:                         document.getElementById(tablecellon).style.display='';
                   3943:                     }
                   3944:                     if (document.getElementById(tablecelloff)) {
                   3945:                         document.getElementById(tablecelloff).style.display='none';
                   3946:                     }
                   3947:                     setvis = 1;
                   3948:                 }
                   3949:                 break;
                   3950:             }
                   3951:         }
                   3952:         if (!setvis) {
                   3953:             if (document.getElementById(tablecellon)) {
                   3954:                 document.getElementById(tablecellon).style.display='none';
                   3955:             }
                   3956:             if (document.getElementById(tablecelloff)) {
                   3957:                 document.getElementById(tablecelloff).style.display='';
                   3958:             }
                   3959:         }
                   3960:     }
                   3961:     return;
                   3962: }
                   3963: // ]]>
                   3964: </script>
                   3965: 
                   3966: ENDSCRIPT
                   3967: }
                   3968: 
1.394     raeburn  3969: sub ipaccess_javascript {
                   3970:     my ($settings) = @_;
                   3971:     my (%ordered,$total,%jstext);
                   3972:     $total = 0;
                   3973:     if (ref($settings) eq 'HASH') {
                   3974:         foreach my $item (keys(%{$settings})) {
                   3975:             if (ref($settings->{$item}) eq 'HASH') {
                   3976:                 my $num = $settings->{$item}{'order'};
                   3977:                 $ordered{$num} = $item;
                   3978:             }
                   3979:         }
                   3980:         $total = scalar(keys(%{$settings}));
                   3981:     }
                   3982:     my @jsarray = ();
                   3983:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3984:         push(@jsarray,$ordered{$item});
                   3985:     }
                   3986:     my $jstext = '    var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3987:     return <<"ENDSCRIPT";
                   3988: <script type="text/javascript">
                   3989: // <![CDATA[
                   3990: function reorderIPaccess(form,item) {
                   3991:     var changedVal;
                   3992: $jstext
                   3993:     var newpos = 'ipaccess_pos_add';
                   3994:     var maxh = 1 + $total;
                   3995:     var current = new Array;
                   3996:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3997:     if (item == newpos) {
                   3998:         changedVal = newitemVal;
                   3999:     } else {
                   4000:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4001:         current[newitemVal] = newpos;
                   4002:     }
                   4003:     for (var i=0; i<ipaccess.length; i++) {
                   4004:         var elementName = 'ipaccess_pos_'+ipaccess[i];
                   4005:         if (elementName != item) {
                   4006:             if (form.elements[elementName]) {
                   4007:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4008:                 current[currVal] = elementName;
                   4009:             }
                   4010:         }
                   4011:     }
                   4012:     var oldVal;
                   4013:     for (var j=0; j<maxh; j++) {
                   4014:         if (current[j] == undefined) {
                   4015:             oldVal = j;
                   4016:         }
                   4017:     }
                   4018:     if (oldVal < changedVal) {
                   4019:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4020:            var elementName = current[k];
                   4021:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4022:         }
                   4023:     } else {
                   4024:         for (var k=changedVal; k<oldVal; k++) {
                   4025:             var elementName = current[k];
                   4026:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4027:         }
                   4028:     }
                   4029:     return;
                   4030: }
                   4031: // ]]>
                   4032: </script>
                   4033: 
                   4034: ENDSCRIPT
                   4035: }
                   4036: 
1.3       raeburn  4037: sub print_autoenroll {
1.30      raeburn  4038:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  4039:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399     raeburn  4040:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
                   4041:         $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
                   4042:     $failsafesty = 'none';
                   4043:     %failsafechecked = (
                   4044:         off => ' checked="checked"',
                   4045:     );
1.3       raeburn  4046:     if (ref($settings) eq 'HASH') {
                   4047:         if (exists($settings->{'run'})) {
                   4048:             if ($settings->{'run'} eq '0') {
                   4049:                 $runoff = ' checked="checked" ';
                   4050:                 $runon = ' ';
                   4051:             } else {
                   4052:                 $runon = ' checked="checked" ';
                   4053:                 $runoff = ' ';
                   4054:             }
                   4055:         } else {
                   4056:             if ($autorun) {
                   4057:                 $runon = ' checked="checked" ';
                   4058:                 $runoff = ' ';
                   4059:             } else {
                   4060:                 $runoff = ' checked="checked" ';
                   4061:                 $runon = ' ';
                   4062:             }
                   4063:         }
1.129     raeburn  4064:         if (exists($settings->{'co-owners'})) {
                   4065:             if ($settings->{'co-owners'} eq '0') {
                   4066:                 $coownersoff = ' checked="checked" ';
                   4067:                 $coownerson = ' ';
                   4068:             } else {
                   4069:                 $coownerson = ' checked="checked" ';
                   4070:                 $coownersoff = ' ';
                   4071:             }
                   4072:         } else {
                   4073:             $coownersoff = ' checked="checked" ';
                   4074:             $coownerson = ' ';
                   4075:         }
1.3       raeburn  4076:         if (exists($settings->{'sender_domain'})) {
                   4077:             $defdom = $settings->{'sender_domain'};
                   4078:         }
1.399     raeburn  4079:         if (exists($settings->{'failsafe'})) {
                   4080:             $failsafe = $settings->{'failsafe'};
                   4081:             if ($failsafe eq 'zero') {
1.400     raeburn  4082:                 $failsafechecked{'zero'} = ' checked="checked"';
1.399     raeburn  4083:                 $failsafechecked{'off'} = '';
                   4084:                 $failsafesty = 'inline-block';
                   4085:             } elsif ($failsafe eq 'any') {
                   4086:                 $failsafechecked{'any'} = ' checked="checked"';
                   4087:                 $failsafechecked{'off'} = '';
                   4088:             }
                   4089:             $autofailsafe = $settings->{'autofailsafe'};
                   4090:         } elsif (exists($settings->{'autofailsafe'})) {
                   4091:             $autofailsafe = $settings->{'autofailsafe'};
                   4092:             if ($autofailsafe ne '') {
                   4093:                 $failsafechecked{'zero'} = ' checked="checked"';
                   4094:                 $failsafe = 'zero';
1.400     raeburn  4095:                 $failsafechecked{'off'} = '';
1.399     raeburn  4096:             }
1.274     raeburn  4097:         }
1.14      raeburn  4098:     } else {
                   4099:         if ($autorun) {
                   4100:             $runon = ' checked="checked" ';
                   4101:             $runoff = ' ';
                   4102:         } else {
                   4103:             $runoff = ' checked="checked" ';
                   4104:             $runon = ' ';
                   4105:         }
1.3       raeburn  4106:     }
                   4107:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  4108:     my $notif_sender;
                   4109:     if (ref($settings) eq 'HASH') {
                   4110:         $notif_sender = $settings->{'sender_uname'};
                   4111:     }
1.3       raeburn  4112:     my $datatable='<tr class="LC_odd_row">'.
                   4113:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  4114:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  4115:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  4116:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4117:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  4118:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  4119:                   '</tr><tr>'.
                   4120:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  4121:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  4122:                   &mt('username').':&nbsp;'.
                   4123:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  4124:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  4125:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   4126:                   '<tr class="LC_odd_row">'.
                   4127:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   4128:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4129:                   '<input type="radio" name="autoassign_coowners"'.
                   4130:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4131:                   '<label><input type="radio" name="autoassign_coowners"'.
                   4132:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  4133:                   '</tr><tr>'.
                   4134:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400     raeburn  4135:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4136:                   '<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; '.
                   4137:                   '<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 />'.
                   4138:                   '<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  4139:                   '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
                   4140:                   '<span class="LC_nobreak">'.
                   4141:                   &mt('Threshold for number of students in section to drop: [_1]',
                   4142:                       '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
                   4143:                   '</span></div></td></tr>';
1.274     raeburn  4144:     $$rowtotal += 4;
1.3       raeburn  4145:     return $datatable;
                   4146: }
                   4147: 
                   4148: sub print_autoupdate {
1.30      raeburn  4149:     my ($position,$dom,$settings,$rowtotal) = @_;
1.385     raeburn  4150:     my ($enable,$datatable);
1.3       raeburn  4151:     if ($position eq 'top') {
1.385     raeburn  4152:         my %choices = &Apache::lonlocal::texthash (
                   4153:                           run        => 'Auto-update active?',
                   4154:                           classlists => 'Update information in classlists?',
                   4155:                           unexpired  => 'Skip updates for users without active or future roles?',
                   4156:                           lastactive => 'Skip updates for inactive users?',
                   4157:         );
                   4158:         my $itemcount = 0;
1.3       raeburn  4159:         my $updateon = ' ';
                   4160:         my $updateoff = ' checked="checked" ';
                   4161:         if (ref($settings) eq 'HASH') {
                   4162:             if ($settings->{'run'} eq '1') {
                   4163:                 $updateon = $updateoff;
                   4164:                 $updateoff = ' ';
                   4165:             }
                   4166:         }
1.385     raeburn  4167:         $enable = '<tr class="LC_odd_row">'.
                   4168:                   '<td>'.$choices{'run'}.'</td>'.
                   4169:                   '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  4170:                   '<input type="radio" name="autoupdate_run"'.
1.397     raeburn  4171:                   $updateoff.'value="0" />'.&mt('No').'</label>&nbsp;'.
1.8       raeburn  4172:                   '<label><input type="radio" name="autoupdate_run"'.
1.385     raeburn  4173:                   $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3       raeburn  4174:                   '</tr>';
1.385     raeburn  4175:         my @toggles = ('classlists','unexpired');
                   4176:         my %defaultchecked = ('classlists' => 'off',
                   4177:                               'unexpired'  => 'off'
                   4178:                               );
                   4179:         $$rowtotal ++;
                   4180:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4181:                                                      \%choices,$itemcount,'','','left','no');
                   4182:         $datatable = $enable.$datatable;
                   4183:         $$rowtotal += $itemcount;
                   4184:         my $lastactiveon = ' ';
                   4185:         my $lastactiveoff = ' checked="checked" ';
                   4186:         my $lastactivestyle = 'none';
                   4187:         my $lastactivedays;
                   4188:         my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
                   4189:         if (ref($settings) eq 'HASH') {
                   4190:             if ($settings->{'lastactive'} =~ /^\d+$/) {
                   4191:                 $lastactiveon = $lastactiveoff;
                   4192:                 $lastactiveoff = ' ';
                   4193:                 $lastactivestyle = 'inline-block';
                   4194:                 $lastactivedays = $settings->{'lastactive'};
                   4195:             }
                   4196:         }
                   4197:         my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4198:         $datatable .= '<tr'.$css_class.'>'.
                   4199:                       '<td>'.$choices{'lastactive'}.'</td>'.
                   4200:                       '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                   4201:                       '<input type="radio" name="lastactive"'.
                   4202:                       $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   4203:                       '&nbsp;<label>'.
                   4204:                       '<input type="radio" name="lastactive"'.
                   4205:                       $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
                   4206:                       '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
                   4207:                       ':&nbsp;'.&mt('inactive = no activity in last [_1] days',
                   4208:                           '<input type="text" size="5" name="lastactivedays" value="'.
                   4209:                           $lastactivedays.'" />').
                   4210:                       '</span></td>'.
                   4211:                       '</tr>';
                   4212:         $$rowtotal ++;
1.131     raeburn  4213:     } elsif ($position eq 'middle') {
                   4214:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4215:         my $numinrow = 3;
                   4216:         my $locknamesettings;
                   4217:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   4218:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  4219:                                     'lockablenames',$rowtotal);
1.131     raeburn  4220:         $$rowtotal ++;
1.3       raeburn  4221:     } else {
1.44      raeburn  4222:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  4223:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  4224:                       'permanentemail','id');
1.33      raeburn  4225:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  4226:         my $numrows = 0;
1.26      raeburn  4227:         if (ref($types) eq 'ARRAY') {
                   4228:             if (@{$types} > 0) {
                   4229:                 $datatable = 
                   4230:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   4231:                                          \@fields,$types,\$numrows);
1.30      raeburn  4232:                     $$rowtotal += @{$types}; 
1.26      raeburn  4233:             }
1.3       raeburn  4234:         }
                   4235:         $datatable .= 
                   4236:             &usertype_update_row($settings,{'default' => $othertitle},
                   4237:                                  \%fieldtitles,\@fields,['default'],
                   4238:                                  \$numrows);
1.30      raeburn  4239:         $$rowtotal ++;     
1.3       raeburn  4240:     }
                   4241:     return $datatable;
                   4242: }
                   4243: 
1.125     raeburn  4244: sub print_autocreate {
                   4245:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  4246:     my (%createon,%createoff,%currhash);
1.125     raeburn  4247:     my @types = ('xml','req');
                   4248:     if (ref($settings) eq 'HASH') {
                   4249:         foreach my $item (@types) {
                   4250:             $createoff{$item} = ' checked="checked" ';
                   4251:             $createon{$item} = ' ';
                   4252:             if (exists($settings->{$item})) {
                   4253:                 if ($settings->{$item}) {
                   4254:                     $createon{$item} = ' checked="checked" ';
                   4255:                     $createoff{$item} = ' ';
                   4256:                 }
                   4257:             }
                   4258:         }
1.210     raeburn  4259:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  4260:             $currhash{$settings->{'xmldc'}} = 1;
                   4261:         }
1.125     raeburn  4262:     } else {
                   4263:         foreach my $item (@types) {
                   4264:             $createoff{$item} = ' checked="checked" ';
                   4265:             $createon{$item} = ' ';
                   4266:         }
                   4267:     }
                   4268:     $$rowtotal += 2;
1.191     raeburn  4269:     my $numinrow = 2;
1.125     raeburn  4270:     my $datatable='<tr class="LC_odd_row">'.
                   4271:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   4272:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4273:                   '<input type="radio" name="autocreate_xml"'.
                   4274:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4275:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  4276:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   4277:                   '</td></tr><tr>'.
                   4278:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   4279:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4280:                   '<input type="radio" name="autocreate_req"'.
                   4281:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4282:                   '<label><input type="radio" name="autocreate_req"'.
                   4283:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  4284:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4285:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  4286:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  4287:     if ($numdc > 1) {
1.247     raeburn  4288:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   4289:                       '</td><td class="LC_left_item">';
1.125     raeburn  4290:     } else {
1.247     raeburn  4291:         $datatable .= &mt('Course creation processed as:').
                   4292:                       '</td><td class="LC_right_item">';
1.125     raeburn  4293:     }
1.247     raeburn  4294:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  4295:     $$rowtotal += $rows;
1.125     raeburn  4296:     return $datatable;
                   4297: }
                   4298: 
1.23      raeburn  4299: sub print_directorysrch {
1.277     raeburn  4300:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4301:     my $datatable;
                   4302:     if ($position eq 'top') {
                   4303:         my $instsrchon = ' ';
                   4304:         my $instsrchoff = ' checked="checked" ';
                   4305:         my ($exacton,$containson,$beginson);
                   4306:         my $instlocalon = ' ';
                   4307:         my $instlocaloff = ' checked="checked" ';
                   4308:         if (ref($settings) eq 'HASH') {
                   4309:             if ($settings->{'available'} eq '1') {
                   4310:                 $instsrchon = $instsrchoff;
                   4311:                 $instsrchoff = ' ';
                   4312:             }
                   4313:             if ($settings->{'localonly'} eq '1') {
                   4314:                 $instlocalon = $instlocaloff;
                   4315:                 $instlocaloff = ' ';
                   4316:             }
                   4317:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   4318:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   4319:                     if ($type eq 'exact') {
                   4320:                         $exacton = ' checked="checked" ';
                   4321:                     } elsif ($type eq 'contains') {
                   4322:                         $containson = ' checked="checked" ';
                   4323:                     } elsif ($type eq 'begins') {
                   4324:                         $beginson = ' checked="checked" ';
                   4325:                     }
                   4326:                 }
                   4327:             } else {
                   4328:                 if ($settings->{'searchtypes'} eq 'exact') {
                   4329:                     $exacton = ' checked="checked" ';
                   4330:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   4331:                     $containson = ' checked="checked" ';
                   4332:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  4333:                     $exacton = ' checked="checked" ';
                   4334:                     $containson = ' checked="checked" ';
                   4335:                 }
                   4336:             }
1.277     raeburn  4337:         }
                   4338:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   4339:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4340: 
                   4341:         my $numinrow = 4;
                   4342:         my $cansrchrow = 0;
                   4343:         $datatable='<tr class="LC_odd_row">'.
                   4344:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   4345:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4346:                    '<input type="radio" name="dirsrch_available"'.
                   4347:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4348:                    '<label><input type="radio" name="dirsrch_available"'.
                   4349:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4350:                    '</tr><tr>'.
                   4351:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   4352:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4353:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   4354:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4355:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   4356:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4357:                    '</tr>';
                   4358:         $$rowtotal += 2;
                   4359:         if (ref($usertypes) eq 'HASH') {
                   4360:             if (keys(%{$usertypes}) > 0) {
                   4361:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  4362:                                              $numinrow,$othertitle,'cansearch',
                   4363:                                              $rowtotal);
1.277     raeburn  4364:                 $cansrchrow = 1;
1.25      raeburn  4365:             }
1.23      raeburn  4366:         }
1.277     raeburn  4367:         if ($cansrchrow) {
                   4368:             $$rowtotal ++;
                   4369:             $datatable .= '<tr>';
                   4370:         } else {
                   4371:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  4372:         }
1.277     raeburn  4373:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   4374:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   4375:         foreach my $title (@{$titleorder}) {
                   4376:             if (defined($searchtitles->{$title})) {
                   4377:                 my $check = ' ';
                   4378:                 if (ref($settings) eq 'HASH') {
                   4379:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   4380:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   4381:                             $check = ' checked="checked" ';
                   4382:                         }
1.39      raeburn  4383:                     }
1.25      raeburn  4384:                 }
1.277     raeburn  4385:                 $datatable .= '<td class="LC_left_item">'.
                   4386:                               '<span class="LC_nobreak"><label>'.
                   4387:                               '<input type="checkbox" name="searchby" '.
                   4388:                               'value="'.$title.'"'.$check.'/>'.
                   4389:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  4390:             }
                   4391:         }
1.277     raeburn  4392:         $datatable .= '</tr></table></td></tr>';
                   4393:         $$rowtotal ++;
                   4394:         if ($cansrchrow) {
                   4395:             $datatable .= '<tr class="LC_odd_row">';
                   4396:         } else {
                   4397:             $datatable .= '<tr>';
                   4398:         }
                   4399:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   4400:                       '<td class="LC_left_item" colspan="2">'.
                   4401:                       '<span class="LC_nobreak"><label>'.
                   4402:                       '<input type="checkbox" name="searchtypes" '.
                   4403:                       $exacton.' value="exact" />'.&mt('Exact match').
                   4404:                       '</label>&nbsp;'.
                   4405:                       '<label><input type="checkbox" name="searchtypes" '.
                   4406:                       $beginson.' value="begins" />'.&mt('Begins with').
                   4407:                       '</label>&nbsp;'.
                   4408:                       '<label><input type="checkbox" name="searchtypes" '.
                   4409:                       $containson.' value="contains" />'.&mt('Contains').
                   4410:                       '</label></span></td></tr>';
                   4411:         $$rowtotal ++;
1.26      raeburn  4412:     } else {
1.277     raeburn  4413:         my $domsrchon = ' checked="checked" ';
                   4414:         my $domsrchoff = ' ';
                   4415:         my $domlocalon = ' ';
                   4416:         my $domlocaloff = ' checked="checked" ';
                   4417:         if (ref($settings) eq 'HASH') {
                   4418:             if ($settings->{'lclocalonly'} eq '1') {
                   4419:                 $domlocalon = $domlocaloff;
                   4420:                 $domlocaloff = ' ';
                   4421:             }
                   4422:             if ($settings->{'lcavailable'} eq '0') {
                   4423:                 $domsrchoff = $domsrchon;
                   4424:                 $domsrchon = ' ';
                   4425:             }
                   4426:         }
                   4427:         $datatable='<tr class="LC_odd_row">'.
                   4428:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   4429:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4430:                       '<input type="radio" name="dirsrch_domavailable"'.
                   4431:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4432:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   4433:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4434:                       '</tr><tr>'.
                   4435:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   4436:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4437:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   4438:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4439:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   4440:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4441:                       '</tr>';
                   4442:         $$rowtotal += 2;
1.26      raeburn  4443:     }
1.25      raeburn  4444:     return $datatable;
                   4445: }
                   4446: 
1.28      raeburn  4447: sub print_contacts {
1.286     raeburn  4448:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  4449:     my $datatable;
                   4450:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  4451:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340     raeburn  4452:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286     raeburn  4453:     if ($position eq 'top') {
                   4454:         if (ref($settings) eq 'HASH') {
                   4455:             foreach my $item (@contacts) {
                   4456:                 if (exists($settings->{$item})) {
                   4457:                     $to{$item} = $settings->{$item};
                   4458:                 }
                   4459:             }
                   4460:         }
                   4461:     } elsif ($position eq 'middle') {
                   4462:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350     raeburn  4463:                      'updatesmail','idconflictsmail','hostipmail');
1.288     raeburn  4464:         foreach my $type (@mailings) {
                   4465:             $otheremails{$type} = '';
                   4466:         }
1.340     raeburn  4467:     } elsif ($position eq 'lower') {
                   4468:         if (ref($settings) eq 'HASH') {
                   4469:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   4470:                 %lonstatus = %{$settings->{'lonstatus'}};
                   4471:             }
                   4472:         }
1.286     raeburn  4473:     } else {
                   4474:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  4475:         foreach my $type (@mailings) {
                   4476:             $otheremails{$type} = '';
                   4477:         }
1.286     raeburn  4478:         $bccemails{'helpdeskmail'} = '';
                   4479:         $bccemails{'otherdomsmail'} = '';
                   4480:         $includestr{'helpdeskmail'} = '';
                   4481:         $includestr{'otherdomsmail'} = '';
                   4482:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   4483:     }
1.28      raeburn  4484:     if (ref($settings) eq 'HASH') {
1.340     raeburn  4485:         unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4486:             foreach my $type (@mailings) {
                   4487:                 if (exists($settings->{$type})) {
                   4488:                     if (ref($settings->{$type}) eq 'HASH') {
                   4489:                         foreach my $item (@contacts) {
                   4490:                             if ($settings->{$type}{$item}) {
                   4491:                                 $checked{$type}{$item} = ' checked="checked" ';
                   4492:                             }
                   4493:                         }
                   4494:                         $otheremails{$type} = $settings->{$type}{'others'};
                   4495:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4496:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   4497:                             if ($settings->{$type}{'include'} ne '') {
                   4498:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4499:                                 $includestr{$type} = &unescape($includestr{$type});
                   4500:                             }
                   4501:                         }
                   4502:                     }
                   4503:                 } elsif ($type eq 'lonstatusmail') {
                   4504:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   4505:                 }
1.28      raeburn  4506:             }
                   4507:         }
1.286     raeburn  4508:         if ($position eq 'bottom') {
                   4509:             foreach my $type (@mailings) {
                   4510:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   4511:                 if ($settings->{$type}{'include'} ne '') {
                   4512:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4513:                     $includestr{$type} = &unescape($includestr{$type});
                   4514:                 }
                   4515:             }
                   4516:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   4517:                 if (ref($fields) eq 'ARRAY') {
                   4518:                     foreach my $field (@{$fields}) {
                   4519:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  4520:                     }
1.286     raeburn  4521:                 }
                   4522:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   4523:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   4524:                 } else {
1.289     raeburn  4525:                     $maxsize = '1.0';
1.286     raeburn  4526:                 }
                   4527:             } else {
                   4528:                 if (ref($fields) eq 'ARRAY') {
                   4529:                     foreach my $field (@{$fields}) {
                   4530:                         $currfield{$field} = 'yes';
1.134     raeburn  4531:                     }
1.28      raeburn  4532:                 }
1.286     raeburn  4533:                 $maxsize = '1.0';
1.28      raeburn  4534:             }
                   4535:         }
                   4536:     } else {
1.286     raeburn  4537:         if ($position eq 'top') {
                   4538:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   4539:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   4540:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   4541:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  4542:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4543:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   4544:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   4545:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350     raeburn  4546:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4547:         } elsif ($position eq 'bottom') {
                   4548:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   4549:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   4550:             if (ref($fields) eq 'ARRAY') {
                   4551:                 foreach my $field (@{$fields}) {
                   4552:                     $currfield{$field} = 'yes';
                   4553:                 }
                   4554:             }
                   4555:             $maxsize = '1.0';
                   4556:         }
1.28      raeburn  4557:     }
                   4558:     my ($titles,$short_titles) = &contact_titles();
                   4559:     my $rownum = 0;
                   4560:     my $css_class;
1.286     raeburn  4561:     if ($position eq 'top') {
                   4562:         foreach my $item (@contacts) {
                   4563:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4564:             $datatable .= '<tr'.$css_class.'>'. 
                   4565:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   4566:                           '</span></td><td class="LC_right_item">'.
                   4567:                           '<input type="text" name="'.$item.'" value="'.
                   4568:                           $to{$item}.'" /></td></tr>';
                   4569:             $rownum ++;
                   4570:         }
1.315     raeburn  4571:     } elsif ($position eq 'bottom') {
                   4572:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4573:         $datatable .= '<tr'.$css_class.'>'.
                   4574:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   4575:                       &mt('(e-mail, subject, and description always shown)').
                   4576:                       '</td><td class="LC_left_item">';
                   4577:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   4578:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   4579:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   4580:             foreach my $field (@{$fields}) {
                   4581:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   4582:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   4583:                     $datatable .= ' '.&mt('(logged-in users)');
                   4584:                 }
                   4585:                 $datatable .='</td><td>';
                   4586:                 my $clickaction;
                   4587:                 if ($field eq 'screenshot') {
                   4588:                     $clickaction = ' onclick="screenshotSize(this);"';
                   4589:                 }
                   4590:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   4591:                     foreach my $option (@{$possoptions->{$field}}) {
                   4592:                         my $checked;
                   4593:                         if ($currfield{$field} eq $option) {
                   4594:                             $checked = ' checked="checked"';
                   4595:                         }
                   4596:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   4597:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   4598:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   4599:                                       '</label></span>'.('&nbsp;'x2);
                   4600:                     }
                   4601:                 }
                   4602:                 if ($field eq 'screenshot') {
                   4603:                     my $display;
                   4604:                     if ($currfield{$field} eq 'no') {
                   4605:                         $display = ' style="display:none"';
                   4606:                     }
1.334     raeburn  4607:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315     raeburn  4608:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   4609:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   4610:                 }
                   4611:                 $datatable .= '</td></tr>';
                   4612:             }
                   4613:             $datatable .= '</table>';
                   4614:         }
                   4615:         $datatable .= '</td></tr>'."\n";
                   4616:         $rownum ++;
                   4617:     }
1.340     raeburn  4618:     unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4619:         foreach my $type (@mailings) {
                   4620:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4621:             $datatable .= '<tr'.$css_class.'>'.
                   4622:                           '<td><span class="LC_nobreak">'.
                   4623:                           $titles->{$type}.': </span></td>'.
                   4624:                           '<td class="LC_left_item">';
                   4625:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4626:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   4627:             }
                   4628:             $datatable .= '<span class="LC_nobreak">';
                   4629:             foreach my $item (@contacts) {
                   4630:                 $datatable .= '<label>'.
                   4631:                               '<input type="checkbox" name="'.$type.'"'.
                   4632:                               $checked{$type}{$item}.
                   4633:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   4634:                               '</label>&nbsp;';
                   4635:             }
                   4636:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4637:                           '<input type="text" name="'.$type.'_others" '.
                   4638:                           'value="'.$otheremails{$type}.'"  />';
                   4639:             my %locchecked;
                   4640:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4641:                 foreach my $loc ('s','b') {
                   4642:                     if ($includeloc{$type} eq $loc) {
                   4643:                         $locchecked{$loc} = ' checked="checked"';
                   4644:                         last;
                   4645:                     }
                   4646:                 }
                   4647:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4648:                               '<input type="text" name="'.$type.'_bcc" '.
                   4649:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   4650:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4651:                               &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4652:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286     raeburn  4653:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4654:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4655:                               ('&nbsp;'x2).
                   4656:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4657:                               '</span></fieldset>';
                   4658:             }
                   4659:             $datatable .= '</td></tr>'."\n";
                   4660:             $rownum ++;
                   4661:         }
1.28      raeburn  4662:     }
1.286     raeburn  4663:     if ($position eq 'middle') {
                   4664:         my %choices;
1.340     raeburn  4665:         my $corelink = &core_link_msu();
                   4666:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286     raeburn  4667:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340     raeburn  4668:                                         $corelink);
                   4669:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   4670:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286     raeburn  4671:         my %defaultchecked = ('reporterrors'  => 'on',
1.340     raeburn  4672:                               'reportupdates' => 'on',
                   4673:                               'reportstatus'  => 'on');
1.286     raeburn  4674:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4675:                                                    \%choices,$rownum);
                   4676:         $datatable .= $reports;
1.340     raeburn  4677:     } elsif ($position eq 'lower') {
1.378     raeburn  4678:         my (%current,%excluded,%weights);
1.340     raeburn  4679:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   4680:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378     raeburn  4681:             $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340     raeburn  4682:         } else {
1.378     raeburn  4683:             $current{'errorthreshold'} = $defaults->{'threshold'};
1.340     raeburn  4684:         }
                   4685:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378     raeburn  4686:             $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340     raeburn  4687:         } else {
1.378     raeburn  4688:             $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340     raeburn  4689:         }
                   4690:         if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341     raeburn  4691:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4692:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   4693:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   4694:                 } else {
                   4695:                     $weights{$type} = $defaults->{$type};
                   4696:                 }
                   4697:             }
                   4698:         } else {
1.341     raeburn  4699:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4700:                 $weights{$type} = $defaults->{$type};
                   4701:             }
                   4702:         }
                   4703:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   4704:             if (@{$lonstatus{'excluded'}} > 0) {
                   4705:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   4706:             }
                   4707:         }
1.378     raeburn  4708:         foreach my $item ('errorthreshold','errorsysmail') { 
                   4709:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4710:             $datatable .= '<tr'.$css_class.'>'.
                   4711:                           '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4712:                           $titles->{$item}.
                   4713:                           '</span></td><td class="LC_left_item">'.
                   4714:                           '<input type="text" name="'.$item.'" value="'.
                   4715:                           $current{$item}.'" size="5" /></td></tr>';
                   4716:             $rownum ++;
                   4717:         }
1.340     raeburn  4718:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4719:         $datatable .= '<tr'.$css_class.'>'.
                   4720:                       '<td class="LC_left_item">'.
                   4721:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   4722:                       '</span></td><td class="LC_left_item"><table><tr>';
1.341     raeburn  4723:         foreach my $type ('E','W','N','U') {
1.340     raeburn  4724:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   4725:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   4726:                           $weights{$type}.'" size="5" /></td>';
                   4727:         }
                   4728:         $datatable .= '</tr></table></tr>';
                   4729:         $rownum ++;
                   4730:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4731:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   4732:                       $titles->{'errorexcluded'}.'</td>'.
                   4733:                       '<td class="LC_left_item"><table>';
                   4734:         my $numinrow = 4;
                   4735:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   4736:         for (my $i=0; $i<@ids; $i++) {
                   4737:             my $rem = $i%($numinrow);
                   4738:             if ($rem == 0) {
                   4739:                 if ($i > 0) {
                   4740:                     $datatable .= '</tr>';
                   4741:                 }
                   4742:                 $datatable .= '<tr>';
                   4743:             }
                   4744:             my $check;
                   4745:             if ($excluded{$ids[$i]}) {
                   4746:                 $check = ' checked="checked" ';
                   4747:             }
                   4748:             $datatable .= '<td class="LC_left_item">'.
                   4749:                           '<span class="LC_nobreak"><label>'.
                   4750:                           '<input type="checkbox" name="errorexcluded" '.
                   4751:                           'value="'.$ids[$i].'"'.$check.' />'.
                   4752:                           $ids[$i].'</label></span></td>';
                   4753:         }
                   4754:         my $colsleft = $numinrow - @ids%($numinrow);
                   4755:         if ($colsleft > 1 ) {
                   4756:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4757:                           '&nbsp;</td>';
                   4758:         } elsif ($colsleft == 1) {
                   4759:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4760:         }
                   4761:         $datatable .= '</tr></table></td></tr>';
                   4762:         $rownum ++;
1.286     raeburn  4763:     } elsif ($position eq 'bottom') {
1.315     raeburn  4764:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4765:         my (@posstypes,%usertypeshash);
                   4766:         if (ref($types) eq 'ARRAY') {
                   4767:             @posstypes = @{$types};
                   4768:         }
                   4769:         if (@posstypes) {
                   4770:             if (ref($usertypes) eq 'HASH') {
                   4771:                 %usertypeshash = %{$usertypes};
                   4772:             }
                   4773:             my @overridden;
                   4774:             my $numinrow = 4;
                   4775:             if (ref($settings) eq 'HASH') {
                   4776:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   4777:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   4778:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   4779:                             push(@overridden,$key);
                   4780:                             foreach my $item (@contacts) {
                   4781:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   4782:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   4783:                                 }
                   4784:                             }
                   4785:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   4786:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   4787:                             $includeloc{'override_'.$key} = '';
                   4788:                             $includestr{'override_'.$key} = '';
                   4789:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   4790:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
                   4791:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   4792:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   4793:                             }
1.286     raeburn  4794:                         }
                   4795:                     }
                   4796:                 }
1.315     raeburn  4797:             }
                   4798:             my $customclass = 'LC_helpdesk_override';
                   4799:             my $optionsprefix = 'LC_options_helpdesk_';
                   4800: 
                   4801:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   4802:  
                   4803:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   4804:                                          $numinrow,$othertitle,'overrides',
                   4805:                                          \$rownum,$onclicktypes,$customclass);
                   4806:             $rownum ++;
                   4807:             $usertypeshash{'default'} = $othertitle;
                   4808:             foreach my $status (@posstypes) {
                   4809:                 my $css_class;
                   4810:                 if ($rownum%2) {
                   4811:                     $css_class = 'LC_odd_row ';
                   4812:                 }
                   4813:                 $css_class .= $customclass;
                   4814:                 my $rowid = $optionsprefix.$status;
                   4815:                 my $hidden = 1;
                   4816:                 my $currstyle = 'display:none';
                   4817:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   4818:                     $currstyle = 'display:table-row';
                   4819:                     $hidden = 0;
                   4820:                 }
                   4821:                 my $key = 'override_'.$status;
                   4822:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   4823:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   4824:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   4825:                                                   \@contacts,$short_titles);
                   4826:                 unless ($hidden) {
                   4827:                     $rownum ++;
1.286     raeburn  4828:                 }
                   4829:             }
1.134     raeburn  4830:         }
1.28      raeburn  4831:     }
1.30      raeburn  4832:     $$rowtotal += $rownum;
1.28      raeburn  4833:     return $datatable;
                   4834: }
                   4835: 
1.340     raeburn  4836: sub core_link_msu {
                   4837:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   4838:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   4839: }
                   4840: 
1.315     raeburn  4841: sub overridden_helpdesk {
                   4842:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   4843:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   4844:     my $class = 'LC_left_item';
                   4845:     if ($css_class) {
                   4846:         $css_class = ' class="'.$css_class.'"';
                   4847:     }
                   4848:     if ($rowid) {
                   4849:         $rowid = ' id="'.$rowid.'"';
                   4850:     }
                   4851:     if ($rowstyle) {
                   4852:         $rowstyle = ' style="'.$rowstyle.'"';
                   4853:     }
                   4854:     my ($output,$description);
                   4855:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   4856:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   4857:               "<td>$description</td>\n".
                   4858:               '<td class="'.$class.'" colspan="2">'.
                   4859:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   4860:               '<span class="LC_nobreak">';
                   4861:     if (ref($contacts) eq 'ARRAY') {
                   4862:         foreach my $item (@{$contacts}) {
                   4863:             my $check;
                   4864:             if (ref($checked) eq 'HASH') {
                   4865:                $check = $checked->{$item};
                   4866:             }
                   4867:             my $title;
                   4868:             if (ref($short_titles) eq 'HASH') {
                   4869:                 $title = $short_titles->{$item}; 
                   4870:             }
                   4871:             $output .= '<label>'.
                   4872:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   4873:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   4874:         }
                   4875:     }
                   4876:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4877:                '<input type="text" name="override_'.$type.'_others" '.
                   4878:                'value="'.$otheremails.'"  />';
                   4879:     my %locchecked;
                   4880:     foreach my $loc ('s','b') {
                   4881:         if ($includeloc eq $loc) {
                   4882:             $locchecked{$loc} = ' checked="checked"';
                   4883:             last;
                   4884:         }
                   4885:     }
                   4886:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4887:                '<input type="text" name="override_'.$type.'_bcc" '.
                   4888:                'value="'.$bccemails.'"  /></fieldset>'.
                   4889:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4890:                &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4891:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315     raeburn  4892:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4893:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4894:                ('&nbsp;'x2).
                   4895:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4896:                '</span></fieldset>'.
                   4897:                '</td></tr>'."\n";
                   4898:     return $output;
                   4899: }
                   4900: 
1.286     raeburn  4901: sub contacts_javascript {
                   4902:     return <<"ENDSCRIPT";
                   4903: 
                   4904: <script type="text/javascript">
                   4905: // <![CDATA[
                   4906: 
                   4907: function screenshotSize(field) {
                   4908:     if (document.getElementById('help_screenshotsize')) {
                   4909:         if (field.value == 'no') {
1.289     raeburn  4910:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  4911:         } else {
                   4912:             document.getElementById('help_screenshotsize').style.display="";
                   4913:         }
                   4914:     }
                   4915:     return;
                   4916: }
                   4917: 
1.315     raeburn  4918: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   4919:     if (form.elements[checkbox].length != undefined) {
                   4920:         var count = 0;
                   4921:         if (docount) {
                   4922:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   4923:                 if (form.elements[checkbox][i].checked) {
                   4924:                     count ++;
                   4925:                 }
                   4926:             }
                   4927:         }
                   4928:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   4929:             var type = form.elements[checkbox][i].value;
                   4930:             if (document.getElementById(prefix+type)) {
                   4931:                 if (form.elements[checkbox][i].checked) {
                   4932:                     document.getElementById(prefix+type).style.display = 'table-row';
                   4933:                     if (count % 2 == 1) {
                   4934:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   4935:                     } else {
                   4936:                         document.getElementById(prefix+type).className = target;
                   4937:                     }
                   4938:                     count ++;
                   4939:                 } else {
                   4940:                     document.getElementById(prefix+type).style.display = 'none';
                   4941:                 }
                   4942:             }
                   4943:         }
                   4944:     }
                   4945:     return;
                   4946: }
                   4947: 
                   4948: 
1.286     raeburn  4949: // ]]>
                   4950: </script>
                   4951: 
                   4952: ENDSCRIPT
                   4953: }
                   4954: 
1.118     jms      4955: sub print_helpsettings {
1.282     raeburn  4956:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4957:     my $confname = $dom.'-domainconfig';
1.285     raeburn  4958:     my $formname = 'display';
1.168     raeburn  4959:     my ($datatable,$itemcount);
1.282     raeburn  4960:     if ($position eq 'top') {
                   4961:         $itemcount = 1;
                   4962:         my (%choices,%defaultchecked,@toggles);
                   4963:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   4964:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   4965:                                      &mt('LON-CAPA bug tracker'),600,500));
                   4966:         %defaultchecked = ('submitbugs' => 'on');
                   4967:         @toggles = ('submitbugs');
                   4968:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4969:                                                      \%choices,$itemcount);
                   4970:         $$rowtotal ++;
                   4971:     } else {
                   4972:         my $css_class;
                   4973:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  4974:         my (%customroles,%ordered,%current);
1.301     raeburn  4975:         if (ref($settings) eq 'HASH') {
                   4976:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   4977:                 %current = %{$settings->{'adhoc'}};
                   4978:             }
1.285     raeburn  4979:         }
                   4980:         my $count = 0;
                   4981:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  4982:             if ($key=~/^rolesdef\_(\w+)$/) {
                   4983:                 my $rolename = $1;
1.285     raeburn  4984:                 my (%privs,$order);
1.282     raeburn  4985:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   4986:                 $customroles{$rolename} = \%privs;
1.285     raeburn  4987:                 if (ref($current{$rolename}) eq 'HASH') {
                   4988:                     $order = $current{$rolename}{'order'};
                   4989:                 }
                   4990:                 if ($order eq '') {
                   4991:                     $order = $count;
                   4992:                 }
                   4993:                 $ordered{$order} = $rolename;
                   4994:                 $count++;
                   4995:             }
                   4996:         }
                   4997:         my $maxnum = scalar(keys(%ordered));
                   4998:         my @roles_by_num = ();
                   4999:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   5000:             push(@roles_by_num,$item);
                   5001:         }
                   5002:         my $context = 'domprefs';
                   5003:         my $crstype = 'Course';
                   5004:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  5005:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  5006:         my ($numstatustypes,@jsarray);
                   5007:         if (ref($types) eq 'ARRAY') {
                   5008:             if (@{$types} > 0) {
                   5009:                 $numstatustypes = scalar(@{$types});
                   5010:                 push(@accesstypes,'status');
                   5011:                 @jsarray = ('bystatus');
1.282     raeburn  5012:             }
                   5013:         }
1.290     raeburn  5014:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  5015:         if (keys(%domhelpdesk)) {
                   5016:             push(@accesstypes,('inc','exc'));
                   5017:             push(@jsarray,('notinc','notexc'));
                   5018:         }
                   5019:         my $hiddenstr = join("','",@jsarray);
1.282     raeburn  5020:         my $context = 'domprefs';
                   5021:         my $crstype = 'Course';
1.285     raeburn  5022:         my $prefix = 'helproles_';
                   5023:         my $add_class = 'LC_hidden';
                   5024:         foreach my $num (@roles_by_num) {
                   5025:             my $role = $ordered{$num};
                   5026:             my ($desc,$access,@statuses);
                   5027:             if (ref($current{$role}) eq 'HASH') {
                   5028:                 $desc = $current{$role}{'desc'};
                   5029:                 $access = $current{$role}{'access'};
                   5030:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   5031:                     @statuses = @{$current{$role}{'insttypes'}};
                   5032:                 }
                   5033:             }
                   5034:             if ($desc eq '') {
                   5035:                 $desc = $role;
                   5036:             }
                   5037:             my $identifier = 'custhelp'.$num;
1.282     raeburn  5038:             my %full=();
                   5039:             my %levels= (
                   5040:                          course => {},
                   5041:                          domain => {},
                   5042:                          system => {},
                   5043:                         );
                   5044:             my %levelscurrent=(
                   5045:                                course => {},
                   5046:                                domain => {},
                   5047:                                system => {},
                   5048:                               );
                   5049:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   5050:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   5051:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  5052:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  5053:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  5054:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   5055:             for (my $k=0; $k<=$maxnum; $k++) {
                   5056:                 my $vpos = $k+1;
                   5057:                 my $selstr;
                   5058:                 if ($k == $num) {
                   5059:                     $selstr = ' selected="selected" ';
                   5060:                 }
                   5061:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5062:             }
                   5063:             $datatable .= '</select>'.('&nbsp;'x2).
                   5064:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   5065:                           '</td>'.
                   5066:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   5067:                           &mt('Name shown to users:').
                   5068:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   5069:                           '</fieldset>'.
                   5070:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   5071:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   5072:                           '<fieldset>'.
                   5073:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  5074:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  5075:                                                                    \%levelscurrent,$identifier,
                   5076:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   5077:                           '</fieldset></td>';
1.282     raeburn  5078:             $itemcount ++;
                   5079:         }
                   5080:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5081:         my $newcust = 'custhelp'.$count;
                   5082:         my (%privs,%levelscurrent);
                   5083:         my %full=();
                   5084:         my %levels= (
                   5085:                      course => {},
                   5086:                      domain => {},
                   5087:                      system => {},
                   5088:                     );
                   5089:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   5090:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  5091:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  5092:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  5093:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   5094:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   5095:         for (my $k=0; $k<$maxnum+1; $k++) {
                   5096:             my $vpos = $k+1;
                   5097:             my $selstr;
                   5098:             if ($k == $maxnum) {
                   5099:                 $selstr = ' selected="selected" ';
                   5100:             }
                   5101:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5102:         }
                   5103:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  5104:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   5105:                       '</label></span></td>'.
1.285     raeburn  5106:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   5107:                       '<span class="LC_nobreak">'.
                   5108:                       &mt('Internal name:').
                   5109:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   5110:                       '</span>'.('&nbsp;'x4).
                   5111:                       '<span class="LC_nobreak">'.
                   5112:                       &mt('Name shown to users:').
                   5113:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   5114:                       '</span></fieldset>'.
                   5115:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   5116:                                              $usertypes,$types,\%domhelpdesk).
                   5117:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  5118:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   5119:                                                                 \@templateroles,$newcust).
                   5120:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   5121:                                                                \%levelscurrent,$newcust).
1.334     raeburn  5122:                       '</fieldset>'.
                   5123:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   5124:                       '</td></tr>';
1.282     raeburn  5125:         $count ++;
                   5126:         $$rowtotal += $count;
                   5127:     }
1.166     raeburn  5128:     return $datatable;
1.121     raeburn  5129: }
                   5130: 
1.285     raeburn  5131: sub adhocbutton {
                   5132:     my ($prefix,$num,$field,$visibility) = @_;
                   5133:     my %lt = &Apache::lonlocal::texthash(
                   5134:                                           show => 'Show details',
                   5135:                                           hide => 'Hide details',
                   5136:                                         );
                   5137:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   5138:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   5139:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   5140:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   5141: }
                   5142: 
                   5143: sub helpsettings_javascript {
                   5144:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   5145:     return unless(ref($roles_by_num) eq 'ARRAY');
                   5146:     my %html_js_lt = &Apache::lonlocal::texthash(
                   5147:                                           show => 'Show details',
                   5148:                                           hide => 'Hide details',
                   5149:                                         );
                   5150:     &html_escape(\%html_js_lt);
                   5151:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   5152:     return <<"ENDSCRIPT";
                   5153: <script type="text/javascript">
                   5154: // <![CDATA[
                   5155: 
                   5156: function reorderHelpRoles(form,item) {
                   5157:     var changedVal;
                   5158: $jstext
                   5159:     var newpos = 'helproles_${total}_pos';
                   5160:     var maxh = 1 + $total;
                   5161:     var current = new Array();
                   5162:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   5163:     if (item == newpos) {
                   5164:         changedVal = newitemVal;
                   5165:     } else {
                   5166:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   5167:         current[newitemVal] = newpos;
                   5168:     }
                   5169:     for (var i=0; i<helproles.length; i++) {
                   5170:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   5171:         if (elementName != item) {
                   5172:             if (form.elements[elementName]) {
                   5173:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   5174:                 current[currVal] = elementName;
                   5175:             }
                   5176:         }
                   5177:     }
                   5178:     var oldVal;
                   5179:     for (var j=0; j<maxh; j++) {
                   5180:         if (current[j] == undefined) {
                   5181:             oldVal = j;
                   5182:         }
                   5183:     }
                   5184:     if (oldVal < changedVal) {
                   5185:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   5186:            var elementName = current[k];
                   5187:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   5188:         }
                   5189:     } else {
                   5190:         for (var k=changedVal; k<oldVal; k++) {
                   5191:             var elementName = current[k];
                   5192:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   5193:         }
                   5194:     }
                   5195:     return;
                   5196: }
                   5197: 
                   5198: function helpdeskAccess(num) {
                   5199:     var curraccess = null;
                   5200:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   5201:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   5202:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   5203:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   5204:             }
                   5205:         }
                   5206:     }
                   5207:     var shown = Array();
                   5208:     var hidden = Array();
                   5209:     if (curraccess == 'none') {
                   5210:         hidden = Array('$hiddenstr');
                   5211:     } else {
                   5212:         if (curraccess == 'status') {
                   5213:             shown = Array('bystatus');
                   5214:             hidden = Array('notinc','notexc');
                   5215:         } else {
                   5216:             if (curraccess == 'exc') {
                   5217:                 shown = Array('notexc');
                   5218:                 hidden = Array('notinc','bystatus');
                   5219:             }
                   5220:             if (curraccess == 'inc') {
                   5221:                 shown = Array('notinc');
                   5222:                 hidden = Array('notexc','bystatus');
                   5223:             }
1.293     raeburn  5224:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  5225:                 hidden = Array('notinc','notexc','bystatus');
                   5226:             }
                   5227:         }
                   5228:     }
                   5229:     if (hidden.length > 0) {
                   5230:         for (var i=0; i<hidden.length; i++) {
                   5231:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   5232:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   5233:             }
                   5234:         }
                   5235:     }
                   5236:     if (shown.length > 0) {
                   5237:         for (var i=0; i<shown.length; i++) {
                   5238:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   5239:                 if (shown[i] == 'privs') {
                   5240:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   5241:                 } else {
                   5242:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   5243:                 }
                   5244:             }
                   5245:         }
                   5246:     }
                   5247:     return;
                   5248: }
                   5249: 
                   5250: function toggleHelpdeskItem(num,field) {
                   5251:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   5252:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  5253:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  5254:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   5255:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5256:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   5257:             }
                   5258:         } else {
                   5259:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   5260:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5261:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   5262:             }
                   5263:         }
                   5264:     }
                   5265:     return;
                   5266: }
                   5267: 
                   5268: // ]]>
                   5269: </script>
                   5270: 
                   5271: ENDSCRIPT
                   5272: }
                   5273: 
                   5274: sub helpdeskroles_access {
                   5275:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   5276:         $usertypes,$types,$domhelpdesk) = @_;
                   5277:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   5278:     my %lt = &Apache::lonlocal::texthash(
                   5279:                     'rou'    => 'Role usage',
                   5280:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  5281:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   5282:                     'dh'     => 'All with domain helpdesk role',
                   5283:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  5284:                     'none'   => 'None',
                   5285:                     'status' => 'Determined based on institutional status',
                   5286:                     'inc'    => 'Include all, but exclude specific personnel',
                   5287:                     'exc'    => 'Exclude all, but include specific personnel',
                   5288:                   );
                   5289:     my %usecheck = (
                   5290:                      all => ' checked="checked"',
                   5291:                    );
                   5292:     my %displaydiv = (
                   5293:                       status => 'none',
                   5294:                       inc    => 'none',
                   5295:                       exc    => 'none',
                   5296:                       priv   => 'block',
                   5297:                      );
                   5298:     my $output;
                   5299:     if (ref($current) eq 'HASH') {
                   5300:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   5301:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   5302:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   5303:                 delete($usecheck{'all'});
                   5304:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   5305:                     my $access = $1;
                   5306:                     $displaydiv{$access} = 'inline';
                   5307:                 } elsif ($current->{access} eq 'none') {
                   5308:                     $displaydiv{'priv'} = 'none';
                   5309:                 }
                   5310:             }
                   5311:         }
                   5312:     }
                   5313:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   5314:               '<p>'.$lt{'whi'}.'</p>';
                   5315:     foreach my $access (@{$accesstypes}) {
                   5316:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   5317:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   5318:                    $lt{$access}.'</label>';
                   5319:         if ($access eq 'status') {
                   5320:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   5321:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   5322:                                                                  $othertitle,$usertypes,$types).
                   5323:                        '</div>';
                   5324:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   5325:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   5326:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5327:                        '</div>';
                   5328:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   5329:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   5330:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5331:                        '</div>';
                   5332:         }
                   5333:         $output .= '</p>';
                   5334:     }
                   5335:     $output .= '</fieldset>';
                   5336:     return $output;
                   5337: }
                   5338: 
1.121     raeburn  5339: sub radiobutton_prefs {
1.192     raeburn  5340:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385     raeburn  5341:         $additional,$align,$firstval) = @_;
1.121     raeburn  5342:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   5343:                    (ref($choices) eq 'HASH'));
                   5344: 
1.170     raeburn  5345:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  5346: 
                   5347:     foreach my $item (@{$toggles}) {
                   5348:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      5349:             $checkedon{$item} = ' checked="checked" ';
                   5350:             $checkedoff{$item} = ' ';
1.121     raeburn  5351:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      5352:             $checkedoff{$item} = ' checked="checked" ';
                   5353:             $checkedon{$item} = ' ';
                   5354:         }
                   5355:     }
                   5356:     if (ref($settings) eq 'HASH') {
1.121     raeburn  5357:         foreach my $item (@{$toggles}) {
1.118     jms      5358:             if ($settings->{$item} eq '1') {
                   5359:                 $checkedon{$item} =  ' checked="checked" ';
                   5360:                 $checkedoff{$item} = ' ';
                   5361:             } elsif ($settings->{$item} eq '0') {
                   5362:                 $checkedoff{$item} =  ' checked="checked" ';
                   5363:                 $checkedon{$item} = ' ';
                   5364:             }
                   5365:         }
1.121     raeburn  5366:     }
1.192     raeburn  5367:     if ($onclick) {
                   5368:         $onclick = ' onclick="'.$onclick.'"';
                   5369:     }
1.121     raeburn  5370:     foreach my $item (@{$toggles}) {
1.118     jms      5371:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  5372:         $datatable .=
1.306     raeburn  5373:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  5374:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  5375:             '</span></td>';
                   5376:         if ($align eq 'left') {
                   5377:             $datatable .= '<td class="LC_left_item">';
                   5378:         } else {
                   5379:             $datatable .= '<td class="LC_right_item">';
                   5380:         }
1.385     raeburn  5381:         $datatable .= '<span class="LC_nobreak">';
                   5382:         if ($firstval eq 'no') {
                   5383:             $datatable .=
                   5384:                 '<label><input type="radio" name="'.
                   5385:                 $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
                   5386:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5387:                 $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
                   5388:         } else {
                   5389:             $datatable .=
                   5390:                 '<label><input type="radio" name="'.
                   5391:                 $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
                   5392:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5393:                 $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
                   5394:         }
                   5395:         $datatable .= '</span>'.$additional.'</td></tr>';
1.118     jms      5396:         $itemcount ++;
1.121     raeburn  5397:     }
                   5398:     return ($datatable,$itemcount);
                   5399: }
                   5400: 
1.267     raeburn  5401: sub print_ltitools {
                   5402:     my ($dom,$settings,$rowtotal) = @_;
                   5403:     my $rownum = 0;
                   5404:     my $css_class;
                   5405:     my $itemcount = 1;
                   5406:     my $maxnum = 0;
                   5407:     my %ordered;
                   5408:     if (ref($settings) eq 'HASH') {
                   5409:         foreach my $item (keys(%{$settings})) {
                   5410:             if (ref($settings->{$item}) eq 'HASH') {
                   5411:                 my $num = $settings->{$item}{'order'};
                   5412:                 $ordered{$num} = $item;
                   5413:             }
                   5414:         }
                   5415:     }
                   5416:     my $confname = $dom.'-domainconfig';
                   5417:     my $switchserver = &check_switchserver($dom,$confname);
                   5418:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  5419:     my $datatable;
1.267     raeburn  5420:     my %lt = &ltitools_names();
                   5421:     my @courseroles = ('cc','in','ta','ep','st');
                   5422:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324     raeburn  5423:     my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267     raeburn  5424:     if (keys(%ordered)) {
                   5425:         my @items = sort { $a <=> $b } keys(%ordered);
                   5426:         for (my $i=0; $i<@items; $i++) {
                   5427:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5428:             my $item = $ordered{$items[$i]};
1.323     raeburn  5429:             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267     raeburn  5430:             if (ref($settings->{$item}) eq 'HASH') {
                   5431:                 $title = $settings->{$item}->{'title'};
                   5432:                 $url = $settings->{$item}->{'url'};
                   5433:                 $key = $settings->{$item}->{'key'};
                   5434:                 $secret = $settings->{$item}->{'secret'};
1.322     raeburn  5435:                 $lifetime = $settings->{$item}->{'lifetime'};
1.267     raeburn  5436:                 my $image = $settings->{$item}->{'image'};
                   5437:                 if ($image ne '') {
                   5438:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   5439:                 }
1.323     raeburn  5440:                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   5441:                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   5442:                 } else {
                   5443:                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   5444:                 }
1.267     raeburn  5445:             }
1.319     raeburn  5446:             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267     raeburn  5447:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5448:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   5449:             for (my $k=0; $k<=$maxnum; $k++) {
                   5450:                 my $vpos = $k+1;
                   5451:                 my $selstr;
                   5452:                 if ($k == $i) {
                   5453:                     $selstr = ' selected="selected" ';
                   5454:                 }
                   5455:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5456:             }
                   5457:             $datatable .= '</select>'.('&nbsp;'x2).
                   5458:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   5459:                 &mt('Delete?').'</label></span></td>'.
                   5460:                 '<td colspan="2">'.
                   5461:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5462:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267     raeburn  5463:                 ('&nbsp;'x2).
                   5464:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   5465:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   5466:                 ('&nbsp;'x2).
                   5467:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   5468:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5469:                 ('&nbsp;'x2).
                   5470:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   5471:                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   5472:                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267     raeburn  5473:                 '<br /><br />'.
1.323     raeburn  5474:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267     raeburn  5475:                 ' value="'.$url.'" /></span>'.
                   5476:                 ('&nbsp;'x2).
1.319     raeburn  5477:                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267     raeburn  5478:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   5479:                 ('&nbsp;'x2).
1.322     raeburn  5480:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   5481:                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   5482:                 ('&nbsp;'x2).
1.267     raeburn  5483:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   5484:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   5485:                 '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
                   5486:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   5487:                 '</fieldset>'.
                   5488:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5489:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   5490:             my %currdisp;
                   5491:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   5492:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   5493:                     $currdisp{'window'} = ' checked="checked"';
1.298     raeburn  5494:                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   5495:                     $currdisp{'tab'} = ' checked="checked"';
1.267     raeburn  5496:                 } else {
                   5497:                     $currdisp{'iframe'} = ' checked="checked"';
                   5498:                 }
                   5499:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   5500:                     $currdisp{'width'} = $1;
                   5501:                 }
                   5502:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   5503:                      $currdisp{'height'} = $1;
                   5504:                 }
1.296     raeburn  5505:                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   5506:                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267     raeburn  5507:             } else {
                   5508:                 $currdisp{'iframe'} = ' checked="checked"';
                   5509:             }
1.298     raeburn  5510:             foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5511:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   5512:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5513:             }
                   5514:             $datatable .= ('&nbsp;'x4);
                   5515:             foreach my $dimen ('width','height') {
                   5516:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5517:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   5518:                               ('&nbsp;'x2);
                   5519:             }
1.334     raeburn  5520:             $datatable .= '</span><br />'.
1.296     raeburn  5521:                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5522:                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296     raeburn  5523:                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   5524:                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   5525:                           '</textarea></div><div style=""></div><br />';
1.319     raeburn  5526:             my %units = (
                   5527:                           'passback' => 'days',
                   5528:                           'roster'   => 'seconds',
                   5529:                         );
1.267     raeburn  5530:             foreach my $extra ('passback','roster') {
1.319     raeburn  5531:                 my $validsty = 'none';
                   5532:                 my $currvalid;
1.267     raeburn  5533:                 my $checkedon = '';
                   5534:                 my $checkedoff = ' checked="checked"';
                   5535:                 if ($settings->{$item}->{$extra}) {
                   5536:                     $checkedon = $checkedoff;
                   5537:                     $checkedoff = '';
1.319     raeburn  5538:                     $validsty = 'inline-block';
                   5539:                     if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
                   5540:                         $currvalid = $settings->{$item}->{$extra.'valid'};
                   5541:                     }
                   5542:                 }
                   5543:                 my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
                   5544:                 $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5545:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
                   5546:                               &mt('No').'</label>'.('&nbsp;'x2).
                   5547:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
                   5548:                               &mt('Yes').'</label></span></div>'.
                   5549:                               '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
                   5550:                               '<span class="LC_nobreak">'.
                   5551:                               &mt("at least [_1] $units{$extra} after launch",
                   5552:                                   '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
                   5553:                               '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5554:             }
1.319     raeburn  5555:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
1.267     raeburn  5556:             if ($imgsrc) {
                   5557:                 $datatable .= $imgsrc.
                   5558:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   5559:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   5560:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   5561:             } else {
                   5562:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5563:             }
                   5564:             if ($switchserver) {
                   5565:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5566:             } else {
                   5567:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   5568:             }
                   5569:             $datatable .= '</span></fieldset>';
1.324     raeburn  5570:             my (%checkedfields,%rolemaps,$userincdom);
1.267     raeburn  5571:             if (ref($settings->{$item}) eq 'HASH') {
                   5572:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   5573:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   5574:                 }
1.324     raeburn  5575:                 $userincdom = $settings->{$item}->{'incdom'};
1.267     raeburn  5576:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   5577:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   5578:                     $checkedfields{'roles'} = 1;
                   5579:                 }
                   5580:             }
                   5581:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5582:                           '<span class="LC_nobreak">';
1.324     raeburn  5583:             my $userfieldstyle = 'display:none;';
                   5584:             my $seluserdom = '';
                   5585:             my $unseluserdom = ' selected="selected"';
1.267     raeburn  5586:             foreach my $field (@fields) {
1.324     raeburn  5587:                 my ($checked,$onclick,$id,$spacer);
1.267     raeburn  5588:                 if ($checkedfields{$field}) {
                   5589:                     $checked = ' checked="checked"';
                   5590:                 }
1.324     raeburn  5591:                 if ($field eq 'user') {
                   5592:                     $id = ' id="ltitools_user_field_'.$i.'"';
                   5593:                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   5594:                     if ($checked) {
                   5595:                         $userfieldstyle = 'display:inline-block';
                   5596:                         if ($userincdom) {
                   5597:                             $seluserdom = $unseluserdom;
                   5598:                             $unseluserdom = '';
                   5599:                         }
                   5600:                     }
                   5601:                 } else {
                   5602:                     $spacer = ('&nbsp;' x2);
                   5603:                 }
1.267     raeburn  5604:                 $datatable .= '<label>'.
1.324     raeburn  5605:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   5606:                               $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5607:             }
1.324     raeburn  5608:             $datatable .= '</span>';
                   5609:             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   5610:                           '<span class="LC_nobreak"> : '.
                   5611:                           '<select name="ltitools_userincdom_'.$i.'">'.
                   5612:                           '<option value="">'.&mt('Select').'</option>'.
                   5613:                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   5614:                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   5615:                           '</select></span></div>';
                   5616:             $datatable .= '</fieldset>'.
1.267     raeburn  5617:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   5618:             foreach my $role (@courseroles) {
                   5619:                 my ($selected,$selectnone);
                   5620:                 if (!$rolemaps{$role}) {
                   5621:                     $selectnone = ' selected="selected"';
                   5622:                 }
1.306     raeburn  5623:                 $datatable .= '<td style="text-align: center">'. 
1.267     raeburn  5624:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5625:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   5626:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5627:                 foreach my $ltirole (@ltiroles) {
                   5628:                     unless ($selectnone) {
                   5629:                         if ($rolemaps{$role} eq $ltirole) {
                   5630:                             $selected = ' selected="selected"';
                   5631:                         } else {
                   5632:                             $selected = '';
                   5633:                         }
                   5634:                     }
                   5635:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   5636:                 }
                   5637:                 $datatable .= '</select></td>';
                   5638:             }
1.273     raeburn  5639:             $datatable .= '</tr></table></fieldset>';
                   5640:             my %courseconfig;
                   5641:             if (ref($settings->{$item}) eq 'HASH') {
                   5642:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   5643:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   5644:                 }
                   5645:             }
                   5646:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5647:             foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  5648:                 my $checked;
                   5649:                 if ($courseconfig{$item}) {
                   5650:                     $checked = ' checked="checked"';
                   5651:                 }
                   5652:                 $datatable .= '<label>'.
                   5653:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372     raeburn  5654:                        $lt{'crs'.$item}.'</label>&nbsp; '."\n";
1.273     raeburn  5655:             }
                   5656:             $datatable .= '</span></fieldset>'.
1.267     raeburn  5657:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5658:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   5659:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   5660:                 my %custom = %{$settings->{$item}->{'custom'}};
                   5661:                 if (keys(%custom) > 0) {
                   5662:                     foreach my $key (sort(keys(%custom))) {
                   5663:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5664:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   5665:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   5666:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   5667:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   5668:                     }
                   5669:                 }
                   5670:             }
                   5671:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5672:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   5673:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   5674:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   5675:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   5676:             $itemcount ++;
                   5677:         }
                   5678:     }
                   5679:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319     raeburn  5680:     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267     raeburn  5681:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   5682:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   5683:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   5684:     for (my $k=0; $k<$maxnum+1; $k++) {
                   5685:         my $vpos = $k+1;
                   5686:         my $selstr;
                   5687:         if ($k == $maxnum) {
                   5688:             $selstr = ' selected="selected" ';
                   5689:         }
                   5690:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5691:     }
                   5692:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  5693:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267     raeburn  5694:                   '<td colspan="2">'.
                   5695:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5696:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267     raeburn  5697:                   ('&nbsp;'x2).
                   5698:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   5699:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   5700:                   ('&nbsp;'x2).
                   5701:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   5702:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5703:                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   5704:                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5705:                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267     raeburn  5706:                   '<br />'.
1.323     raeburn  5707:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267     raeburn  5708:                   ('&nbsp;'x2).
                   5709:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   5710:                   ('&nbsp;'x2).
1.322     raeburn  5711:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   5712:                   ('&nbsp;'x2).
1.267     raeburn  5713:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   5714:                   '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
                   5715:                   '</fieldset>'.
                   5716:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5717:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   5718:     my %defaultdisp;
                   5719:     $defaultdisp{'iframe'} = ' checked="checked"';
1.298     raeburn  5720:     foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5721:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   5722:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5723:     }
                   5724:     $datatable .= ('&nbsp;'x4);
                   5725:     foreach my $dimen ('width','height') {
                   5726:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5727:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   5728:                       ('&nbsp;'x2);
                   5729:     }
1.334     raeburn  5730:     $datatable .= '</span><br />'.
1.296     raeburn  5731:                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5732:                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296     raeburn  5733:                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334     raeburn  5734:                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296     raeburn  5735:                   '</div><div style=""></div><br />';
1.319     raeburn  5736:     my %units = (
                   5737:                   'passback' => 'days',
                   5738:                   'roster'   => 'seconds',
                   5739:                 );
                   5740:     my %defaulttimes = (
                   5741:                      'passback' => '7',
1.322     raeburn  5742:                      'roster'   => '300',
1.319     raeburn  5743:                    );
1.267     raeburn  5744:     foreach my $extra ('passback','roster') {
1.319     raeburn  5745:         my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
                   5746:         $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5747:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
                   5748:                       &mt('No').'</label></span>'.('&nbsp;'x2).'<span class="LC_nobreak">'.
                   5749:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
                   5750:                       &mt('Yes').'</label></span></div>'.
                   5751:                       '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
                   5752:                       '<span class="LC_nobreak">'.
                   5753:                       &mt("at least [_1] $units{$extra} after launch",
                   5754:                           '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
                   5755:                       '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5756:     }
1.319     raeburn  5757:     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
1.267     raeburn  5758:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5759:     if ($switchserver) {
                   5760:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5761:     } else {
                   5762:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   5763:     }
                   5764:     $datatable .= '</span></fieldset>'.
                   5765:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5766:                   '<span class="LC_nobreak">';
                   5767:     foreach my $field (@fields) {
1.324     raeburn  5768:         my ($id,$onclick,$spacer);
                   5769:         if ($field eq 'user') {
                   5770:             $id = ' id="ltitools_user_field_add"';
                   5771:             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   5772:         } else {
                   5773:             $spacer = ('&nbsp;' x2);
                   5774:         }
1.267     raeburn  5775:         $datatable .= '<label>'.
1.324     raeburn  5776:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   5777:                       $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5778:     }
1.324     raeburn  5779:     $datatable .= '</span>'.
                   5780:                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   5781:                   '<span class="LC_nobreak"> : '.
                   5782:                   '<select name="ltitools_userincdom_add">'.
                   5783:                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   5784:                   '<option value="0">'.&mt('username').'</option>'.
                   5785:                   '<option value="1">'.&mt('username:domain').'</option>'.
                   5786:                   '</select></span></div></fieldset>';
                   5787:     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267     raeburn  5788:     foreach my $role (@courseroles) {
                   5789:         my ($checked,$checkednone);
1.306     raeburn  5790:         $datatable .= '<td style="text-align: center">'.
1.267     raeburn  5791:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5792:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   5793:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   5794:         foreach my $ltirole (@ltiroles) {
                   5795:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   5796:         }
                   5797:         $datatable .= '</select></td>';
                   5798:     }
                   5799:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  5800:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5801:     foreach my $item ('label','title','target','linktext','explanation','append') {
1.296     raeburn  5802:         $datatable .= '<label>'.
                   5803:                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   5804:                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
1.273     raeburn  5805:     }
                   5806:     $datatable .= '</span></fieldset>'.
1.267     raeburn  5807:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5808:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   5809:                   '<tr><td><span class="LC_nobreak">'.
                   5810:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   5811:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   5812:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334     raeburn  5813:                   '</table></fieldset>'."\n".
1.267     raeburn  5814:                   '</td>'."\n".
                   5815:                   '</tr>'."\n";
                   5816:     $itemcount ++;
                   5817:     return $datatable;
                   5818: }
                   5819: 
                   5820: sub ltitools_names {
                   5821:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  5822:                                           'title'          => 'Title',
                   5823:                                           'version'        => 'Version',
                   5824:                                           'msgtype'        => 'Message Type',
1.323     raeburn  5825:                                           'sigmethod'      => 'Signature Method',
1.296     raeburn  5826:                                           'url'            => 'URL',
                   5827:                                           'key'            => 'Key',
1.322     raeburn  5828:                                           'lifetime'       => 'Nonce lifetime (s)',
1.296     raeburn  5829:                                           'secret'         => 'Secret',
                   5830:                                           'icon'           => 'Icon',   
1.324     raeburn  5831:                                           'user'           => 'User',
1.296     raeburn  5832:                                           'fullname'       => 'Full Name',
                   5833:                                           'firstname'      => 'First Name',
                   5834:                                           'lastname'       => 'Last Name',
                   5835:                                           'email'          => 'E-mail',
                   5836:                                           'roles'          => 'Role',
1.298     raeburn  5837:                                           'window'         => 'Window',
                   5838:                                           'tab'            => 'Tab',
1.296     raeburn  5839:                                           'iframe'         => 'iFrame',
                   5840:                                           'height'         => 'Height',
                   5841:                                           'width'          => 'Width',
                   5842:                                           'linktext'       => 'Default Link Text',
                   5843:                                           'explanation'    => 'Default Explanation',
                   5844:                                           'passback'       => 'Tool can return grades:',
                   5845:                                           'roster'         => 'Tool can retrieve roster:',
                   5846:                                           'crstarget'      => 'Display target',
                   5847:                                           'crslabel'       => 'Course label',
                   5848:                                           'crstitle'       => 'Course title', 
                   5849:                                           'crslinktext'    => 'Link Text',
                   5850:                                           'crsexplanation' => 'Explanation',
1.318     raeburn  5851:                                           'crsappend'      => 'Provider URL',
1.267     raeburn  5852:                                         );
                   5853:     return %lt;
                   5854: }
                   5855: 
1.372     raeburn  5856: sub print_proctoring {
                   5857:     my ($dom,$settings,$rowtotal) = @_;
                   5858:     my $itemcount = 1;
                   5859:     my (%ordered,%providernames,%current,%currentdef);
                   5860:     my $confname = $dom.'-domainconfig';
                   5861:     my $switchserver = &check_switchserver($dom,$confname);
                   5862:     if (ref($settings) eq 'HASH') {
                   5863:         foreach my $item (keys(%{$settings})) {
                   5864:             if (ref($settings->{$item}) eq 'HASH') {
                   5865:                 my $num = $settings->{$item}{'order'};
                   5866:                 $ordered{$num} = $item;
                   5867:             }
                   5868:         }
                   5869:     } else {
                   5870:         %ordered = (
                   5871:                      1 => 'proctorio',
                   5872:                      2 => 'examity',
                   5873:                    );
                   5874:     }
                   5875:     %providernames = &proctoring_providernames();
                   5876:     my $maxnum = scalar(keys(%ordered));
                   5877:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   5878:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   5879:     if (ref($requref) eq 'HASH') {
                   5880:         %requserfields = %{$requref};
                   5881:     }
                   5882:     if (ref($opturef) eq 'HASH') {
                   5883:         %optuserfields = %{$opturef};
                   5884:     }
                   5885:     if (ref($defref) eq 'HASH') {
                   5886:         %defaults = %{$defref};
                   5887:     }
                   5888:     if (ref($extref) eq 'HASH') {
                   5889:         %extended = %{$extref};
                   5890:     }
                   5891:     if (ref($crsref) eq 'HASH') {
                   5892:         %crsconf = %{$crsref};
                   5893:     }
                   5894:     if (ref($rolesref) eq 'ARRAY') {
                   5895:         @courseroles = @{$rolesref};
                   5896:     }
                   5897:     if (ref($ltiref) eq 'ARRAY') {
                   5898:         @ltiroles = @{$ltiref};
                   5899:     }
                   5900:     my $datatable;
                   5901:     my $css_class;
                   5902:     if (keys(%ordered)) {
                   5903:         my @items = sort { $a <=> $b } keys(%ordered);
                   5904:         for (my $i=0; $i<@items; $i++) {
                   5905:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5906:             my $provider = $ordered{$items[$i]};
                   5907:             my $optionsty = 'none';
                   5908:             my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
                   5909:                 %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
                   5910:             if (ref($settings) eq 'HASH') {
                   5911:                 if (ref($settings->{$provider}) eq 'HASH') {
                   5912:                     %current = %{$settings->{$provider}};
                   5913:                     if ($current{'available'}) {
                   5914:                         $optionsty = 'block';
                   5915:                         $available = 1;
                   5916:                     }
                   5917:                     if ($current{'lifetime'} =~ /^\d+$/) {
                   5918:                         $lifetime = $current{'lifetime'};
                   5919:                     }
                   5920:                     if ($current{'version'} =~ /^\d+\.\d+$/) {
                   5921:                         $version = $current{'version'};
                   5922:                     }
                   5923:                     if ($current{'image'} ne '') {
                   5924:                         $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
                   5925:                     }
                   5926:                     if (ref($current{'fields'}) eq 'ARRAY') {
                   5927:                         map { $checkedfields{$_} = 1; } @{$current{'fields'}};
                   5928:                     }
                   5929:                     $userincdom = $current{'incdom'};
                   5930:                     if (ref($current{'roles'}) eq 'HASH') {
                   5931:                         %rolemaps = %{$current{'roles'}};
                   5932:                         $checkedfields{'roles'} = 1;
                   5933:                     }
                   5934:                     if (ref($current{'defaults'}) eq 'ARRAY') {
                   5935:                         foreach my $val (@{$current{'defaults'}}) {
                   5936:                             if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
                   5937:                                 $inuse{$val} = 1;
                   5938:                             } else {
                   5939:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5940:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5941:                                         if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
                   5942:                                             $inuse{$poss} = $val;
                   5943:                                             last;
                   5944:                                         }
                   5945:                                     }
                   5946:                                 }
                   5947:                             }
                   5948:                         }
                   5949:                     } elsif (ref($current{'defaults'}) eq 'HASH') {
                   5950:                         foreach my $key (keys(%{$current{'defaults'}})) {
                   5951:                             my $currval = $current{'defaults'}{$key}; 
                   5952:                             if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
                   5953:                                 $inuse{$key} = 1;
                   5954:                             } else {
                   5955:                                 my $match;
                   5956:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5957:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5958:                                         if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
                   5959:                                             $inuse{$poss} = $key;
                   5960:                                             last;
                   5961:                                         }
                   5962:                                     } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
                   5963:                                         foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
                   5964:                                             if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
                   5965:                                                 if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
                   5966:                                                     $currentdef{$inner} = $currval;
                   5967:                                                     $match = 1;
                   5968:                                                     last;
                   5969:                                                 }
                   5970:                                             } elsif ($inner eq $key) {
                   5971:                                                 $currentdef{$key} = $currval;
                   5972:                                                 $match = 1;
                   5973:                                                 last;
                   5974:                                             }
                   5975:                                         }
                   5976:                                     }
                   5977:                                     last if ($match);
                   5978:                                 }
                   5979:                             }
                   5980:                         }
                   5981:                     }
                   5982:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   5983:                         map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
                   5984:                     }
                   5985:                 }
                   5986:             }
                   5987:             my %lt = &proctoring_titles($provider);
                   5988:             my %fieldtitles = &proctoring_fieldtitles($provider);
                   5989:             my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
                   5990:             my %checkedavailable = (
                   5991:                                    yes => '',
                   5992:                                    no  => ' checked="checked"',
                   5993:                                  );
                   5994:             if ($available) {
                   5995:                 $checkedavailable{'yes'} = $checkedavailable{'no'};
                   5996:                 $checkedavailable{'no'} = '';
                   5997:             }
                   5998:             my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
                   5999:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6000:                          .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
                   6001:             for (my $k=0; $k<$maxnum; $k++) {
                   6002:                 my $vpos = $k+1;
                   6003:                 my $selstr;
                   6004:                 if ($k == $i) {
                   6005:                     $selstr = ' selected="selected" ';
                   6006:                 }
                   6007:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6008:             }
                   6009:             if ($version eq '') {
                   6010:                 if ($provider eq 'proctorio') {
                   6011:                     $version = '1.0';
                   6012:                 } elsif ($provider eq 'examity') {
                   6013:                     $version = '1.1';
                   6014:                 }
                   6015:             }
                   6016:             if ($lifetime eq '') {
                   6017:                 $lifetime = '300';
                   6018:             }
                   6019:             $datatable .=
                   6020:                 '</select>'.('&nbsp;'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
                   6021:                 '<span class="LC_nobreak">'.$lt{'avai'}.'&nbsp;'.
                   6022:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6023:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
                   6024:                 '</td>'.
                   6025:                 '<td colspan="2">'.
                   6026:                 '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
                   6027:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
                   6028:                 '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
                   6029:                 ('&nbsp;'x2).
                   6030:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
                   6031:                 '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   6032:                 '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
                   6033:                 ('&nbsp;'x2).
                   6034:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
                   6035:                 '<br />'.
                   6036:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
                   6037:                 '<br />'.
                   6038:                 '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
                   6039:                 ('&nbsp;'x2).
                   6040:                 '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
                   6041:                 '<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";
                   6042:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   6043:             if ($imgsrc) {
                   6044:                 $datatable .= $imgsrc.
                   6045:                               '<label><input type="checkbox" name="proctoring_image_del"'.
                   6046:                               ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
                   6047:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:');
                   6048:             }
                   6049:             $datatable .= '&nbsp;';
                   6050:             if ($switchserver) {
                   6051:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   6052:             } else {
                   6053:                 $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
                   6054:             }
                   6055:             unless ($imgsrc) {
                   6056:                 $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
                   6057:             }
                   6058:             $datatable .= '</fieldset>'."\n";
                   6059:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   6060:                 if (@{$requserfields{$provider}} > 0) {
                   6061:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
                   6062:                     foreach my $field (@{$requserfields{$provider}}) {
                   6063:                         $datatable .= '<span class="LC_nobreak">'.
                   6064:                                       '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
                   6065:                                       $lt{$field}.'</label>';
                   6066:                         if ($field eq 'user') {
                   6067:                             my $seluserdom = '';
                   6068:                             my $unseluserdom = ' selected="selected"';
                   6069:                             if ($userincdom) {
                   6070:                                 $seluserdom = $unseluserdom;
                   6071:                                 $unseluserdom = '';
                   6072:                             }
                   6073:                             $datatable .= ':&nbsp;'.
                   6074:                                 '<select name="proctoring_userincdom_'.$provider.'">'.
                   6075:                                 '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
                   6076:                                 '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
                   6077:                                 '</select>&nbsp;';
                   6078:                         } else {
                   6079:                             $datatable .= '&nbsp;';
                   6080:                             if ($field eq 'roles') {
                   6081:                                 $showroles = 1; 
                   6082:                             } 
                   6083:                         }
                   6084:                         $datatable .= '</span> ';
                   6085:                     }
                   6086:                 }
                   6087:                 $datatable .= '</fieldset>'."\n";
                   6088:             }
                   6089:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   6090:                 if (@{$optuserfields{$provider}} > 0) {
                   6091:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>'; 
                   6092:                     foreach my $field (@{$optuserfields{$provider}}) {
                   6093:                         my $checked;
                   6094:                         if ($checkedfields{$field}) {
                   6095:                             $checked = ' checked="checked"';
                   6096:                         }
                   6097:                         $datatable .= '<span class="LC_nobreak">'.
                   6098:                                       '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span>&nbsp; ';
                   6099:                     }
                   6100:                     $datatable .= '</fieldset>'."\n";
                   6101:                 }
                   6102:             }
                   6103:             if (ref($defaults{$provider}) eq 'ARRAY') {
                   6104:                 if (@{$defaults{$provider}}) {
                   6105:                     my (%options,@selectboxes);
                   6106:                     if (ref($extended{$provider}) eq 'HASH') {
                   6107:                         %options = %{$extended{$provider}};
                   6108:                     }
                   6109:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
                   6110:                     my ($rem,$numinrow,$dropdowns);
                   6111:                     if ($provider eq 'proctorio') { 
                   6112:                         $datatable .= '<table>';
                   6113:                         $numinrow = 4;
                   6114:                     }
                   6115:                     my $i = 0;
                   6116:                     foreach my $field (@{$defaults{$provider}}) {
                   6117:                         my $checked;
                   6118:                         if ($inuse{$field}) {
                   6119:                             $checked = ' checked="checked"';
                   6120:                         }
                   6121:                         if ($provider eq 'examity') {
                   6122:                             if ($field eq 'display') {
                   6123:                                 $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
                   6124:                                 foreach my $option ('iframe','tab','window') {
                   6125:                                     my $checkdisp;
                   6126:                                     if ($currentdef{'target'} eq $option) {
                   6127:                                         $checkdisp = ' checked="checked"';
                   6128:                                     }
                   6129:                                     $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
                   6130:                                     $fieldtitles{$option}.'</label>'.('&nbsp;'x2);
                   6131:                                 }
                   6132:                                 $datatable .= ('&nbsp;'x4);
                   6133:                                 foreach my $dimen ('width','height') {
                   6134:                                     $datatable .= '<label>'.$fieldtitles{$dimen}.'&nbsp;'.
                   6135:                                                   '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
                   6136:                                                   'value="'.$currentdef{$dimen}.'" /></label>'.
                   6137:                                                   ('&nbsp;'x2);
                   6138:                                 }
                   6139:                                 $datatable .= '</span><br />'.
                   6140:                                               '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
                   6141:                                               '<input type="text" name="proctoring_linktext_'.$provider.'" '.
                   6142:                                               'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
                   6143:                                               '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
                   6144:                                               '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
                   6145:                                               $currentdef{'explanation'}.
                   6146:                                               '</textarea></div><div style=""></div><br />';
                   6147:                             }
                   6148:                         } else {
                   6149:                             if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   6150:                                 my ($output,$selnone);
                   6151:                                 unless ($checked) {
                   6152:                                     $selnone = ' selected="selected"';
                   6153:                                 }
                   6154:                                 $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
                   6155:                                            '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
                   6156:                                            '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>'; 
                   6157:                                 foreach my $option (@{$options{$field}}) {
                   6158:                                     my $sel; 
                   6159:                                     if ($inuse{$field} eq $option) {
                   6160:                                         $sel = ' selected="selected"';
                   6161:                                     }
                   6162:                                     $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
                   6163:                                 }
                   6164:                                 $output .= '</select></span>';
                   6165:                                 push(@selectboxes,$output);
                   6166:                             } else {
                   6167:                                 $rem = $i%($numinrow);
                   6168:                                 if ($rem == 0) {
                   6169:                                     if ($i > 0) {
                   6170:                                         $datatable .= '</tr>';
                   6171:                                     }
                   6172:                                     $datatable .= '<tr>';
                   6173:                                 }
                   6174:                                 $datatable .= '<td class="LC_left_item">'.
                   6175:                                               '<span class="LC_nobreak">'.
                   6176:                                               '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
                   6177:                                               $fieldtitles{$field}.'</label></span></td>';
                   6178:                                 $i++;
                   6179:                             }
                   6180:                         }
                   6181:                     }
                   6182:                     if ($provider eq 'proctorio') {
                   6183:                         if ($numinrow) {
                   6184:                             $rem = $i%$numinrow;
                   6185:                         }
                   6186:                         my $colsleft = $numinrow - $rem;
                   6187:                         if ($colsleft > 1) {
                   6188:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6189:                         } else {
                   6190:                             $datatable .= '<td class="LC_left_item">';
                   6191:                         }
                   6192:                         $datatable .= '&nbsp;'.
                   6193:                                       '</td></tr></table>';
                   6194:                         if (@selectboxes) {
                   6195:                             $datatable .= '<hr /><table>';
                   6196:                             $numinrow = 2;
                   6197:                             for (my $i=0; $i<@selectboxes; $i++) {
                   6198:                                 $rem = $i%($numinrow);
                   6199:                                 if ($rem == 0) {
                   6200:                                     if ($i > 0) {
                   6201:                                         $datatable .= '</tr>';
                   6202:                                     }
                   6203:                                     $datatable .= '<tr>';
                   6204:                                 }
                   6205:                                 $datatable .= '<td class="LC_left_item">'.
                   6206:                                               $selectboxes[$i].'</td>';
                   6207:                             }
                   6208:                             if ($numinrow) {
                   6209:                                 $rem = $i%$numinrow;
                   6210:                             }
                   6211:                             $colsleft = $numinrow - $rem;
                   6212:                             if ($colsleft > 1) {
                   6213:                                 $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6214:                             } else {
                   6215:                                 $datatable .= '<td class="LC_left_item">';
                   6216:                             }
                   6217:                             $datatable .= '&nbsp;'.
                   6218:                                           '</td></tr></table>';
                   6219:                         }
                   6220:                     }
                   6221:                     $datatable .= '</fieldset>';
                   6222:                 }
                   6223:                 if (ref($crsconf{$provider}) eq 'ARRAY') {
                   6224:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6225:                                   '<legend>'.&mt('Configurable in course').'</legend>';
                   6226:                     my ($rem,$numinrow);
                   6227:                     if ($provider eq 'proctorio') {
                   6228:                         $datatable .= '<table>';
                   6229:                         $numinrow = 4;
                   6230:                     }
                   6231:                     my $i = 0;
                   6232:                     foreach my $item (@{$crsconf{$provider}}) {
                   6233:                         my $name;
                   6234:                         if ($provider eq 'examity') {
                   6235:                             $name = $lt{'crs'.$item};
                   6236:                         } elsif ($provider eq 'proctorio') {
                   6237:                             $name = $fieldtitles{$item};
                   6238:                             $rem = $i%($numinrow);
                   6239:                             if ($rem == 0) {
                   6240:                                 if ($i > 0) {
                   6241:                                     $datatable .= '</tr>';
                   6242:                                 }
                   6243:                                 $datatable .= '<tr>';
                   6244:                             }
                   6245:                             $datatable .= '<td class="LC_left_item>';
                   6246:                         }
                   6247:                         my $checked;
                   6248:                         if ($crsconfig{$item}) {
                   6249:                             $checked = ' checked="checked"';
                   6250:                         }
                   6251:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   6252:                                       '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
                   6253:                                       $name.'</label></span>';
                   6254:                         if ($provider eq 'examity') {
                   6255:                             $datatable .= '&nbsp; ';
                   6256:                         }
                   6257:                         $datatable .= "\n";
                   6258:                         $i++;
                   6259:                     }
                   6260:                     if ($provider eq 'proctorio') {
                   6261:                         if ($numinrow) {
                   6262:                             $rem = $i%$numinrow;
                   6263:                         }
                   6264:                         my $colsleft = $numinrow - $rem;
                   6265:                         if ($colsleft > 1) {
                   6266:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6267:                         } else {
                   6268:                             $datatable .= '<td class="LC_left_item">';
                   6269:                         }
                   6270:                         $datatable .= '&nbsp;'.
                   6271:                                       '</td></tr></table>';
                   6272:                     }
                   6273:                     $datatable .= '</fieldset>';
                   6274:                 }
                   6275:                 if ($showroles) {
                   6276:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6277:                                   '<legend>'.&mt('Role mapping').'</legend><table><tr>';
                   6278:                     foreach my $role (@courseroles) {
                   6279:                         my ($selected,$selectnone);
                   6280:                         if (!$rolemaps{$role}) {
                   6281:                             $selectnone = ' selected="selected"';
                   6282:                         }
                   6283:                         $datatable .= '<td style="text-align: center">'.
                   6284:                                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   6285:                                       '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
                   6286:                                       '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6287:                         foreach my $ltirole (@ltiroles) {
                   6288:                             unless ($selectnone) {
                   6289:                                 if ($rolemaps{$role} eq $ltirole) {
                   6290:                                     $selected = ' selected="selected"';
                   6291:                                 } else {
                   6292:                                     $selected = '';
                   6293:                                 }
                   6294:                             }
                   6295:                             $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   6296:                         }
                   6297:                         $datatable .= '</select></td>';
                   6298:                     }
                   6299:                     $datatable .= '</tr></table></fieldset>'.
                   6300:                                   '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6301:                                   '<legend>'.&mt('Custom items sent on launch').'</legend>'.
                   6302:                                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   6303:                                   '<tr><td></td><td>lms</td>'.
                   6304:                                   '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
                   6305:                                   ' value="Loncapa" disabled="disabled"/></td></tr>';
                   6306:                     if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
                   6307:                         (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
                   6308:                         my %custom = %{$settings->{$provider}->{'custom'}};
                   6309:                         if (keys(%custom) > 0) {
                   6310:                             foreach my $key (sort(keys(%custom))) {
                   6311:                                 next if ($key eq 'lms');
                   6312:                                 $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6313:                                               '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
                   6314:                                               $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   6315:                                               '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
                   6316:                                               ' value="'.$custom{$key}.'" /></td></tr>';
                   6317:                             }
                   6318:                         }
                   6319:                     }
                   6320:                     $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6321:                                   '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
                   6322:                                   &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
                   6323:                                   '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
                   6324:                                   '</table></fieldset></td></tr>'."\n";
                   6325:                 }
                   6326:                 $datatable .= '</td></tr>';
                   6327:             }
                   6328:             $itemcount ++;
                   6329:         }
                   6330:     }
                   6331:     return $datatable;
                   6332: }
                   6333: 
                   6334: sub proctoring_data {
                   6335:     my $requserfields = {
                   6336:                       proctorio => ['user'],
                   6337:                       examity   => ['roles','user'],
                   6338:                      };
                   6339:     my $optuserfields = {
                   6340:                         proctorio => ['fullname'],
                   6341:                         examity   => ['fullname','firstname','lastname','email'],
                   6342:                      };
                   6343:     my $defaults = {
                   6344:                   proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6345:                                 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6346:                                 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6347:                                 'closetabs','onescreen','print','downloads','cache','rightclick',
                   6348:                                 'reentry','calculator','whiteboard'],
                   6349:                   examity   => ['display'],
                   6350:                 };
                   6351:     my $extended = { 
                   6352:                   proctorio => {
                   6353:                                  verifyid => ['verifyidauto','verifyidlive'],
                   6354:                                  fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
                   6355:                                  tabslinks => ['notabs','linksonly'],
                   6356:                                  reentry => ['noreentry','agentreentry'],
                   6357:                                  calculator => ['calculatorbasic','calculatorsci'],
                   6358:                                },
                   6359:                   examity => {
                   6360:                                display => {
                   6361:                                            target      => ['iframe','tab','window'],
                   6362:                                            width       => '',
                   6363:                                            height      => '',
                   6364:                                            linktext    => '',
                   6365:                                            explanation => '',
                   6366:                                           },
                   6367:                              },
                   6368:                 };
                   6369:     my $crsconf = {
                   6370:                  proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6371:                                'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6372:                                'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6373:                                'closetabs','onescreen','print','downloads','cache','rightclick',
                   6374:                                'reentry','calculator','whiteboard'],
                   6375:                  examity => ['label','title','target','linktext','explanation','append'],
                   6376:                };
                   6377:     my $courseroles = ['cc','in','ta','ep','st'];
                   6378:     my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
                   6379:     return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
                   6380: }
                   6381: 
                   6382: sub proctoring_titles {
                   6383:     my ($item) = @_;
                   6384:     my (%common_lt,%custom_lt);
                   6385:     %common_lt = &Apache::lonlocal::texthash (
                   6386:                      'avai'      => 'Available?',
                   6387:                      'base'      => 'Basic Settings',
                   6388:                      'requ'      => 'User data required to be sent on launch',
                   6389:                      'optu'      => 'User data optionally sent on launch',
                   6390:                      'udsl'      => 'User data sent on launch',
                   6391:                      'defa'      => 'Defaults for items configurable in course',
                   6392:                      'sigmethod' => 'Signature Method',
                   6393:                      'key'       => 'Key',
                   6394:                      'lifetime'  => 'Nonce lifetime (s)',
                   6395:                      'secret'    => 'Secret',
                   6396:                      'icon'      => 'Icon',
                   6397:                      'fullname'  => 'Full Name',
                   6398:                      'visible'   => 'Visible input',
                   6399:                      'username'  => 'username',
                   6400:                      'user'      => 'User',
                   6401:                  );
                   6402:     if ($item eq 'proctorio') {
                   6403:         %custom_lt = &Apache::lonlocal::texthash (
                   6404:                          'version'        => 'OAuth version',
                   6405:                          'url'            => 'API URL',
                   6406:                          'uname:dom'      => 'username-domain',
                   6407:         );
                   6408:     } elsif ($item eq 'examity') {
                   6409:         %custom_lt = &Apache::lonlocal::texthash (
                   6410:                          'version'        => 'LTI Version',
                   6411:                          'url'            => 'URL',
                   6412:                          'uname:dom'      => 'username:domain',
                   6413:                          'msgtype'        => 'Message Type',
                   6414:                          'firstname'      => 'First Name',
                   6415:                          'lastname'       => 'Last Name',
                   6416:                          'email'          => 'E-mail',
                   6417:                          'roles'          => 'Role',
                   6418:                          'crstarget'      => 'Display target',
                   6419:                          'crslabel'       => 'Course label',
                   6420:                          'crstitle'       => 'Course title', 
                   6421:                          'crslinktext'    => 'Link Text',
                   6422:                          'crsexplanation' => 'Explanation',
                   6423:                          'crsappend'      => 'Provider URL',
                   6424:         );
                   6425:     }
                   6426:     my %lt = (%common_lt,%custom_lt);
                   6427:     return %lt;
                   6428: }
                   6429: 
                   6430: sub proctoring_fieldtitles {
                   6431:     my ($item) = @_;
                   6432:     if ($item eq 'proctorio') {
                   6433:         return &Apache::lonlocal::texthash (
                   6434:                   'recordvideo' => 'Record video',
                   6435:                   'recordaudio' => 'Record audio',
                   6436:                   'recordscreen' => 'Record screen',
                   6437:                   'recordwebtraffic' => 'Record web traffic',
                   6438:                   'recordroomstart' => 'Record room scan',
                   6439:                   'verifyvideo' => 'Verify webcam',
                   6440:                   'verifyaudio' => 'Verify microphone',
                   6441:                   'verifydesktop' => 'Verify desktop recording',
                   6442:                   'verifyid' => 'Photo ID verification',
                   6443:                   'verifysignature' => 'Require signature',
                   6444:                   'fullscreen' => 'Fullscreen',
                   6445:                   'clipboard' => 'Disable copy/paste',
                   6446:                   'tabslinks' => 'New tabs/windows',
                   6447:                   'closetabs' => 'Close other tabs',
                   6448:                   'onescreen' => 'Limit to single screen',
                   6449:                   'print' => 'Disable Printing',
                   6450:                   'downloads' => 'Disable Downloads',
                   6451:                   'cache' => 'Empty cache after exam',
                   6452:                   'rightclick' => 'Disable right click',
                   6453:                   'reentry' => 'Re-entry to exam',
                   6454:                   'calculator' => 'Onscreen calculator',
                   6455:                   'whiteboard' => 'Onscreen whiteboard',
                   6456:                   'verifyidauto' => 'Automated verification',
                   6457:                   'verifyidlive' => 'Live agent verification',
                   6458:                   'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
                   6459:                   'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
                   6460:                   'fullscreensever' => 'Forced, navigation away ends exam',
                   6461:                   'notabs' => 'Disaallowed',
                   6462:                   'linksonly' => 'Allowed from links in exam',
                   6463:                   'noreentry' => 'Disallowed',
                   6464:                   'agentreentry' => 'Agent required for re-entry',
                   6465:                   'calculatorbasic' => 'Basic',
                   6466:                   'calculatorsci' => 'Scientific',
                   6467:         );
                   6468:     } elsif ($item eq 'examity') {
                   6469:         return &Apache::lonlocal::texthash (
                   6470:                 'target'         => 'Display target',   
                   6471:                 'window'         => 'Window',
                   6472:                 'tab'            => 'Tab',
                   6473:                 'iframe'         => 'iFrame',
                   6474:                 'height'         => 'Height (pixels)',
                   6475:                 'width'          => 'Width (pixels)',
                   6476:                 'linktext'       => 'Default Link Text',
                   6477:                 'explanation'    => 'Default Explanation',
                   6478:                 'append'         => 'Provider URL',
                   6479:         );
                   6480:     }
                   6481: }
                   6482: 
                   6483: sub proctoring_providernames {
                   6484:     return (
                   6485:              proctorio => 'Proctorio',
                   6486:              examity   => 'Examity',
                   6487:            );
                   6488: }
                   6489: 
1.320     raeburn  6490: sub print_lti {
1.405     raeburn  6491:     my ($position,$dom,$settings,$rowtotal) = @_;
1.320     raeburn  6492:     my $itemcount = 1;
1.405     raeburn  6493:     my ($datatable,$css_class);
                   6494:     my (%rules,%encrypt,%privkeys,%linkprot);
1.320     raeburn  6495:     if (ref($settings) eq 'HASH') {
1.405     raeburn  6496:         if ($position eq 'top') {
                   6497:             if (exists($settings->{'encrypt'})) {
                   6498:                 if (ref($settings->{'encrypt'}) eq 'HASH') {
                   6499:                     foreach my $key (keys(%{$settings->{'encrypt'}})) {
                   6500:                         if ($key eq 'consumers') {
                   6501:                             $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
                   6502:                         } else {
                   6503:                             $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
                   6504:                         }
                   6505:                     }
                   6506:                 }
                   6507:             }
                   6508:             if (exists($settings->{'private'})) {
                   6509:                 if (ref($settings->{'private'}) eq 'HASH') {
                   6510:                     if (ref($settings->{'private'}) eq 'HASH') {
                   6511:                         if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
                   6512:                             map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
                   6513:                         }
                   6514:                     }
                   6515:                 }
                   6516:             }
                   6517:         } elsif ($position eq 'middle') {
                   6518:             if (exists($settings->{'rules'})) {
                   6519:                 if (ref($settings->{'rules'}) eq 'HASH') {
                   6520:                     %rules = %{$settings->{'rules'}};
                   6521:                 }
                   6522:             }
                   6523:         } elsif ($position eq 'lower') {
                   6524:             if (exists($settings->{'linkprot'})) {
                   6525:                 if (ref($settings->{'linkprot'}) eq 'HASH') {
                   6526:                     %linkprot = %{$settings->{'linkprot'}};
1.406     raeburn  6527:                     if ($linkprot{'lock'}) {
                   6528:                         delete($linkprot{'lock'});
                   6529:                     }
1.405     raeburn  6530:                 }
                   6531:             }
                   6532:         } else {
                   6533:             foreach my $key ('encrypt','private','rules','linkprot') {
                   6534:                 if (exists($settings->{$key})) {
                   6535:                     delete($settings->{$key});
1.390     raeburn  6536:                 }
1.320     raeburn  6537:             }
                   6538:         }
                   6539:     }
1.405     raeburn  6540:     if ($position eq 'top') {
                   6541:         my @ids=&Apache::lonnet::current_machine_ids();
                   6542:         my %servers = &Apache::lonnet::get_servers($dom,'library');
                   6543:         my $primary = &Apache::lonnet::domain($dom,'primary');
                   6544:         my ($extra,$numshown);
                   6545:         foreach my $hostid (sort(keys(%servers))) {
                   6546:             my ($showextra,$divsty,$switch);
                   6547:             if ($hostid eq $primary) {
                   6548:                 if (($encrypt{'ltisec_consumers'}) || ($encrypt{'ltisec_domlinkprot'})) {
                   6549:                     $showextra = 1;
                   6550:                 }
                   6551:             }
                   6552:             if ($encrypt{'ltisec_crslinkprot'}) {
                   6553:                 $showextra = 1;
                   6554:             }
                   6555:             unless (grep(/^\Q$hostid\E$/,@ids)) {
                   6556:                 $switch = 1;
                   6557:             }
                   6558:             if ($showextra) {
                   6559:                 $numshown ++;
                   6560:                 $divsty = 'display:inline-block'; 
                   6561:             } else {
                   6562:                 $divsty = 'display:none';
                   6563:             } 
                   6564:             $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
                   6565:                       '<legend>'.$hostid.'</legend>';
                   6566:             if ($switch) {
                   6567:                 my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&amp;role='.
                   6568:                                    &HTML::Entities::encode($env{'request.role'},'\'<>"&').
                   6569:                                    '&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
                   6570:                 if (exists($privkeys{$hostid})) {
                   6571:                     $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
                   6572:                               '<span class="LC_nobreak">'.
                   6573:                               &mt('Encryption Key').': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   6574:                               '<span class="LC_nobreak">'.&mt('Change?').
                   6575:                               '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
                   6576:                               ('&nbsp;'x2).
                   6577:                               '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
                   6578:                               '</label>&nbsp;&nbsp;</span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
                   6579:                               '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
                   6580:                               '</span></div>';
                   6581:                 } else {
                   6582:                     $extra .= '<span class="LC_nobreak">'.
                   6583:                               &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
                   6584:                               '</span>'."\n";
                   6585:                 }
                   6586:             } elsif (exists($privkeys{$hostid})) {
                   6587:                 $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
                   6588:                           &mt('Encryption Key').': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   6589:                           '<span class="LC_nobreak">'.&mt('Change?').
                   6590:                           '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
                   6591:                           ('&nbsp;'x2).
                   6592:                           '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
                   6593:                           '</label>&nbsp;&nbsp;</span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
                   6594:                           '<span class="LC_nobreak">'.&mt('New Key').':'.
1.415     raeburn  6595:                           '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
1.405     raeburn  6596:                           '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
                   6597:                           '</span></div>';
                   6598:             } else {
                   6599:                 $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
1.415     raeburn  6600:                           '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
1.405     raeburn  6601:                           '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
                   6602:             }
                   6603:             $extra .= '</fieldset>';
                   6604:         }
                   6605:         my %choices = &Apache::lonlocal::texthash (
                   6606:                                                       ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
                   6607:                                                       ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
                   6608:                                                       ltisec_consumers   => 'Encrypt stored consumer secrets defined in domain',
                   6609:                                                   );
                   6610:         my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
                   6611:         my %defaultchecked = (
                   6612:                                'ltisec_crslinkprot' => 'off',
                   6613:                                'ltisec_domlinkprot' => 'off',
                   6614:                                'ltisec_consumers'   => 'off',
                   6615:                              );
                   6616:         my ($onclick,$itemcount);
                   6617:         $onclick = 'javascript:toggleLTIEncKey(this.form);';
                   6618:         ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
                   6619:                                                      \%choices,$itemcount,$onclick,'','left','no');
                   6620: 
                   6621:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6622:         my $noprivkeysty = 'display:inline-block';
                   6623:         if ($numshown) {
                   6624:             $noprivkeysty = 'display:none'; 
                   6625:         }
                   6626:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
                   6627:                       '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
                   6628:                       '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
                   6629:                       $extra.
                   6630:                       '</td></tr>';
                   6631:         $itemcount ++;                
                   6632:         $$rowtotal += $itemcount;
                   6633:     } elsif ($position eq 'middle') {
                   6634:         $datatable = &password_rules('secrets',\$itemcount,\%rules);
1.406     raeburn  6635:         $$rowtotal += $itemcount;
1.405     raeburn  6636:     } elsif ($position eq 'lower') {
1.406     raeburn  6637:          $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.405     raeburn  6638:     } else {
                   6639:         my $maxnum = 0;
                   6640:         my %ordered;
                   6641:         if (ref($settings) eq 'HASH') {
                   6642:             foreach my $item (keys(%{$settings})) {
                   6643:                 if (ref($settings->{$item}) eq 'HASH') {
                   6644:                     my $num = $settings->{$item}{'order'};
                   6645:                     if ($num eq '') {
                   6646:                         $num = scalar(keys(%{$settings}));
                   6647:                     }
                   6648:                     $ordered{$num} = $item;
                   6649:                 }
1.352     raeburn  6650:             }
1.405     raeburn  6651:         }
                   6652:         $maxnum = scalar(keys(%ordered));
                   6653:         my %lt = &lti_names();
                   6654:         if (keys(%ordered)) {
                   6655:             my @items = sort { $a <=> $b } keys(%ordered);
                   6656:             for (my $i=0; $i<@items; $i++) {
                   6657:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6658:                 my $item = $ordered{$items[$i]};
                   6659:                 my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
                   6660:                 if (ref($settings->{$item}) eq 'HASH') {
                   6661:                     $key = $settings->{$item}->{'key'};
                   6662:                     $secret = $settings->{$item}->{'secret'};
                   6663:                     $lifetime = $settings->{$item}->{'lifetime'};
                   6664:                     $consumer = $settings->{$item}->{'consumer'};
                   6665:                     $requser = $settings->{$item}->{'requser'};
                   6666:                     $crsinc = $settings->{$item}->{'crsinc'};
                   6667:                     $current = $settings->{$item};
                   6668:                 }
                   6669:                 my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
                   6670:                 my %checkedrequser = (
                   6671:                                        yes => ' checked="checked"',
                   6672:                                        no  => '',
                   6673:                                      );
                   6674:                 if (!$requser) {
                   6675:                     $checkedrequser{'no'} = $checkedrequser{'yes'};
                   6676:                     $checkedrequser{'yes'} = '';
                   6677:                 }
                   6678:                 my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
                   6679:                 my %checkedcrsinc = (
1.391     raeburn  6680:                                       yes => ' checked="checked"',
                   6681:                                       no  => '',
1.405     raeburn  6682:                                     );
                   6683:                 if (!$crsinc) {
                   6684:                     $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
                   6685:                     $checkedcrsinc{'yes'} = '';
                   6686:                 }
                   6687:                 my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
                   6688:                 $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6689:                              .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
                   6690:                 for (my $k=0; $k<=$maxnum; $k++) {
                   6691:                     my $vpos = $k+1;
                   6692:                     my $selstr;
                   6693:                     if ($k == $i) {
                   6694:                         $selstr = ' selected="selected" ';
                   6695:                     }
                   6696:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320     raeburn  6697:                 }
1.405     raeburn  6698:                 $datatable .= '</select>'.('&nbsp;'x2).
                   6699:                     '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
                   6700:                     &mt('Delete?').'</label></span></td>'.
                   6701:                     '<td colspan="2">'.
                   6702:                     '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6703:                     '<span class="LC_nobreak">'.$lt{'consumer'}.
                   6704:                     ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
                   6705:                     ('&nbsp;'x2).
                   6706:                     '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                   6707:                     '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   6708:                     ('&nbsp;'x2).
                   6709:                     '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
                   6710:                     'value="'.$lifetime.'" size="3" /></span>'.
                   6711:                     ('&nbsp;'x2).
                   6712:                     '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6713:                     '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6714:                     '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
                   6715:                     '<br /><br />'.
                   6716:                     '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6717:                     '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6718:                     '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
                   6719:                     ('&nbsp;'x4).
                   6720:                     '<span class="LC_nobreak">'.$lt{'key'}.
                   6721:                     ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
                   6722:                     ('&nbsp;'x2).
                   6723:                     '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   6724:                     '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
                   6725:                     '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
                   6726:                     '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
                   6727:                     '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
                   6728:                 $itemcount ++;
1.320     raeburn  6729:             }
                   6730:         }
1.405     raeburn  6731:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6732:         my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
                   6733:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   6734:                       '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
                   6735:                       '<select name="lti_pos_add"'.$chgstr.'>';
                   6736:         for (my $k=0; $k<$maxnum+1; $k++) {
                   6737:             my $vpos = $k+1;
                   6738:             my $selstr;
                   6739:             if ($k == $maxnum) {
                   6740:                 $selstr = ' selected="selected" ';
                   6741:             }
                   6742:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320     raeburn  6743:         }
1.405     raeburn  6744:         $datatable .= '</select>&nbsp;'."\n".
                   6745:                       '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   6746:                       '<td colspan="2">'.
                   6747:                       '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6748:                       '<span class="LC_nobreak">'.$lt{'consumer'}.
                   6749:                       ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
                   6750:                       ('&nbsp;'x2).
                   6751:                       '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   6752:                       '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   6753:                       ('&nbsp;'x2).
                   6754:                       '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
                   6755:                       ('&nbsp;'x2).
                   6756:                       '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6757:                       '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6758:                       '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
                   6759:                       '<br /><br />'.
                   6760:                       '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6761:                       '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6762:                       '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
                   6763:                       ('&nbsp;'x4).
                   6764:                       '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
                   6765:                       ('&nbsp;'x2).
                   6766:                       '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
                   6767:                       '<label><input type="checkbox" name="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".
                   6768:                       '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
                   6769:                       '</td>'."\n".
                   6770:                       '</tr>'."\n";
                   6771:         $itemcount ++;
1.320     raeburn  6772:     }
1.405     raeburn  6773:     $$rowtotal += $itemcount;
                   6774:     return $datatable;
1.320     raeburn  6775: }
                   6776: 
                   6777: sub lti_names {
                   6778:     my %lt = &Apache::lonlocal::texthash(
                   6779:                                           'version'   => 'LTI Version',
                   6780:                                           'url'       => 'URL',
                   6781:                                           'key'       => 'Key',
1.322     raeburn  6782:                                           'lifetime'  => 'Nonce lifetime (s)',
1.345     raeburn  6783:                                           'consumer'  => 'Consumer',
1.320     raeburn  6784:                                           'secret'    => 'Secret',
1.345     raeburn  6785:                                           'requser'   => "User's identity sent",
1.391     raeburn  6786:                                           'crsinc'    => "Course's identity sent",
1.320     raeburn  6787:                                           'email'     => 'Email address',
                   6788:                                           'sourcedid' => 'User ID',
                   6789:                                           'other'     => 'Other',
                   6790:                                           'passback'  => 'Can return grades to Consumer:',
                   6791:                                           'roster'    => 'Can retrieve roster from Consumer:',
1.326     raeburn  6792:                                           'topmenu'   => 'Display LON-CAPA page header',
1.345     raeburn  6793:                                           'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320     raeburn  6794:                                         );
                   6795:     return %lt;
                   6796: }
                   6797: 
                   6798: sub lti_options {
1.325     raeburn  6799:     my ($num,$current,$itemcount,%lt) = @_;
1.363     raeburn  6800:     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320     raeburn  6801:     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
                   6802:     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392     raeburn  6803:     $checked{'storecrs'}{'Y'} = ' checked="checked"';
                   6804:     $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320     raeburn  6805:     $checked{'mapcrstype'} = {};
                   6806:     $checked{'makeuser'} = {};
                   6807:     $checked{'selfenroll'} = {};
                   6808:     $checked{'crssec'} = {};
                   6809:     $checked{'crssecsrc'} = {};
1.325     raeburn  6810:     $checked{'lcauth'} = {};
1.326     raeburn  6811:     $checked{'menuitem'} = {};
1.325     raeburn  6812:     if ($num eq 'add') {
                   6813:         $checked{'lcauth'}{'lti'} = ' checked="checked"';
                   6814:     }
1.320     raeburn  6815:     my $userfieldsty = 'none';
                   6816:     my $crsfieldsty = 'none';
                   6817:     my $crssecfieldsty = 'none';
                   6818:     my $secsrcfieldsty = 'none';
1.363     raeburn  6819:     my $callbacksty = 'none';
1.337     raeburn  6820:     my $passbacksty = 'none';
1.345     raeburn  6821:     my $optionsty = 'block';
1.391     raeburn  6822:     my $crssty = 'block';
1.325     raeburn  6823:     my $lcauthparm;
                   6824:     my $lcauthparmstyle = 'display:none';
                   6825:     my $lcauthparmtext;
1.326     raeburn  6826:     my $menusty;
1.325     raeburn  6827:     my $numinrow = 4;
1.326     raeburn  6828:     my %menutitles = &ltimenu_titles();
1.320     raeburn  6829: 
                   6830:     if (ref($current) eq 'HASH') {
1.345     raeburn  6831:         if (!$current->{'requser'}) {
                   6832:             $optionsty = 'none';
1.391     raeburn  6833:             $crssty = 'none';
                   6834:         } elsif (!$current->{'crsinc'}) {
                   6835:             $crssty = 'none';
1.345     raeburn  6836:         }
1.320     raeburn  6837:         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
                   6838:             $checked{'mapuser'}{'sourcedid'} = '';
                   6839:             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
                   6840:                 $checked{'mapuser'}{'email'} = ' checked="checked"'; 
                   6841:             } else {
                   6842:                 $checked{'mapuser'}{'other'} = ' checked="checked"';
                   6843:                 $userfield = $current->{'mapuser'};
                   6844:                 $userfieldsty = 'inline-block';
                   6845:             }
                   6846:         }
                   6847:         if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
                   6848:             $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
                   6849:             if ($current->{'mapcrs'} eq 'context_id') {
                   6850:                 $checked{'mapcrs'}{'context_id'} = ' checked="checked"'; 
                   6851:             } else {
                   6852:                 $checked{'mapcrs'}{'other'} = ' checked="checked"';
                   6853:                 $cidfield = $current->{'mapcrs'};
                   6854:                 $crsfieldsty = 'inline-block';
                   6855:             }
                   6856:         }
                   6857:         if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
                   6858:             foreach my $type (@{$current->{'mapcrstype'}}) {
                   6859:                 $checked{'mapcrstype'}{$type} = ' checked="checked"';
                   6860:             }
                   6861:         }
1.392     raeburn  6862:         if (!$current->{'storecrs'}) {
                   6863:             $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
                   6864:             $checked{'storecrs'}{'Y'} = '';
                   6865:         }
1.345     raeburn  6866:         if ($current->{'makecrs'}) {
1.320     raeburn  6867:             $checked{'makecrs'}{'Y'} = '  checked="checked"';
1.326     raeburn  6868:         }
1.320     raeburn  6869:         if (ref($current->{'makeuser'}) eq 'ARRAY') {
                   6870:             foreach my $role (@{$current->{'makeuser'}}) {
                   6871:                 $checked{'makeuser'}{$role} = ' checked="checked"';
                   6872:             }
                   6873:         }
1.325     raeburn  6874:         if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
                   6875:             $checked{'lcauth'}{$1} = ' checked="checked"';
                   6876:             unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   6877:                 $lcauthparm = $current->{'lcauthparm'};
                   6878:                 $lcauthparmstyle = 'display:table-row'; 
                   6879:                 if ($current->{'lcauth'} eq 'localauth') {
                   6880:                     $lcauthparmtext = &mt('Local auth argument');
                   6881:                 } else {
                   6882:                     $lcauthparmtext = &mt('Kerberos domain');
                   6883:                 }
                   6884:             }
                   6885:         }
1.320     raeburn  6886:         if (ref($current->{'selfenroll'}) eq 'ARRAY') {
                   6887:             foreach my $role (@{$current->{'selfenroll'}}) {
                   6888:                 $checked{'selfenroll'}{$role} = ' checked="checked"';
                   6889:             }
                   6890:         }
                   6891:         if (ref($current->{'maproles'}) eq 'HASH') {
                   6892:             %rolemaps = %{$current->{'maproles'}};
                   6893:         }
                   6894:         if ($current->{'section'} ne '') {
                   6895:             $checked{'crssec'}{'Y'} = '  checked="checked"'; 
                   6896:             $crssecfieldsty = 'inline-block';
                   6897:             if ($current->{'section'} eq 'course_section_sourcedid') {
                   6898:                 $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
                   6899:             } else {
                   6900:                 $checked{'crssecsrc'}{'other'} = ' checked="checked"';
                   6901:                 $crssecsrc = $current->{'section'};
                   6902:                 $secsrcfieldsty = 'inline-block';
                   6903:             }
                   6904:         } else {
                   6905:             $checked{'crssec'}{'N'} = ' checked="checked"';
                   6906:         }
1.363     raeburn  6907:         if ($current->{'callback'} ne '') {
                   6908:             $callback = $current->{'callback'};
                   6909:             $checked{'callback'}{'Y'} = ' checked="checked"';
                   6910:             $callbacksty = 'inline-block';
                   6911:         } else {
                   6912:             $checked{'callback'}{'N'} = ' checked="checked"';
                   6913:         }
1.326     raeburn  6914:         if ($current->{'topmenu'}) {
                   6915:             $checked{'topmenu'}{'Y'} = ' checked="checked"';
                   6916:         } else {
                   6917:             $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6918:         }
                   6919:         if ($current->{'inlinemenu'}) {
                   6920:             $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
                   6921:         } else {
                   6922:             $checked{'inlinemenu'}{'N'} = ' checked="checked"';
                   6923:         }
                   6924:         if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
                   6925:             $menusty = 'inline-block';
                   6926:             if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   6927:                 foreach my $item (@{$current->{'lcmenu'}}) {
                   6928:                     if (exists($menutitles{$item})) {
                   6929:                         $checked{'menuitem'}{$item} = ' checked="checked"';
                   6930:                     }
                   6931:                 }
                   6932:             }
                   6933:         } else {
                   6934:             $menusty = 'none';
                   6935:         }
1.320     raeburn  6936:     } else {
                   6937:         $checked{'makecrs'}{'N'} = ' checked="checked"';
                   6938:         $checked{'crssec'}{'N'} = ' checked="checked"';
1.363     raeburn  6939:         $checked{'callback'}{'N'} = ' checked="checked"';
1.326     raeburn  6940:         $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6941:         $checked{'inlinemenu'}{'Y'} = ' checked="checked"'; 
                   6942:         $checked{'menuitem'}{'grades'} = ' checked="checked"';
                   6943:         $menusty = 'inline-block'; 
1.320     raeburn  6944:     }
1.325     raeburn  6945:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  6946:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   6947:                                official   => 'Official',
                   6948:                                unofficial => 'Unofficial',
                   6949:                                community  => 'Community',
                   6950:                                textbook   => 'Textbook',
                   6951:                                placement  => 'Placement Test',
1.325     raeburn  6952:                                lti        => 'LTI Provider',
1.320     raeburn  6953:     );
1.325     raeburn  6954:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6955:     my %shortauth = (
                   6956:                      internal => 'int',
                   6957:                      krb4 => 'krb4',
                   6958:                      krb5 => 'krb5',
                   6959:                      localauth  => 'loc'
                   6960:                     );
                   6961:     my %authnames = &authtype_names();
1.320     raeburn  6962:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   6963:     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
                   6964:     my @courseroles = ('cc','in','ta','ep','st');
                   6965:     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
                   6966:     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
                   6967:     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363     raeburn  6968:     my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320     raeburn  6969:     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325     raeburn  6970:     my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326     raeburn  6971:     my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391     raeburn  6972:     my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392     raeburn  6973:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').':&nbsp;'.
1.391     raeburn  6974:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
                   6975:                  $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6976:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
                   6977:                  $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
                   6978:                  '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
                   6979:                  '<span class="LC_nobreak">'.&mt('Parameter').': '.
                   6980:                  '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
                   6981:                  '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
                   6982:                  '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320     raeburn  6983:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
                   6984:     foreach my $option ('sourcedid','email','other') {
                   6985:         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
                   6986:                    $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
                   6987:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6988:     }
                   6989:     $output .= '</span></div>'.
                   6990:                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                   6991:                '<input type="text" name="lti_customuser_'.$num.'" '.
1.372     raeburn  6992:                'value="'.$userfield.'" /></div></fieldset>'.
1.391     raeburn  6993:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320     raeburn  6994:     foreach my $ltirole (@ltiroles) {
                   6995:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
                   6996:                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';     
                   6997:     }
                   6998:     $output .= '</fieldset>'.
1.391     raeburn  6999:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325     raeburn  7000:                '<table>'.
                   7001:                &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                   7002:                '</table>'.
                   7003:                '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                   7004:                '<td class="LC_left_item">';
                   7005:     foreach my $auth ('lti',@authtypes) {
                   7006:         my $authtext;
                   7007:         if ($auth eq 'lti') {
                   7008:             $authtext = &mt('None');
                   7009:         } else {
                   7010:             $authtext = $authnames{$shortauth{$auth}};
                   7011:         }
                   7012:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                   7013:                    '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                   7014:                    $authtext.'</label></span> &nbsp;';
                   7015:     }
                   7016:     $output .= '</td></tr>'.
                   7017:                '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                   7018:                '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                   7019:                '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                   7020:                '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                   7021:                '</table></fieldset>'.
1.391     raeburn  7022:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
                   7023:                &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
                   7024:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                   7025:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                   7026:                $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   7027:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
                   7028:                $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
                   7029:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   7030:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                   7031:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                   7032:                $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   7033:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
                   7034:                $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
                   7035:      $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   7036:                '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                   7037:                '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
                   7038:     foreach my $type ('fullname','coursetitle','role','logout','grades') {
                   7039:         $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                   7040:                    $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                   7041:                    ('&nbsp;'x2);
                   7042:     }
                   7043:     $output .= '</span></div></fieldset>'.
                   7044:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320     raeburn  7045:                '<div class="LC_floatleft"><span class="LC_nobreak">'.
                   7046:                &mt('Unique course identifier').':&nbsp;';
                   7047:     foreach my $option ('course_offering_sourcedid','context_id','other') {
                   7048:         $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
                   7049:                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                   7050:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   7051:     }
1.334     raeburn  7052:     $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320     raeburn  7053:                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                   7054:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   7055:                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
                   7056:     foreach my $type (@coursetypes) {
                   7057:         $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
                   7058:                    $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
                   7059:                    ('&nbsp;'x2);
                   7060:     }
1.392     raeburn  7061:     $output .= '</span><br /><br />'.
                   7062:                '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').':&nbsp;'.
                   7063:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
                   7064:                $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   7065:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
                   7066:                $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   7067:                '</fieldset>'.
1.391     raeburn  7068:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
                   7069:     foreach my $ltirole (@lticourseroles) {
                   7070:         my ($selected,$selectnone);
                   7071:         if ($rolemaps{$ltirole} eq '') {
                   7072:             $selectnone = ' selected="selected"';
                   7073:         }
                   7074:         $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
                   7075:                    '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
                   7076:                    '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   7077:         foreach my $role (@courseroles) {
                   7078:             unless ($selectnone) {
                   7079:                 if ($rolemaps{$ltirole} eq $role) {
                   7080:                     $selected = ' selected="selected"';
                   7081:                 } else {
                   7082:                     $selected = '';
                   7083:                 }
                   7084:             }
                   7085:             $output .= '<option value="'.$role.'"'.$selected.'>'.
                   7086:                        &Apache::lonnet::plaintext($role,'Course').
                   7087:                        '</option>';
                   7088:         }
                   7089:         $output .= '</select></td>';
                   7090:     }
                   7091:     $output .= '</tr></table></fieldset>'.
                   7092:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320     raeburn  7093:                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                   7094:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                   7095:                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   7096:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                   7097:                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   7098:                '</fieldset>'.
1.391     raeburn  7099:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320     raeburn  7100:     foreach my $lticrsrole (@lticourseroles) {
                   7101:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                   7102:                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
                   7103:     }
                   7104:     $output .= '</fieldset>'.
1.391     raeburn  7105:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320     raeburn  7106:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                   7107:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                   7108:                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   7109:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334     raeburn  7110:                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320     raeburn  7111:                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                   7112:                '<span class="LC_nobreak">'.&mt('From').':<label>'.
                   7113:                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
                   7114:                $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
                   7115:                &mt('Standard field').'</label>'.('&nbsp;'x2).
                   7116:                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                   7117:                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334     raeburn  7118:                '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320     raeburn  7119:                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337     raeburn  7120:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
                   7121:     my ($pb1p1chk,$pb1p0chk,$onclickpb);
                   7122:     foreach my $extra ('roster','passback') {
1.320     raeburn  7123:         my $checkedon = '';
                   7124:         my $checkedoff = ' checked="checked"';
1.337     raeburn  7125:         if ($extra eq 'passback') {
                   7126:             $pb1p1chk = ' checked="checked"';
                   7127:             $pb1p0chk = '';
                   7128:             $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"'; 
                   7129:         } else {
                   7130:             $onclickpb = ''; 
                   7131:         }
1.320     raeburn  7132:         if (ref($current) eq 'HASH') {
                   7133:             if (($current->{$extra})) {
                   7134:                 $checkedon = $checkedoff;
                   7135:                 $checkedoff = '';
1.337     raeburn  7136:                 if ($extra eq 'passback') {
                   7137:                     $passbacksty = 'inline-block';
                   7138:                 }
                   7139:                 if ($current->{'passbackformat'} eq '1.0') {
                   7140:                     $pb1p0chk =  ' checked="checked"';
                   7141:                     $pb1p1chk = '';
                   7142:                 }
1.320     raeburn  7143:             }
                   7144:         }
                   7145:         $output .= $lt{$extra}.'&nbsp;'.
1.337     raeburn  7146:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320     raeburn  7147:                    &mt('No').'</label>'.('&nbsp;'x2).
1.339     raeburn  7148:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320     raeburn  7149:                    &mt('Yes').'</label><br />';
                   7150:     }
1.337     raeburn  7151:     $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                   7152:                '<span class="LC_nobreak">'.&mt('Grade format').
                   7153:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                   7154:                &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                   7155:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363     raeburn  7156:                &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391     raeburn  7157:                '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334     raeburn  7158:     $output .= '</span></div></fieldset>';
1.320     raeburn  7159: #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
                   7160: #
                   7161: #    $output .= '</fieldset>'.
                   7162: #        '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
                   7163:     return $output;
                   7164: }
                   7165: 
1.326     raeburn  7166: sub ltimenu_titles {
                   7167:     return &Apache::lonlocal::texthash(
                   7168:                                         fullname    => 'Full name',
                   7169:                                         coursetitle => 'Course title',
                   7170:                                         role        => 'Role',
                   7171:                                         logout      => 'Logout',
                   7172:                                         grades      => 'Grades',
                   7173:     );
                   7174: }
                   7175: 
1.405     raeburn  7176: sub check_switchserver {
                   7177:     my ($home) = @_;
                   7178:     my $switchserver;
                   7179:     if ($home ne '') {
                   7180:         my $allowed;
                   7181:         my @ids=&Apache::lonnet::current_machine_ids();
                   7182:         foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   7183:         if (!$allowed) {
                   7184:             $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role='.
                   7185:                           &HTML::Entities::encode($env{'request.role'},'\'<>"&').
                   7186:                           '&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
                   7187:         }
                   7188:     }
                   7189:     return $switchserver;
                   7190: }
                   7191: 
1.121     raeburn  7192: sub print_coursedefaults {
1.139     raeburn  7193:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  7194:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  7195:     my $itemcount = 1;
1.192     raeburn  7196:     my %choices =  &Apache::lonlocal::texthash (
                   7197:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  7198:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  7199:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   7200:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  7201:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   7202:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398     raeburn  7203:         inline_chem          => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314     raeburn  7204:         texengine            => 'Default method to display mathematics',
1.257     raeburn  7205:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  7206:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   7207:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405     raeburn  7208:         ltiauth              => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.192     raeburn  7209:     );
1.198     raeburn  7210:     my %staticdefaults = (
                   7211:                            anonsurvey_threshold => 10,
                   7212:                            uploadquota          => 500,
1.257     raeburn  7213:                            postsubmit           => 60,
1.276     raeburn  7214:                            mysqltables          => 172800,
1.198     raeburn  7215:                          );
1.139     raeburn  7216:     if ($position eq 'top') {
1.257     raeburn  7217:         %defaultchecked = (
                   7218:                             'canuse_pdfforms' => 'off',
                   7219:                             'uselcmath'       => 'on',
                   7220:                             'usejsme'         => 'on',
1.398     raeburn  7221:                             'inline_chem'     => 'on',
1.289     raeburn  7222:                             'canclone'        => 'none',
1.257     raeburn  7223:                           );
1.398     raeburn  7224:         @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349     raeburn  7225:         my $deftex = $Apache::lonnet::deftex;
1.314     raeburn  7226:         if (ref($settings) eq 'HASH') {
                   7227:             if ($settings->{'texengine'}) {
                   7228:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   7229:                     $deftex = $settings->{'texengine'};
                   7230:                 }
                   7231:             }
                   7232:         }
                   7233:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7234:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   7235:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   7236:                        '</span></td><td class="LC_right_item">'.
                   7237:                        '<select name="texengine">'."\n";
                   7238:         my %texoptions = (
                   7239:                             MathJax  => 'MathJax',
                   7240:                             mimetex  => &mt('Convert to Images'),
                   7241:                             tth      => &mt('TeX to HTML'),
                   7242:                          );
                   7243:         foreach my $renderer ('MathJax','mimetex','tth') {
                   7244:             my $selected = '';
                   7245:             if ($renderer eq $deftex) {
                   7246:                 $selected = ' selected="selected"';
                   7247:             }
                   7248:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   7249:         }
                   7250:         $mathdisp .= '</select></td></tr>'."\n";
                   7251:         $itemcount ++;
1.139     raeburn  7252:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  7253:                                                      \%choices,$itemcount);
1.314     raeburn  7254:         $datatable = $mathdisp.$datatable;
1.264     raeburn  7255:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7256:         $datatable .=
1.306     raeburn  7257:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  7258:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   7259:             '</span></td><td class="LC_left_item">';
                   7260:         my $currcanclone = 'none';
                   7261:         my $onclick;
                   7262:         my @cloneoptions = ('none','domain');
1.380     raeburn  7263:         my %clonetitles = &Apache::lonlocal::texthash (
1.264     raeburn  7264:                              none     => 'No additional course requesters',
                   7265:                              domain   => "Any course requester in course's domain",
                   7266:                              instcode => 'Course requests for official courses ...',
                   7267:                           );
                   7268:         my (%codedefaults,@code_order,@posscodes);
                   7269:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   7270:                                                     \@code_order) eq 'ok') {
                   7271:             if (@code_order > 0) {
                   7272:                 push(@cloneoptions,'instcode');
                   7273:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   7274:             }
                   7275:         }
                   7276:         if (ref($settings) eq 'HASH') {
                   7277:             if ($settings->{'canclone'}) {
                   7278:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   7279:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   7280:                         if (@code_order > 0) {
                   7281:                             $currcanclone = 'instcode';
                   7282:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   7283:                         }
                   7284:                     }
                   7285:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   7286:                     $currcanclone = $settings->{'canclone'};
                   7287:                 }
                   7288:             }
1.289     raeburn  7289:         }
1.264     raeburn  7290:         foreach my $option (@cloneoptions) {
                   7291:             my ($checked,$additional);
                   7292:             if ($currcanclone eq $option) {
                   7293:                 $checked = ' checked="checked"';
                   7294:             }
                   7295:             if ($option eq 'instcode') {
                   7296:                 if (@code_order) {
                   7297:                     my $show = 'none';
                   7298:                     if ($checked) {
                   7299:                         $show = 'block';
                   7300:                     }
1.317     raeburn  7301:                     $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264     raeburn  7302:                                   &mt('Institutional codes for new and cloned course have identical:').
                   7303:                                   '<br />';
                   7304:                     foreach my $item (@code_order) {
                   7305:                         my $codechk;
                   7306:                         if ($checked) {
                   7307:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   7308:                                 $codechk = ' checked="checked"';
                   7309:                             }
                   7310:                         }
                   7311:                         $additional .= '<label>'.
                   7312:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   7313:                                        $item.'</label>';
                   7314:                     }
                   7315:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   7316:                 }
                   7317:             }
                   7318:             $datatable .=
                   7319:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   7320:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   7321:                 '</label>&nbsp;'.$additional.'</span><br />';
                   7322:         }
                   7323:         $datatable .= '</td>'.
                   7324:                       '</tr>';
                   7325:         $itemcount ++;
1.139     raeburn  7326:     } else {
                   7327:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  7328:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  7329:         my $currusecredits = 0;
1.257     raeburn  7330:         my $postsubmitclient = 1;
1.405     raeburn  7331:         my $ltiauth = 0;
1.271     raeburn  7332:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  7333:         if (ref($settings) eq 'HASH') {
1.404     raeburn  7334:             if ($settings->{'ltiauth'}) {
                   7335:                 $ltiauth = 1;
1.405     raeburn  7336:             }
1.139     raeburn  7337:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  7338:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   7339:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   7340:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   7341:                 }
                   7342:             }
1.192     raeburn  7343:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  7344:                 foreach my $type (@types) {
                   7345:                     next if ($type eq 'community');
                   7346:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   7347:                     if ($defcredits{$type} ne '') {
                   7348:                         $currusecredits = 1;
                   7349:                     }
                   7350:                 }
                   7351:             }
                   7352:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   7353:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   7354:                     $postsubmitclient = 0;
                   7355:                     foreach my $type (@types) {
                   7356:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7357:                     }
                   7358:                 } else {
                   7359:                     foreach my $type (@types) {
                   7360:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   7361:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  7362:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  7363:                             } else {
                   7364:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7365:                             }
                   7366:                         } else {
                   7367:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7368:                         }
                   7369:                     }
                   7370:                 }
                   7371:             } else {
                   7372:                 foreach my $type (@types) {
                   7373:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  7374:                 }
                   7375:             }
1.276     raeburn  7376:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   7377:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   7378:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   7379:                 }
                   7380:             } else {
                   7381:                 foreach my $type (@types) {
                   7382:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   7383:                 }
                   7384:             }
1.258     raeburn  7385:         } else {
                   7386:             foreach my $type (@types) {
                   7387:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7388:             }
1.139     raeburn  7389:         }
                   7390:         if (!$currdefresponder) {
1.198     raeburn  7391:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  7392:         } elsif ($currdefresponder < 1) {
                   7393:             $currdefresponder = 1;
                   7394:         }
1.198     raeburn  7395:         foreach my $type (@types) {
                   7396:             if ($curruploadquota{$type} eq '') {
                   7397:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   7398:             }
                   7399:         }
1.139     raeburn  7400:         $datatable .=
1.192     raeburn  7401:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7402:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  7403:                 '</span></td>'.
                   7404:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7405:                 '<input type="text" name="anonsurvey_threshold"'.
                   7406:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  7407:                 '</td></tr>'."\n";
                   7408:         $itemcount ++;
                   7409:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7410:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7411:                       $choices{'uploadquota'}.
                   7412:                       '</span></td>'.
1.306     raeburn  7413:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  7414:                       '<table><tr>';
1.198     raeburn  7415:         foreach my $type (@types) {
1.306     raeburn  7416:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  7417:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   7418:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   7419:         }
                   7420:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  7421:         $itemcount ++;
1.236     raeburn  7422:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  7423:         my $display = 'none';
1.192     raeburn  7424:         if ($currusecredits) {
                   7425:             $display = 'block';
                   7426:         }
                   7427:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  7428:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   7429:         foreach my $type (@types) {
                   7430:             next if ($type eq 'community');
1.306     raeburn  7431:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7432:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  7433:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  7434:         }
                   7435:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  7436:         %defaultchecked = ('coursecredits' => 'off');
                   7437:         @toggles = ('coursecredits');
                   7438:         my $current = {
                   7439:                         'coursecredits' => $currusecredits,
                   7440:                       };
                   7441:         (my $table,$itemcount) =
                   7442:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  7443:                                \%choices,$itemcount,$onclick,$additional,'left');
                   7444:         $datatable .= $table;
                   7445:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   7446:         my $display = 'none';
                   7447:         if ($postsubmitclient) {
                   7448:             $display = 'block';
                   7449:         }
                   7450:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  7451:                       &mt('Number of seconds submit is disabled').'<br />'.
                   7452:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   7453:                       '<table><tr>';
1.257     raeburn  7454:         foreach my $type (@types) {
1.306     raeburn  7455:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7456:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   7457:                            $deftimeout{$type}.'" size="5" /></td>';
                   7458:         }
                   7459:         $additional .= '</tr></table></div>'."\n";
                   7460:         %defaultchecked = ('postsubmit' => 'on');
                   7461:         @toggles = ('postsubmit');
1.280     raeburn  7462:         $current = {
                   7463:                        'postsubmit' => $postsubmitclient,
                   7464:                    };
1.257     raeburn  7465:         ($table,$itemcount) =
                   7466:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   7467:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  7468:         $datatable .= $table;
1.276     raeburn  7469:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7470:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7471:                       $choices{'mysqltables'}.
                   7472:                       '</span></td>'.
1.306     raeburn  7473:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  7474:                       '<table><tr>';
                   7475:         foreach my $type (@types) {
1.306     raeburn  7476:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  7477:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  7478:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  7479:         }
                   7480:         $datatable .= '</tr></table></td></tr>'."\n";
                   7481:         $itemcount ++;
1.404     raeburn  7482:         %defaultchecked = ('ltiauth' => 'off');
                   7483:         @toggles = ('ltiauth');
                   7484:         $current = {
                   7485:                        'ltiauth' => $ltiauth,
                   7486:                    };
                   7487:         ($table,$itemcount) =
                   7488:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   7489:                                \%choices,$itemcount,undef,undef,'left');
                   7490:         $datatable .= $table;
                   7491:         $itemcount ++;
1.139     raeburn  7492:     }
1.192     raeburn  7493:     $$rowtotal += $itemcount;
1.121     raeburn  7494:     return $datatable;
1.118     jms      7495: }
                   7496: 
1.231     raeburn  7497: sub print_selfenrollment {
                   7498:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7499:     my ($css_class,$datatable);
                   7500:     my $itemcount = 1;
1.271     raeburn  7501:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  7502:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  7503:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   7504:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  7505:         my @rows;
                   7506:         my $key;
                   7507:         if ($position eq 'top') {
                   7508:             $key = 'admin'; 
                   7509:             if (ref($rowsref) eq 'ARRAY') {
                   7510:                 @rows = @{$rowsref};
                   7511:             }
                   7512:         } elsif ($position eq 'middle') {
                   7513:             $key = 'default';
                   7514:             @rows = ('types','registered','approval','limit');
                   7515:         }
                   7516:         foreach my $row (@rows) {
                   7517:             if (defined($titlesref->{$row})) {
                   7518:                 $itemcount ++;
                   7519:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7520:                 $datatable .= '<tr'.$css_class.'>'.
                   7521:                               '<td>'.$titlesref->{$row}.'</td>'.
                   7522:                               '<td class="LC_left_item">'.
                   7523:                               '<table><tr>';
                   7524:                 my (%current,%currentcap);
                   7525:                 if (ref($settings) eq 'HASH') {
                   7526:                     if (ref($settings->{$key}) eq 'HASH') {
                   7527:                         foreach my $type (@types) {
                   7528:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7529:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   7530:                             }
                   7531:                             if (($row eq 'limit') && ($key eq 'default')) {
                   7532:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7533:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   7534:                                 }
                   7535:                             }
                   7536:                         }
                   7537:                     }
                   7538:                 }
                   7539:                 my %roles = (
                   7540:                              '0' => &Apache::lonnet::plaintext('dc'),
                   7541:                             ); 
                   7542:             
                   7543:                 foreach my $type (@types) {
                   7544:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   7545:                         $datatable .= '<th>'.&mt($type).'</th>';
                   7546:                     }
                   7547:                 }
                   7548:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   7549:                     $datatable .= '</tr><tr>';
                   7550:                 }
                   7551:                 foreach my $type (@types) {
                   7552:                     if ($type eq 'community') {
                   7553:                         $roles{'1'} = &mt('Community personnel');
                   7554:                     } else {
                   7555:                         $roles{'1'} = &mt('Course personnel');
                   7556:                     }
                   7557:                     $datatable .= '<td style="vertical-align: top">';
                   7558:                     if ($position eq 'top') {
                   7559:                         my %checked;
                   7560:                         if ($current{$type} eq '0') {
                   7561:                             $checked{'0'} = ' checked="checked"';
                   7562:                         } else {
                   7563:                             $checked{'1'} = ' checked="checked"';
                   7564:                         }
                   7565:                         foreach my $role ('1','0') {
                   7566:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7567:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   7568:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   7569:                                           $roles{$role}.'</label></span> ';
                   7570:                         }
                   7571:                     } else {
                   7572:                         if ($row eq 'types') {
                   7573:                             my %checked;
                   7574:                             if ($current{$type} =~ /^(all|dom)$/) {
                   7575:                                 $checked{$1} = ' checked="checked"';
                   7576:                             } else {
                   7577:                                 $checked{''} = ' checked="checked"';
                   7578:                             }
                   7579:                             foreach my $val ('','dom','all') {
                   7580:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7581:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7582:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7583:                             }
                   7584:                         } elsif ($row eq 'registered') {
                   7585:                             my %checked;
                   7586:                             if ($current{$type} eq '1') {
                   7587:                                 $checked{'1'} = ' checked="checked"';
                   7588:                             } else {
                   7589:                                 $checked{'0'} = ' checked="checked"';
                   7590:                             }
                   7591:                             foreach my $val ('0','1') {
                   7592:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7593:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7594:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7595:                             }
                   7596:                         } elsif ($row eq 'approval') {
                   7597:                             my %checked;
                   7598:                             if ($current{$type} =~ /^([12])$/) {
                   7599:                                 $checked{$1} = ' checked="checked"';
                   7600:                             } else {
                   7601:                                 $checked{'0'} = ' checked="checked"';
                   7602:                             }
                   7603:                             for my $val (0..2) {
                   7604:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7605:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7606:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7607:                             }
                   7608:                         } elsif ($row eq 'limit') {
                   7609:                             my %checked;
                   7610:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   7611:                                 $checked{$1} = ' checked="checked"';
                   7612:                             } else {
                   7613:                                 $checked{'none'} = ' checked="checked"';
                   7614:                             }
                   7615:                             my $cap;
                   7616:                             if ($currentcap{$type} =~ /^\d+$/) {
                   7617:                                 $cap = $currentcap{$type};
                   7618:                             }
                   7619:                             foreach my $val ('none','allstudents','selfenrolled') {
                   7620:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7621:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7622:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7623:                             }
                   7624:                             $datatable .= '<br />'.
                   7625:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   7626:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   7627:                                           '</span>'; 
                   7628:                         }
                   7629:                     }
                   7630:                     $datatable .= '</td>';
                   7631:                 }
                   7632:                 $datatable .= '</tr>';
                   7633:             }
                   7634:             $datatable .= '</table></td></tr>';
                   7635:         }
                   7636:     } elsif ($position eq 'bottom') {
1.235     raeburn  7637:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   7638:     }
                   7639:     $$rowtotal += $itemcount;
                   7640:     return $datatable;
                   7641: }
                   7642: 
                   7643: sub print_validation_rows {
                   7644:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   7645:     my ($itemsref,$namesref,$fieldsref);
                   7646:     if ($caller eq 'selfenroll') { 
                   7647:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   7648:     } elsif ($caller eq 'requestcourses') {
                   7649:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   7650:     }
                   7651:     my %currvalidation;
                   7652:     if (ref($settings) eq 'HASH') {
                   7653:         if (ref($settings->{'validation'}) eq 'HASH') {
                   7654:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  7655:         }
1.235     raeburn  7656:     }
                   7657:     my $datatable;
                   7658:     my $itemcount = 0;
                   7659:     foreach my $item (@{$itemsref}) {
                   7660:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7661:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7662:                       $namesref->{$item}.
                   7663:                       '</span></td>'.
                   7664:                       '<td class="LC_left_item">';
                   7665:         if (($item eq 'url') || ($item eq 'button')) {
                   7666:             $datatable .= '<span class="LC_nobreak">'.
                   7667:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   7668:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   7669:         } elsif ($item eq 'fields') {
                   7670:             my @currfields;
                   7671:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   7672:                 @currfields = @{$currvalidation{$item}};
                   7673:             }
                   7674:             foreach my $field (@{$fieldsref}) {
                   7675:                 my $check = '';
                   7676:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   7677:                     $check = ' checked="checked"';
                   7678:                 }
                   7679:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7680:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   7681:                               ' value="'.$field.'"'.$check.' />'.$field.
                   7682:                               '</label></span> ';
                   7683:             }
                   7684:         } elsif ($item eq 'markup') {
1.334     raeburn  7685:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235     raeburn  7686:                            $currvalidation{$item}.
1.231     raeburn  7687:                               '</textarea>';
1.235     raeburn  7688:         }
                   7689:         $datatable .= '</td></tr>'."\n";
                   7690:         if (ref($rowtotal)) {
1.231     raeburn  7691:             $itemcount ++;
                   7692:         }
                   7693:     }
1.235     raeburn  7694:     if ($caller eq 'requestcourses') {
                   7695:         my %currhash;
1.248     raeburn  7696:         if (ref($settings) eq 'HASH') {
                   7697:             if (ref($settings->{'validation'}) eq 'HASH') {
                   7698:                 if ($settings->{'validation'}{'dc'} ne '') {
                   7699:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   7700:                 }
1.235     raeburn  7701:             }
                   7702:         }
                   7703:         my $numinrow = 2;
                   7704:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   7705:                                                        'validationdc',%currhash);
1.247     raeburn  7706:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334     raeburn  7707:         $datatable .= '<tr'.$css_class.'><td>';
1.235     raeburn  7708:         if ($numdc > 1) {
1.247     raeburn  7709:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  7710:         } else {
1.247     raeburn  7711:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  7712:         }
1.247     raeburn  7713:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  7714:         $itemcount ++;
                   7715:     }
                   7716:     if (ref($rowtotal)) {
                   7717:         $$rowtotal += $itemcount;
                   7718:     }
1.231     raeburn  7719:     return $datatable;
                   7720: }
                   7721: 
1.357     raeburn  7722: sub print_privacy {
                   7723:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7724:     my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
                   7725:     my $itemcount = 0;
1.417     raeburn  7726:     if ($position eq 'top') {
                   7727:         $numinrow = 2;
                   7728:     } else {
1.357     raeburn  7729:         @items = ('domain','author','course','community');
                   7730:         %names = &Apache::lonlocal::texthash (
                   7731:                      domain => 'Assigned domain role(s)',
                   7732:                      author => 'Assigned co-author role(s)',
                   7733:                      course => 'Assigned course role(s)',
1.416     raeburn  7734:                      community => 'Assigned community role(s)',
1.357     raeburn  7735:                  );
                   7736:         $numinrow = 4;
                   7737:         ($othertitle,$usertypes,$types) =
                   7738:             &Apache::loncommon::sorted_inst_types($dom);
                   7739:     }
                   7740:     if (($position eq 'top') || ($position eq 'middle')) {
                   7741:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   7742:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   7743:         if ($position eq 'top') {
                   7744:             my %curr;
                   7745:             my @options = ('none','user','domain','auto');
                   7746:             my %titles = &Apache::lonlocal::texthash (
                   7747:                 none   => 'Not allowed',
                   7748:                 user   => 'User authorizes',
                   7749:                 domain => 'DC authorizes',
                   7750:                 auto   => 'Unrestricted',
                   7751:                 instdom => 'Other domain shares institution/provider',
                   7752:                 extdom => 'Other domain has different institution/provider',
1.418     raeburn  7753:                 notify => 'Notify when role needs authorization',
1.357     raeburn  7754:             );
                   7755:             my %names = &Apache::lonlocal::texthash (
                   7756:                 domain => 'Domain role',
                   7757:                 author => 'Co-author role',
                   7758:                 course => 'Course role',
                   7759:                 community => 'Community role',
                   7760:             );
                   7761:             my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7762:             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7763:             foreach my $domtype ('instdom','extdom') {
                   7764:                 my (%checked,$skip);
                   7765:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7766:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                   7767:                               '<td class="LC_left_item">';
                   7768:                 if ($domtype eq 'instdom') {
                   7769:                     unless (@instdoms > 1) {
                   7770:                         $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                   7771:                         $skip = 1;
                   7772:                     }
                   7773:                 } elsif ($domtype eq 'extdom') {
                   7774:                     if (keys(%by_location) == 0) {
                   7775:                         $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                   7776:                         $skip = 1;
                   7777:                     }
                   7778:                 }
                   7779:                 unless ($skip) {
                   7780:                     foreach my $roletype ('domain','author','course','community') {
                   7781:                         $checked{'auto'} = ' checked="checked"';
                   7782:                         if (ref($settings) eq 'HASH') {
                   7783:                             if (ref($settings->{approval}) eq 'HASH') {
                   7784:                                 if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                   7785:                                     if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                   7786:                                         $checked{$1} = ' checked="checked"';
                   7787:                                         $checked{'auto'} = '';
                   7788:                                     }
                   7789:                                 }
                   7790:                             }
                   7791:                         }
                   7792:                         $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                   7793:                         foreach my $option (@options) {
                   7794:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7795:                                           '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                   7796:                                           'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   7797:                                           '</label></span>&nbsp; ';
                   7798:                         }
                   7799:                         $datatable .= '</fieldset>';
                   7800:                     }
                   7801:                 }
                   7802:                 $datatable .= '</td></tr>';
                   7803:                 $itemcount ++;
                   7804:             }
1.417     raeburn  7805:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7806:             $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
                   7807:                           '<td class="LC_left_item">';
                   7808:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   7809:                 my %curr;
                   7810:                 if (ref($settings) eq 'HASH') {
                   7811:                     if ($settings->{'notify'} ne '') {
                   7812:                         map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
                   7813:                     }
                   7814:                 }
                   7815:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7816:                 my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
                   7817:                                                              'privacy_notify',%curr);
                   7818:                 if ($numdc > 0) {
                   7819:                     $datatable .= $table;
                   7820:                 } else {
                   7821:                     $datatable .= &mt('There are no active Domain Coordinators');
                   7822:                 }
                   7823:             } else {
                   7824:                 $datatable .= &mt('Nothing to set here, as there are no other domains');
                   7825:             }
                   7826:             $datatable .='</td></tr>';
1.357     raeburn  7827:         } elsif ($position eq 'middle') {
                   7828:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   7829:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7830:                     foreach my $item (@{$types}) {
                   7831:                         $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                   7832:                                                                $numinrow,$itemcount,'','','','','',
                   7833:                                                                '',$usertypes->{$item});
                   7834:                         $itemcount ++;
                   7835:                     }
                   7836:                 }
                   7837:                 $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                   7838:                                                        $numinrow,$itemcount,'','','','','',
                   7839:                                                        '',$othertitle);
                   7840:                 $itemcount ++;
                   7841:             } else {
1.360     raeburn  7842:                 my (@insttypes,%insttitles);
                   7843:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7844:                     @insttypes = @{$types};
                   7845:                     %insttitles = %{$usertypes};
                   7846:                 }
                   7847:                 foreach my $item (@insttypes,'default') {
                   7848:                     my $title;
                   7849:                     if ($item eq 'default') {
                   7850:                         $title = $othertitle;
                   7851:                     } else {
                   7852:                         $title = $insttitles{$item};
                   7853:                     }
                   7854:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7855:                     $datatable .= '<tr'.$css_class.'>'.
                   7856:                                   '<td class="LC_left_item">'.$title.'</td>'.
                   7857:                                   '<td class="LC_left_item">'.
                   7858:                                   &mt('Nothing to set here, as there are no other domains').
                   7859:                                   '</td></tr>';
                   7860:                     $itemcount ++;
                   7861:                 }
1.357     raeburn  7862:             }
                   7863:         }
                   7864:     } else {
                   7865:         my $prefix;
                   7866:         if ($position eq 'lower') {
                   7867:             $prefix = 'priv';
                   7868:         } else {
                   7869:             $prefix = 'unpriv';
                   7870:         }
                   7871:         foreach my $item (@items) {
                   7872:             $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                   7873:                                                    $numinrow,$itemcount,'','','','','',
                   7874:                                                    '',$names{$item});
                   7875:             $itemcount ++;
                   7876:         }
                   7877:     }
                   7878:     if (ref($rowtotal)) {
                   7879:         $$rowtotal += $itemcount;
                   7880:     }
                   7881:     return $datatable;
                   7882: }
                   7883: 
1.354     raeburn  7884: sub print_passwords {
                   7885:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   7886:     my ($datatable,$css_class);
                   7887:     my $itemcount = 0;
                   7888:     my %titles = &Apache::lonlocal::texthash (
                   7889:         captcha        => '"Forgot Password" CAPTCHA validation',
                   7890:         link           => 'Reset link expiration (hours)',
                   7891:         case           => 'Case-sensitive usernames/e-mail',
                   7892:         prelink        => 'Information required (form 1)',
                   7893:         postlink       => 'Information required (form 2)',
                   7894:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   7895:         customtext     => 'Domain specific text (HTML)',
                   7896:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   7897:         intauth_check  => 'Check bcrypt cost if authenticated',
                   7898:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   7899:         permanent      => 'Permanent e-mail address',
                   7900:         critical       => 'Critical notification address',
                   7901:         notify         => 'Notification address',
                   7902:         min            => 'Minimum password length',
                   7903:         max            => 'Maximum password length',
                   7904:         chars          => 'Required characters',
                   7905:         expire         => 'Password expiration (days)',
1.356     raeburn  7906:         numsaved       => 'Number of previous passwords to save and disallow reuse',
1.354     raeburn  7907:     );
                   7908:     if ($position eq 'top') {
                   7909:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7910:         my $shownlinklife = 2;
                   7911:         my $prelink = 'both';
                   7912:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   7913:         if (ref($settings) eq 'HASH') {
                   7914:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   7915:                 $shownlinklife = $settings->{resetlink};
                   7916:             }
                   7917:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   7918:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   7919:             }
                   7920:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   7921:                 $prelink = $settings->{resetprelink};
                   7922:             }
                   7923:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   7924:                 %postlink = %{$settings->{resetpostlink}};
                   7925:             }
                   7926:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   7927:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   7928:             }
                   7929:             if ($settings->{resetremove}) {
                   7930:                 $nostdtext = 1;
                   7931:             }
                   7932:             if ($settings->{resetcustom}) {
                   7933:                 $customurl = $settings->{resetcustom};
                   7934:             }
                   7935:         } else {
                   7936:             if (ref($types) eq 'ARRAY') {
                   7937:                 foreach my $item (@{$types}) {
                   7938:                     $casesens{$item} = 1;
                   7939:                     $postlink{$item} = ['username','email'];
                   7940:                 }
                   7941:             }
                   7942:             $casesens{'default'} = 1;
                   7943:             $postlink{'default'} = ['username','email'];
                   7944:             $prelink = 'both';
                   7945:             %emailsrc = (
                   7946:                           permanent => 1,
                   7947:                           critical  => 1,
                   7948:                           notify    => 1,
                   7949:             );
                   7950:         }
                   7951:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   7952:         $itemcount ++;
                   7953:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7954:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   7955:                       '<td class="LC_left_item">'.
                   7956:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   7957:                       'name="passwords_link" size="3" /></td></tr>';
                   7958:         $itemcount ++;
                   7959:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7960:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   7961:                       '<td class="LC_left_item">';
                   7962:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7963:             foreach my $item (@{$types}) {
                   7964:                 my $checkedcase;
                   7965:                 if ($casesens{$item}) {
                   7966:                     $checkedcase = ' checked="checked"';
                   7967:                 }
                   7968:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7969:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   7970:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369     raeburn  7971:                               '</span>&nbsp;&nbsp; ';
1.354     raeburn  7972:             }
                   7973:         }
                   7974:         my $checkedcase;
                   7975:         if ($casesens{'default'}) {
                   7976:             $checkedcase = ' checked="checked"';
                   7977:         }
                   7978:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   7979:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   7980:                       $othertitle.'</label></span></td>';
                   7981:         $itemcount ++;
                   7982:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7983:         my %checkedpre = (
                   7984:                              both => ' checked="checked"',
                   7985:                              either => '',
                   7986:                          );
                   7987:         if ($prelink eq 'either') {
                   7988:             $checkedpre{either} = ' checked="checked"';
                   7989:             $checkedpre{both} = '';
                   7990:         }
                   7991:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   7992:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   7993:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   7994:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   7995:                       '<span class="LC_nobreak"><label>'.
                   7996:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   7997:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   7998:         $itemcount ++;
                   7999:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8000:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   8001:                       '<td class="LC_left_item">';
                   8002:         my %postlinked;
                   8003:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   8004:             foreach my $item (@{$types}) {
                   8005:                 undef(%postlinked);
                   8006:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   8007:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   8008:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   8009:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   8010:                 }
                   8011:                 foreach my $field ('email','username') {
                   8012:                     my $checked;
                   8013:                     if ($postlinked{$field}) {
                   8014:                         $checked = ' checked="checked"';
                   8015:                     }
                   8016:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   8017:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   8018:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   8019:                                   '<span>&nbsp;&nbsp; ';
                   8020:                 }
                   8021:                 $datatable .= '</fieldset>';
                   8022:             }
                   8023:         }
                   8024:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   8025:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   8026:         }
                   8027:         $datatable .= '<fieldset style="display: inline-block;">'.
                   8028:                       '<legend>'.$othertitle.'</legend>';
                   8029:         foreach my $field ('email','username') {
                   8030:             my $checked;
                   8031:             if ($postlinked{$field}) {
                   8032:                 $checked = ' checked="checked"';
                   8033:             }
                   8034:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8035:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   8036:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   8037:                           '<span>&nbsp;&nbsp; ';
                   8038:         }
                   8039:         $datatable .= '</fieldset></td></tr>';
                   8040:         $itemcount ++;
                   8041:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8042:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   8043:                       '<td class="LC_left_item">';
                   8044:         foreach my $type ('permanent','critical','notify') {
                   8045:             my $checkedemail;
                   8046:             if ($emailsrc{$type}) {
                   8047:                 $checkedemail = ' checked="checked"';
                   8048:             }
                   8049:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8050:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   8051:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   8052:                           '<span>&nbsp;&nbsp; ';
                   8053:         }
                   8054:         $datatable .= '</td></tr>';
                   8055:         $itemcount ++;
                   8056:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8057:         my $switchserver = &check_switchserver($dom,$confname);
                   8058:         my ($showstd,$noshowstd);
                   8059:         if ($nostdtext) {
                   8060:             $noshowstd = ' checked="checked"';
                   8061:         } else {
                   8062:             $showstd = ' checked="checked"';
                   8063:         }
                   8064:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   8065:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8066:                       &mt('Retain standard text:').
                   8067:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   8068:                       &mt('Yes').'</label>'.'&nbsp;'.
                   8069:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   8070:                       &mt('No').'</label></span><br />'.
                   8071:                       '<span class="LC_fontsize_small">'.
                   8072:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   8073:                       &mt('Include custom text:');
                   8074:         if ($customurl) {
1.369     raeburn  8075:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354     raeburn  8076:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   8077:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   8078:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   8079:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   8080:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   8081:         }
                   8082:         if ($switchserver) {
                   8083:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   8084:         } else {
                   8085:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   8086:                          '<input type="file" name="passwords_customfile" /></span>';
                   8087:         }
                   8088:         $datatable .= '</td></tr>';
                   8089:     } elsif ($position eq 'middle') {
                   8090:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   8091:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   8092:         my %defaults;
                   8093:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   8094:             %defaults = %{$domconf{'defaults'}};
                   8095:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   8096:                 $defaults{'intauth_cost'} = 10;
                   8097:             }
                   8098:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   8099:                 $defaults{'intauth_check'} = 0;
                   8100:             }
                   8101:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   8102:                 $defaults{'intauth_switch'} = 0;
                   8103:             }
                   8104:         } else {
                   8105:             %defaults = (
                   8106:                           'intauth_cost'   => 10,
                   8107:                           'intauth_check'  => 0,
                   8108:                           'intauth_switch' => 0,
                   8109:                         );
                   8110:         }
                   8111:         foreach my $item (@items) {
                   8112:             if ($itemcount%2) {
                   8113:                 $css_class = '';
                   8114:             } else {
                   8115:                 $css_class = ' class="LC_odd_row" ';
                   8116:             }
                   8117:             $datatable .= '<tr'.$css_class.'>'.
                   8118:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   8119:                           '</span></td><td class="LC_left_item" colspan="3">';
                   8120:             if ($item eq 'intauth_switch') {
                   8121:                 my @options = (0,1,2);
                   8122:                 my %optiondesc = &Apache::lonlocal::texthash (
                   8123:                                    0 => 'No',
                   8124:                                    1 => 'Yes',
                   8125:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   8126:                                  );
                   8127:                 $datatable .= '<table width="100%">';
                   8128:                 foreach my $option (@options) {
                   8129:                     my $checked = ' ';
                   8130:                     if ($defaults{$item} eq $option) {
                   8131:                         $checked = ' checked="checked"';
                   8132:                     }
                   8133:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   8134:                                   '<label><input type="radio" name="'.$item.
                   8135:                                   '" value="'.$option.'"'.$checked.' />'.
                   8136:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   8137:                 }
                   8138:                 $datatable .= '</table>';
                   8139:             } elsif ($item eq 'intauth_check') {
                   8140:                 my @options = (0,1,2);
                   8141:                 my %optiondesc = &Apache::lonlocal::texthash (
                   8142:                                    0 => 'No',
                   8143:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   8144:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   8145:                                  );
                   8146:                 $datatable .= '<table width="100%">';
                   8147:                 foreach my $option (@options) {
                   8148:                     my $checked = ' ';
                   8149:                     my $onclick;
                   8150:                     if ($defaults{$item} eq $option) {
                   8151:                         $checked = ' checked="checked"';
                   8152:                     }
                   8153:                     if ($option == 2) {
                   8154:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   8155:                     }
                   8156:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   8157:                                   '<label><input type="radio" name="'.$item.
                   8158:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   8159:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   8160:                 }
                   8161:                 $datatable .= '</table>';
                   8162:             } else {
                   8163:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   8164:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   8165:             }
                   8166:             $datatable .= '</td></tr>';
                   8167:             $itemcount ++;
                   8168:         }
                   8169:     } elsif ($position eq 'lower') {
1.405     raeburn  8170:         $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354     raeburn  8171:     } else {
1.359     raeburn  8172:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   8173:         my %ownerchg = (
                   8174:                           by  => {},
                   8175:                           for => {},
                   8176:                        );
                   8177:         my %ownertitles = &Apache::lonlocal::texthash (
                   8178:                             by  => 'Course owner status(es) allowed',
                   8179:                             for => 'Student status(es) allowed',
                   8180:                           );
1.354     raeburn  8181:         if (ref($settings) eq 'HASH') {
1.359     raeburn  8182:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   8183:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   8184:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   8185:                 }
                   8186:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   8187:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   8188:                 }
1.354     raeburn  8189:             }
                   8190:         }
                   8191:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8192:         $datatable .= '<tr '.$css_class.'>'.
                   8193:                       '<td>'.
                   8194:                       &mt('Requirements').'<ul>'.
1.359     raeburn  8195:                       '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354     raeburn  8196:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   8197:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359     raeburn  8198:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354     raeburn  8199:                       '</ul>'.
                   8200:                       '</td>'.
1.359     raeburn  8201:                       '<td class="LC_left_item">';
                   8202:         foreach my $item ('by','for') {
                   8203:             $datatable .= '<fieldset style="display: inline-block;">'.
                   8204:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   8205:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   8206:                 foreach my $type (@{$types}) {
                   8207:                     my $checked;
                   8208:                     if ($ownerchg{$item}{$type}) {
                   8209:                         $checked = ' checked="checked"';
                   8210:                     }
                   8211:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   8212:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   8213:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369     raeburn  8214:                                   '</span>&nbsp;&nbsp; ';
1.359     raeburn  8215:                 }
                   8216:             }
                   8217:             my $checked;
                   8218:             if ($ownerchg{$item}{'default'}) {
                   8219:                 $checked = ' checked="checked"';
                   8220:             }
                   8221:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   8222:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   8223:                           $othertitle.'</label></span></fieldset>';
                   8224:         }
                   8225:         $datatable .= '</td></tr>';
1.354     raeburn  8226:     }
                   8227:     return $datatable;
                   8228: }
                   8229: 
1.405     raeburn  8230: sub password_rules {
                   8231:     my ($prefix,$itemcountref,$settings) = @_;
                   8232:     my ($min,$max,%chars,$expire,$numsaved,$numinrow);
                   8233:     my %titles;
                   8234:     if ($prefix eq 'passwords') {
                   8235:         %titles = &Apache::lonlocal::texthash (
                   8236:             min            => 'Minimum password length',
                   8237:             max            => 'Maximum password length',
                   8238:             chars          => 'Required characters',
                   8239:         );
                   8240:     } elsif ($prefix eq 'secrets') {
                   8241:         %titles = &Apache::lonlocal::texthash (
                   8242:             min            => 'Minimum secret length',
                   8243:             max            => 'Maximum secret length',
                   8244:             chars          => 'Required characters',
                   8245:         );
                   8246:     }
                   8247:     $min = $Apache::lonnet::passwdmin;
                   8248:     my $datatable;
                   8249:     my $itemcount;
                   8250:     if (ref($itemcountref)) {
                   8251:         $itemcount = $$itemcountref;
                   8252:     }
                   8253:     if (ref($settings) eq 'HASH') {
                   8254:         if ($settings->{min}) {
                   8255:             $min = $settings->{min};
                   8256:         }
                   8257:         if ($settings->{max}) {
                   8258:             $max = $settings->{max};
                   8259:         }
                   8260:         if (ref($settings->{chars}) eq 'ARRAY') {
                   8261:             map { $chars{$_} = 1; } (@{$settings->{chars}});
                   8262:         }
                   8263:         if ($prefix eq 'passwords') { 
                   8264:             if ($settings->{expire}) {
                   8265:                 $expire = $settings->{expire};
                   8266:             }
                   8267:             if ($settings->{numsaved}) {
                   8268:                 $numsaved = $settings->{numsaved};
                   8269:             }
                   8270:         }
                   8271:     }
                   8272:     my %rulenames = &Apache::lonlocal::texthash(
                   8273:                                                  uc => 'At least one upper case letter',
                   8274:                                                  lc => 'At least one lower case letter',
                   8275:                                                  num => 'At least one number',
                   8276:                                                  spec => 'At least one non-alphanumeric',
                   8277:                                                );
                   8278:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8279:     $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   8280:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8281:                   '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
                   8282:                   'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8283:                   '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
                   8284:                   '</span></td></tr>';
                   8285:     $itemcount ++;
                   8286:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8287:     $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   8288:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8289:                   '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
                   8290:                   'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8291:                   '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   8292:                   '</span></td></tr>';
                   8293:     $itemcount ++;
                   8294:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8295:     $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   8296:                   '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   8297:                   '</span></td>';
                   8298:     my $numinrow = 2;
                   8299:     my @possrules = ('uc','lc','num','spec');
                   8300:     $datatable .= '<td class="LC_left_item"><table>';
                   8301:     for (my $i=0; $i<@possrules; $i++) {
                   8302:         my ($rem,$checked);
                   8303:         if ($chars{$possrules[$i]}) {
                   8304:             $checked = ' checked="checked"';
                   8305:         }
                   8306:         $rem = $i%($numinrow);
                   8307:         if ($rem == 0) {
                   8308:             if ($i > 0) {
                   8309:                 $datatable .= '</tr>';
                   8310:             }
                   8311:             $datatable .= '<tr>';
                   8312:         }
                   8313:         $datatable .= '<td><span class="LC_nobreak"><label>'.
                   8314:                       '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   8315:                       $rulenames{$possrules[$i]}.'</label></span></td>';
                   8316:     }
                   8317:     my $rem = @possrules%($numinrow);
                   8318:     my $colsleft = $numinrow - $rem;
                   8319:     if ($colsleft > 1 ) {
                   8320:         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8321:                       '&nbsp;</td>';
                   8322:     } elsif ($colsleft == 1) {
                   8323:         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   8324:     }
                   8325:     $datatable .='</table></td></tr>';
                   8326:     $itemcount ++;
                   8327:     if ($prefix eq 'passwords') {
                   8328:         $titles{'expire'} = &mt('Password expiration (days)');
                   8329:         $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
                   8330:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8331:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                   8332:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8333:                       '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
                   8334:                       'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8335:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                   8336:                       '</span></td></tr>';
                   8337:         $itemcount ++;
                   8338:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8339:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   8340:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   8341:                       '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
                   8342:                       'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   8343:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   8344:                       '</span></td></tr>';
                   8345:         $itemcount ++;
                   8346:     }
                   8347:     if (ref($itemcountref)) {
                   8348:         $$itemcountref += $itemcount;
                   8349:     }
                   8350:     return $datatable;
                   8351: }
                   8352: 
1.373     raeburn  8353: sub print_wafproxy {
                   8354:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8355:     my $css_class;
                   8356:     my $itemcount = 0;
                   8357:     my $datatable;
                   8358:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  8359:     my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374     raeburn  8360:     my %lt = &wafproxy_titles();
1.373     raeburn  8361:     foreach my $server (sort(keys(%servers))) {
                   8362:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381     raeburn  8363:         next if ($serverhome eq '');
1.373     raeburn  8364:         my $serverdom;
                   8365:         if ($serverhome ne $server) {
                   8366:             $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381     raeburn  8367:             if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
                   8368:                 $othercontrol{$server} = $serverdom;
                   8369:             }
1.373     raeburn  8370:         } else {
                   8371:             $serverdom = &Apache::lonnet::host_domain($server);
1.381     raeburn  8372:             next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373     raeburn  8373:             if ($serverdom ne $dom) {
                   8374:                 $othercontrol{$server} = $serverdom;
                   8375:             } else {
                   8376:                 $setdom = 1;
                   8377:                 if (ref($settings) eq 'HASH') {
                   8378:                     if (ref($settings->{'alias'}) eq 'HASH') {
                   8379:                         $aliases{$dom} = $settings->{'alias'};
1.381     raeburn  8380:                         if ($aliases{$dom} ne '') {
                   8381:                             $showdom = 1;
                   8382:                         }
1.373     raeburn  8383:                     }
1.388     raeburn  8384:                     if (ref($settings->{'saml'}) eq 'HASH') {
                   8385:                         $saml{$dom} = $settings->{'saml'};
                   8386:                     }
1.373     raeburn  8387:                 }
                   8388:             }
                   8389:         }
                   8390:     }
1.381     raeburn  8391:     if ($setdom) {
                   8392:         %{$values{$dom}} = ();
                   8393:         if (ref($settings) eq 'HASH') {
                   8394:             foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   8395:                 $values{$dom}{$item} = $settings->{$item};
                   8396:             }
                   8397:         }
                   8398:     }
1.373     raeburn  8399:     if (keys(%othercontrol)) {
                   8400:         %otherdoms = reverse(%othercontrol);
                   8401:         foreach my $domain (keys(%otherdoms)) {
                   8402:             %{$values{$domain}} = ();
                   8403:             my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383     raeburn  8404:             if (ref($config{'wafproxy'}) eq 'HASH') {
                   8405:                 $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388     raeburn  8406:                 if (exists($config{'wafproxy'}{'saml'})) { 
                   8407:                     $saml{$domain} = $config{'wafproxy'}{'saml'};
                   8408:                 }
1.383     raeburn  8409:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   8410:                     $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373     raeburn  8411:                 }
                   8412:             }
                   8413:         }
                   8414:     }
                   8415:     if ($position eq 'top') {
                   8416:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381     raeburn  8417:         my %aliasinfo;
1.373     raeburn  8418:         foreach my $server (sort(keys(%servers))) {
1.381     raeburn  8419:             $itemcount ++;
                   8420:             my $dom_in_effect;
                   8421:             my $aliasrows = '<tr>'.
1.383     raeburn  8422:                             '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8423:                             &mt('Hostname').':&nbsp;'.
                   8424:                             '<i>'.&Apache::lonnet::hostname($server).'</i></td><td>&nbsp;</td>';
1.373     raeburn  8425:             if ($othercontrol{$server}) {
1.381     raeburn  8426:                 $dom_in_effect = $othercontrol{$server};
1.388     raeburn  8427:                 my ($current,$forsaml);
1.383     raeburn  8428:                 if (ref($aliases{$dom_in_effect}) eq 'HASH') {
                   8429:                     $current = $aliases{$dom_in_effect}{$server};
1.373     raeburn  8430:                 }
1.388     raeburn  8431:                 if (ref($saml{$dom_in_effect}) eq 'HASH') {
                   8432:                     if ($saml{$dom_in_effect}{$server}) {
                   8433:                         $forsaml = 1;
                   8434:                     }
                   8435:                 }
1.383     raeburn  8436:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8437:                               &mt('Alias').':&nbsp';
1.373     raeburn  8438:                 if ($current) {
1.381     raeburn  8439:                     $aliasrows .= $current;
1.388     raeburn  8440:                     if ($forsaml) {
1.396     raeburn  8441:                          $aliasrows .= '&nbsp;('.&mt('also for SSO Auth').')';
1.388     raeburn  8442:                     }
1.373     raeburn  8443:                 } else {
1.383     raeburn  8444:                     $aliasrows .= &mt('None');
1.373     raeburn  8445:                 }
1.383     raeburn  8446:                 $aliasrows .= '&nbsp;<span class="LC_small">('.
                   8447:                               &mt('controlled by domain: [_1]',
                   8448:                                   '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373     raeburn  8449:             } else {
1.381     raeburn  8450:                 $dom_in_effect = $dom;
1.388     raeburn  8451:                 my ($current,$samlon,$samloff);
                   8452:                 $samloff = ' checked="checked"';
1.373     raeburn  8453:                 if (ref($aliases{$dom}) eq 'HASH') {
                   8454:                     if ($aliases{$dom}{$server}) {
                   8455:                         $current = $aliases{$dom}{$server};
                   8456:                     }
                   8457:                 }
1.388     raeburn  8458:                 if (ref($saml{$dom}) eq 'HASH') {
                   8459:                     if ($saml{$dom}{$server}) {
                   8460:                         $samlon = $samloff;
                   8461:                         undef($samloff);
                   8462:                     }
                   8463:                 }
1.383     raeburn  8464:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8465:                               &mt('Alias').':&nbsp;'.
1.381     raeburn  8466:                               '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388     raeburn  8467:                               'value="'.$current.'" size="30" />'.
                   8468:                               ('&nbsp;'x2).'<span class="LC_nobreak">'.
1.396     raeburn  8469:                               &mt('Alias used for SSO Auth').':&nbsp;<label>'.
1.388     raeburn  8470:                               '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
                   8471:                               &mt('No').'</label>&nbsp;<label>'. 
                   8472:                               '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
                   8473:                               &mt('Yes').'</label></span>'.
                   8474:                               '</td>'; 
1.381     raeburn  8475:             }
                   8476:             $aliasrows .= '</tr>';
                   8477:             $aliasinfo{$dom_in_effect} .= $aliasrows;
                   8478:         }
                   8479:         if ($aliasinfo{$dom}) {
                   8480:             my ($onclick,$wafon,$wafoff,$showtable);
                   8481:             $onclick = ' onclick="javascript:toggleWAF();"';
                   8482:             $wafoff = ' checked="checked"';
                   8483:             $showtable = ' style="display:none";';
                   8484:             if ($showdom) {
                   8485:                 $wafon = $wafoff;
                   8486:                 $wafoff = '';
                   8487:                 $showtable = ' style="display:inline;"';
                   8488:             }
                   8489:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8490:             $datatable = '<tr'.$css_class.'>'.
                   8491:                          '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
                   8492:                          '<span class="LC_nobreak">'.&mt('WAF in use?').'&nbsp;<label>'.
                   8493:                          '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
                   8494:                          &mt('Yes').'</label>'.('&nbsp;'x2).'<label>'.
                   8495:                          '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
                   8496:                          &mt('No').'</label></span></td>'.
                   8497:                          '<td class="LC_left_item">'.
                   8498:                          '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
                   8499:                          '</table></td></tr>';
                   8500:             $itemcount++;
                   8501:         }
1.383     raeburn  8502:         if (keys(%otherdoms)) {
                   8503:             foreach my $key (sort(keys(%otherdoms))) {
1.381     raeburn  8504:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383     raeburn  8505:                 $datatable .= '<tr'.$css_class.'>'.
                   8506:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
                   8507:                               '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
                   8508:                               '</table></td></tr>';
1.381     raeburn  8509:                 $itemcount++;
1.373     raeburn  8510:             }
                   8511:         }
                   8512:     } else {
1.383     raeburn  8513:         my %ip_methods = &remoteip_methods();
1.373     raeburn  8514:         if ($setdom) {
                   8515:             $itemcount ++;
                   8516:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381     raeburn  8517:             my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382     raeburn  8518:                 $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381     raeburn  8519:             $wafstyle = ' style="display:none;"';
                   8520:             $nowafstyle = ' style="display:table-row;"';
                   8521:             $currwafdisplay = ' style="display: none"';
                   8522:             $wafrangestyle = ' style="display: none"';
                   8523:             $curr_remotip = 'n';
1.382     raeburn  8524:             $ssltossl = ' checked="checked"';
1.381     raeburn  8525:             if ($showdom) {
                   8526:                 $wafstyle = ' style="display:table-row;"';
                   8527:                 $nowafstyle =  ' style="display:none;"';
                   8528:                 if (keys(%{$values{$dom}})) {
                   8529:                     if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
                   8530:                         $curr_remotip = $values{$dom}{remoteip};
                   8531:                     }
                   8532:                     if ($curr_remotip eq 'h') {
                   8533:                         $currwafdisplay = ' style="display:table-row"';
                   8534:                         $wafrangestyle = ' style="display:inline-block;"';
                   8535:                     }
1.382     raeburn  8536:                     if ($values{$dom}{'sslopt'}) {
                   8537:                         $alltossl = ' checked="checked"';
                   8538:                         $ssltossl = '';
                   8539:                     }
1.381     raeburn  8540:                 }
                   8541:                 if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
                   8542:                     $vpndircheck = ' checked="checked"';
                   8543:                     $currwafvpn = ' style="display:table-row;"';
                   8544:                     $wafrangestyle = ' style="display:inline-block;"';
                   8545:                 } else {
                   8546:                     $vpnaliascheck = ' checked="checked"';
                   8547:                     $currwafvpn = ' style="display:none;"';
                   8548:                 }
                   8549:             }
                   8550:             $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                   8551:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
                   8552:                           '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
                   8553:                           '</tr>'.
                   8554:                           '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374     raeburn  8555:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381     raeburn  8556:                           '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393     raeburn  8557:                           &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   8558:                           &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381     raeburn  8559:                           '<td class="LC_left_item"><table>'.
                   8560:                           '<tr>'.
                   8561:                           '<td valign="top">'.$lt{'remoteip'}.':&nbsp;'.
                   8562:                           '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
                   8563:             foreach my $option ('m','h','n') {
                   8564:                 my $sel;
                   8565:                 if ($option eq $curr_remotip) {
                   8566:                    $sel = ' selected="selected"';
                   8567:                 }
                   8568:                 $datatable .= '<option value="'.$option.'"'.$sel.'>'.
                   8569:                               $ip_methods{$option}.'</option>';
                   8570:             }
                   8571:             $datatable .= '</select></td></tr>'."\n".
                   8572:                           '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
                   8573:                           $lt{'ipheader'}.':&nbsp;'.
                   8574:                           '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
                   8575:                           'name="wafproxy_ipheader" />'.
                   8576:                           '</td></tr>'."\n".
                   8577:                           '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382     raeburn  8578:                           $lt{'trusted'}.':<br />'.
1.381     raeburn  8579:                           '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
                   8580:                           $values{$dom}{'trusted'}.'</textarea>'.
                   8581:                           '</td></tr>'."\n".
                   8582:                           '<tr><td><hr /></td></tr>'."\n".
                   8583:                           '<tr>'.
                   8584:                           '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
                   8585:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
                   8586:                           $lt{'vpndirect'}.'</label>'.('&nbsp;'x2).
                   8587:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
                   8588:                           $lt{'vpnaliased'}.'</label></span></td></tr>';
                   8589:             foreach my $item ('vpnint','vpnext') {
                   8590:                 $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382     raeburn  8591:                               '<td valign="top">'.$lt{$item}.':<br />'.
1.381     raeburn  8592:                               '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
                   8593:                               $values{$dom}{$item}.'</textarea>'.
                   8594:                               '</td></tr>'."\n";
1.373     raeburn  8595:             }
1.382     raeburn  8596:             $datatable .= '<tr><td><hr /></td></tr>'."\n".
                   8597:                           '<tr>'.
                   8598:                           '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
                   8599:                           '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
                   8600:                           $lt{'alltossl'}.'</label>'.('&nbsp;'x2).
                   8601:                           '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
                   8602:                           $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
                   8603:                           '</table></td></tr>';
1.373     raeburn  8604:         }
                   8605:         if (keys(%otherdoms)) {
                   8606:             foreach my $domain (sort(keys(%otherdoms))) {
                   8607:                 $itemcount ++;
                   8608:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8609:                 $datatable .= '<tr'.$css_class.'>'.
1.383     raeburn  8610:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374     raeburn  8611:                               '<td class="LC_left_item"><table>';
1.382     raeburn  8612:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  8613:                     my $showval = &mt('None');
1.382     raeburn  8614:                     if ($item eq 'ssl') {
                   8615:                         $showval = $lt{'ssltossl'};
                   8616:                     }
1.373     raeburn  8617:                     if ($values{$domain}{$item}) {
1.381     raeburn  8618:                         $showval = $values{$domain}{$item};
1.382     raeburn  8619:                         if ($item eq 'ssl') {
                   8620:                             $showval = $lt{'alltossl'};
1.383     raeburn  8621:                         } elsif ($item eq 'remoteip') {
                   8622:                             $showval = $ip_methods{$values{$domain}{$item}};
1.382     raeburn  8623:                         }
1.373     raeburn  8624:                     }
                   8625:                     $datatable .= '<tr>'.
                   8626:                                   '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';
                   8627:                 }
1.381     raeburn  8628:                 $datatable .= '</table></td></tr>';
1.373     raeburn  8629:             }
                   8630:         }
                   8631:     }
                   8632:     $$rowtotal += $itemcount;
                   8633:     return $datatable;
                   8634: }
                   8635: 
                   8636: sub wafproxy_titles {
                   8637:     return &Apache::lonlocal::texthash(
1.381     raeburn  8638:                remoteip   => "Method for determining user's IP",
                   8639:                ipheader   => 'Request header containing remote IP',
                   8640:                trusted    => 'Trusted IP range(s)',
                   8641:                vpnaccess  => 'Access from institutional VPN',
                   8642:                vpndirect  => 'via regular hostname (no WAF)',
                   8643:                vpnaliased => 'via aliased hostname (WAF)',
                   8644:                vpnint     => 'Internal IP Range(s) for VPN sessions',
                   8645:                vpnext     => 'IP Range(s) for backend WAF connections',
1.382     raeburn  8646:                sslopt     => 'Forwarding http/https',
1.381     raeburn  8647:                alltossl   => 'WAF forwards both http and https requests to https',
                   8648:                ssltossl   => 'WAF forwards http requests to http and https to https',
                   8649:            );
                   8650: }
                   8651: 
                   8652: sub remoteip_methods {
                   8653:     return &Apache::lonlocal::texthash(
                   8654:               m => 'Use Apache mod_remoteip',
                   8655:               h => 'Use headers parsed by LON-CAPA',
                   8656:               n => 'Not in use',
1.373     raeburn  8657:            );
                   8658: }
                   8659: 
1.137     raeburn  8660: sub print_usersessions {
                   8661:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  8662:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  8663:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8664:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  8665: 
                   8666:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  8667:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  8668:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  8669:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  8670:     if ($position eq 'top') {
1.152     raeburn  8671:         if (keys(%serverhomes) > 1) {
1.145     raeburn  8672:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.371     raeburn  8673:             my ($curroffloadnow,$curroffloadoth);
1.261     raeburn  8674:             if (ref($settings) eq 'HASH') {
                   8675:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   8676:                     $curroffloadnow = $settings->{'offloadnow'};
                   8677:                 }
1.371     raeburn  8678:                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   8679:                     $curroffloadoth = $settings->{'offloadoth'};
                   8680:                 }
1.261     raeburn  8681:             }
1.371     raeburn  8682:             my $other_insts = scalar(keys(%by_location));
                   8683:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   8684:                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  8685:         } else {
1.140     raeburn  8686:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  8687:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   8688:                           '</td></tr>';
1.140     raeburn  8689:         }
1.137     raeburn  8690:     } else {
1.279     raeburn  8691:         my %titles = &usersession_titles();
                   8692:         my ($prefix,@types);
                   8693:         if ($position eq 'bottom') {
                   8694:             $prefix = 'remote';
                   8695:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  8696:         } else {
1.279     raeburn  8697:             $prefix = 'hosted';
                   8698:             @types = ('excludedomain','includedomain');
                   8699:         }
                   8700:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8701:     }
                   8702:     $$rowtotal += $itemcount;
                   8703:     return $datatable;
                   8704: }
                   8705: 
                   8706: sub rules_by_location {
                   8707:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   8708:     my ($datatable,$itemcount,$css_class);
                   8709:     if (keys(%{$by_location}) == 0) {
                   8710:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8711:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   8712:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   8713:                      '</td></tr>';
                   8714:         $itemcount = 1;
                   8715:     } else {
                   8716:         $itemcount = 0;
                   8717:         my $numinrow = 5;
                   8718:         my (%current,%checkedon,%checkedoff);
                   8719:         my @locations = sort(keys(%{$by_location}));
                   8720:         foreach my $type (@{$types}) {
                   8721:             $checkedon{$type} = '';
                   8722:             $checkedoff{$type} = ' checked="checked"';
                   8723:         }
                   8724:         if (ref($settings) eq 'HASH') {
                   8725:             if (ref($settings->{$prefix}) eq 'HASH') {
                   8726:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   8727:                     $current{$key} = $settings->{$prefix}{$key};
                   8728:                     if ($key eq 'version') {
                   8729:                         if ($current{$key} ne '') {
1.145     raeburn  8730:                             $checkedon{$key} = ' checked="checked"';
                   8731:                             $checkedoff{$key} = '';
                   8732:                         }
1.279     raeburn  8733:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   8734:                         $checkedon{$key} = ' checked="checked"';
                   8735:                         $checkedoff{$key} = '';
1.137     raeburn  8736:                     }
                   8737:                 }
                   8738:             }
1.279     raeburn  8739:         }
                   8740:         foreach my $type (@{$types}) {
                   8741:             next if ($type ne 'version' && !@locations);
                   8742:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8743:             $datatable .= '<tr'.$css_class.'>
                   8744:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   8745:                            <span class="LC_nobreak">&nbsp;
                   8746:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   8747:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   8748:             if ($type eq 'version') {
                   8749:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   8750:                 my $selector = '<select name="'.$prefix.'_version">';
                   8751:                 foreach my $version (@lcversions) {
                   8752:                     my $selected = '';
                   8753:                     if ($current{'version'} eq $version) {
                   8754:                         $selected = ' selected="selected"';
1.145     raeburn  8755:                     }
1.279     raeburn  8756:                     $selector .= ' <option value="'.$version.'"'.
                   8757:                                  $selected.'>'.$version.'</option>';
                   8758:                 }
                   8759:                 $selector .= '</select> ';
                   8760:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   8761:             } else {
                   8762:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   8763:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   8764:                              ' />'.('&nbsp;'x2).
                   8765:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   8766:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   8767:                              "\n".
                   8768:                              '</div><div><table>';
                   8769:                 my $rem;
                   8770:                 for (my $i=0; $i<@locations; $i++) {
                   8771:                     my ($showloc,$value,$checkedtype);
                   8772:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   8773:                         my $ip = $by_location->{$locations[$i]}->[0];
                   8774:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8775:                             $value = join(':',@{$by_ip->{$ip}});
                   8776:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   8777:                             if (ref($current{$type}) eq 'ARRAY') {
                   8778:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   8779:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   8780:                                         $checkedtype = ' checked="checked"';
                   8781:                                         last;
1.145     raeburn  8782:                                     }
1.138     raeburn  8783:                                 }
                   8784:                             }
                   8785:                         }
1.137     raeburn  8786:                     }
1.279     raeburn  8787:                     $rem = $i%($numinrow);
                   8788:                     if ($rem == 0) {
                   8789:                         if ($i > 0) {
                   8790:                             $datatable .= '</tr>';
                   8791:                         }
                   8792:                         $datatable .= '<tr>';
                   8793:                     }
                   8794:                     $datatable .= '<td class="LC_left_item">'.
                   8795:                                   '<span class="LC_nobreak"><label>'.
                   8796:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   8797:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   8798:                                   '</label></span></td>';
                   8799:                 }
                   8800:                 $rem = @locations%($numinrow);
                   8801:                 my $colsleft = $numinrow - $rem;
                   8802:                 if ($colsleft > 1 ) {
                   8803:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8804:                                   '&nbsp;</td>';
                   8805:                 } elsif ($colsleft == 1) {
                   8806:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  8807:                 }
1.279     raeburn  8808:                 $datatable .= '</tr></table>';
1.137     raeburn  8809:             }
1.279     raeburn  8810:             $datatable .= '</td></tr>';
                   8811:             $itemcount ++;
1.137     raeburn  8812:         }
                   8813:     }
1.279     raeburn  8814:     return ($datatable,$itemcount);
1.137     raeburn  8815: }
                   8816: 
1.275     raeburn  8817: sub print_ssl {
                   8818:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8819:     my ($css_class,$datatable);
                   8820:     my $itemcount = 1;
                   8821:     if ($position eq 'top') {
1.281     raeburn  8822:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8823:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8824:         my $same_institution;
                   8825:         if ($intdom ne '') {
                   8826:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   8827:             if (ref($internet_names) eq 'ARRAY') {
                   8828:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   8829:                     $same_institution = 1;
                   8830:                 }
                   8831:             }
                   8832:         }
1.275     raeburn  8833:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  8834:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   8835:         if ($same_institution) {
                   8836:             my %domservers = &Apache::lonnet::get_servers($dom);
                   8837:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   8838:         } else {
                   8839:             $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.");
                   8840:         }
                   8841:         $datatable .= '</td></tr>';
1.275     raeburn  8842:         $itemcount ++;
                   8843:     } else {
                   8844:         my %titles = &ssl_titles();
                   8845:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   8846:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8847:         my @alldoms = &Apache::lonnet::all_domains();
                   8848:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   8849:         my @domservers = &Apache::lonnet::get_servers($dom);
                   8850:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8851:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  8852:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   8853:             my $legacy;
                   8854:             unless (ref($settings) eq 'HASH') {
                   8855:                 my $name;
                   8856:                 if ($position eq 'connto') {
                   8857:                     $name = 'loncAllowInsecure';
                   8858:                 } else {
                   8859:                     $name = 'londAllowInsecure';
                   8860:                 }
                   8861:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   8862:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8863:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   8864:                     my %what = (
                   8865:                                    $name => 1,
                   8866:                                );
                   8867:                     my ($result,$returnhash) =
                   8868:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   8869:                     if ($result eq 'ok') {
                   8870:                         if (ref($returnhash) eq 'HASH') {
                   8871:                             $legacy = $returnhash->{$name};
                   8872:                         }
                   8873:                     }
                   8874:                 } else {
                   8875:                     $legacy = $Apache::lonnet::perlvar{$name};
                   8876:                 }
                   8877:             }
1.275     raeburn  8878:             foreach my $type ('dom','intdom','other') {
                   8879:                 my %checked;
                   8880:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8881:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   8882:                               '<td class="LC_right_item">';
                   8883:                 my $skip; 
                   8884:                 if ($type eq 'dom') {
                   8885:                     unless (keys(%servers) > 1) {
                   8886:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   8887:                         $skip = 1;
                   8888:                     }
                   8889:                 }
                   8890:                 if ($type eq 'intdom') {
                   8891:                     unless (@instdoms > 1) {
                   8892:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   8893:                         $skip = 1;
                   8894:                     } 
                   8895:                 } elsif ($type eq 'other') {
                   8896:                     if (keys(%by_location) == 0) {
                   8897:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   8898:                         $skip = 1;
                   8899:                     }
                   8900:                 }
                   8901:                 unless ($skip) {
                   8902:                     $checked{'yes'} = ' checked="checked"'; 
                   8903:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  8904:                         if (ref($settings->{$position}) eq 'HASH') {
                   8905:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  8906:                                 $checked{$1} = $checked{'yes'};
                   8907:                                 delete($checked{'yes'}); 
                   8908:                             }
                   8909:                         }
1.293     raeburn  8910:                     } else {
                   8911:                         if ($legacy == 0) {
                   8912:                             $checked{'req'} = $checked{'yes'};
                   8913:                             delete($checked{'yes'});    
                   8914:                         }
1.275     raeburn  8915:                     }
                   8916:                     foreach my $option ('no','yes','req') {
                   8917:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  8918:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  8919:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   8920:                                       '</label></span>'.('&nbsp;'x2);
                   8921:                     }
                   8922:                 }
                   8923:                 $datatable .= '</td></tr>';
                   8924:                 $itemcount ++; 
                   8925:             }
                   8926:         } else {
                   8927:             my $prefix = 'replication';
                   8928:             my @types = ('certreq','nocertreq');
1.279     raeburn  8929:             if (keys(%by_location) == 0) {
                   8930:                 $datatable .= '<tr'.$css_class.'><td>'.
                   8931:                               &mt('Nothing to set here, as there are no other institutions').
                   8932:                               '</td></tr>';
                   8933:                 $itemcount ++;
1.275     raeburn  8934:             } else {
1.279     raeburn  8935:                 ($datatable,$itemcount) = 
                   8936:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  8937:             }
                   8938:         }
                   8939:     }
                   8940:     $$rowtotal += $itemcount;
                   8941:     return $datatable;
                   8942: }
                   8943: 
                   8944: sub ssl_titles {
                   8945:     return &Apache::lonlocal::texthash (
                   8946:                dom           => 'LON-CAPA servers/VMs from same domain',
                   8947:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   8948:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  8949:                connto        => 'Connections to other servers',
                   8950:                connfrom      => 'Connections from other servers',
1.275     raeburn  8951:                replication   => 'Replicating content to other institutions',
                   8952:                certreq       => 'Client certificate required, but specific domains exempt',
                   8953:                nocertreq     => 'No client certificate required, except for specific domains',
                   8954:                no            => 'SSL not used',
                   8955:                yes           => 'SSL Optional (used if available)',
                   8956:                req           => 'SSL Required',
                   8957:     );
1.279     raeburn  8958: }
                   8959: 
                   8960: sub print_trust {
                   8961:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   8962:     my ($css_class,$datatable,%checked,%choices);
                   8963:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8964:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8965:     my $itemcount = 1;
                   8966:     my %titles = &trust_titles();
                   8967:     my @types = ('exc','inc');
                   8968:     if ($prefix eq 'top') {
                   8969:         $prefix = 'content';
                   8970:     } elsif ($prefix eq 'bottom') {
                   8971:         $prefix = 'msg';
                   8972:     }
                   8973:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8974:     $$rowtotal += $itemcount;
                   8975:     return $datatable;
                   8976: }
                   8977: 
                   8978: sub trust_titles {
                   8979:     return &Apache::lonlocal::texthash(
                   8980:                content  => "Access to this domain's content by others",
                   8981:                shared   => "Access to other domain's content by this domain",
                   8982:                enroll   => "Enrollment in this domain's courses by others", 
                   8983:                othcoau  => "Co-author roles in this domain for others",
                   8984:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   8985:                domroles => "Domain roles in this domain assignable to others",
                   8986:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   8987:                reqcrs   => "Requests for creation of courses in this domain by others",
                   8988:                msg      => "Users in other domains can send messages to this domain",
                   8989:                exc      => "Allow all, but exclude specific domains",
                   8990:                inc      => "Deny all, but include specific domains",
                   8991:            );
1.275     raeburn  8992: } 
                   8993: 
1.138     raeburn  8994: sub build_location_hashes {
1.275     raeburn  8995:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  8996:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  8997:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  8998:     my %iphost = &Apache::lonnet::get_iphost();
                   8999:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   9000:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   9001:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   9002:         foreach my $id (@{$iphost{$primary_ip}}) {
                   9003:             my $intdom = &Apache::lonnet::internet_dom($id);
                   9004:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   9005:                 push(@{$intdoms},$intdom);
                   9006:             }
                   9007:         }
                   9008:     }
                   9009:     foreach my $ip (keys(%iphost)) {
                   9010:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   9011:             foreach my $id (@{$iphost{$ip}}) {
                   9012:                 my $location = &Apache::lonnet::internet_dom($id);
                   9013:                 if ($location) {
1.275     raeburn  9014:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   9015:                         my $dom = &Apache::lonnet::host_domain($id);
                   9016:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   9017:                             push(@{$instdoms},$dom);
                   9018:                         }
                   9019:                         next;
                   9020:                     }
1.138     raeburn  9021:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   9022:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   9023:                             push(@{$by_ip->{$ip}},$location);
                   9024:                         }
                   9025:                     } else {
                   9026:                         $by_ip->{$ip} = [$location];
                   9027:                     }
                   9028:                 }
                   9029:             }
                   9030:         }
                   9031:     }
                   9032:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   9033:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   9034:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   9035:             my $first = $by_ip->{$ip}->[0];
                   9036:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   9037:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   9038:                     push(@{$by_location->{$first}},$ip);
                   9039:                 }
                   9040:             } else {
                   9041:                 $by_location->{$first} = [$ip];
                   9042:             }
                   9043:         }
                   9044:     }
                   9045:     return;
                   9046: }
                   9047: 
1.145     raeburn  9048: sub current_offloads_to {
                   9049:     my ($dom,$settings,$servers) = @_;
                   9050:     my (%spareid,%otherdomconfigs);
1.152     raeburn  9051:     if (ref($servers) eq 'HASH') {
1.145     raeburn  9052:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   9053:             my $gotspares;
1.152     raeburn  9054:             if (ref($settings) eq 'HASH') {
                   9055:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   9056:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   9057:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   9058:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   9059:                         $gotspares = 1;
                   9060:                     }
1.145     raeburn  9061:                 }
                   9062:             }
                   9063:             unless ($gotspares) {
                   9064:                 my $gotspares;
                   9065:                 my $serverhomeID =
                   9066:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   9067:                 my $serverhomedom =
                   9068:                     &Apache::lonnet::host_domain($serverhomeID);
                   9069:                 if ($serverhomedom ne $dom) {
                   9070:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   9071:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   9072:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   9073:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   9074:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   9075:                                 $gotspares = 1;
                   9076:                             }
                   9077:                         }
                   9078:                     } else {
                   9079:                         $otherdomconfigs{$serverhomedom} =
                   9080:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   9081:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   9082:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   9083:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   9084:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   9085:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   9086:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   9087:                                         $gotspares = 1;
                   9088:                                     }
                   9089:                                 }
                   9090:                             }
                   9091:                         }
                   9092:                     }
                   9093:                 }
                   9094:             }
                   9095:             unless ($gotspares) {
                   9096:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   9097:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   9098:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   9099:                } else {
                   9100:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   9101:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   9102:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   9103:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   9104:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   9105:                     } else {
1.150     raeburn  9106:                         my %what = (
                   9107:                              spareid => 1,
                   9108:                         );
                   9109:                         my ($result,$returnhash) = 
                   9110:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   9111:                         if ($result eq 'ok') { 
                   9112:                             if (ref($returnhash) eq 'HASH') {
                   9113:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   9114:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   9115:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   9116:                                 }
                   9117:                             }
1.145     raeburn  9118:                         }
                   9119:                     }
                   9120:                 }
                   9121:             }
                   9122:         }
                   9123:     }
                   9124:     return %spareid;
                   9125: }
                   9126: 
                   9127: sub spares_row {
1.371     raeburn  9128:     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   9129:         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  9130:     my $css_class;
                   9131:     my $numinrow = 4;
                   9132:     my $itemcount = 1;
                   9133:     my $datatable;
1.152     raeburn  9134:     my %typetitles = &sparestype_titles();
                   9135:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  9136:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  9137:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   9138:             my ($othercontrol,$serverdom);
                   9139:             if ($serverhome ne $server) {
                   9140:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   9141:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   9142:             } else {
                   9143:                 $serverdom = &Apache::lonnet::host_domain($server);
                   9144:                 if ($serverdom ne $dom) {
                   9145:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   9146:                 }
                   9147:             }
                   9148:             next unless (ref($spareid->{$server}) eq 'HASH');
1.371     raeburn  9149:             my ($checkednow,$checkedoth);
1.261     raeburn  9150:             if (ref($curroffloadnow) eq 'HASH') {
                   9151:                 if ($curroffloadnow->{$server}) {
                   9152:                     $checkednow = ' checked="checked"';
                   9153:                 }
                   9154:             }
1.371     raeburn  9155:             if (ref($curroffloadoth) eq 'HASH') {
                   9156:                 if ($curroffloadoth->{$server}) {
                   9157:                     $checkedoth = ' checked="checked"';
                   9158:                 }
                   9159:             }
1.145     raeburn  9160:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   9161:             $datatable .= '<tr'.$css_class.'>
                   9162:                            <td rowspan="2">
1.183     bisitz   9163:                             <span class="LC_nobreak">'.
                   9164:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  9165:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  9166:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  9167:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371     raeburn  9168:                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.183     bisitz   9169:                           "\n";
1.371     raeburn  9170:             if ($other_insts) {
                   9171:                 $datatable .= '<br />'.
                   9172:                               '<span class="LC_nobreak">'."\n".
                   9173:                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   9174:                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   9175:                           "\n";
                   9176:             }
1.145     raeburn  9177:             my (%current,%canselect);
1.152     raeburn  9178:             my @choices = 
                   9179:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   9180:             foreach my $type ('primary','default') {
                   9181:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  9182:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   9183:                         my @spares = @{$spareid->{$server}{$type}};
                   9184:                         if (@spares > 0) {
1.152     raeburn  9185:                             if ($othercontrol) {
                   9186:                                 $current{$type} = join(', ',@spares);
                   9187:                             } else {
                   9188:                                 $current{$type} .= '<table>';
                   9189:                                 my $numspares = scalar(@spares);
                   9190:                                 for (my $i=0;  $i<@spares; $i++) {
                   9191:                                     my $rem = $i%($numinrow);
                   9192:                                     if ($rem == 0) {
                   9193:                                         if ($i > 0) {
                   9194:                                             $current{$type} .= '</tr>';
                   9195:                                         }
                   9196:                                         $current{$type} .= '<tr>';
1.145     raeburn  9197:                                     }
1.152     raeburn  9198:                                     $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;'.
                   9199:                                                        $spareid->{$server}{$type}[$i].
                   9200:                                                        '</label></td>'."\n";
                   9201:                                 }
                   9202:                                 my $rem = @spares%($numinrow);
                   9203:                                 my $colsleft = $numinrow - $rem;
                   9204:                                 if ($colsleft > 1 ) {
                   9205:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   9206:                                                        '" class="LC_left_item">'.
                   9207:                                                        '&nbsp;</td>';
                   9208:                                 } elsif ($colsleft == 1) {
                   9209:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  9210:                                 }
1.152     raeburn  9211:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  9212:                             }
1.145     raeburn  9213:                         }
                   9214:                     }
                   9215:                     if ($current{$type} eq '') {
                   9216:                         $current{$type} = &mt('None specified');
                   9217:                     }
1.152     raeburn  9218:                     if ($othercontrol) {
                   9219:                         if ($type eq 'primary') {
                   9220:                             $canselect{$type} = $othercontrol;
                   9221:                         }
                   9222:                     } else {
                   9223:                         $canselect{$type} = 
                   9224:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   9225:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   9226:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   9227:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   9228:                         if (@choices > 0) {
                   9229:                             foreach my $lonhost (@choices) {
                   9230:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   9231:                             }
                   9232:                         }
                   9233:                         $canselect{$type} .= '</select>'."\n";
                   9234:                     }
                   9235:                 } else {
                   9236:                     $current{$type} = &mt('Could not be determined');
                   9237:                     if ($type eq 'primary') {
                   9238:                         $canselect{$type} =  $othercontrol;
                   9239:                     }
1.145     raeburn  9240:                 }
1.152     raeburn  9241:                 if ($type eq 'default') {
                   9242:                     $datatable .= '<tr'.$css_class.'>';
                   9243:                 }
                   9244:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   9245:                               '<td>'.$current{$type}.'</td>'."\n".
                   9246:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  9247:             }
                   9248:             $itemcount ++;
                   9249:         }
                   9250:     }
                   9251:     $$rowtotal += $itemcount;
                   9252:     return $datatable;
                   9253: }
                   9254: 
1.152     raeburn  9255: sub possible_newspares {
                   9256:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   9257:     my $serverhostname = &Apache::lonnet::hostname($server);
                   9258:     my %excluded;
                   9259:     if ($serverhostname ne '') {
                   9260:         %excluded = (
                   9261:                        $serverhostname => 1,
                   9262:                     );
                   9263:     }
                   9264:     if (ref($currspares) eq 'HASH') {
                   9265:         foreach my $type (keys(%{$currspares})) {
                   9266:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   9267:                 if (@{$currspares->{$type}} > 0) {
                   9268:                     foreach my $curr (@{$currspares->{$type}}) {
                   9269:                         my $hostname = &Apache::lonnet::hostname($curr);
                   9270:                         $excluded{$hostname} = 1;
                   9271:                     }
                   9272:                 }
                   9273:             }
                   9274:         }
                   9275:     }
                   9276:     my @choices;
                   9277:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   9278:         if (keys(%{$serverhomes}) > 1) {
                   9279:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   9280:                 unless ($excluded{$name}) {
                   9281:                     if (exists($altids->{$serverhomes->{$name}})) {
                   9282:                         push(@choices,$altids->{$serverhomes->{$name}});
                   9283:                     } else {
                   9284:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  9285:                     }
                   9286:                 }
                   9287:             }
                   9288:         }
                   9289:     }
1.152     raeburn  9290:     return sort(@choices);
1.145     raeburn  9291: }
                   9292: 
1.150     raeburn  9293: sub print_loadbalancing {
                   9294:     my ($dom,$settings,$rowtotal) = @_;
                   9295:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9296:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9297:     my $numinrow = 1;
                   9298:     my $datatable;
                   9299:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342     raeburn  9300:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  9301:     if (ref($settings) eq 'HASH') {
                   9302:         %existing = %{$settings};
                   9303:     }
                   9304:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   9305:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  9306:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  9307:     } else {
                   9308:         return;
                   9309:     }
                   9310:     my ($othertitle,$usertypes,$types) =
                   9311:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  9312:     my $rownum = 8;
1.150     raeburn  9313:     if (ref($types) eq 'ARRAY') {
                   9314:         $rownum += scalar(@{$types});
                   9315:     }
1.171     raeburn  9316:     my @css_class = ('LC_odd_row','LC_even_row');
                   9317:     my $balnum = 0;
                   9318:     my $islast;
                   9319:     my (@toshow,$disabledtext);
                   9320:     if (keys(%currbalancer) > 0) {
                   9321:         @toshow = sort(keys(%currbalancer));
                   9322:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   9323:             push(@toshow,'');
                   9324:         }
                   9325:     } else {
                   9326:         @toshow = ('');
                   9327:         $disabledtext = &mt('No existing load balancer');
                   9328:     }
                   9329:     foreach my $lonhost (@toshow) {
                   9330:         if ($balnum == scalar(@toshow)-1) {
                   9331:             $islast = 1;
                   9332:         } else {
                   9333:             $islast = 0;
                   9334:         }
                   9335:         my $cssidx = $balnum%2;
                   9336:         my $targets_div_style = 'display: none';
                   9337:         my $disabled_div_style = 'display: block';
                   9338:         my $homedom_div_style = 'display: none';
                   9339:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  9340:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  9341:                       '<p>';
                   9342:         if ($lonhost eq '') {
1.210     raeburn  9343:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  9344:             if (keys(%currbalancer) > 0) {
                   9345:                 $datatable .= &mt('Add balancer:');
                   9346:             } else {
                   9347:                 $datatable .= &mt('Enable balancer:');
                   9348:             }
                   9349:             $datatable .= '&nbsp;'.
                   9350:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   9351:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   9352:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   9353:                           '<option value="" selected="selected">'.&mt('None').
                   9354:                           '</option>'."\n";
                   9355:             foreach my $server (sort(keys(%servers))) {
                   9356:                 next if ($currbalancer{$server});
                   9357:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   9358:             }
1.210     raeburn  9359:             $datatable .=
1.171     raeburn  9360:                 '</select>'."\n".
                   9361:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   9362:         } else {
                   9363:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   9364:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   9365:                            &mt('Stop balancing').'</label>'.
                   9366:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   9367:             $targets_div_style = 'display: block';
                   9368:             $disabled_div_style = 'display: none';
                   9369:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   9370:                 $homedom_div_style = 'display: block';
                   9371:             }
                   9372:         }
1.306     raeburn  9373:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  9374:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   9375:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   9376:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   9377:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   9378:         my @sparestypes = ('primary','default');
                   9379:         my %typetitles = &sparestype_titles();
1.284     raeburn  9380:         my %hostherechecked = (
                   9381:                                   no => ' checked="checked"',
                   9382:                               );
1.342     raeburn  9383:         my %balcookiechecked = (
                   9384:                                   no => ' checked="checked"', 
                   9385:                                );
1.171     raeburn  9386:         foreach my $sparetype (@sparestypes) {
                   9387:             my $targettable;
                   9388:             for (my $i=0; $i<$numspares; $i++) {
                   9389:                 my $checked;
                   9390:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   9391:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   9392:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   9393:                             $checked = ' checked="checked"';
                   9394:                         }
                   9395:                     }
                   9396:                 }
                   9397:                 my ($chkboxval,$disabled);
                   9398:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   9399:                     $chkboxval = $spares[$i];
                   9400:                 }
                   9401:                 if (exists($currbalancer{$spares[$i]})) {
                   9402:                     $disabled = ' disabled="disabled"';
                   9403:                 }
1.210     raeburn  9404:                 $targettable .=
1.253     raeburn  9405:                     '<td><span class="LC_nobreak"><label>'.
                   9406:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  9407:                     $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  9408:                     '</span></label></span></td>';
1.171     raeburn  9409:                 my $rem = $i%($numinrow);
                   9410:                 if ($rem == 0) {
                   9411:                     if (($i > 0) && ($i < $numspares-1)) {
                   9412:                         $targettable .= '</tr>';
                   9413:                     }
                   9414:                     if ($i < $numspares-1) {
                   9415:                         $targettable .= '<tr>';
1.150     raeburn  9416:                     }
                   9417:                 }
                   9418:             }
1.171     raeburn  9419:             if ($targettable ne '') {
                   9420:                 my $rem = $numspares%($numinrow);
                   9421:                 my $colsleft = $numinrow - $rem;
                   9422:                 if ($colsleft > 1 ) {
                   9423:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9424:                                     '&nbsp;</td>';
                   9425:                 } elsif ($colsleft == 1) {
                   9426:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   9427:                 }
                   9428:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   9429:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   9430:             }
1.284     raeburn  9431:             $hostherechecked{$sparetype} = '';
                   9432:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   9433:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   9434:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   9435:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   9436:                         $hostherechecked{'no'} = '';
                   9437:                     }
                   9438:                 }
                   9439:             }
                   9440:         }
1.342     raeburn  9441:         if ($currcookies{$lonhost}) {
                   9442:             %balcookiechecked = (
                   9443:                                     yes => ' checked="checked"',
                   9444:                                 );
                   9445:         }
1.284     raeburn  9446:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   9447:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   9448:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   9449:         foreach my $sparetype (@sparestypes) {
                   9450:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   9451:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   9452:                           '</i></label><br />';
1.171     raeburn  9453:         }
1.342     raeburn  9454:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   9455:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   9456:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   9457:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   9458:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   9459:                       '</div></td></tr>'.
1.171     raeburn  9460:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   9461:                                            $othertitle,$usertypes,$types,\%servers,
                   9462:                                            \%currbalancer,$lonhost,
                   9463:                                            $targets_div_style,$homedom_div_style,
                   9464:                                            $css_class[$cssidx],$balnum,$islast);
                   9465:         $$rowtotal += $rownum;
                   9466:         $balnum ++;
                   9467:     }
                   9468:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   9469:     return $datatable;
                   9470: }
                   9471: 
                   9472: sub get_loadbalancers_config {
1.342     raeburn  9473:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171     raeburn  9474:     return unless ((ref($servers) eq 'HASH') &&
                   9475:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342     raeburn  9476:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   9477:                    (ref($currcookies) eq 'HASH'));
1.171     raeburn  9478:     if (keys(%{$existing}) > 0) {
                   9479:         my $oldlonhost;
                   9480:         foreach my $key (sort(keys(%{$existing}))) {
                   9481:             if ($key eq 'lonhost') {
                   9482:                 $oldlonhost = $existing->{'lonhost'};
                   9483:                 $currbalancer->{$oldlonhost} = 1;
                   9484:             } elsif ($key eq 'targets') {
                   9485:                 if ($oldlonhost) {
                   9486:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   9487:                 }
                   9488:             } elsif ($key eq 'rules') {
                   9489:                 if ($oldlonhost) {
                   9490:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   9491:                 }
                   9492:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   9493:                 $currbalancer->{$key} = 1;
                   9494:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   9495:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.342     raeburn  9496:                 if ($existing->{$key}{'cookie'}) {
                   9497:                     $currcookies->{$key} = 1;
                   9498:                 }
1.150     raeburn  9499:             }
                   9500:         }
1.171     raeburn  9501:     } else {
                   9502:         my ($balancerref,$targetsref) =
                   9503:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   9504:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   9505:             foreach my $server (sort(keys(%{$balancerref}))) {
                   9506:                 $currbalancer->{$server} = 1;
                   9507:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  9508:             }
                   9509:         }
                   9510:     }
1.171     raeburn  9511:     return;
1.150     raeburn  9512: }
                   9513: 
                   9514: sub loadbalancing_rules {
                   9515:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  9516:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   9517:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  9518:     my $output;
1.171     raeburn  9519:     my $num = 0;
1.210     raeburn  9520:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  9521:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   9522:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   9523:         foreach my $type (@{$alltypes}) {
1.171     raeburn  9524:             $num ++;
1.150     raeburn  9525:             my $current;
                   9526:             if (ref($currrules) eq 'HASH') {
                   9527:                 $current = $currrules->{$type};
                   9528:             }
1.253     raeburn  9529:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  9530:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  9531:                     $current = '';
                   9532:                 }
                   9533:             }
                   9534:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  9535:                                              $servers,$currbalancer,$lonhost,$dom,
                   9536:                                              $targets_div_style,$homedom_div_style,
                   9537:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  9538:         }
                   9539:     }
                   9540:     return $output;
                   9541: }
                   9542: 
                   9543: sub loadbalancing_titles {
                   9544:     my ($dom,$intdom,$usertypes,$types) = @_;
                   9545:     my %othertypes = (
                   9546:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   9547:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   9548:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   9549:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  9550:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   9551:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  9552:                      );
1.209     raeburn  9553:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  9554:     my @available;
1.150     raeburn  9555:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  9556:         @available = @{$types};
1.150     raeburn  9557:     }
1.302     raeburn  9558:     unless (grep(/^default$/,@available)) {
                   9559:         push(@available,'default');
                   9560:     }
                   9561:     unshift(@alltypes,@available);
1.150     raeburn  9562:     my %titles;
                   9563:     foreach my $type (@alltypes) {
                   9564:         if ($type =~ /^_LC_/) {
                   9565:             $titles{$type} = $othertypes{$type};
                   9566:         } elsif ($type eq 'default') {
                   9567:             $titles{$type} = &mt('All users from [_1]',$dom);
                   9568:             if (ref($types) eq 'ARRAY') {
                   9569:                 if (@{$types} > 0) {
                   9570:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   9571:                 }
                   9572:             }
                   9573:         } elsif (ref($usertypes) eq 'HASH') {
                   9574:             $titles{$type} = $usertypes->{$type};
                   9575:         }
                   9576:     }
                   9577:     return (\@alltypes,\%othertypes,\%titles);
                   9578: }
                   9579: 
                   9580: sub loadbalance_rule_row {
1.171     raeburn  9581:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   9582:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  9583:     my @rulenames;
1.150     raeburn  9584:     my %ruletitles = &offloadtype_text();
1.209     raeburn  9585:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  9586:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  9587:     } else {
1.209     raeburn  9588:         @rulenames = ('default','homeserver');
                   9589:         if ($type eq '_LC_external') {
                   9590:             push(@rulenames,'externalbalancer');
                   9591:         } else {
                   9592:             push(@rulenames,'specific');
                   9593:         }
                   9594:         push(@rulenames,'none');
1.150     raeburn  9595:     }
                   9596:     my $style = $targets_div_style;
1.253     raeburn  9597:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  9598:         $style = $homedom_div_style;
                   9599:     }
1.171     raeburn  9600:     my $space;
                   9601:     if ($islast && $num == 1) {
1.317     raeburn  9602:         $space = '<div style="display:inline-block;">&nbsp;</div>';
1.171     raeburn  9603:     }
1.210     raeburn  9604:     my $output =
1.306     raeburn  9605:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  9606:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   9607:         '<td valaign="top">'.$space.
                   9608:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  9609:     for (my $i=0; $i<@rulenames; $i++) {
                   9610:         my $rule = $rulenames[$i];
                   9611:         my ($checked,$extra);
                   9612:         if ($rulenames[$i] eq 'default') {
                   9613:             $rule = '';
                   9614:         }
                   9615:         if ($rulenames[$i] eq 'specific') {
                   9616:             if (ref($servers) eq 'HASH') {
                   9617:                 my $default;
                   9618:                 if (($current ne '') && (exists($servers->{$current}))) {
                   9619:                     $checked = ' checked="checked"';
                   9620:                 }
                   9621:                 unless ($checked) {
                   9622:                     $default = ' selected="selected"';
                   9623:                 }
1.210     raeburn  9624:                 $extra =
1.171     raeburn  9625:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9626:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9627:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   9628:                     '<option value=""'.$default.'></option>'."\n";
                   9629:                 foreach my $server (sort(keys(%{$servers}))) {
                   9630:                     if (ref($currbalancer) eq 'HASH') {
                   9631:                         next if (exists($currbalancer->{$server}));
                   9632:                     }
1.150     raeburn  9633:                     my $selected;
1.171     raeburn  9634:                     if ($server eq $current) {
1.150     raeburn  9635:                         $selected = ' selected="selected"';
                   9636:                     }
1.171     raeburn  9637:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  9638:                 }
                   9639:                 $extra .= '</select>';
                   9640:             }
                   9641:         } elsif ($rule eq $current) {
                   9642:             $checked = ' checked="checked"';
                   9643:         }
                   9644:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  9645:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   9646:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   9647:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  9648:                    ')"'.$checked.' />&nbsp;';
                   9649:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   9650:             $output .= $ruletitles{'particular'};
                   9651:         } else {
                   9652:             $output .= $ruletitles{$rulenames[$i]};
                   9653:         }
                   9654:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  9655:     }
                   9656:     $output .= '</div></td></tr>'."\n";
                   9657:     return $output;
                   9658: }
                   9659: 
                   9660: sub offloadtype_text {
                   9661:     my %ruletitles = &Apache::lonlocal::texthash (
                   9662:            'default'          => 'Offloads to default destinations',
                   9663:            'homeserver'       => "Offloads to user's home server",
                   9664:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   9665:            'specific'         => 'Offloads to specific server',
1.161     raeburn  9666:            'none'             => 'No offload',
1.209     raeburn  9667:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   9668:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  9669:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  9670:     );
                   9671:     return %ruletitles;
                   9672: }
                   9673: 
                   9674: sub sparestype_titles {
                   9675:     my %typestitles = &Apache::lonlocal::texthash (
                   9676:                           'primary' => 'primary',
                   9677:                           'default' => 'default',
                   9678:                       );
                   9679:     return %typestitles;
                   9680: }
                   9681: 
1.28      raeburn  9682: sub contact_titles {
                   9683:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  9684:                    'supportemail'    => 'Support E-mail address',
                   9685:                    'adminemail'      => 'Default Server Admin E-mail address',
                   9686:                    'errormail'       => 'Error reports to be e-mailed to',
                   9687:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  9688:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   9689:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  9690:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   9691:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   9692:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  9693:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350     raeburn  9694:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.378     raeburn  9695:                    'errorthreshold'  => 'Error count threshold for status e-mail to admin(s)',
                   9696:                    'errorsysmail'    => 'Error count threshold for e-mail to developer group',
1.340     raeburn  9697:                    'errorweights'    => 'Weights used to compute error count',
                   9698:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  9699:                  );
                   9700:     my %short_titles = &Apache::lonlocal::texthash (
                   9701:                            adminemail   => 'Admin E-mail address',
                   9702:                            supportemail => 'Support E-mail',
                   9703:                        );   
                   9704:     return (\%titles,\%short_titles);
                   9705: }
                   9706: 
1.286     raeburn  9707: sub helpform_fields {
                   9708:     my %titles =  &Apache::lonlocal::texthash (
                   9709:                        'username'   => 'Name',
                   9710:                        'user'       => 'Username/domain',
                   9711:                        'phone'      => 'Phone',
                   9712:                        'cc'         => 'Cc e-mail',
                   9713:                        'course'     => 'Course Details',
                   9714:                        'section'    => 'Sections',
1.289     raeburn  9715:                        'screenshot' => 'File upload',
1.286     raeburn  9716:     );
                   9717:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   9718:     my %possoptions = (
                   9719:                         username     => ['yes','no','req'],
1.289     raeburn  9720:                         phone        => ['yes','no','req'],
1.286     raeburn  9721:                         user         => ['yes','no'],
1.289     raeburn  9722:                         cc           => ['yes','no'],
1.286     raeburn  9723:                         course       => ['yes','no'],
                   9724:                         section      => ['yes','no'],
                   9725:                         screenshot   => ['yes','no'],
                   9726:                       );
                   9727:     my %fieldoptions = &Apache::lonlocal::texthash (
                   9728:                          'yes'  => 'Optional',
                   9729:                          'req'  => 'Required',
                   9730:                          'no'   => "Not shown",
                   9731:     );
                   9732:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   9733: }
                   9734: 
1.72      raeburn  9735: sub tool_titles {
                   9736:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  9737:                      aboutme    => 'Personal web page',
1.86      raeburn  9738:                      blog       => 'Blog',
1.162     raeburn  9739:                      webdav     => 'WebDAV',
1.86      raeburn  9740:                      portfolio  => 'Portfolio',
1.413     raeburn  9741:                      timezone   => 'Can set time zone',
1.88      bisitz   9742:                      official   => 'Official courses (with institutional codes)',
                   9743:                      unofficial => 'Unofficial courses',
1.98      raeburn  9744:                      community  => 'Communities',
1.216     raeburn  9745:                      textbook   => 'Textbook courses',
1.271     raeburn  9746:                      placement  => 'Placement tests',
1.86      raeburn  9747:                  );
1.72      raeburn  9748:     return %titles;
                   9749: }
                   9750: 
1.101     raeburn  9751: sub courserequest_titles {
                   9752:     my %titles = &Apache::lonlocal::texthash (
                   9753:                                    official   => 'Official',
                   9754:                                    unofficial => 'Unofficial',
                   9755:                                    community  => 'Communities',
1.216     raeburn  9756:                                    textbook   => 'Textbook',
1.271     raeburn  9757:                                    placement  => 'Placement tests',
1.325     raeburn  9758:                                    lti        => 'LTI Provider',
1.101     raeburn  9759:                                    norequest  => 'Not allowed',
1.325     raeburn  9760:                                    approval   => 'Approval by DC',
1.101     raeburn  9761:                                    validate   => 'With validation',
                   9762:                                    autolimit  => 'Numerical limit',
1.103     raeburn  9763:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  9764:                  );
                   9765:     return %titles;
                   9766: }
                   9767: 
1.163     raeburn  9768: sub authorrequest_titles {
                   9769:     my %titles = &Apache::lonlocal::texthash (
                   9770:                                    norequest  => 'Not allowed',
                   9771:                                    approval   => 'Approval by Dom. Coord.',
                   9772:                                    automatic  => 'Automatic approval',
                   9773:                  );
                   9774:     return %titles;
1.210     raeburn  9775: }
1.163     raeburn  9776: 
1.101     raeburn  9777: sub courserequest_conditions {
                   9778:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  9779:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   9780:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  9781:                  );
                   9782:     return %conditions;
                   9783: }
                   9784: 
                   9785: 
1.27      raeburn  9786: sub print_usercreation {
1.30      raeburn  9787:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  9788:     my $numinrow = 4;
1.28      raeburn  9789:     my $datatable;
                   9790:     if ($position eq 'top') {
1.30      raeburn  9791:         $$rowtotal ++;
1.34      raeburn  9792:         my $rowcount = 0;
1.32      raeburn  9793:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  9794:         if (ref($rules) eq 'HASH') {
                   9795:             if (keys(%{$rules}) > 0) {
1.32      raeburn  9796:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   9797:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  9798:                 $$rowtotal ++;
1.32      raeburn  9799:                 $rowcount ++;
                   9800:             }
                   9801:         }
                   9802:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   9803:         if (ref($idrules) eq 'HASH') {
                   9804:             if (keys(%{$idrules}) > 0) {
                   9805:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   9806:                                                 $idruleorder,$numinrow,$rowcount);
                   9807:                 $$rowtotal ++;
                   9808:                 $rowcount ++;
1.28      raeburn  9809:             }
                   9810:         }
1.39      raeburn  9811:         if ($rowcount == 0) {
                   9812:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   9813:             $$rowtotal ++;
                   9814:             $rowcount ++;
                   9815:         }
1.34      raeburn  9816:     } elsif ($position eq 'middle') {
1.224     raeburn  9817:         my @creators = ('author','course','requestcrs');
1.37      raeburn  9818:         my ($rules,$ruleorder) =
                   9819:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  9820:         my %lt = &usercreation_types();
                   9821:         my %checked;
                   9822:         if (ref($settings) eq 'HASH') {
                   9823:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9824:                 foreach my $item (@creators) {
                   9825:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   9826:                 }
                   9827:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   9828:                 foreach my $item (@creators) {
                   9829:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   9830:                         $checked{$item} = 'none';
                   9831:                     }
                   9832:                 }
                   9833:             }
                   9834:         }
                   9835:         my $rownum = 0;
                   9836:         foreach my $item (@creators) {
                   9837:             $rownum ++;
1.224     raeburn  9838:             if ($checked{$item} eq '') {
                   9839:                 $checked{$item} = 'any';
1.34      raeburn  9840:             }
                   9841:             my $css_class;
                   9842:             if ($rownum%2) {
                   9843:                 $css_class = '';
                   9844:             } else {
                   9845:                 $css_class = ' class="LC_odd_row" ';
                   9846:             }
                   9847:             $datatable .= '<tr'.$css_class.'>'.
                   9848:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  9849:                          '</span></td><td style="text-align: right">';
1.224     raeburn  9850:             my @options = ('any');
                   9851:             if (ref($rules) eq 'HASH') {
                   9852:                 if (keys(%{$rules}) > 0) {
                   9853:                     push(@options,('official','unofficial'));
1.37      raeburn  9854:                 }
                   9855:             }
1.224     raeburn  9856:             push(@options,'none');
1.37      raeburn  9857:             foreach my $option (@options) {
1.50      raeburn  9858:                 my $type = 'radio';
1.34      raeburn  9859:                 my $check = ' ';
1.224     raeburn  9860:                 if ($checked{$item} eq $option) {
                   9861:                     $check = ' checked="checked" ';
1.34      raeburn  9862:                 } 
                   9863:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  9864:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  9865:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   9866:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   9867:             }
                   9868:             $datatable .= '</td></tr>';
                   9869:         }
1.28      raeburn  9870:     } else {
                   9871:         my @contexts = ('author','course','domain');
1.325     raeburn  9872:         my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  9873:         my %checked;
                   9874:         if (ref($settings) eq 'HASH') {
                   9875:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   9876:                 foreach my $item (@contexts) {
                   9877:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   9878:                         foreach my $auth (@authtypes) {
                   9879:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   9880:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   9881:                             }
                   9882:                         }
                   9883:                     }
                   9884:                 }
1.27      raeburn  9885:             }
1.35      raeburn  9886:         } else {
                   9887:             foreach my $item (@contexts) {
1.36      raeburn  9888:                 foreach my $auth (@authtypes) {
1.35      raeburn  9889:                     $checked{$item}{$auth} = ' checked="checked" ';
                   9890:                 }
                   9891:             }
1.27      raeburn  9892:         }
1.28      raeburn  9893:         my %title = &context_names();
                   9894:         my %authname = &authtype_names();
                   9895:         my $rownum = 0;
                   9896:         my $css_class; 
                   9897:         foreach my $item (@contexts) {
                   9898:             if ($rownum%2) {
                   9899:                 $css_class = '';
                   9900:             } else {
                   9901:                 $css_class = ' class="LC_odd_row" ';
                   9902:             }
1.30      raeburn  9903:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  9904:                             '<td>'.$title{$item}.
                   9905:                             '</td><td class="LC_left_item">'.
                   9906:                             '<span class="LC_nobreak">';
                   9907:             foreach my $auth (@authtypes) {
                   9908:                 $datatable .= '<label>'. 
                   9909:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   9910:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   9911:                               $authname{$auth}.'</label>&nbsp;';
                   9912:             }
                   9913:             $datatable .= '</span></td></tr>';
                   9914:             $rownum ++;
1.27      raeburn  9915:         }
1.30      raeburn  9916:         $$rowtotal += $rownum;
1.27      raeburn  9917:     }
                   9918:     return $datatable;
                   9919: }
                   9920: 
1.224     raeburn  9921: sub print_selfcreation {
                   9922:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  9923:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   9924:         $emaildomain,$datatable);
1.224     raeburn  9925:     if (ref($settings) eq 'HASH') {
                   9926:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9927:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  9928:             if (ref($createsettings) eq 'HASH') {
                   9929:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   9930:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   9931:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   9932:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   9933:                         @selfcreate = ('email','login','sso');
                   9934:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   9935:                         @selfcreate = ($createsettings->{'selfcreate'});
                   9936:                     }
                   9937:                 }
                   9938:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   9939:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  9940:                 }
1.305     raeburn  9941:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   9942:                     $emailoptions = $createsettings->{'emailoptions'};
                   9943:                 }
1.303     raeburn  9944:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   9945:                     $emailverified = $createsettings->{'emailverified'};
                   9946:                 }
                   9947:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   9948:                     $emaildomain = $createsettings->{'emaildomain'};
                   9949:                 }
1.224     raeburn  9950:             }
                   9951:         }
                   9952:     }
                   9953:     my %radiohash;
                   9954:     my $numinrow = 4;
                   9955:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  9956:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  9957:     if ($position eq 'top') {
                   9958:         my %choices = &Apache::lonlocal::texthash (
                   9959:                                                       cancreate_login      => 'Institutional Login',
                   9960:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   9961:                                                   );
                   9962:         my @toggles = sort(keys(%choices));
                   9963:         my %defaultchecked = (
                   9964:                                'cancreate_login' => 'off',
                   9965:                                'cancreate_sso'   => 'off',
                   9966:                              );
1.228     raeburn  9967:         my ($onclick,$itemcount);
1.224     raeburn  9968:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   9969:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  9970:         $$rowtotal += $itemcount;
                   9971:         
1.224     raeburn  9972:         if (ref($usertypes) eq 'HASH') {
                   9973:             if (keys(%{$usertypes}) > 0) {
                   9974:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   9975:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  9976:                                              'statustocreate',$rowtotal);
1.224     raeburn  9977:                 $$rowtotal ++;
                   9978:             }
                   9979:         }
1.240     raeburn  9980:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   9981:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9982:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   9983:         my $rem;
                   9984:         my $numperrow = 2;
                   9985:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   9986:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  9987:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  9988:                      '<td class="LC_left_item">'."\n".
1.334     raeburn  9989:                      '<table>'."\n";
1.240     raeburn  9990:         for (my $i=0; $i<@fields; $i++) {
                   9991:             $rem = $i%($numperrow);
                   9992:             if ($rem == 0) {
                   9993:                 if ($i > 0) {
                   9994:                     $datatable .= '</tr>';
                   9995:                 }
                   9996:                 $datatable .= '<tr>';
                   9997:             }
                   9998:             my $currval;
1.248     raeburn  9999:             if (ref($createsettings) eq 'HASH') {
                   10000:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   10001:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   10002:                 }
1.240     raeburn  10003:             }
                   10004:             $datatable .= '<td class="LC_left_item">'.
                   10005:                           '<span class="LC_nobreak">'.
                   10006:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   10007:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   10008:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   10009:         }
                   10010:         my $colsleft = $numperrow - $rem;
                   10011:         if ($colsleft > 1 ) {
                   10012:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   10013:                          '&nbsp;</td>';
                   10014:         } elsif ($colsleft == 1) {
                   10015:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   10016:         }
                   10017:         $datatable .= '</tr></table></td></tr>';
                   10018:         $$rowtotal ++;
1.224     raeburn  10019:     } elsif ($position eq 'middle') {
                   10020:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  10021:         my @posstypes;
1.224     raeburn  10022:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  10023:             @posstypes = @{$types};
                   10024:         }
                   10025:         unless (grep(/^default$/,@posstypes)) {
                   10026:             push(@posstypes,'default');
                   10027:         }
                   10028:         my %usertypeshash;
                   10029:         if (ref($usertypes) eq 'HASH') {
                   10030:             %usertypeshash = %{$usertypes};
                   10031:         }
                   10032:         $usertypeshash{'default'} = $othertitle;
                   10033:         foreach my $status (@posstypes) {
                   10034:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   10035:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   10036:             $$rowtotal ++;
1.224     raeburn  10037:         }
                   10038:     } else {
1.236     raeburn  10039:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  10040:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  10041:                                                   );
                   10042:         my @toggles = sort(keys(%choices));
                   10043:         my %defaultchecked = (
                   10044:                                'cancreate_email' => 'off',
                   10045:                              );
1.305     raeburn  10046:         my $customclass = 'LC_selfcreate_email';
                   10047:         my $classprefix = 'LC_canmodify_emailusername_';
                   10048:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  10049:         my $display = 'none';
1.305     raeburn  10050:         my $rowstyle = 'display:none';
1.236     raeburn  10051:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   10052:             $display = 'block';
1.305     raeburn  10053:             $rowstyle = 'display:table-row';
1.236     raeburn  10054:         }
1.305     raeburn  10055:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   10056:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   10057:                                                      \%choices,$$rowtotal,$onclick);
                   10058:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   10059:                                          $rowstyle);
                   10060:         $$rowtotal ++;
                   10061:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   10062:                                       $rowstyle);
                   10063:         $$rowtotal ++;
                   10064:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  10065:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  10066:         my ($emailrules,$emailruleorder) =
                   10067:             &Apache::lonnet::inst_userrules($dom,'email');
                   10068:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   10069:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   10070:         if (ref($types) eq 'ARRAY') {
                   10071:             @posstypes = @{$types};
                   10072:         }
                   10073:         if (@posstypes) {
                   10074:             unless (grep(/^default$/,@posstypes)) {
                   10075:                 push(@posstypes,'default');
1.302     raeburn  10076:             }
                   10077:             if (ref($usertypes) eq 'HASH') {
                   10078:                 %usertypeshash = %{$usertypes};
                   10079:             }
1.305     raeburn  10080:             my $currassign;
                   10081:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   10082:                 $currassign = {
                   10083:                                   selfassign => $domdefaults{'inststatusguest'},
                   10084:                               };
                   10085:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   10086:             } else {
                   10087:                 $currassign = { selfassign => [] };
                   10088:             }
                   10089:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   10090:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   10091:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   10092:                                          $numinrow,$othertitle,'selfassign',
                   10093:                                          $rowtotal,$onclicktypes,$customclass,
                   10094:                                          $rowstyle);
                   10095:             $$rowtotal ++;
1.302     raeburn  10096:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  10097:             foreach my $status (@posstypes) {
                   10098:                 my $css_class;
                   10099:                 if ($$rowtotal%2) {
                   10100:                     $css_class = 'LC_odd_row ';
                   10101:                 }
                   10102:                 $css_class .= $customclass;
                   10103:                 my $rowid = $optionsprefix.$status;
                   10104:                 my $hidden = 1;
                   10105:                 my $currstyle = 'display:none';
                   10106:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   10107:                     $currstyle = $rowstyle;
                   10108:                     $hidden = 0; 
                   10109:                 }
                   10110:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   10111:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   10112:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   10113:                 unless ($hidden) {
                   10114:                     $$rowtotal ++;
                   10115:                 }
1.224     raeburn  10116:             }
1.302     raeburn  10117:         } else {
1.305     raeburn  10118:             my $css_class;
                   10119:             if ($$rowtotal%2) {
                   10120:                 $css_class = 'LC_odd_row ';
                   10121:             }
                   10122:             $css_class .= $customclass;
1.302     raeburn  10123:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  10124:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   10125:                                          $emailrules,$emailruleorder,$settings,'default','',
                   10126:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   10127:             $$rowtotal ++;
1.224     raeburn  10128:         }
                   10129:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  10130:         $numinrow = 1;
1.305     raeburn  10131:         if (@posstypes) {
                   10132:             foreach my $status (@posstypes) {
                   10133:                 my $rowid = $classprefix.$status;
                   10134:                 my $datarowstyle = 'display:none';
                   10135:                 if (grep(/^\Q$status\E$/,@ordered)) { 
                   10136:                     $datarowstyle = $rowstyle; 
                   10137:                 }
                   10138:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   10139:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   10140:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   10141:                 unless ($datarowstyle eq 'display:none') {
                   10142:                     $$rowtotal ++;
                   10143:                 }
1.224     raeburn  10144:             }
1.305     raeburn  10145:         } else {
                   10146:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   10147:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   10148:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  10149:         }
                   10150:     }
                   10151:     return $datatable;
                   10152: }
                   10153: 
1.305     raeburn  10154: sub selfcreate_javascript {
                   10155:     return <<"ENDSCRIPT";
                   10156: 
                   10157: <script type="text/javascript">
                   10158: // <![CDATA[
                   10159: 
                   10160: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   10161:     var x = document.getElementsByClassName(target);
                   10162:     var insttypes = 0;
                   10163:     var insttypeRegExp = new RegExp(prefix);
                   10164:     if ((x.length != undefined) && (x.length > 0)) {
                   10165:         if (form.elements[radio].length != undefined) {
                   10166:             for (var i=0; i<form.elements[radio].length; i++) {
                   10167:                 if (form.elements[radio][i].checked) {
                   10168:                     if (form.elements[radio][i].value == 1) {
                   10169:                         for (var j=0; j<x.length; j++) {
                   10170:                             if (x[j].id == 'undefined') {
                   10171:                                 x[j].style.display = 'table-row';
                   10172:                             } else if (insttypeRegExp.test(x[j].id)) {
                   10173:                                 insttypes ++;
                   10174:                             } else {
                   10175:                                 x[j].style.display = 'table-row';
                   10176:                             }
                   10177:                         }
                   10178:                     } else {
                   10179:                         for (var j=0; j<x.length; j++) {
                   10180:                             x[j].style.display = 'none';
                   10181:                         }
1.236     raeburn  10182:                     }
1.305     raeburn  10183:                     break;
                   10184:                 }
                   10185:             }
                   10186:             if (insttypes > 0) {
                   10187:                 toggleDataRow(form,checkbox,target,altprefix);
                   10188:                 toggleDataRow(form,checkbox,target,prefix,1);
                   10189:             }
                   10190:         }
                   10191:     }
                   10192:     return;
                   10193: }
                   10194: 
                   10195: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   10196:     if (form.elements[checkbox].length != undefined) {
                   10197:         var count = 0;
                   10198:         if (docount) {
                   10199:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   10200:                 if (form.elements[checkbox][i].checked) {
                   10201:                     count ++;
1.236     raeburn  10202:                 }
1.305     raeburn  10203:             }
                   10204:         }
                   10205:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   10206:             var type = form.elements[checkbox][i].value;
                   10207:             if (document.getElementById(prefix+type)) {
                   10208:                 if (form.elements[checkbox][i].checked) {
                   10209:                     document.getElementById(prefix+type).style.display = 'table-row';
                   10210:                     if (count % 2 == 1) {
                   10211:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   10212:                     } else {
                   10213:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  10214:                     }
1.305     raeburn  10215:                     count ++;
1.236     raeburn  10216:                 } else {
1.305     raeburn  10217:                     document.getElementById(prefix+type).style.display = 'none';
                   10218:                 }
                   10219:             }
                   10220:         }
                   10221:     }
                   10222:     return;
                   10223: }
                   10224: 
                   10225: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   10226:     var caller = radio+'_'+status;
                   10227:     if (form.elements[caller].length != undefined) {
                   10228:         for (var i=0; i<form.elements[caller].length; i++) {
                   10229:             if (form.elements[caller][i].checked) {
                   10230:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   10231:                     var curr = form.elements[caller][i].value;
                   10232:                     if (prefix) {
                   10233:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   10234:                     }
                   10235:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   10236:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   10237:                     if (curr == 'custom') {
                   10238:                         if (prefix) { 
                   10239:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   10240:                         }
                   10241:                     } else if (curr == 'inst') {
                   10242:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   10243:                     } else if (curr == 'noninst') {
                   10244:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  10245:                     }
1.305     raeburn  10246:                     break;
1.236     raeburn  10247:                 }
                   10248:             }
                   10249:         }
                   10250:     }
                   10251: }
                   10252: 
1.305     raeburn  10253: // ]]>
                   10254: </script>
                   10255: 
                   10256: ENDSCRIPT
                   10257: }
                   10258: 
                   10259: sub noninst_users {
                   10260:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   10261:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                   10262:     my $class = 'LC_left_item';
                   10263:     if ($css_class) {
                   10264:         $css_class = ' class="'.$css_class.'"'; 
                   10265:     }
                   10266:     if ($rowid) {
                   10267:         $rowid = ' id="'.$rowid.'"';
                   10268:     }
                   10269:     if ($rowstyle) {
                   10270:         $rowstyle = ' style="'.$rowstyle.'"';
                   10271:     }
                   10272:     my ($output,$description);
                   10273:     if ($type eq 'default') {
                   10274:         $description = &mt('Requests for: [_1]',$typetitle);
                   10275:     } else {
                   10276:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   10277:     }
                   10278:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   10279:               "<td>$description</td>\n".           
                   10280:               '<td class="'.$class.'" colspan="2">'.
                   10281:               '<table><tr>';
                   10282:     my %headers = &Apache::lonlocal::texthash( 
                   10283:               approve  => 'Processing',
                   10284:               email    => 'E-mail',
                   10285:               username => 'Username',
                   10286:     );
                   10287:     foreach my $item ('approve','email','username') {
                   10288:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  10289:     }
1.305     raeburn  10290:     $output .= '</tr><tr>';
                   10291:     foreach my $item ('approve','email','username') {
1.306     raeburn  10292:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  10293:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   10294:         if ($item eq 'approve') {
                   10295:             %choices = &Apache::lonlocal::texthash (
                   10296:                                                      automatic => 'Automatically approved',
                   10297:                                                      approval  => 'Queued for approval',
                   10298:                                                    );
                   10299:             @options = ('automatic','approval');
                   10300:             $hashref = $processing;
                   10301:             $defoption = 'automatic';
                   10302:             $name = 'cancreate_emailprocess_'.$type;
                   10303:         } elsif ($item eq 'email') {
                   10304:             %choices = &Apache::lonlocal::texthash (
                   10305:                                                      any     => 'Any e-mail',
                   10306:                                                      inst    => 'Institutional only',
                   10307:                                                      noninst => 'Non-institutional only',
                   10308:                                                      custom  => 'Custom restrictions',
                   10309:                                                    );
                   10310:             @options = ('any','inst','noninst');
                   10311:             my $showcustom;
                   10312:             if (ref($emailrules) eq 'HASH') {
                   10313:                 if (keys(%{$emailrules}) > 0) {
                   10314:                     push(@options,'custom');
                   10315:                     $showcustom = 'cancreate_emailrule';
                   10316:                     if (ref($settings) eq 'HASH') {
                   10317:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   10318:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   10319:                                 if (exists($emailrules->{$rule})) {
                   10320:                                     $hascustom ++;
                   10321:                                 }
                   10322:                             }
                   10323:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   10324:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   10325:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   10326:                                     if (exists($emailrules->{$rule})) {
                   10327:                                         $hascustom ++;
                   10328:                                     }
                   10329:                                 }
                   10330:                             }
                   10331:                         }
                   10332:                     }
                   10333:                 }
                   10334:             }
                   10335:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   10336:                                                      "'cancreate_emaildomain','$type'".');"';
                   10337:             $hashref = $emailoptions;
                   10338:             $defoption = 'any';
                   10339:             $name = 'cancreate_emailoptions_'.$type;
                   10340:         } elsif ($item eq 'username') {
                   10341:             %choices = &Apache::lonlocal::texthash (
                   10342:                                                      all    => 'Same as e-mail',
                   10343:                                                      first  => 'Omit @domain',
                   10344:                                                      free   => 'Free to choose',
                   10345:                                                    );
                   10346:             @options = ('all','first','free');
                   10347:             $hashref = $emailverified;
                   10348:             $defoption = 'all';
                   10349:             $name = 'cancreate_usernameoptions_'.$type;
                   10350:         }
                   10351:         foreach my $option (@options) {
                   10352:             my $checked;
                   10353:             if (ref($hashref) eq 'HASH') {
                   10354:                 if ($type eq '') {
                   10355:                     if (!exists($hashref->{'default'})) {
                   10356:                         if ($option eq $defoption) {
                   10357:                             $checked = ' checked="checked"';
                   10358:                         }
                   10359:                     } else {
                   10360:                         if ($hashref->{'default'} eq $option) {
                   10361:                             $checked = ' checked="checked"';
                   10362:                         }
1.303     raeburn  10363:                     }
                   10364:                 } else {
1.305     raeburn  10365:                     if (!exists($hashref->{$type})) {
                   10366:                         if ($option eq $defoption) {
                   10367:                             $checked = ' checked="checked"';
                   10368:                         }
                   10369:                     } else {
                   10370:                         if ($hashref->{$type} eq $option) {
                   10371:                             $checked = ' checked="checked"';
                   10372:                         }
1.303     raeburn  10373:                     }
                   10374:                 }
1.305     raeburn  10375:             } elsif (($item eq 'email') && ($hascustom)) {
                   10376:                 if ($option eq 'custom') {
                   10377:                     $checked = ' checked="checked"';
                   10378:                 }
                   10379:             } elsif ($option eq $defoption) {
                   10380:                 $checked = ' checked="checked"';
                   10381:             }
                   10382:             $output .= '<span class="LC_nobreak"><label>'.
                   10383:                        '<input type="radio" name="'.$name.'"'.
                   10384:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   10385:                        $choices{$option}.'</label></span><br />';
                   10386:             if ($item eq 'email') {
                   10387:                 if ($option eq 'custom') {
                   10388:                     my $id = 'cancreate_emailrule_'.$type;
                   10389:                     my $display = 'none';
                   10390:                     if ($checked) {
                   10391:                         $display = 'inline';
1.303     raeburn  10392:                     }
1.305     raeburn  10393:                     my $numinrow = 2;
                   10394:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   10395:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   10396:                                &user_formats_row('email',$settings,$emailrules,
                   10397:                                                  $emailruleorder,$numinrow,'',$type);
                   10398:                               '</table></fieldset>';
                   10399:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   10400:                     my %text = &Apache::lonlocal::texthash (
                   10401:                                                              inst    => 'must end:',
                   10402:                                                              noninst => 'cannot end:',
                   10403:                                                            );
                   10404:                     my $value;
                   10405:                     if (ref($emaildomain) eq 'HASH') {
                   10406:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   10407:                             $value = $emaildomain->{$type}->{$option}; 
1.303     raeburn  10408:                         }
                   10409:                     }
1.305     raeburn  10410:                     if ($value eq '') {
                   10411:                         $value = '@'.$intdom;
                   10412:                     }
                   10413:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   10414:                     my $display = 'none';
                   10415:                     if ($checked) {
                   10416:                         $display = 'inline';
                   10417:                     }
                   10418:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   10419:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   10420:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   10421:                                '</div>';
1.303     raeburn  10422:                 }
                   10423:             }
                   10424:         }
1.305     raeburn  10425:         $output .= '</td>'."\n";
1.303     raeburn  10426:     }
1.305     raeburn  10427:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  10428:     return $output;
                   10429: }
                   10430: 
1.165     raeburn  10431: sub captcha_choice {
1.305     raeburn  10432:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  10433:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   10434:         $vertext,$currver);
1.165     raeburn  10435:     my %lt = &captcha_phrases();
                   10436:     $keyentry = 'hidden';
1.354     raeburn  10437:     my $colspan=2;
1.165     raeburn  10438:     if ($context eq 'cancreate') {
1.224     raeburn  10439:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  10440:     } elsif ($context eq 'login') {
                   10441:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.354     raeburn  10442:     } elsif ($context eq 'passwords') {
                   10443:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   10444:         $colspan=1;
1.165     raeburn  10445:     }
                   10446:     if (ref($settings) eq 'HASH') {
                   10447:         if ($settings->{'captcha'}) {
                   10448:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   10449:         } else {
                   10450:             $checked{'original'} = ' checked="checked"';
                   10451:         }
                   10452:         if ($settings->{'captcha'} eq 'recaptcha') {
                   10453:             $pubtext = $lt{'pub'};
                   10454:             $privtext = $lt{'priv'};
                   10455:             $keyentry = 'text';
1.269     raeburn  10456:             $vertext = $lt{'ver'};
                   10457:             $currver = $settings->{'recaptchaversion'};
                   10458:             if ($currver ne '2') {
                   10459:                 $currver = 1;
                   10460:             }
1.165     raeburn  10461:         }
                   10462:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   10463:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   10464:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   10465:         }
                   10466:     } else {
                   10467:         $checked{'original'} = ' checked="checked"';
                   10468:     }
1.305     raeburn  10469:     my $css_class;
                   10470:     if ($itemcount%2) {
                   10471:         $css_class = 'LC_odd_row';
                   10472:     }
                   10473:     if ($customcss) {
                   10474:         $css_class .= " $customcss";
                   10475:     }
                   10476:     $css_class =~ s/^\s+//;
                   10477:     if ($css_class) {
                   10478:         $css_class = ' class="'.$css_class.'"';
                   10479:     }
                   10480:     if ($rowstyle) {
                   10481:         $css_class .= ' style="'.$rowstyle.'"';
                   10482:     }
1.169     raeburn  10483:     my $output = '<tr'.$css_class.'>'.
1.354     raeburn  10484:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165     raeburn  10485:                  '<table><tr><td>'."\n";
                   10486:     foreach my $option ('original','recaptcha','notused') {
                   10487:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   10488:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   10489:                    $lt{$option}.'</label></span>';
                   10490:         unless ($option eq 'notused') {
                   10491:             $output .= ('&nbsp;'x2)."\n";
                   10492:         }
                   10493:     }
                   10494: #
                   10495: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   10496: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  10497: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  10498: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  10499: #
1.165     raeburn  10500:     $output .= '</td></tr>'."\n".
1.305     raeburn  10501:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  10502:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   10503:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   10504:                $currpub.'" size="40" /></span><br />'."\n".
                   10505:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   10506:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  10507:                $currpriv.'" size="40" /></span><br />'.
                   10508:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   10509:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   10510:                $currver.'" size="3" /></span><br />'.
                   10511:                '</td></tr></table>'."\n".
1.165     raeburn  10512:                '</td></tr>';
                   10513:     return $output;
                   10514: }
                   10515: 
1.32      raeburn  10516: sub user_formats_row {
1.305     raeburn  10517:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  10518:     my $output;
                   10519:     my %text = (
                   10520:                    'username' => 'new usernames',
                   10521:                    'id'       => 'IDs',
                   10522:                );
1.409     raeburn  10523:     unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305     raeburn  10524:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   10525:         $output = '<tr '.$css_class.'>'.
                   10526:                   '<td><span class="LC_nobreak">'.
                   10527:                   &mt("Format rules to check for $text{$type}: ").
                   10528:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  10529:     }
1.27      raeburn  10530:     my $rem;
                   10531:     if (ref($ruleorder) eq 'ARRAY') {
                   10532:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   10533:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   10534:                 my $rem = $i%($numinrow);
                   10535:                 if ($rem == 0) {
                   10536:                     if ($i > 0) {
                   10537:                         $output .= '</tr>';
                   10538:                     }
                   10539:                     $output .= '<tr>';
                   10540:                 }
                   10541:                 my $check = ' ';
1.39      raeburn  10542:                 if (ref($settings) eq 'HASH') {
                   10543:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   10544:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   10545:                             $check = ' checked="checked" ';
                   10546:                         }
1.305     raeburn  10547:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   10548:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   10549:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   10550:                                 $check = ' checked="checked" ';
                   10551:                             }
                   10552:                         }
1.27      raeburn  10553:                     }
                   10554:                 }
1.305     raeburn  10555:                 my $name = $type.'_rule';
                   10556:                 if ($type eq 'email') {
                   10557:                     $name .= '_'.$status;
                   10558:                 }
1.27      raeburn  10559:                 $output .= '<td class="LC_left_item">'.
                   10560:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  10561:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  10562:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   10563:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   10564:             }
                   10565:         }
                   10566:         $rem = @{$ruleorder}%($numinrow);
                   10567:     }
1.305     raeburn  10568:     my $colsleft;
                   10569:     if ($rem) {
                   10570:         $colsleft = $numinrow - $rem;
                   10571:     }
1.27      raeburn  10572:     if ($colsleft > 1 ) {
                   10573:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   10574:                    '&nbsp;</td>';
                   10575:     } elsif ($colsleft == 1) {
                   10576:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   10577:     }
1.409     raeburn  10578:     $output .= '</tr>';
                   10579:     unless (($type eq 'email') || ($type eq 'unamemap')) {
                   10580:         $output .= '</table></td></tr>';
1.305     raeburn  10581:     }
1.27      raeburn  10582:     return $output;
                   10583: }
                   10584: 
1.34      raeburn  10585: sub usercreation_types {
                   10586:     my %lt = &Apache::lonlocal::texthash (
                   10587:                     author     => 'When adding a co-author',
                   10588:                     course     => 'When adding a user to a course',
1.100     raeburn  10589:                     requestcrs => 'When requesting a course',
1.34      raeburn  10590:                     any        => 'Any',
                   10591:                     official   => 'Institutional only ',
                   10592:                     unofficial => 'Non-institutional only',
                   10593:                     none       => 'None',
                   10594:     );
                   10595:     return %lt;
1.48      raeburn  10596: }
1.34      raeburn  10597: 
1.224     raeburn  10598: sub selfcreation_types {
                   10599:     my %lt = &Apache::lonlocal::texthash (
                   10600:                     selfcreate => 'User creates own account',
                   10601:                     any        => 'Any',
                   10602:                     official   => 'Institutional only ',
                   10603:                     unofficial => 'Non-institutional only',
                   10604:                     email      => 'E-mail address',
                   10605:                     login      => 'Institutional Login',
                   10606:                     sso        => 'SSO',
                   10607:              );
                   10608: }
                   10609: 
1.28      raeburn  10610: sub authtype_names {
                   10611:     my %lt = &Apache::lonlocal::texthash(
                   10612:                       int    => 'Internal',
                   10613:                       krb4   => 'Kerberos 4',
                   10614:                       krb5   => 'Kerberos 5',
                   10615:                       loc    => 'Local',
1.325     raeburn  10616:                       lti    => 'LTI',
1.28      raeburn  10617:                   );
                   10618:     return %lt;
                   10619: }
                   10620: 
                   10621: sub context_names {
                   10622:     my %context_title = &Apache::lonlocal::texthash(
                   10623:        author => 'Creating users when an Author',
                   10624:        course => 'Creating users when in a course',
                   10625:        domain => 'Creating users when a Domain Coordinator',
                   10626:     );
                   10627:     return %context_title;
                   10628: }
                   10629: 
1.33      raeburn  10630: sub print_usermodification {
                   10631:     my ($position,$dom,$settings,$rowtotal) = @_;
                   10632:     my $numinrow = 4;
                   10633:     my ($context,$datatable,$rowcount);
                   10634:     if ($position eq 'top') {
                   10635:         $rowcount = 0;
                   10636:         $context = 'author'; 
                   10637:         foreach my $role ('ca','aa') {
                   10638:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10639:                                                    $numinrow,$rowcount);
                   10640:             $$rowtotal ++;
                   10641:             $rowcount ++;
                   10642:         }
1.230     raeburn  10643:     } elsif ($position eq 'bottom') {
1.33      raeburn  10644:         $context = 'course';
                   10645:         $rowcount = 0;
                   10646:         foreach my $role ('st','ep','ta','in','cr') {
                   10647:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10648:                                                    $numinrow,$rowcount);
                   10649:             $$rowtotal ++;
                   10650:             $rowcount ++;
                   10651:         }
                   10652:     }
                   10653:     return $datatable;
                   10654: }
                   10655: 
1.43      raeburn  10656: sub print_defaults {
1.236     raeburn  10657:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  10658:     my $rownum = 0;
1.294     raeburn  10659:     my ($datatable,$css_class,$titles);
                   10660:     unless ($position eq 'bottom') {
                   10661:         $titles = &defaults_titles($dom);
                   10662:     }
1.236     raeburn  10663:     if ($position eq 'top') {
                   10664:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   10665:                      'datelocale_def','portal_def');
                   10666:         my %defaults;
                   10667:         if (ref($settings) eq 'HASH') {
                   10668:             %defaults = %{$settings};
1.43      raeburn  10669:         } else {
1.236     raeburn  10670:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10671:             foreach my $item (@items) {
                   10672:                 $defaults{$item} = $domdefaults{$item};
                   10673:             }
1.43      raeburn  10674:         }
1.236     raeburn  10675:         foreach my $item (@items) {
                   10676:             if ($rownum%2) {
                   10677:                 $css_class = '';
                   10678:             } else {
                   10679:                 $css_class = ' class="LC_odd_row" ';
                   10680:             }
                   10681:             $datatable .= '<tr'.$css_class.'>'.
                   10682:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   10683:                           '</span></td><td class="LC_right_item" colspan="3">';
                   10684:             if ($item eq 'auth_def') {
1.325     raeburn  10685:                 my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236     raeburn  10686:                 my %shortauth = (
                   10687:                                  internal => 'int',
                   10688:                                  krb4 => 'krb4',
                   10689:                                  krb5 => 'krb5',
1.325     raeburn  10690:                                  localauth  => 'loc',
                   10691:                                  lti => 'lti',
1.236     raeburn  10692:                                 );
                   10693:                 my %authnames = &authtype_names();
                   10694:                 foreach my $auth (@authtypes) {
                   10695:                     my $checked = ' ';
                   10696:                     if ($defaults{$item} eq $auth) {
                   10697:                         $checked = ' checked="checked" ';
                   10698:                     }
                   10699:                     $datatable .= '<label><input type="radio" name="'.$item.
                   10700:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   10701:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   10702:                 }
                   10703:             } elsif ($item eq 'timezone_def') {
                   10704:                 my $includeempty = 1;
                   10705:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   10706:             } elsif ($item eq 'datelocale_def') {
                   10707:                 my $includeempty = 1;
                   10708:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   10709:             } elsif ($item eq 'lang_def') {
1.263     raeburn  10710:                 my $includeempty = 1;
                   10711:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414     raeburn  10712:             } elsif ($item eq 'portal_def') {
                   10713:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   10714:                               $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
                   10715:                 my $portalsty = 'none';
                   10716:                 if ($defaults{$item}) {
                   10717:                     $portalsty = 'block';
                   10718:                 }
                   10719:                 foreach my $field ('email','web') {
                   10720:                     my $checkedoff = ' checked="checked"';
                   10721:                     my $checkedon;
                   10722:                     if ($defaults{$item.'_'.$field}) {
                   10723:                         $checkedon = $checkedoff;
                   10724:                         $checkedoff = '';
                   10725:                     } 
                   10726:                     $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
                   10727:                               '<span class="LC_nobreak">'.$titles->{$field}.'&nbsp;'.
                   10728:                               '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
                   10729:                               ('&nbsp;'x2).
                   10730:                               '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
                   10731:                               '</div>';
                   10732:                 }
1.236     raeburn  10733:             } else {
1.414     raeburn  10734:                 $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43      raeburn  10735:             }
1.236     raeburn  10736:             $datatable .= '</td></tr>';
                   10737:             $rownum ++;
                   10738:         }
1.409     raeburn  10739:     } elsif ($position eq 'middle') {
1.294     raeburn  10740:         my %defaults;
                   10741:         if (ref($settings) eq 'HASH') {
1.354     raeburn  10742:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   10743:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   10744:                 for (my $i=0; $i<$maxnum; $i++) {
                   10745:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10746:                     my $item = $settings->{'inststatusorder'}->[$i];
                   10747:                     my $title = $settings->{'inststatustypes'}->{$item};
                   10748:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   10749:                     $datatable .= '<tr'.$css_class.'>'.
                   10750:                                   '<td><span class="LC_nobreak">'.
                   10751:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   10752:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10753:                         my $vpos = $k+1;
                   10754:                         my $selstr;
                   10755:                         if ($k == $i) {
                   10756:                             $selstr = ' selected="selected" ';
                   10757:                         }
                   10758:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10759:                     }
                   10760:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   10761:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   10762:                                   &mt('delete').'</span></td>'.
1.380     raeburn  10763:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354     raeburn  10764:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   10765:                                   '</span></td></tr>';
                   10766:                 }
                   10767:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10768:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   10769:                 $datatable .= '<tr '.$css_class.'>'.
                   10770:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   10771:                 for (my $k=0; $k<=$maxnum; $k++) {
                   10772:                     my $vpos = $k+1;
                   10773:                     my $selstr;
                   10774:                     if ($k == $maxnum) {
                   10775:                         $selstr = ' selected="selected" ';
                   10776:                     }
                   10777:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10778:                 }
                   10779:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                   10780:                               '<input type="text" size="10" name="addinststatus" value="" />'.
                   10781:                               '&nbsp;'.&mt('(new)').
                   10782:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380     raeburn  10783:                               &mt('Name displayed').':'.
1.354     raeburn  10784:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   10785:                               '</tr>'."\n";
                   10786:                 $rownum ++;
1.294     raeburn  10787:             }
1.354     raeburn  10788:         }
1.409     raeburn  10789:     } else {
                   10790:         my ($unamemaprules,$ruleorder) =
                   10791:             &Apache::lonnet::inst_userrules($dom,'unamemap');
                   10792:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10793:         if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   10794:             my $numinrow = 2;
                   10795:             $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
                   10796:                           &user_formats_row('unamemap',$settings,$unamemaprules,
                   10797:                                             $ruleorder,$numinrow).
                   10798:                           '</table></td></tr>';
                   10799:         }
                   10800:         if ($datatable eq '') {
                   10801:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
                   10802:                           &mt('No rules set for domain in customized localenroll.pm').
                   10803:                           '</td></tr>';
                   10804:         }
1.354     raeburn  10805:     }
                   10806:     $$rowtotal += $rownum;
1.43      raeburn  10807:     return $datatable;
                   10808: }
                   10809: 
1.168     raeburn  10810: sub get_languages_hash {
                   10811:     my %langchoices;
                   10812:     foreach my $id (&Apache::loncommon::languageids()) {
                   10813:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   10814:         if ($code ne '') {
                   10815:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   10816:         }
                   10817:     }
                   10818:     return %langchoices;
                   10819: }
                   10820: 
1.43      raeburn  10821: sub defaults_titles {
1.141     raeburn  10822:     my ($dom) = @_;
1.43      raeburn  10823:     my %titles = &Apache::lonlocal::texthash (
                   10824:                    'auth_def'      => 'Default authentication type',
                   10825:                    'auth_arg_def'  => 'Default authentication argument',
                   10826:                    'lang_def'      => 'Default language',
1.54      raeburn  10827:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  10828:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  10829:                    'portal_def'     => 'Portal/Default URL',
1.414     raeburn  10830:                    'email'          => 'Email links use portal URL',
                   10831:                    'web'            => 'Public web links use portal URL',
1.294     raeburn  10832:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   10833:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   10834:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  10835:                  );
1.141     raeburn  10836:     if ($dom) {
                   10837:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   10838:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   10839:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   10840:         $protocol = 'http' if ($protocol ne 'https');
                   10841:         if ($uint_dom) {
                   10842:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   10843:                                          $uint_dom);
                   10844:         }
                   10845:     }
1.43      raeburn  10846:     return (\%titles);
                   10847: }
                   10848: 
1.346     raeburn  10849: sub print_scantron {
                   10850:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   10851:     if ($position eq 'top') {
                   10852:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   10853:     } else {
                   10854:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   10855:     }
                   10856: }
                   10857: 
                   10858: sub scantron_javascript {
                   10859:     return <<"ENDSCRIPT";
                   10860: 
                   10861: <script type="text/javascript">
                   10862: // <![CDATA[
                   10863: 
                   10864: function toggleScantron(form) {
1.347     raeburn  10865:     var csvfieldset = new Array();
1.346     raeburn  10866:     if (document.getElementById('scantroncsv_cols')) {
1.347     raeburn  10867:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   10868:     }
                   10869:     if (document.getElementById('scantroncsv_options')) {
                   10870:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   10871:     }
                   10872:     if (csvfieldset.length) {
1.346     raeburn  10873:         if (document.getElementById('scantronconfcsv')) {
1.347     raeburn  10874:             var scantroncsv = document.getElementById('scantronconfcsv');
1.346     raeburn  10875:             if (scantroncsv.checked) {
1.347     raeburn  10876:                 for (var i=0; i<csvfieldset.length; i++) {
                   10877:                     csvfieldset[i].style.display = 'block';
                   10878:                 }
1.346     raeburn  10879:             } else {
1.347     raeburn  10880:                 for (var i=0; i<csvfieldset.length; i++) {
                   10881:                     csvfieldset[i].style.display = 'none';
                   10882:                 }
1.346     raeburn  10883:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   10884:                 if (csvselects.length) {
                   10885:                     for (var j=0; j<csvselects.length; j++) {
                   10886:                         csvselects[j].selectedIndex = 0;
                   10887:                     }
                   10888:                 }
                   10889:             }
                   10890:         }
                   10891:     }
                   10892:     return;
                   10893: }
                   10894: // ]]>
                   10895: </script>
                   10896: 
                   10897: ENDSCRIPT
                   10898: 
                   10899: }
                   10900: 
1.46      raeburn  10901: sub print_scantronformat {
                   10902:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   10903:     my $itemcount = 1;
1.60      raeburn  10904:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   10905:         %confhash);
1.46      raeburn  10906:     my $switchserver = &check_switchserver($dom,$confname);
                   10907:     my %lt = &Apache::lonlocal::texthash (
1.95      www      10908:                 default => 'Default bubblesheet format file error',
                   10909:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  10910:              );
                   10911:     my %scantronfiles = (
                   10912:         default => 'default.tab',
                   10913:         custom => 'custom.tab',
                   10914:     );
                   10915:     foreach my $key (keys(%scantronfiles)) {
                   10916:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   10917:                               .$scantronfiles{$key};
                   10918:     }
                   10919:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   10920:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   10921:         if (!$switchserver) {
                   10922:             my $servadm = $r->dir_config('lonAdmEMail');
                   10923:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   10924:             if ($configuserok eq 'ok') {
                   10925:                 if ($author_ok eq 'ok') {
                   10926:                     my %legacyfile = (
1.346     raeburn  10927:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   10928:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  10929:                     );
                   10930:                     my %md5chk;
                   10931:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  10932:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   10933:                         chomp($md5chk{$type});
1.46      raeburn  10934:                     }
                   10935:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   10936:                         foreach my $type (keys(%legacyfile)) {
1.346     raeburn  10937:                             ($scantronurls{$type},my $error) =
1.46      raeburn  10938:                                 &legacy_scantronformat($r,$dom,$confname,
                   10939:                                                  $type,$legacyfile{$type},
                   10940:                                                  $scantronurls{$type},
                   10941:                                                  $scantronfiles{$type});
1.60      raeburn  10942:                             if ($error ne '') {
                   10943:                                 $error{$type} = $error;
                   10944:                             }
                   10945:                         }
                   10946:                         if (keys(%error) == 0) {
                   10947:                             $is_custom = 1;
1.346     raeburn  10948:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  10949:                                 $scantronurls{'custom'};
1.346     raeburn  10950:                             my $putresult =
1.60      raeburn  10951:                                 &Apache::lonnet::put_dom('configuration',
                   10952:                                                          \%confhash,$dom);
                   10953:                             if ($putresult ne 'ok') {
1.346     raeburn  10954:                                 $error{'custom'} =
1.60      raeburn  10955:                                     '<span class="LC_error">'.
                   10956:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10957:                             }
1.46      raeburn  10958:                         }
                   10959:                     } else {
1.60      raeburn  10960:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  10961:                             &legacy_scantronformat($r,$dom,$confname,
                   10962:                                           'default',$legacyfile{'default'},
                   10963:                                           $scantronurls{'default'},
                   10964:                                           $scantronfiles{'default'});
1.60      raeburn  10965:                         if ($error eq '') {
                   10966:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   10967:                             my $putresult =
                   10968:                                 &Apache::lonnet::put_dom('configuration',
                   10969:                                                          \%confhash,$dom);
                   10970:                             if ($putresult ne 'ok') {
                   10971:                                 $error{'default'} =
                   10972:                                     '<span class="LC_error">'.
                   10973:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10974:                             }
                   10975:                         } else {
                   10976:                             $error{'default'} = $error;
                   10977:                         }
1.46      raeburn  10978:                     }
                   10979:                 }
                   10980:             }
                   10981:         } else {
1.95      www      10982:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  10983:         }
                   10984:     }
                   10985:     if (ref($settings) eq 'HASH') {
                   10986:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   10987:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   10988:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   10989:                 $scantronurl = '';
                   10990:             } else {
                   10991:                 $scantronurl = $settings->{'scantronformat'};
                   10992:             }
                   10993:             $is_custom = 1;
                   10994:         } else {
                   10995:             $scantronurl = $scantronurls{'default'};
                   10996:         }
                   10997:     } else {
1.60      raeburn  10998:         if ($is_custom) {
                   10999:             $scantronurl = $scantronurls{'custom'};
                   11000:         } else {
                   11001:             $scantronurl = $scantronurls{'default'};
                   11002:         }
1.46      raeburn  11003:     }
                   11004:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11005:     $datatable .= '<tr'.$css_class.'>';
                   11006:     if (!$is_custom) {
1.65      raeburn  11007:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   11008:                       '<span class="LC_nobreak">';
1.46      raeburn  11009:         if ($scantronurl) {
1.199     raeburn  11010:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   11011:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  11012:         } else {
                   11013:             $datatable = &mt('File unavailable for display');
                   11014:         }
1.65      raeburn  11015:         $datatable .= '</span></td>';
1.60      raeburn  11016:         if (keys(%error) == 0) { 
1.306     raeburn  11017:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  11018:             if (!$switchserver) {
                   11019:                 $datatable .= &mt('Upload:').'<br />';
                   11020:             }
                   11021:         } else {
                   11022:             my $errorstr;
                   11023:             foreach my $key (sort(keys(%error))) {
                   11024:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   11025:             }
                   11026:             $datatable .= '<td>'.$errorstr;
                   11027:         }
1.46      raeburn  11028:     } else {
                   11029:         if (keys(%error) > 0) {
                   11030:             my $errorstr;
                   11031:             foreach my $key (sort(keys(%error))) {
                   11032:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   11033:             } 
1.60      raeburn  11034:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  11035:         } elsif ($scantronurl) {
1.199     raeburn  11036:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   11037:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  11038:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  11039:                           $link.
                   11040:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   11041:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  11042:                           '<td><span class="LC_nobreak">&nbsp;'.
                   11043:                           &mt('Replace:').'</span><br />';
1.46      raeburn  11044:         }
                   11045:     }
                   11046:     if (keys(%error) == 0) {
                   11047:         if ($switchserver) {
                   11048:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   11049:         } else {
1.65      raeburn  11050:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   11051:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  11052:         }
                   11053:     }
                   11054:     $datatable .= '</td></tr>';
                   11055:     $$rowtotal ++;
                   11056:     return $datatable;
                   11057: }
                   11058: 
                   11059: sub legacy_scantronformat {
                   11060:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   11061:     my ($url,$error);
                   11062:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   11063:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   11064:         (my $result,$url) =
                   11065:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   11066:                          '','',$newfile);
                   11067:         if ($result ne 'ok') {
1.130     raeburn  11068:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  11069:         }
                   11070:     }
                   11071:     return ($url,$error);
                   11072: }
1.43      raeburn  11073: 
1.346     raeburn  11074: sub print_scantronconfig {
                   11075:     my ($dom,$settings,$rowtotal) = @_;
                   11076:     my $itemcount = 2;
                   11077:     my $is_checked = ' checked="checked"';
1.347     raeburn  11078:     my %optionson = (
                   11079:                      hdr => ' checked="checked"',
                   11080:                      pad => ' checked="checked"',
                   11081:                      rem => ' checked="checked"',
                   11082:                     );
                   11083:     my %optionsoff = (
                   11084:                       hdr => '',
                   11085:                       pad => '',
                   11086:                       rem => '',
                   11087:                      );
1.346     raeburn  11088:     my $currcsvsty = 'none';
1.347     raeburn  11089:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346     raeburn  11090:     my @fields = &scantroncsv_fields();
                   11091:     my %titles = &scantronconfig_titles();
                   11092:     if (ref($settings) eq 'HASH') {
                   11093:         if (ref($settings->{config}) eq 'HASH') {
                   11094:             if ($settings->{config}->{dat}) {
                   11095:                 $checked{'dat'} = $is_checked;
                   11096:             }
                   11097:             if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347     raeburn  11098:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   11099:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   11100:                     if (keys(%csvfields) > 0) {
                   11101:                         $checked{'csv'} = $is_checked;
                   11102:                         $currcsvsty = 'block';
                   11103:                     }
                   11104:                 }
                   11105:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   11106:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   11107:                     foreach my $option (keys(%optionson)) {
                   11108:                         unless ($csvoptions{$option}) {
                   11109:                             $optionsoff{$option} = $optionson{$option};
                   11110:                             $optionson{$option} = '';
                   11111:                         }
                   11112:                     }
1.346     raeburn  11113:                 }
                   11114:             }
                   11115:         } else {
                   11116:             $checked{'dat'} = $is_checked;
                   11117:         }
                   11118:     } else {
                   11119:         $checked{'dat'} = $is_checked;
                   11120:     }
                   11121:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   11122:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   11123:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   11124:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   11125:     foreach my $item ('dat','csv') {
                   11126:         my $id;
                   11127:         if ($item eq 'csv') {
                   11128:             $id = 'id="scantronconfcsv" ';
1.347     raeburn  11129:         }
1.346     raeburn  11130:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   11131:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   11132:         if ($item eq 'csv') {
                   11133:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   11134:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   11135:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   11136:             foreach my $col (@fields) {
                   11137:                 my $selnone;
                   11138:                 if ($csvfields{$col} eq '') {
                   11139:                     $selnone = ' selected="selected"';
                   11140:                 }
                   11141:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   11142:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   11143:                               '<option value=""'.$selnone.'></option>';
                   11144:                 for (my $i=0; $i<20; $i++) {
                   11145:                     my $shown = $i+1;
                   11146:                     my $sel;
                   11147:                     unless ($selnone) {
                   11148:                         if (exists($csvfields{$col})) {
                   11149:                             if ($csvfields{$col} == $i) {
                   11150:                                 $sel = ' selected="selected"';
                   11151:                             }
                   11152:                         }
                   11153:                     }
                   11154:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   11155:                 }
                   11156:                 $datatable .= '</select></td></tr>';
                   11157:            }
1.347     raeburn  11158:            $datatable .= '</table></fieldset>'.
                   11159:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   11160:                          '<legend>'.&mt('CSV Options').'</legend>';
                   11161:            foreach my $option ('hdr','pad','rem') {
                   11162:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   11163:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   11164:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   11165:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   11166:            }
                   11167:            $datatable .= '</fieldset>';
1.346     raeburn  11168:            $itemcount ++;
                   11169:         }
                   11170:     }
                   11171:     $datatable .= '</td></tr>';
                   11172:     $$rowtotal ++;
                   11173:     return $datatable;
                   11174: }
                   11175: 
                   11176: sub scantronconfig_titles {
                   11177:     return &Apache::lonlocal::texthash(
                   11178:                                           dat => 'Standard format (.dat)',
                   11179:                                           csv => 'Comma separated values (.csv)',
1.347     raeburn  11180:                                           hdr => 'Remove first line in file (contains column titles)',
                   11181:                                           pad => 'Prepend 0s to PaperID',
1.348     raeburn  11182:                                           rem => 'Remove leading spaces (except Question Response columns)',
1.346     raeburn  11183:                                           CODE => 'CODE',
                   11184:                                           ID   => 'Student ID',
                   11185:                                           PaperID => 'Paper ID',
                   11186:                                           FirstName => 'First Name',
                   11187:                                           LastName => 'Last Name',
                   11188:                                           FirstQuestion => 'First Question Response',
                   11189:                                           Section => 'Section',
                   11190:     );
                   11191: }
                   11192: 
                   11193: sub scantroncsv_fields {
                   11194:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   11195: }
                   11196: 
1.49      raeburn  11197: sub print_coursecategories {
1.57      raeburn  11198:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   11199:     my $datatable;
                   11200:     if ($position eq 'top') {
1.238     raeburn  11201:         my (%checked);
                   11202:         my @catitems = ('unauth','auth');
                   11203:         my @cattypes = ('std','domonly','codesrch','none');
                   11204:         $checked{'unauth'} = 'std';
                   11205:         $checked{'auth'} = 'std';
                   11206:         if (ref($settings) eq 'HASH') {
                   11207:             foreach my $type (@cattypes) {
                   11208:                 if ($type eq $settings->{'unauth'}) {
                   11209:                     $checked{'unauth'} = $type;
                   11210:                 }
                   11211:                 if ($type eq $settings->{'auth'}) {
                   11212:                     $checked{'auth'} = $type;
                   11213:                 }
                   11214:             }
                   11215:         }
                   11216:         my %lt = &Apache::lonlocal::texthash (
                   11217:                                                unauth   => 'Catalog type for unauthenticated users',
                   11218:                                                auth     => 'Catalog type for authenticated users',
                   11219:                                                none     => 'No catalog',
                   11220:                                                std      => 'Standard catalog',
                   11221:                                                domonly  => 'Domain-only catalog',
                   11222:                                                codesrch => "Code search form",
                   11223:                                              );
                   11224:        my $itemcount = 0;
                   11225:        foreach my $item (@catitems) {
                   11226:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   11227:            $datatable .= '<tr '.$css_class.'>'.
                   11228:                          '<td>'.$lt{$item}.'</td>'.
                   11229:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   11230:            foreach my $type (@cattypes) {
                   11231:                my $ischecked;
                   11232:                if ($checked{$item} eq $type) {
                   11233:                    $ischecked=' checked="checked"';
                   11234:                }
                   11235:                $datatable .= '<label>'.
                   11236:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   11237:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   11238:            }
1.327     raeburn  11239:            $datatable .= '</span></td></tr>';
1.238     raeburn  11240:            $itemcount ++;
                   11241:         }
                   11242:         $$rowtotal += $itemcount;
                   11243:     } elsif ($position eq 'middle') {
1.57      raeburn  11244:         my $toggle_cats_crs = ' ';
                   11245:         my $toggle_cats_dom = ' checked="checked" ';
                   11246:         my $can_cat_crs = ' ';
                   11247:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  11248:         my $toggle_catscomm_comm = ' ';
                   11249:         my $toggle_catscomm_dom = ' checked="checked" ';
                   11250:         my $can_catcomm_comm = ' ';
                   11251:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  11252:         my $toggle_catsplace_place = ' ';
                   11253:         my $toggle_catsplace_dom = ' checked="checked" ';
                   11254:         my $can_catplace_place = ' ';
                   11255:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  11256: 
1.57      raeburn  11257:         if (ref($settings) eq 'HASH') {
                   11258:             if ($settings->{'togglecats'} eq 'crs') {
                   11259:                 $toggle_cats_crs = $toggle_cats_dom;
                   11260:                 $toggle_cats_dom = ' ';
                   11261:             }
                   11262:             if ($settings->{'categorize'} eq 'crs') {
                   11263:                 $can_cat_crs = $can_cat_dom;
                   11264:                 $can_cat_dom = ' ';
                   11265:             }
1.120     raeburn  11266:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   11267:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   11268:                 $toggle_catscomm_dom = ' ';
                   11269:             }
                   11270:             if ($settings->{'categorizecomm'} eq 'comm') {
                   11271:                 $can_catcomm_comm = $can_catcomm_dom;
                   11272:                 $can_catcomm_dom = ' ';
                   11273:             }
1.272     raeburn  11274:             if ($settings->{'togglecatsplace'} eq 'place') {
                   11275:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   11276:                 $toggle_catsplace_dom = ' ';
                   11277:             }
                   11278:             if ($settings->{'categorizeplace'} eq 'place') {
                   11279:                 $can_catplace_place = $can_catplace_dom;
                   11280:                 $can_catplace_dom = ' ';
                   11281:             }
1.57      raeburn  11282:         }
                   11283:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  11284:                      togglecats      => 'Show/Hide a course in catalog',
                   11285:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   11286:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   11287:                      categorize      => 'Assign a category to a course',
                   11288:                      categorizecomm  => 'Assign a category to a community',
                   11289:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  11290:                     );
                   11291:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  11292:                      dom   => 'Set in Domain',
                   11293:                      crs   => 'Set in Course',
                   11294:                      comm  => 'Set in Community',
                   11295:                      place => 'Set in Placement Test',
1.57      raeburn  11296:                     );
                   11297:         $datatable = '<tr class="LC_odd_row">'.
                   11298:                   '<td>'.$title{'togglecats'}.'</td>'.
                   11299:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   11300:                   '<input type="radio" name="togglecats"'.
                   11301:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11302:                   '<label><input type="radio" name="togglecats"'.
                   11303:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   11304:                   '</tr><tr>'.
                   11305:                   '<td>'.$title{'categorize'}.'</td>'.
                   11306:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   11307:                   '<label><input type="radio" name="categorize"'.
                   11308:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11309:                   '<label><input type="radio" name="categorize"'.
                   11310:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  11311:                   '</tr><tr class="LC_odd_row">'.
                   11312:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   11313:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   11314:                   '<input type="radio" name="togglecatscomm"'.
                   11315:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11316:                   '<label><input type="radio" name="togglecatscomm"'.
                   11317:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   11318:                   '</tr><tr>'.
                   11319:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   11320:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   11321:                   '<label><input type="radio" name="categorizecomm"'.
                   11322:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11323:                   '<label><input type="radio" name="categorizecomm"'.
                   11324:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327     raeburn  11325:                   '</tr><tr class="LC_odd_row">'.
1.272     raeburn  11326:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   11327:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   11328:                   '<input type="radio" name="togglecatsplace"'.
                   11329:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11330:                   '<label><input type="radio" name="togglecatscomm"'.
                   11331:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   11332:                   '</tr><tr>'.
                   11333:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   11334:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   11335:                   '<label><input type="radio" name="categorizeplace"'.
                   11336:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   11337:                   '<label><input type="radio" name="categorizeplace"'.
                   11338:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  11339:                   '</tr>';
1.272     raeburn  11340:         $$rowtotal += 6;
1.57      raeburn  11341:     } else {
                   11342:         my $css_class;
                   11343:         my $itemcount = 1;
                   11344:         my $cathash; 
                   11345:         if (ref($settings) eq 'HASH') {
                   11346:             $cathash = $settings->{'cats'};
                   11347:         }
                   11348:         if (ref($cathash) eq 'HASH') {
                   11349:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   11350:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   11351:                                                    \%allitems,\%idx,\@jsarray);
                   11352:             my $maxdepth = scalar(@cats);
                   11353:             my $colattrib = '';
                   11354:             if ($maxdepth > 2) {
                   11355:                 $colattrib = ' colspan="2" ';
                   11356:             }
                   11357:             my @path;
                   11358:             if (@cats > 0) {
                   11359:                 if (ref($cats[0]) eq 'ARRAY') {
                   11360:                     my $numtop = @{$cats[0]};
                   11361:                     my $maxnum = $numtop;
1.120     raeburn  11362:                     my %default_names = (
                   11363:                           instcode    => &mt('Official courses'),
                   11364:                           communities => &mt('Communities'),
1.272     raeburn  11365:                           placement   => &mt('Placement Tests'),
1.120     raeburn  11366:                     );
                   11367: 
                   11368:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   11369:                         ($cathash->{'instcode::0'} eq '') ||
                   11370:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  11371:                         ($cathash->{'communities::0'} eq '') ||
                   11372:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   11373:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  11374:                         $maxnum ++;
                   11375:                     }
                   11376:                     my $lastidx;
                   11377:                     for (my $i=0; $i<$numtop; $i++) {
                   11378:                         my $parent = $cats[0][$i];
                   11379:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11380:                         my $item = &escape($parent).'::0';
                   11381:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   11382:                         $lastidx = $idx{$item};
                   11383:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   11384:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   11385:                         for (my $k=0; $k<=$maxnum; $k++) {
                   11386:                             my $vpos = $k+1;
                   11387:                             my $selstr;
                   11388:                             if ($k == $i) {
                   11389:                                 $selstr = ' selected="selected" ';
                   11390:                             }
                   11391:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   11392:                         }
1.214     raeburn  11393:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  11394:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  11395:                             $datatable .=  '<span class="LC_nobreak">'
                   11396:                                            .$default_names{$parent}.'</span>';
                   11397:                             if ($parent eq 'instcode') {
                   11398:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   11399:                                               .&mt('with institutional codes')
                   11400:                                               .')</span></td><td'.$colattrib.'>';
                   11401:                             } else {
                   11402:                                 $datatable .= '<table><tr><td>';
                   11403:                             }
                   11404:                             $datatable .= '<span class="LC_nobreak">'
                   11405:                                           .'<label><input type="radio" name="'
                   11406:                                           .$parent.'" value="1" checked="checked" />'
                   11407:                                           .&mt('Display').'</label>';
                   11408:                             if ($parent eq 'instcode') {
                   11409:                                 $datatable .= '&nbsp;';
                   11410:                             } else {
                   11411:                                 $datatable .= '</span></td></tr><tr><td>'
                   11412:                                               .'<span class="LC_nobreak">';
                   11413:                             }
                   11414:                             $datatable .= '<label><input type="radio" name="'
                   11415:                                           .$parent.'" value="0" />'
                   11416:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  11417:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  11418:                                 $datatable .= '</td></tr></table>';
                   11419:                             }
                   11420:                             $datatable .= '</td>';
1.57      raeburn  11421:                         } else {
                   11422:                             $datatable .= $parent
1.214     raeburn  11423:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   11424:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  11425:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   11426:                         }
                   11427:                         my $depth = 1;
                   11428:                         push(@path,$parent);
                   11429:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   11430:                         pop(@path);
                   11431:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   11432:                         $itemcount ++;
                   11433:                     }
1.48      raeburn  11434:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  11435:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   11436:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  11437:                     for (my $k=0; $k<=$maxnum; $k++) {
                   11438:                         my $vpos = $k+1;
                   11439:                         my $selstr;
1.57      raeburn  11440:                         if ($k == $numtop) {
1.48      raeburn  11441:                             $selstr = ' selected="selected" ';
                   11442:                         }
                   11443:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   11444:                     }
1.59      bisitz   11445:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  11446:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   11447:                                   .'</tr>'."\n";
1.48      raeburn  11448:                     $itemcount ++;
1.272     raeburn  11449:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  11450:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   11451:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11452:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   11453:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   11454:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   11455:                             for (my $k=0; $k<=$maxnum; $k++) {
                   11456:                                 my $vpos = $k+1;
                   11457:                                 my $selstr;
                   11458:                                 if ($k == $maxnum) {
                   11459:                                     $selstr = ' selected="selected" ';
                   11460:                                 }
                   11461:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  11462:                             }
1.120     raeburn  11463:                             $datatable .= '</select></span></td>'.
                   11464:                                           '<td><span class="LC_nobreak">'.
                   11465:                                           $default_names{$default}.'</span>';
                   11466:                             if ($default eq 'instcode') {
                   11467:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   11468:                                               .&mt('with institutional codes').')</span>';
                   11469:                             }
                   11470:                             $datatable .= '</td>'
                   11471:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   11472:                                           .&mt('Display').'</label>&nbsp;'
                   11473:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   11474:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  11475:                         }
                   11476:                     }
                   11477:                 }
1.57      raeburn  11478:             } else {
                   11479:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  11480:             }
                   11481:         } else {
1.327     raeburn  11482:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  11483:                           .&initialize_categories($itemcount);
1.48      raeburn  11484:         }
1.57      raeburn  11485:         $$rowtotal += $itemcount;
1.48      raeburn  11486:     }
                   11487:     return $datatable;
                   11488: }
                   11489: 
1.69      raeburn  11490: sub print_serverstatuses {
                   11491:     my ($dom,$settings,$rowtotal) = @_;
                   11492:     my $datatable;
                   11493:     my @pages = &serverstatus_pages();
                   11494:     my (%namedaccess,%machineaccess);
                   11495:     foreach my $type (@pages) {
                   11496:         $namedaccess{$type} = '';
                   11497:         $machineaccess{$type}= '';
                   11498:     }
                   11499:     if (ref($settings) eq 'HASH') {
                   11500:         foreach my $type (@pages) {
                   11501:             if (exists($settings->{$type})) {
                   11502:                 if (ref($settings->{$type}) eq 'HASH') {
                   11503:                     foreach my $key (keys(%{$settings->{$type}})) {
                   11504:                         if ($key eq 'namedusers') {
                   11505:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   11506:                         } elsif ($key eq 'machines') {
                   11507:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   11508:                         }
                   11509:                     }
                   11510:                 }
                   11511:             }
                   11512:         }
                   11513:     }
1.81      raeburn  11514:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  11515:     my $rownum = 0;
                   11516:     my $css_class;
                   11517:     foreach my $type (@pages) {
                   11518:         $rownum ++;
                   11519:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   11520:         $datatable .= '<tr'.$css_class.'>'.
                   11521:                       '<td><span class="LC_nobreak">'.
                   11522:                       $titles->{$type}.'</span></td>'.
                   11523:                       '<td class="LC_left_item">'.
                   11524:                       '<input type="text" name="'.$type.'_namedusers" '.
                   11525:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   11526:                       '<td class="LC_right_item">'.
                   11527:                       '<span class="LC_nobreak">'.
                   11528:                       '<input type="text" name="'.$type.'_machines" '.
                   11529:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.334     raeburn  11530:                       '</span></td></tr>'."\n";
1.69      raeburn  11531:     }
                   11532:     $$rowtotal += $rownum;
                   11533:     return $datatable;
                   11534: }
                   11535: 
                   11536: sub serverstatus_pages {
                   11537:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  11538:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   11539:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   11540:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  11541: }
                   11542: 
1.236     raeburn  11543: sub defaults_javascript {
                   11544:     my ($settings) = @_;
1.354     raeburn  11545:     return unless (ref($settings) eq 'HASH');
1.414     raeburn  11546:     my $portal_js = <<"ENDPORTAL";
                   11547: 
                   11548: function portalExtras(caller) {
                   11549:     var x = caller.value;
                   11550:     var y = new Array('email','web');
                   11551:     for (var i=0; i<y.length; i++) { 
                   11552:         if (document.getElementById('portal_def_'+y[i]+'_div')) {
                   11553:             var z = document.getElementById('portal_def_'+y[i]+'_div');
                   11554:             if (x.length > 0) {
                   11555:                 z.style.display = 'block';
                   11556:             } else {
                   11557:                 z.style.display = 'none';
                   11558:             }
                   11559:         }
                   11560:     }
                   11561: }
                   11562: ENDPORTAL
1.236     raeburn  11563:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   11564:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   11565:         if ($maxnum eq '') {
                   11566:             $maxnum = 0;
                   11567:         }
                   11568:         $maxnum ++;
1.249     raeburn  11569:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  11570:         return <<"ENDSCRIPT";
                   11571: <script type="text/javascript">
                   11572: // <![CDATA[
                   11573: function reorderTypes(form,caller) {
                   11574:     var changedVal;
                   11575: $jstext 
                   11576:     var newpos = 'addinststatus_pos';
                   11577:     var current = new Array;
                   11578:     var maxh = $maxnum;
                   11579:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11580:     var oldVal;
                   11581:     if (caller == newpos) {
                   11582:         changedVal = newitemVal;
                   11583:     } else {
                   11584:         var curritem = 'inststatus_pos_'+caller;
                   11585:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   11586:         current[newitemVal] = newpos;
                   11587:     }
                   11588:     for (var i=0; i<inststatuses.length; i++) {
                   11589:         if (inststatuses[i] != caller) {
                   11590:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   11591:             if (form.elements[elementName]) {
                   11592:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11593:                 current[currVal] = elementName;
                   11594:             }
                   11595:         }
                   11596:     }
                   11597:     for (var j=0; j<maxh; j++) {
                   11598:         if (current[j] == undefined) {
                   11599:             oldVal = j;
                   11600:         }
                   11601:     }
                   11602:     if (oldVal < changedVal) {
                   11603:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11604:            var elementName = current[k];
                   11605:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11606:         }
                   11607:     } else {
                   11608:         for (var k=changedVal; k<oldVal; k++) {
                   11609:             var elementName = current[k];
                   11610:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11611:         }
                   11612:     }
                   11613:     return;
                   11614: }
                   11615: 
1.414     raeburn  11616: $portal_js
                   11617: 
                   11618: // ]]>
                   11619: </script>
                   11620: 
                   11621: ENDSCRIPT
                   11622:     } else {
                   11623: return <<"ENDSCRIPT";
                   11624: <script type="text/javascript">
                   11625: // <![CDATA[
                   11626: $portal_js
1.236     raeburn  11627: // ]]>
                   11628: </script>
                   11629: 
                   11630: ENDSCRIPT
                   11631:     }
1.354     raeburn  11632:     return;
                   11633: }
                   11634: 
                   11635: sub passwords_javascript {
1.405     raeburn  11636:     my ($prefix) = @_;
                   11637:     my %intalert;
                   11638:     if ($prefix eq 'passwords') {
                   11639:         %intalert = &Apache::lonlocal::texthash (
                   11640:             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.',
                   11641:             authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   11642:             passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   11643:             passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   11644:             passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   11645:             passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   11646:         );
                   11647:     } elsif ($prefix eq 'secrets') {
                   11648:         %intalert = &Apache::lonlocal::texthash (
                   11649:             passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
                   11650:             passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
                   11651:         );
                   11652:     }
1.365     raeburn  11653:     &js_escape(\%intalert);
                   11654:     my $defmin = $Apache::lonnet::passwdmin;
1.405     raeburn  11655:     my $intauthjs; 
                   11656:     if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354     raeburn  11657: 
                   11658: function warnIntAuth(field) {
                   11659:     if (field.name == 'intauth_check') {
                   11660:         if (field.value == '2') {
1.365     raeburn  11661:             alert('$intalert{authcheck}');
1.354     raeburn  11662:         }
                   11663:     }
                   11664:     if (field.name == 'intauth_cost') {
                   11665:         field.value.replace(/\s/g,'');
                   11666:         if (field.value != '') {
                   11667:             var regexdigit=/^\\d+\$/;
                   11668:             if (!regexdigit.test(field.value)) {
1.365     raeburn  11669:                 alert('$intalert{authcost}');
                   11670:             }
                   11671:         }
                   11672:     }
                   11673:     return;
                   11674: }
                   11675: 
1.405     raeburn  11676: ENDSCRIPT
                   11677: 
                   11678:      }
                   11679: 
                   11680:      $intauthjs .= <<"ENDSCRIPT";
                   11681: 
                   11682: function warnInt$prefix(field) {
1.365     raeburn  11683:     field.value.replace(/^\s+/,'');
                   11684:     field.value.replace(/\s+\$/,'');
                   11685:     var regexdigit=/^\\d+\$/;
1.408     raeburn  11686:     if (field.name == '${prefix}_min') {
1.365     raeburn  11687:         if (field.value == '') {
                   11688:             alert('$intalert{passmin}');
                   11689:             field.value = '$defmin';
                   11690:         } else {
                   11691:             if (!regexdigit.test(field.value)) {
                   11692:                 alert('$intalert{passmin}');
                   11693:                 field.value = '$defmin';
                   11694:             }
1.366     raeburn  11695:             var minval = parseInt(field.value,10);
1.365     raeburn  11696:             if (minval < $defmin) {
                   11697:                 alert('$intalert{passmin}');
                   11698:                 field.value = '$defmin';
                   11699:             }
                   11700:         }
                   11701:     } else {
                   11702:         if (field.value == '0') {
                   11703:             field.value = '';
                   11704:         }
                   11705:         if (field.value != '') {
1.408     raeburn  11706:             if (field.name == '${prefix}_expire') {
1.365     raeburn  11707:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/; 
                   11708:                 if (!regexpposnum.test(field.value)) {
                   11709:                     alert('$intalert{passexp}');
                   11710:                     field.value = '';
                   11711:                 } else {
                   11712:                     var expval = parseFloat(field.value);
                   11713:                     if (expval == 0) {
                   11714:                         alert('$intalert{passexp}');
                   11715:                         field.value = '';
                   11716:                     }
                   11717:                 }
                   11718:             } else {
                   11719:                 if (!regexdigit.test(field.value)) {
1.408     raeburn  11720:                     if (field.name == '${prefix}_max') {
1.365     raeburn  11721:                         alert('$intalert{passmax}');
                   11722:                     } else {
1.408     raeburn  11723:                         if (field.name == '${prefix}_numsaved') {
1.365     raeburn  11724:                             alert('$intalert{passnum}');
                   11725:                         }
                   11726:                     }
1.370     raeburn  11727:                     field.value = '';
1.365     raeburn  11728:                 }
1.354     raeburn  11729:             }
                   11730:         }
                   11731:     }
                   11732:     return;
                   11733: }
                   11734: 
                   11735: ENDSCRIPT
                   11736:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  11737: }
                   11738: 
1.49      raeburn  11739: sub coursecategories_javascript {
                   11740:     my ($settings) = @_;
1.57      raeburn  11741:     my ($output,$jstext,$cathash);
1.49      raeburn  11742:     if (ref($settings) eq 'HASH') {
1.57      raeburn  11743:         $cathash = $settings->{'cats'};
                   11744:     }
                   11745:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  11746:         my (@cats,@jsarray,%idx);
1.57      raeburn  11747:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  11748:         if (@jsarray > 0) {
                   11749:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   11750:             for (my $i=0; $i<@jsarray; $i++) {
                   11751:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   11752:                     my $catstr = join('","',@{$jsarray[$i]});
                   11753:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   11754:                 }
                   11755:             }
                   11756:         }
                   11757:     } else {
                   11758:         $jstext  = '    var categories = Array(1);'."\n".
                   11759:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   11760:     }
1.237     bisitz   11761:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   11762:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  11763:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  11764:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   11765:     &js_escape(\$instcode_reserved);
                   11766:     &js_escape(\$communities_reserved);
1.272     raeburn  11767:     &js_escape(\$placement_reserved);
1.265     damieng  11768:     &js_escape(\$choose_again);
1.49      raeburn  11769:     $output = <<"ENDSCRIPT";
                   11770: <script type="text/javascript">
1.109     raeburn  11771: // <![CDATA[
1.49      raeburn  11772: function reorderCats(form,parent,item,idx) {
                   11773:     var changedVal;
                   11774: $jstext
                   11775:     var newpos = 'addcategory_pos';
                   11776:     if (parent == '') {
                   11777:         var has_instcode = 0;
                   11778:         var maxtop = categories[idx].length;
                   11779:         for (var j=0; j<maxtop; j++) {
                   11780:             if (categories[idx][j] == 'instcode::0') {
                   11781:                 has_instcode == 1;
                   11782:             }
                   11783:         }
                   11784:         if (has_instcode == 0) {
                   11785:             categories[idx][maxtop] = 'instcode_pos';
                   11786:         }
                   11787:     } else {
                   11788:         newpos += '_'+parent;
                   11789:     }
                   11790:     var maxh = 1 + categories[idx].length;
                   11791:     var current = new Array;
                   11792:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11793:     if (item == newpos) {
                   11794:         changedVal = newitemVal;
                   11795:     } else {
                   11796:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   11797:         current[newitemVal] = newpos;
                   11798:     }
                   11799:     for (var i=0; i<categories[idx].length; i++) {
                   11800:         var elementName = categories[idx][i];
                   11801:         if (elementName != item) {
                   11802:             if (form.elements[elementName]) {
                   11803:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11804:                 current[currVal] = elementName;
                   11805:             }
                   11806:         }
                   11807:     }
                   11808:     var oldVal;
                   11809:     for (var j=0; j<maxh; j++) {
                   11810:         if (current[j] == undefined) {
                   11811:             oldVal = j;
                   11812:         }
                   11813:     }
                   11814:     if (oldVal < changedVal) {
                   11815:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11816:            var elementName = current[k];
                   11817:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11818:         }
                   11819:     } else {
                   11820:         for (var k=changedVal; k<oldVal; k++) {
                   11821:             var elementName = current[k];
                   11822:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11823:         }
                   11824:     }
                   11825:     return;
                   11826: }
1.120     raeburn  11827: 
                   11828: function categoryCheck(form) {
                   11829:     if (form.elements['addcategory_name'].value == 'instcode') {
                   11830:         alert('$instcode_reserved\\n$choose_again');
                   11831:         return false;
                   11832:     }
                   11833:     if (form.elements['addcategory_name'].value == 'communities') {
                   11834:         alert('$communities_reserved\\n$choose_again');
                   11835:         return false;
                   11836:     }
1.272     raeburn  11837:     if (form.elements['addcategory_name'].value == 'placement') {
                   11838:         alert('$placement_reserved\\n$choose_again');
                   11839:         return false;
                   11840:     }
1.120     raeburn  11841:     return true;
                   11842: }
                   11843: 
1.109     raeburn  11844: // ]]>
1.49      raeburn  11845: </script>
                   11846: 
                   11847: ENDSCRIPT
                   11848:     return $output;
                   11849: }
                   11850: 
1.48      raeburn  11851: sub initialize_categories {
                   11852:     my ($itemcount) = @_;
1.120     raeburn  11853:     my ($datatable,$css_class,$chgstr);
1.380     raeburn  11854:     my %default_names = &Apache::lonlocal::texthash (
1.120     raeburn  11855:                       instcode    => 'Official courses (with institutional codes)',
                   11856:                       communities => 'Communities',
1.272     raeburn  11857:                       placement   => 'Placement Tests',
1.120     raeburn  11858:                         );
1.328     raeburn  11859:     my %selnum = (
                   11860:                    instcode    => '0',
                   11861:                    communities => '1',
                   11862:                    placement   => '2',
                   11863:                  );
                   11864:     my %selected;
1.272     raeburn  11865:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  11866:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327     raeburn  11867:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328     raeburn  11868:         map { $selected{$selnum{$_}} = '' } keys(%selnum);
                   11869:         $selected{$selnum{$default}} = ' selected="selected"';
1.120     raeburn  11870:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328     raeburn  11871:                      .'<select name="'.$default.'_pos"'.$chgstr.'>'
                   11872:                      .'<option value="0"'.$selected{'0'}.'>1</option>'
                   11873:                      .'<option value="1"'.$selected{'1'}.'>2</option>'
                   11874:                      .'<option value="2"'.$selected{'2'}.'>3</option>'
                   11875:                      .'<option value="3">4</option></select>&nbsp;'
1.120     raeburn  11876:                      .$default_names{$default}
                   11877:                      .'</span></td><td><span class="LC_nobreak">'
                   11878:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   11879:                      .&mt('Display').'</label>&nbsp;<label>'
                   11880:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  11881:                  .'</label></span></td></tr>';
1.120     raeburn  11882:         $itemcount ++;
                   11883:     }
1.48      raeburn  11884:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  11885:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  11886:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  11887:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   11888:                   .'<option value="0">1</option>'
                   11889:                   .'<option value="1">2</option>'
1.328     raeburn  11890:                   .'<option value="2">3</option>'
                   11891:                   .'<option value="3" selected="selected">4</option></select>&nbsp;'
1.327     raeburn  11892:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                   11893:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   11894:                   .'</td></tr>';
1.48      raeburn  11895:     return $datatable;
                   11896: }
                   11897: 
                   11898: sub build_category_rows {
1.49      raeburn  11899:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   11900:     my ($text,$name,$item,$chgstr);
1.48      raeburn  11901:     if (ref($cats) eq 'ARRAY') {
                   11902:         my $maxdepth = scalar(@{$cats});
                   11903:         if (ref($cats->[$depth]) eq 'HASH') {
                   11904:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   11905:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   11906:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  11907:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  11908:                 my ($idxnum,$parent_name,$parent_item);
                   11909:                 my $higher = $depth - 1;
                   11910:                 if ($higher == 0) {
                   11911:                     $parent_name = &escape($parent).'::'.$higher;
                   11912:                 } else {
                   11913:                     if (ref($path) eq 'ARRAY') {
                   11914:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11915:                     }
                   11916:                 }
                   11917:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  11918:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  11919:                     if ($j < $numchildren) {
1.48      raeburn  11920:                         $name = $cats->[$depth]{$parent}[$j];
                   11921:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  11922:                         $idxnum = $idx->{$item};
                   11923:                     } else {
                   11924:                         $name = $parent_name;
                   11925:                         $item = $parent_item;
1.48      raeburn  11926:                     }
1.49      raeburn  11927:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   11928:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  11929:                     for (my $i=0; $i<=$numchildren; $i++) {
                   11930:                         my $vpos = $i+1;
                   11931:                         my $selstr;
                   11932:                         if ($j == $i) {
                   11933:                             $selstr = ' selected="selected" ';
                   11934:                         }
                   11935:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   11936:                     }
                   11937:                     $text .= '</select>&nbsp;';
                   11938:                     if ($j < $numchildren) {
                   11939:                         my $deeper = $depth+1;
                   11940:                         $text .= $name.'&nbsp;'
                   11941:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   11942:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   11943:                         if(ref($path) eq 'ARRAY') {
                   11944:                             push(@{$path},$name);
1.49      raeburn  11945:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  11946:                             pop(@{$path});
                   11947:                         }
                   11948:                     } else {
1.330     raeburn  11949:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  11950:                         if ($j == $numchildren) {
                   11951:                             $text .= $name;
                   11952:                         } else {
                   11953:                             $text .= $item;
                   11954:                         }
                   11955:                         $text .= '" value="" />';
                   11956:                     }
                   11957:                     $text .= '</td></tr>';
                   11958:                 }
                   11959:                 $text .= '</table></td>';
                   11960:             } else {
                   11961:                 my $higher = $depth-1;
                   11962:                 if ($higher == 0) {
                   11963:                     $name = &escape($parent).'::'.$higher;
                   11964:                 } else {
                   11965:                     if (ref($path) eq 'ARRAY') {
                   11966:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11967:                     }
                   11968:                 }
                   11969:                 my $colspan;
                   11970:                 if ($parent ne 'instcode') {
                   11971:                     $colspan = $maxdepth - $depth - 1;
1.330     raeburn  11972:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  11973:                 }
                   11974:             }
                   11975:         }
                   11976:     }
                   11977:     return $text;
                   11978: }
                   11979: 
1.33      raeburn  11980: sub modifiable_userdata_row {
1.305     raeburn  11981:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357     raeburn  11982:         $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228     raeburn  11983:     my ($role,$rolename,$statustype);
                   11984:     $role = $item;
1.224     raeburn  11985:     if ($context eq 'cancreate') {
1.305     raeburn  11986:         if ($item =~ /^(emailusername)_(.+)$/) {
                   11987:             $role = $1;
                   11988:             $statustype = $2;
1.228     raeburn  11989:             if (ref($usertypes) eq 'HASH') {
                   11990:                 if ($usertypes->{$statustype}) {
                   11991:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   11992:                 } else {
                   11993:                     $rolename = &mt('Data provided by user');
                   11994:                 }
                   11995:             }
1.224     raeburn  11996:         }
                   11997:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  11998:         if (ref($usertypes) eq 'HASH') {
                   11999:             $rolename = $usertypes->{$role};
                   12000:         } else {
                   12001:             $rolename = $role;
                   12002:         }
1.325     raeburn  12003:     } elsif ($context eq 'lti') {
                   12004:         $rolename = &mt('Institutional data used (if available)');
1.357     raeburn  12005:     } elsif ($context eq 'privacy') {
                   12006:         $rolename = $itemdesc;
1.33      raeburn  12007:     } else {
1.63      raeburn  12008:         if ($role eq 'cr') {
                   12009:             $rolename = &mt('Custom role');
                   12010:         } else {
                   12011:             $rolename = &Apache::lonnet::plaintext($role);
                   12012:         }
1.33      raeburn  12013:     }
1.224     raeburn  12014:     my (@fields,%fieldtitles);
                   12015:     if (ref($fieldsref) eq 'ARRAY') {
                   12016:         @fields = @{$fieldsref};
                   12017:     } else {
                   12018:         @fields = ('lastname','firstname','middlename','generation',
                   12019:                    'permanentemail','id');
                   12020:     }
                   12021:     if ((ref($titlesref) eq 'HASH')) {
                   12022:         %fieldtitles = %{$titlesref};
                   12023:     } else {
                   12024:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12025:     }
1.33      raeburn  12026:     my $output;
1.305     raeburn  12027:     my $css_class;
                   12028:     if ($rowcount%2) {
                   12029:         $css_class = 'LC_odd_row';
                   12030:     }
                   12031:     if ($customcss) {
                   12032:         $css_class .= " $customcss";
                   12033:     }
                   12034:     $css_class =~ s/^\s+//;
                   12035:     if ($css_class) {
                   12036:         $css_class = ' class="'.$css_class.'"';
                   12037:     }
                   12038:     if ($rowstyle) {
                   12039:         $css_class .= ' style="'.$rowstyle.'"';
                   12040:     }
                   12041:     if ($rowid) {
                   12042:         $rowid = ' id="'.$rowid.'"';
                   12043:     }
                   12044:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  12045:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   12046:               '<td class="LC_left_item" colspan="2"><table>';
                   12047:     my $rem;
                   12048:     my %checks;
1.325     raeburn  12049:     my %current;
1.33      raeburn  12050:     if (ref($settings) eq 'HASH') {
1.325     raeburn  12051:         my $hashref;
                   12052:         if ($context eq 'lti') {
                   12053:             if (ref($settings) eq 'HASH') {
                   12054:                 $hashref = $settings->{'instdata'};
                   12055:             }
1.357     raeburn  12056:         } elsif ($context eq 'privacy') {
                   12057:             my ($key,$inner) = split(/_/,$role);
                   12058:             if (ref($settings) eq 'HASH') {
                   12059:                 if (ref($settings->{$key}) eq 'HASH') {
                   12060:                     $hashref = $settings->{$key}->{$inner};
                   12061:                 }
                   12062:             }
1.325     raeburn  12063:         } elsif (ref($settings->{$context}) eq 'HASH') {
1.33      raeburn  12064:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325     raeburn  12065:                 $hashref = $settings->{'lti_instdata'};
                   12066:             }
                   12067:             if ($role eq 'emailusername') {
                   12068:                 if ($statustype) {
                   12069:                     if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   12070:                         $hashref = $settings->{$context}->{$role}->{$statustype};
1.228     raeburn  12071:                     }
1.325     raeburn  12072:                 }
                   12073:             }
                   12074:         }
                   12075:         if (ref($hashref) eq 'HASH') { 
                   12076:             foreach my $field (@fields) {
                   12077:                 if ($hashref->{$field}) {
                   12078:                     if ($role eq 'emailusername') {
                   12079:                         $checks{$field} = $hashref->{$field};
                   12080:                     } else {
                   12081:                         $checks{$field} = ' checked="checked" ';
1.33      raeburn  12082:                     }
                   12083:                 }
                   12084:             }
                   12085:         }
                   12086:     }
1.305     raeburn  12087:  
                   12088:     my $total = scalar(@fields);
                   12089:     for (my $i=0; $i<$total; $i++) {
                   12090:         $rem = $i%($numinrow);
1.33      raeburn  12091:         if ($rem == 0) {
                   12092:             if ($i > 0) {
                   12093:                 $output .= '</tr>';
                   12094:             }
                   12095:             $output .= '<tr>';
                   12096:         }
                   12097:         my $check = ' ';
1.228     raeburn  12098:         unless ($role eq 'emailusername') {
                   12099:             if (exists($checks{$fields[$i]})) {
1.354     raeburn  12100:                 $check = $checks{$fields[$i]};
1.357     raeburn  12101:             } elsif ($context eq 'privacy') {
                   12102:                 if ($role =~ /^priv_(domain|course)$/) {
                   12103:                     if (ref($settings) ne 'HASH') {
                   12104:                         $check = ' checked="checked" ';
                   12105:                     }
                   12106:                 } elsif ($role =~ /^priv_(author|community)$/) {
                   12107:                     if (ref($settings) ne 'HASH') {
                   12108:                         unless ($fields[$i] eq 'id') {
                   12109:                             $check = ' checked="checked" ';
                   12110:                         }
                   12111:                     }
                   12112:                 } elsif ($role =~ /^(unpriv|othdom)_/) {
                   12113:                     if (ref($settings) ne 'HASH') {
                   12114:                         if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                   12115:                             $check = ' checked="checked" ';
                   12116:                         }
                   12117:                     }
                   12118:                 }
1.325     raeburn  12119:             } elsif ($context ne 'lti') {
1.228     raeburn  12120:                 if ($role eq 'st') {
                   12121:                     if (ref($settings) ne 'HASH') {
                   12122:                         $check = ' checked="checked" '; 
                   12123:                     }
1.33      raeburn  12124:                 }
                   12125:             }
                   12126:         }
                   12127:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  12128:                    '<span class="LC_nobreak">';
1.325     raeburn  12129:         my $prefix = 'canmodify';
1.228     raeburn  12130:         if ($role eq 'emailusername') {
                   12131:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   12132:                 $checks{$fields[$i]} = 'omit';
                   12133:             }
                   12134:             foreach my $option ('required','optional','omit') {
                   12135:                 my $checked='';
                   12136:                 if ($checks{$fields[$i]} eq $option) {
                   12137:                     $checked='checked="checked" ';
                   12138:                 }
                   12139:                 $output .= '<label>'.
1.325     raeburn  12140:                            '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228     raeburn  12141:                            &mt($option).'</label>'.('&nbsp;' x2);
                   12142:             }
                   12143:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   12144:         } else {
1.325     raeburn  12145:             if ($context eq 'lti') {
                   12146:                 $prefix = 'lti';
1.357     raeburn  12147:             } elsif ($context eq 'privacy') {
                   12148:                 $prefix = 'privacy';
1.325     raeburn  12149:             }
1.228     raeburn  12150:             $output .= '<label>'.
1.325     raeburn  12151:                        '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228     raeburn  12152:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   12153:                        '</label>';
                   12154:         }
                   12155:         $output .= '</span></td>';
1.33      raeburn  12156:     }
1.305     raeburn  12157:     $rem = $total%$numinrow;
                   12158:     my $colsleft;
                   12159:     if ($rem) {
                   12160:         $colsleft = $numinrow - $rem;
                   12161:     }
                   12162:     if ($colsleft > 1) {
1.33      raeburn  12163:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   12164:                    '&nbsp;</td>';
                   12165:     } elsif ($colsleft == 1) {
                   12166:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   12167:     }
                   12168:     $output .= '</tr></table></td></tr>';
                   12169:     return $output;
                   12170: }
1.28      raeburn  12171: 
1.93      raeburn  12172: sub insttypes_row {
1.305     raeburn  12173:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   12174:         $customcss,$rowstyle) = @_;
1.93      raeburn  12175:     my %lt = &Apache::lonlocal::texthash (
                   12176:                       cansearch => 'Users allowed to search',
                   12177:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  12178:                       lockablenames => 'User preference to lock name',
1.305     raeburn  12179:                       selfassign    => 'Self-reportable affiliations',
1.315     raeburn  12180:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  12181:              );
                   12182:     my $showdom;
                   12183:     if ($context eq 'cansearch') {
                   12184:         $showdom = ' ('.$dom.')';
                   12185:     }
1.165     raeburn  12186:     my $class = 'LC_left_item';
                   12187:     if ($context eq 'statustocreate') {
                   12188:         $class = 'LC_right_item';
                   12189:     }
1.305     raeburn  12190:     my $css_class;
                   12191:     if ($$rowtotal%2) {
                   12192:         $css_class = 'LC_odd_row';
                   12193:     }
                   12194:     if ($customcss) {
                   12195:         $css_class .= ' '.$customcss;
                   12196:     }
                   12197:     $css_class =~ s/^\s+//;
                   12198:     if ($css_class) {
                   12199:         $css_class = ' class="'.$css_class.'"';
                   12200:     }
                   12201:     if ($rowstyle) {
                   12202:         $css_class .= ' style="'.$rowstyle.'"';
                   12203:     }
                   12204:     if ($onclick) {
                   12205:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  12206:     }
                   12207:     my $output = '<tr'.$css_class.'>'.
                   12208:                  '<td>'.$lt{$context}.$showdom.
                   12209:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  12210:     my $rem;
                   12211:     if (ref($types) eq 'ARRAY') {
                   12212:         for (my $i=0; $i<@{$types}; $i++) {
                   12213:             if (defined($usertypes->{$types->[$i]})) {
                   12214:                 my $rem = $i%($numinrow);
                   12215:                 if ($rem == 0) {
                   12216:                     if ($i > 0) {
                   12217:                         $output .= '</tr>';
                   12218:                     }
                   12219:                     $output .= '<tr>';
1.23      raeburn  12220:                 }
1.26      raeburn  12221:                 my $check = ' ';
1.99      raeburn  12222:                 if (ref($settings) eq 'HASH') {
                   12223:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   12224:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   12225:                             $check = ' checked="checked" ';
                   12226:                         }
1.315     raeburn  12227:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   12228:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   12229:                             $check = ' checked="checked" ';
                   12230:                         }
1.99      raeburn  12231:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  12232:                         $check = ' checked="checked" ';
                   12233:                     }
1.23      raeburn  12234:                 }
1.26      raeburn  12235:                 $output .= '<td class="LC_left_item">'.
                   12236:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  12237:                            '<input type="checkbox" name="'.$context.'" '.
1.305     raeburn  12238:                            'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26      raeburn  12239:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  12240:             }
                   12241:         }
1.26      raeburn  12242:         $rem = @{$types}%($numinrow);
1.23      raeburn  12243:     }
                   12244:     my $colsleft = $numinrow - $rem;
1.315     raeburn  12245:     if ($context eq 'overrides') {
                   12246:         if ($colsleft > 1) {
                   12247:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   12248:         } else {
                   12249:             $output .= '<td class="LC_left_item">';
                   12250:         }
                   12251:         $output .= '&nbsp;';  
1.23      raeburn  12252:     } else {
1.334     raeburn  12253:         if ($rem == 0) {
1.315     raeburn  12254:             $output .= '<tr>';
                   12255:         }
                   12256:         if ($colsleft > 1) {
                   12257:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   12258:         } else {
                   12259:             $output .= '<td class="LC_left_item">';
                   12260:         }
                   12261:         my $defcheck = ' ';
                   12262:         if (ref($settings) eq 'HASH') {  
                   12263:             if (ref($settings->{$context}) eq 'ARRAY') {
                   12264:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   12265:                     $defcheck = ' checked="checked" ';
                   12266:                 }
                   12267:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  12268:                 $defcheck = ' checked="checked" ';
                   12269:             }
1.26      raeburn  12270:         }
1.315     raeburn  12271:         $output .= '<span class="LC_nobreak"><label>'.
                   12272:                    '<input type="checkbox" name="'.$context.'" '.
                   12273:                    'value="default"'.$defcheck.$onclick.' />'.
                   12274:                    $othertitle.'</label></span>';
1.23      raeburn  12275:     }
1.315     raeburn  12276:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  12277:     return $output;
1.23      raeburn  12278: }
                   12279: 
                   12280: sub sorted_searchtitles {
                   12281:     my %searchtitles = &Apache::lonlocal::texthash(
                   12282:                          'uname' => 'username',
                   12283:                          'lastname' => 'last name',
                   12284:                          'lastfirst' => 'last name, first name',
                   12285:                      );
                   12286:     my @titleorder = ('uname','lastname','lastfirst');
                   12287:     return (\%searchtitles,\@titleorder);
                   12288: }
                   12289: 
1.25      raeburn  12290: sub sorted_searchtypes {
                   12291:     my %srchtypes_desc = (
                   12292:                            exact    => 'is exact match',
                   12293:                            contains => 'contains ..',
                   12294:                            begins   => 'begins with ..',
                   12295:                          );
                   12296:     my @srchtypeorder = ('exact','begins','contains');
                   12297:     return (\%srchtypes_desc,\@srchtypeorder);
                   12298: }
                   12299: 
1.3       raeburn  12300: sub usertype_update_row {
                   12301:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   12302:     my $datatable;
                   12303:     my $numinrow = 4;
                   12304:     foreach my $type (@{$types}) {
                   12305:         if (defined($usertypes->{$type})) {
                   12306:             $$rownums ++;
                   12307:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   12308:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   12309:                           '</td><td class="LC_left_item"><table>';
                   12310:             for (my $i=0; $i<@{$fields}; $i++) {
                   12311:                 my $rem = $i%($numinrow);
                   12312:                 if ($rem == 0) {
                   12313:                     if ($i > 0) {
                   12314:                         $datatable .= '</tr>';
                   12315:                     }
                   12316:                     $datatable .= '<tr>';
                   12317:                 }
                   12318:                 my $check = ' ';
1.39      raeburn  12319:                 if (ref($settings) eq 'HASH') {
                   12320:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   12321:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   12322:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   12323:                                 $check = ' checked="checked" ';
                   12324:                             }
1.3       raeburn  12325:                         }
                   12326:                     }
                   12327:                 }
                   12328: 
                   12329:                 if ($i == @{$fields}-1) {
                   12330:                     my $colsleft = $numinrow - $rem;
                   12331:                     if ($colsleft > 1) {
                   12332:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   12333:                     } else {
                   12334:                         $datatable .= '<td>';
                   12335:                     }
                   12336:                 } else {
                   12337:                     $datatable .= '<td>';
                   12338:                 }
1.8       raeburn  12339:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   12340:                               '<input type="checkbox" name="updateable_'.$type.
                   12341:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   12342:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  12343:             }
                   12344:             $datatable .= '</tr></table></td></tr>';
                   12345:         }
                   12346:     }
                   12347:     return $datatable;
1.1       raeburn  12348: }
                   12349: 
                   12350: sub modify_login {
1.205     raeburn  12351:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  12352:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386     raeburn  12353:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412     raeburn  12354:         %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168     raeburn  12355:     %title = ( coursecatalog => 'Display course catalog',
                   12356:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  12357:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  12358:                newuser => 'Link for visitors to create a user account',
1.386     raeburn  12359:                loginheader => 'Log-in box header',
                   12360:                saml => 'Dual SSO and non-SSO login');
1.168     raeburn  12361:     @offon = ('off','on');
1.112     raeburn  12362:     if (ref($domconfig{login}) eq 'HASH') {
                   12363:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   12364:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   12365:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   12366:             }
                   12367:         }
1.386     raeburn  12368:         if (ref($domconfig{login}{'saml'}) eq 'HASH') {
                   12369:             foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
                   12370:                 if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
                   12371:                     $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
                   12372:                     $saml{$lonhost} = 1;
                   12373:                     $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
                   12374:                     $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
                   12375:                     $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                   12376:                     $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                   12377:                     $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412     raeburn  12378:                     $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386     raeburn  12379:                     $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                   12380:                 }
                   12381:             }
                   12382:         }
1.112     raeburn  12383:     }
1.9       raeburn  12384:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   12385:                                            \%domconfig,\%loginhash);
1.188     raeburn  12386:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  12387:     foreach my $item (@toggles) {
                   12388:         $loginhash{login}{$item} = $env{'form.'.$item};
                   12389:     }
1.41      raeburn  12390:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  12391:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   12392:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   12393:                                          \%loginhash);
                   12394:     }
1.110     raeburn  12395: 
1.149     raeburn  12396:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  12397:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  12398:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  12399:     if (keys(%servers) > 1) {
                   12400:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  12401:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   12402:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   12403:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   12404:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   12405:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   12406:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   12407:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   12408:                         $changes{'loginvia'}{$lonhost} = 1;
                   12409:                     } else {
                   12410:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   12411:                         $changes{'loginvia'}{$lonhost} = 1;
                   12412:                     }
                   12413:                 } else {
                   12414:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   12415:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   12416:                         $changes{'loginvia'}{$lonhost} = 1;
                   12417:                     }
                   12418:                 }
                   12419:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   12420:                     foreach my $item (@loginvia_attribs) {
                   12421:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   12422:                     }
                   12423:                 } else {
                   12424:                     foreach my $item (@loginvia_attribs) {
                   12425:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   12426:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   12427:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   12428:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   12429:                                 $new = '/';
                   12430:                             }
                   12431:                         }
                   12432:                         if (($item eq 'custompath') && 
                   12433:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   12434:                             $new = '';
                   12435:                         }
                   12436:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   12437:                             $changes{'loginvia'}{$lonhost} = 1;
                   12438:                         }
                   12439:                         if ($item eq 'exempt') {
1.256     raeburn  12440:                             $new = &check_exempt_addresses($new);
1.128     raeburn  12441:                         }
                   12442:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   12443:                     }
                   12444:                 }
1.112     raeburn  12445:             } else {
1.128     raeburn  12446:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   12447:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  12448:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  12449:                     foreach my $item (@loginvia_attribs) {
                   12450:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   12451:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   12452:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   12453:                                 $new = '/';
                   12454:                             }
                   12455:                         }
                   12456:                         if (($item eq 'custompath') && 
                   12457:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   12458:                             $new = '';
                   12459:                         }
                   12460:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   12461:                     }
1.110     raeburn  12462:                 }
                   12463:             }
                   12464:         }
                   12465:     }
1.119     raeburn  12466: 
1.168     raeburn  12467:     my $servadm = $r->dir_config('lonAdmEMail');
                   12468:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   12469:     if (ref($domconfig{'login'}) eq 'HASH') {
                   12470:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   12471:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   12472:                 if ($lang eq 'nolang') {
                   12473:                     push(@currlangs,$lang);
                   12474:                 } elsif (defined($langchoices{$lang})) {
                   12475:                     push(@currlangs,$lang);
                   12476:                 } else {
                   12477:                     next;
                   12478:                 }
                   12479:             }
                   12480:         }
                   12481:     }
                   12482:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   12483:     if (@currlangs > 0) {
                   12484:         foreach my $lang (@currlangs) {
                   12485:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   12486:                 $changes{'helpurl'}{$lang} = 1;
                   12487:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   12488:                 $changes{'helpurl'}{$lang} = 1;
                   12489:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   12490:                 push(@newlangs,$lang);
                   12491:             } else {
                   12492:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   12493:             }
                   12494:         }
                   12495:     }
                   12496:     unless (grep(/^nolang$/,@currlangs)) {
                   12497:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   12498:             $changes{'helpurl'}{'nolang'} = 1;
                   12499:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   12500:             push(@newlangs,'nolang');
                   12501:         }
                   12502:     }
                   12503:     if ($env{'form.loginhelpurl_add_lang'}) {
                   12504:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   12505:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   12506:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   12507:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   12508:         }
                   12509:     }
                   12510:     if ((@newlangs > 0) || ($addedfile)) {
                   12511:         my $error;
                   12512:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12513:         if ($configuserok eq 'ok') {
                   12514:             if ($switchserver) {
                   12515:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   12516:             } elsif ($author_ok eq 'ok') {
                   12517:                 my @allnew = @newlangs;
                   12518:                 if ($addedfile ne '') {
                   12519:                     push(@allnew,$addedfile);
                   12520:                 }
                   12521:                 foreach my $lang (@allnew) {
                   12522:                     my $formelem = 'loginhelpurl_'.$lang;
                   12523:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   12524:                         $formelem = 'loginhelpurl_add_file';
                   12525:                     }
                   12526:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12527:                                                                "help/$lang",'','',$newfile{$lang});
                   12528:                     if ($result eq 'ok') {
                   12529:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   12530:                         $changes{'helpurl'}{$lang} = 1;
                   12531:                     } else {
                   12532:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   12533:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  12534:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  12535:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   12536:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   12537:                         }
                   12538:                     }
                   12539:                 }
                   12540:             } else {
                   12541:                 $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);
                   12542:             }
                   12543:         } else {
                   12544:             $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);
                   12545:         }
                   12546:         if ($error) {
                   12547:             &Apache::lonnet::logthis($error);
                   12548:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12549:         }
                   12550:     }
1.256     raeburn  12551: 
                   12552:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   12553:     if (ref($domconfig{'login'}) eq 'HASH') {
                   12554:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   12555:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   12556:                 if ($domservers{$lonhost}) {
                   12557:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12558:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  12559:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  12560:                     }
                   12561:                 }
                   12562:             }
                   12563:         }
                   12564:     }
                   12565:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   12566:     foreach my $lonhost (sort(keys(%domservers))) {
                   12567:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12568:             $changes{'headtag'}{$lonhost} = 1;
                   12569:         } else {
                   12570:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   12571:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   12572:             }
                   12573:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   12574:                 push(@newhosts,$lonhost);
                   12575:             } elsif ($currheadtagurls{$lonhost}) {
                   12576:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   12577:                 if ($currexempt{$lonhost}) {
1.289     raeburn  12578:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  12579:                         $changes{'headtag'}{$lonhost} = 1;
                   12580:                     }
                   12581:                 } elsif ($possexempt{$lonhost}) {
                   12582:                     $changes{'headtag'}{$lonhost} = 1;
                   12583:                 }
                   12584:                 if ($possexempt{$lonhost}) {
                   12585:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12586:                 }
                   12587:             }
                   12588:         }
                   12589:     }
                   12590:     if (@newhosts) {
                   12591:         my $error;
                   12592:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12593:         if ($configuserok eq 'ok') {
                   12594:             if ($switchserver) {
                   12595:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   12596:             } elsif ($author_ok eq 'ok') {
                   12597:                 foreach my $lonhost (@newhosts) {
                   12598:                     my $formelem = 'loginheadtag_'.$lonhost;
                   12599:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12600:                                                                           "login/headtag/$lonhost",'','',
                   12601:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   12602:                     if ($result eq 'ok') {
                   12603:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   12604:                         $changes{'headtag'}{$lonhost} = 1;
                   12605:                         if ($possexempt{$lonhost}) {
                   12606:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12607:                         }
                   12608:                     } else {
                   12609:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   12610:                                            $newheadtagurls{$lonhost},$result);
                   12611:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12612:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   12613:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   12614:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   12615:                         }
                   12616:                     }
                   12617:                 }
                   12618:             } else {
                   12619:                 $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);
                   12620:             }
                   12621:         } else {
                   12622:             $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);
                   12623:         }
                   12624:         if ($error) {
                   12625:             &Apache::lonnet::logthis($error);
                   12626:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12627:         }
                   12628:     }
1.386     raeburn  12629:     my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
                   12630:     my @newsamlimgs;
                   12631:     foreach my $lonhost (keys(%domservers)) {
                   12632:         if ($env{'form.saml_'.$lonhost}) {
                   12633:             if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                   12634:                 push(@newsamlimgs,$lonhost);
                   12635:             }
1.412     raeburn  12636:             foreach my $item ('text','alt','url','title','window','notsso') {
1.386     raeburn  12637:                 $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
                   12638:             }
                   12639:             if ($saml{$lonhost}) {
1.412     raeburn  12640:                 if ($env{'form.saml_window_'.$lonhost} ne '1') {
                   12641:                     $env{'form.saml_window_'.$lonhost} = '';
                   12642:                 }
1.386     raeburn  12643:                 if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
                   12644: #FIXME Need to obsolete published image
                   12645:                     delete($currsaml{$lonhost}{'img'});
                   12646:                     $changes{'saml'}{$lonhost} = 1;
                   12647:                 }
                   12648:                 if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
                   12649:                     $changes{'saml'}{$lonhost} = 1;
                   12650:                 }
                   12651:                 if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
                   12652:                     $changes{'saml'}{$lonhost} = 1;
                   12653:                 }
                   12654:                 if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
                   12655:                     $changes{'saml'}{$lonhost} = 1;
                   12656:                 }
                   12657:                 if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
                   12658:                     $changes{'saml'}{$lonhost} = 1;
                   12659:                 }
1.412     raeburn  12660:                 if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
                   12661:                     $changes{'saml'}{$lonhost} = 1;
                   12662:                 }
1.386     raeburn  12663:                 if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
                   12664:                     $changes{'saml'}{$lonhost} = 1;
                   12665:                 }
                   12666:             } else {
                   12667:                 $changes{'saml'}{$lonhost} = 1;
                   12668:             }
1.412     raeburn  12669:             foreach my $item ('text','alt','url','title','window','notsso') {
1.386     raeburn  12670:                 $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
                   12671:             }
                   12672:         } else {
1.389     raeburn  12673:             if ($saml{$lonhost}) {  
                   12674:                 $changes{'saml'}{$lonhost} = 1;
                   12675:                 delete($currsaml{$lonhost});
                   12676:             }
1.386     raeburn  12677:         }
                   12678:     }
                   12679:     foreach my $posshost (keys(%currsaml)) {
                   12680:         unless (exists($domservers{$posshost})) { 
                   12681:             delete($currsaml{$posshost}); 
                   12682:         }
                   12683:     }
                   12684:     %{$loginhash{'login'}{'saml'}} = %currsaml;
                   12685:     if (@newsamlimgs) {
                   12686:         my $error;
                   12687:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12688:         if ($configuserok eq 'ok') {
                   12689:             if ($switchserver) {
                   12690:                 $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
                   12691:             } elsif ($author_ok eq 'ok') {
                   12692:                 foreach my $lonhost (@newsamlimgs) {
                   12693:                     my $formelem = 'saml_img_'.$lonhost;
                   12694:                     my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12695:                                                         "login/saml/$lonhost",'','',
                   12696:                                                         $env{'form.saml_img_'.$lonhost.'.filename'});
                   12697:                     if ($result eq 'ok') {
                   12698:                         $currsaml{$lonhost}{'img'} = $imgurl;
                   12699:                         $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
                   12700:                         $changes{'saml'}{$lonhost} = 1;
                   12701:                     } else {
                   12702:                         my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
                   12703:                                            $lonhost,$result);
                   12704:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12705:                     }
                   12706:                 }
                   12707:             } else {
                   12708:                 $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);
                   12709:             }
                   12710:         } else {
                   12711:             $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);
                   12712:         }
                   12713:         if ($error) {
                   12714:             &Apache::lonnet::logthis($error);
                   12715:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12716:         }
                   12717:     }
1.169     raeburn  12718:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  12719: 
                   12720:     my $defaulthelpfile = '/adm/loginproblems.html';
                   12721:     my $defaulttext = &mt('Default in use');
                   12722: 
1.1       raeburn  12723:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   12724:                                              $dom);
                   12725:     if ($putresult eq 'ok') {
1.188     raeburn  12726:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  12727:         my %defaultchecked = (
                   12728:                     'coursecatalog' => 'on',
1.188     raeburn  12729:                     'helpdesk'      => 'on',
1.42      raeburn  12730:                     'adminmail'     => 'off',
1.43      raeburn  12731:                     'newuser'       => 'off',
1.42      raeburn  12732:         );
1.55      raeburn  12733:         if (ref($domconfig{'login'}) eq 'HASH') {
                   12734:             foreach my $item (@toggles) {
                   12735:                 if ($defaultchecked{$item} eq 'on') { 
                   12736:                     if (($domconfig{'login'}{$item} eq '0') &&
                   12737:                         ($env{'form.'.$item} eq '1')) {
                   12738:                         $changes{$item} = 1;
                   12739:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12740:                               $domconfig{'login'}{$item} eq '1') &&
                   12741:                              ($env{'form.'.$item} eq '0')) {
                   12742:                         $changes{$item} = 1;
                   12743:                     }
                   12744:                 } elsif ($defaultchecked{$item} eq 'off') {
                   12745:                     if (($domconfig{'login'}{$item} eq '1') &&
                   12746:                         ($env{'form.'.$item} eq '0')) {
                   12747:                         $changes{$item} = 1;
                   12748:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12749:                               $domconfig{'login'}{$item} eq '0') &&
                   12750:                              ($env{'form.'.$item} eq '1')) {
                   12751:                         $changes{$item} = 1;
                   12752:                     }
1.42      raeburn  12753:                 }
                   12754:             }
1.41      raeburn  12755:         }
1.6       raeburn  12756:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  12757:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386     raeburn  12758:             if (exists($changes{'saml'})) {
                   12759:                 my $hostid_in_use;
                   12760:                 my @hosts = &Apache::lonnet::current_machine_ids();
                   12761:                 if (@hosts > 1) {
                   12762:                     foreach my $hostid (@hosts) {
                   12763:                         if (&Apache::lonnet::host_domain($hostid) eq $dom) {
                   12764:                             $hostid_in_use = $hostid;
                   12765:                             last;
                   12766:                         }
                   12767:                     }
                   12768:                 } else {
                   12769:                     $hostid_in_use = $r->dir_config('lonHostID');
                   12770:                 }
                   12771:                 if (($hostid_in_use) &&
                   12772:                     (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387     raeburn  12773:                     &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386     raeburn  12774:                 }
                   12775:                 if (ref($lastactref) eq 'HASH') {
                   12776:                     if (ref($changes{'saml'}) eq 'HASH') {
                   12777:                         my %updates;
                   12778:                         map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
                   12779:                         $lastactref->{'samllanding'} = \%updates;
                   12780:                     }
                   12781:                 }
                   12782:             }
1.212     raeburn  12783:             if (ref($lastactref) eq 'HASH') {
                   12784:                 $lastactref->{'domainconfig'} = 1;
                   12785:             }
1.1       raeburn  12786:             $resulttext = &mt('Changes made:').'<ul>';
                   12787:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   12788:                 if ($item eq 'loginvia') {
1.112     raeburn  12789:                     if (ref($changes{$item}) eq 'HASH') {
                   12790:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   12791:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  12792:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   12793:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   12794:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   12795:                                     $protocol = 'http' if ($protocol ne 'https');
                   12796:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   12797: 
                   12798:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   12799:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   12800:                                     } else {
                   12801:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   12802:                                     }
                   12803:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   12804:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   12805:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   12806:                                     }
                   12807:                                     $resulttext .= '</li>';
                   12808:                                 } else {
                   12809:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   12810:                                 }
1.112     raeburn  12811:                             } else {
1.128     raeburn  12812:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  12813:                             }
                   12814:                         }
1.128     raeburn  12815:                         $resulttext .= '</ul></li>';
1.112     raeburn  12816:                     }
1.168     raeburn  12817:                 } elsif ($item eq 'helpurl') {
                   12818:                     if (ref($changes{$item}) eq 'HASH') {
                   12819:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   12820:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   12821:                                 my ($chg,$link);
                   12822:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   12823:                                 if ($lang eq 'nolang') {
                   12824:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   12825:                                 } else {
                   12826:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   12827:                                 }
                   12828:                                 $resulttext .= '<li>'.$chg.'</li>';
                   12829:                             } else {
                   12830:                                 my $chg;
                   12831:                                 if ($lang eq 'nolang') {
                   12832:                                     $chg = &mt('custom log-in help file for no preferred language');
                   12833:                                 } else {
                   12834:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   12835:                                 }
                   12836:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   12837:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   12838:                                                       '?inhibitmenu=yes',$chg,600,500).
                   12839:                                                '</li>';
                   12840:                             }
                   12841:                         }
                   12842:                     }
1.256     raeburn  12843:                 } elsif ($item eq 'headtag') {
                   12844:                     if (ref($changes{$item}) eq 'HASH') {
                   12845:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12846:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12847:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   12848:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12849:                                 $resulttext .= '<li><a href="'.
                   12850:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   12851:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   12852:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   12853:                                 if ($possexempt{$lonhost}) {
                   12854:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   12855:                                 } else {
                   12856:                                     $resulttext .= &mt('included for any client IP');
                   12857:                                 }
                   12858:                                 $resulttext .= '</li>';
                   12859:                             }
                   12860:                         }
                   12861:                     }
1.386     raeburn  12862:                 } elsif ($item eq 'saml') {
                   12863:                     if (ref($changes{$item}) eq 'HASH') {
                   12864:                         my %notlt = (
                   12865:                                        text   => 'Text for log-in by SSO',
                   12866:                                        img    => 'SSO button image',
                   12867:                                        alt    => 'Alt text for button image',
                   12868:                                        url    => 'SSO URL',
                   12869:                                        title  => 'Tooltip for SSO link',
1.412     raeburn  12870:                                        window => 'Pop-up window if iframe',
1.386     raeburn  12871:                                        notsso => 'Text for non-SSO log-in',
                   12872:                                     );
                   12873:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12874:                             if (ref($currsaml{$lonhost}) eq 'HASH') {
                   12875:                                 $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
                   12876:                                                '<ul>';
1.412     raeburn  12877:                                 foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386     raeburn  12878:                                     if ($currsaml{$lonhost}{$key} eq '') {
                   12879:                                         $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
                   12880:                                     } else {
                   12881:                                         my $value = "'$currsaml{$lonhost}{$key}'";
                   12882:                                         if ($key eq 'img') {
                   12883:                                             $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412     raeburn  12884:                                         } elsif ($key eq 'window') {
                   12885:                                             $value = 'On';
1.386     raeburn  12886:                                         }
                   12887:                                         $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                   12888:                                                                   $value).'</li>';
                   12889:                                     }
                   12890:                                 }
                   12891:                                 $resulttext .= '</ul></li>';
                   12892:                             } else {
                   12893:                                 $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
                   12894:                             }
                   12895:                         }
                   12896:                     }
1.169     raeburn  12897:                 } elsif ($item eq 'captcha') {
                   12898:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  12899:                         my $chgtxt;
1.169     raeburn  12900:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   12901:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   12902:                         } else {
                   12903:                             my %captchas = &captcha_phrases();
                   12904:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   12905:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   12906:                             } else {
                   12907:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   12908:                             }
                   12909:                         }
                   12910:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12911:                     }
                   12912:                 } elsif ($item eq 'recaptchakeys') {
                   12913:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12914:                         my ($privkey,$pubkey);
                   12915:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   12916:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   12917:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   12918:                         }
                   12919:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   12920:                         if (!$pubkey) {
                   12921:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   12922:                         } else {
                   12923:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   12924:                         }
                   12925:                         if (!$privkey) {
                   12926:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   12927:                         } else {
1.251     raeburn  12928:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  12929:                         }
                   12930:                         $chgtxt .= '</ul>';
                   12931:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12932:                     }
1.269     raeburn  12933:                 } elsif ($item eq 'recaptchaversion') {
                   12934:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12935:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  12936:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  12937:                                            '</li>';
                   12938:                         }
                   12939:                     }
1.41      raeburn  12940:                 } else {
                   12941:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   12942:                 }
1.1       raeburn  12943:             }
1.6       raeburn  12944:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  12945:         } else {
                   12946:             $resulttext = &mt('No changes made to log-in page settings');
                   12947:         }
                   12948:     } else {
1.11      albertel 12949:         $resulttext = '<span class="LC_error">'.
                   12950: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  12951:     }
1.6       raeburn  12952:     if ($errors) {
1.9       raeburn  12953:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  12954:                        $errors.'</ul>';
                   12955:     }
                   12956:     return $resulttext;
                   12957: }
                   12958: 
1.256     raeburn  12959: sub check_exempt_addresses {
                   12960:     my ($iplist) = @_;
                   12961:     $iplist =~ s/^\s+//;
                   12962:     $iplist =~ s/\s+$//;
                   12963:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   12964:     my (@okips,$new);
                   12965:     foreach my $ip (@poss_ips) {
                   12966:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   12967:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   12968:                 push(@okips,$ip);
                   12969:             }
                   12970:         }
                   12971:     }
                   12972:     if (@okips > 0) {
                   12973:         $new = join(',',@okips);
                   12974:     } else {
                   12975:         $new = '';
                   12976:     }
                   12977:     return $new;
                   12978: }
                   12979: 
1.6       raeburn  12980: sub color_font_choices {
                   12981:     my %choices =
                   12982:         &Apache::lonlocal::texthash (
                   12983:             img => "Header",
                   12984:             bgs => "Background colors",
                   12985:             links => "Link colors",
1.55      raeburn  12986:             images => "Images",
1.6       raeburn  12987:             font => "Font color",
1.201     raeburn  12988:             fontmenu => "Font menu",
1.76      raeburn  12989:             pgbg => "Page",
1.6       raeburn  12990:             tabbg => "Header",
                   12991:             sidebg => "Border",
                   12992:             link => "Link",
                   12993:             alink => "Active link",
                   12994:             vlink => "Visited link",
                   12995:         );
                   12996:     return %choices;
                   12997: }
                   12998: 
1.394     raeburn  12999: sub modify_ipaccess {
                   13000:     my ($dom,$lastactref,%domconfig) = @_;
                   13001:     my (@allpos,%changes,%confhash,$errors,$resulttext);
                   13002:     my (@items,%deletions,%itemids,@warnings);
                   13003:     my ($typeorder,$types) = &commblocktype_text();
                   13004:     if ($env{'form.ipaccess_add'}) {
                   13005:         my $name = $env{'form.ipaccess_name_add'};
                   13006:         my ($newid,$error) = &get_ipaccess_id($dom,$name);
                   13007:         if ($newid) {
                   13008:             $itemids{'add'} = $newid;
                   13009:             push(@items,'add');
                   13010:             $changes{$newid} = 1;
                   13011:         } else {
                   13012:             $error = &mt('Failed to acquire unique ID for new IP access control item');
                   13013:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13014:         }
                   13015:     }
                   13016:     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   13017:         my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
                   13018:         if (@todelete) {
                   13019:             map { $deletions{$_} = 1; } @todelete;
                   13020:         }
                   13021:         my $maxnum = $env{'form.ipaccess_maxnum'};
                   13022:         for (my $i=0; $i<$maxnum; $i++) {
                   13023:             my $itemid = $env{'form.ipaccess_id_'.$i};
                   13024:             $itemid =~ s/\D+//g;
                   13025:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   13026:                 if ($deletions{$itemid}) {
                   13027:                     $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
                   13028:                 } else {
                   13029:                     push(@items,$i);
                   13030:                     $itemids{$i} = $itemid;
                   13031:                 }
                   13032:             }
                   13033:         }
                   13034:     }
                   13035:     foreach my $idx (@items) {
                   13036:         my $itemid = $itemids{$idx};
                   13037:         next unless ($itemid);
                   13038:         my %current;
                   13039:         unless ($idx eq 'add') {
                   13040:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   13041:                 %current = %{$domconfig{'ipaccess'}{$itemid}};
                   13042:             }
                   13043:         }
                   13044:         my $position = $env{'form.ipaccess_pos_'.$itemid};
                   13045:         $position =~ s/\D+//g;
                   13046:         if ($position ne '') {
                   13047:             $allpos[$position] = $itemid;
                   13048:         }
                   13049:         my $name = $env{'form.ipaccess_name_'.$idx};
                   13050:         $name =~ s/^\s+|\s+$//g;
                   13051:         $confhash{$itemid}{'name'} = $name;
                   13052:         my $possrange = $env{'form.ipaccess_range_'.$idx};
                   13053:         $possrange =~ s/^\s+|\s+$//g;
                   13054:         unless ($possrange eq '') {
                   13055:             $possrange =~ s/[\r\n]+/\s/g;
                   13056:             $possrange =~ s/\s*-\s*/-/g;
                   13057:             $possrange =~ s/\s+/,/g;
                   13058:             $possrange =~ s/,+/,/g;
                   13059:             if ($possrange ne '') {
                   13060:                 my (@ok,$count);
                   13061:                 $count = 0; 
                   13062:                 foreach my $poss (split(/\,/,$possrange)) {
                   13063:                     $count ++;
                   13064:                     $poss = &validate_ip_pattern($poss);
                   13065:                     if ($poss ne '') {
                   13066:                         push(@ok,$poss);
                   13067:                     }
                   13068:                 }
                   13069:                 my $diff = $count - scalar(@ok);
                   13070:                 if ($diff) {
                   13071:                     $errors .= '<li><span class="LC_error">'.
                   13072:                                &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
                   13073:                                    $diff,$name).
                   13074:                                '</span></li>';
                   13075:                 }
                   13076:                 if (@ok) {
                   13077:                     my @cidr_list;
                   13078:                     foreach my $item (@ok) {
                   13079:                         @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   13080:                     }
                   13081:                     $confhash{$itemid}{'ip'} = join(',',@cidr_list);
                   13082:                 }
                   13083:             }
                   13084:         }
                   13085:         foreach my $field ('name','ip') {
                   13086:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   13087:                 if ($current{$field} ne $confhash{$itemid}{$field}) {
                   13088:                     $changes{$itemid} = 1;
                   13089:                     last;
                   13090:                 }
                   13091:             }
                   13092:         }
                   13093:         $confhash{$itemid}{'commblocks'} = {};
                   13094:          
                   13095:         my %commblocks;
                   13096:         map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);  
                   13097:         foreach my $type (@{$typeorder}) {
                   13098:             if ($commblocks{$type}) {
                   13099:                 $confhash{$itemid}{'commblocks'}{$type} = 'on';
                   13100:             }
                   13101:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   13102:                 if (ref($current{'commblocks'}) eq 'HASH') {
                   13103:                     if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
                   13104:                         $changes{$itemid} = 1;
                   13105:                     }
                   13106:                 } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
                   13107:                     $changes{$itemid} = 1;
                   13108:                 }
                   13109:             }
                   13110:         }
                   13111:         $confhash{$itemid}{'courses'} = {};
                   13112:         my %crsdeletions;
                   13113:         my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
                   13114:         if (@delcrs) {
                   13115:             map { $crsdeletions{$_} = 1; } @delcrs;
                   13116:         }
                   13117:         if (ref($current{'courses'}) eq 'HASH') {
                   13118:             foreach my $cid (sort(keys(%{$current{'courses'}}))) {
                   13119:                 if ($crsdeletions{$cid}) {
                   13120:                     $changes{$itemid} = 1;
                   13121:                 } else {
                   13122:                     $confhash{$itemid}{'courses'}{$cid} = 1;
                   13123:                 }
                   13124:             }
                   13125:         }
                   13126:         $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
                   13127:         $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
                   13128:         if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) && 
                   13129:             ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
                   13130:             if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
                   13131:                                             $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
                   13132:                 $errors .= '<li><span class="LC_error">'.
                   13133:                            &mt('Invalid courseID [_1] omitted from list of allowed courses',
                   13134:                                $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
                   13135:                            '</span></li>';
                   13136:             } else {
                   13137:                 $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
                   13138:                 $changes{$itemid} = 1;
                   13139:             }
                   13140:         }
                   13141:     }
                   13142:     if (@allpos > 0) {
                   13143:         my $idx = 0;
                   13144:         foreach my $itemid (@allpos) {
                   13145:             if ($itemid ne '') {
                   13146:                 $confhash{$itemid}{'order'} = $idx;
                   13147:                 unless ($changes{$itemid}) {
                   13148:                     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   13149:                         if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   13150:                             if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
                   13151:                                 $changes{$itemid} = 1;
                   13152:                             }
                   13153:                         }
                   13154:                     }
                   13155:                 }
                   13156:                 $idx ++;
                   13157:             }
                   13158:         }
                   13159:     }
                   13160:     if (keys(%changes)) {
                   13161:         my %defaultshash = (
                   13162:                               ipaccess => \%confhash,
                   13163:                            );
                   13164:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   13165:                                                  $dom);
                   13166:         if ($putresult eq 'ok') {
                   13167:             my $cachetime = 1800;
                   13168:             &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
                   13169:             if (ref($lastactref) eq 'HASH') {
                   13170:                 $lastactref->{'ipaccess'} = 1;
                   13171:             }
                   13172:             $resulttext = &mt('Changes made:').'<ul>';
                   13173:             my %bynum;
                   13174:             foreach my $itemid (sort(keys(%changes))) {
                   13175:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   13176:                     my $position = $confhash{$itemid}{'order'};
                   13177:                     if ($position =~ /^\d+$/) {
                   13178:                         $bynum{$position} = $itemid;
                   13179:                     }
                   13180:                 }
                   13181:             }
                   13182:             if (keys(%deletions)) {
                   13183:                 foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
                   13184:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   13185:                 }
                   13186:             }
                   13187:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   13188:                 my $itemid = $bynum{$pos};
                   13189:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   13190:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
                   13191:                     my $position = $pos + 1;
                   13192:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   13193:                     if ($confhash{$itemid}{'ip'} eq '') {
                   13194:                         $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
                   13195:                     } else {
                   13196:                         $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
                   13197:                     }
                   13198:                     if (keys(%{$confhash{$itemid}{'commblocks'}})) {
                   13199:                         $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
                   13200:                                                   join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
                   13201:                                        '</li>';
                   13202:                     } else {
                   13203:                         $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
                   13204:                     }
                   13205:                     if (keys(%{$confhash{$itemid}{'courses'}})) {
                   13206:                         my @courses;
                   13207:                         foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
                   13208:                             my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1}); 
                   13209:                             push(@courses,$courseinfo{'description'}.' ('.$cid.')');
                   13210:                         }
                   13211:                         $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
                   13212:                                              join('</li><li>',@courses).'</li></ul>';
                   13213:                     } else {
                   13214:                         $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
                   13215:                     }
1.395     raeburn  13216:                     $resulttext .= '</ul></li>';
1.394     raeburn  13217:                 }
                   13218:             }
1.395     raeburn  13219:             $resulttext .= '</ul>';
1.394     raeburn  13220:         } else {
                   13221:             $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   13222:         }
                   13223:     } else {
                   13224:         $resulttext = &mt('No changes made');
                   13225:     }
                   13226:     if ($errors) {
                   13227:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   13228:                        $errors.'</ul></p>';
                   13229:     }
                   13230:     return $resulttext;
                   13231: }
                   13232: 
                   13233: sub get_ipaccess_id {
                   13234:     my ($domain,$location) = @_;
                   13235:     # get lock on ipaccess db
                   13236:     my $lockhash = {
                   13237:                       lock => $env{'user.name'}.
                   13238:                               ':'.$env{'user.domain'},
                   13239:                    };
                   13240:     my $tries = 0;
                   13241:     my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   13242:     my ($id,$error);
                   13243: 
                   13244:     while (($gotlock ne 'ok') && ($tries<10)) {
                   13245:         $tries ++;
                   13246:         sleep (0.1);
                   13247:         $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   13248:     }
                   13249:     if ($gotlock eq 'ok') {
                   13250:         my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
                   13251:         if ($currids{'lock'}) {
                   13252:             delete($currids{'lock'});
                   13253:             if (keys(%currids)) {
                   13254:                 my @curr = sort { $a <=> $b } keys(%currids);
                   13255:                 if ($curr[-1] =~ /^\d+$/) {
                   13256:                     $id = 1 + $curr[-1];
                   13257:                 }
                   13258:             } else {
                   13259:                 $id = 1;
                   13260:             }
                   13261:             if ($id) {
                   13262:                 unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
                   13263:                     $error = 'nostore';
                   13264:                 }
                   13265:             } else {
                   13266:                 $error = 'nonumber';
                   13267:             }
                   13268:         }
                   13269:         my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
                   13270:     } else {
                   13271:         $error = 'nolock';
                   13272:     }
                   13273:     return ($id,$error);
                   13274: }
                   13275: 
1.6       raeburn  13276: sub modify_rolecolors {
1.205     raeburn  13277:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  13278:     my ($resulttext,%rolehash);
                   13279:     $rolehash{'rolecolors'} = {};
1.55      raeburn  13280:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   13281:         if ($domconfig{'rolecolors'} eq '') {
                   13282:             $domconfig{'rolecolors'} = {};
                   13283:         }
                   13284:     }
1.9       raeburn  13285:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  13286:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   13287:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   13288:                                              $dom);
                   13289:     if ($putresult eq 'ok') {
                   13290:         if (keys(%changes) > 0) {
1.41      raeburn  13291:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  13292:             if (ref($lastactref) eq 'HASH') {
                   13293:                 $lastactref->{'domainconfig'} = 1;
                   13294:             }
1.6       raeburn  13295:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   13296:                                              $rolehash{'rolecolors'});
                   13297:         } else {
                   13298:             $resulttext = &mt('No changes made to default color schemes');
                   13299:         }
                   13300:     } else {
1.11      albertel 13301:         $resulttext = '<span class="LC_error">'.
                   13302: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  13303:     }
                   13304:     if ($errors) {
                   13305:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   13306:                        $errors.'</ul>';
                   13307:     }
                   13308:     return $resulttext;
                   13309: }
                   13310: 
                   13311: sub modify_colors {
1.9       raeburn  13312:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  13313:     my (%changes,%choices);
1.51      raeburn  13314:     my @bgs;
1.6       raeburn  13315:     my @links = ('link','alink','vlink');
1.41      raeburn  13316:     my @logintext;
1.6       raeburn  13317:     my @images;
                   13318:     my $servadm = $r->dir_config('lonAdmEMail');
                   13319:     my $errors;
1.200     raeburn  13320:     my %defaults;
1.6       raeburn  13321:     foreach my $role (@{$roles}) {
                   13322:         if ($role eq 'login') {
1.12      raeburn  13323:             %choices = &login_choices();
1.41      raeburn  13324:             @logintext = ('textcol','bgcol');
1.12      raeburn  13325:         } else {
                   13326:             %choices = &color_font_choices();
                   13327:         }
                   13328:         if ($role eq 'login') {
1.41      raeburn  13329:             @images = ('img','logo','domlogo','login');
1.51      raeburn  13330:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  13331:         } else {
                   13332:             @images = ('img');
1.200     raeburn  13333:             @bgs = ('pgbg','tabbg','sidebg');
                   13334:         }
                   13335:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   13336:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   13337:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   13338:         }
                   13339:         if ($role eq 'login') {
                   13340:             foreach my $item (@logintext) {
1.234     raeburn  13341:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   13342:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   13343:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   13344:                 }
                   13345:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  13346:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   13347:                 }
                   13348:             }
                   13349:         } else {
1.234     raeburn  13350:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   13351:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   13352:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   13353:             }
                   13354:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  13355:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   13356:             }
1.6       raeburn  13357:         }
1.200     raeburn  13358:         foreach my $item (@bgs) {
1.234     raeburn  13359:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   13360:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   13361:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   13362:             }
                   13363:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  13364:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   13365:             }
                   13366:         }
                   13367:         foreach my $item (@links) {
1.234     raeburn  13368:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   13369:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   13370:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   13371:             }
                   13372:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  13373:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   13374:             }
1.6       raeburn  13375:         }
1.46      raeburn  13376:         my ($configuserok,$author_ok,$switchserver) = 
                   13377:             &config_check($dom,$confname,$servadm);
1.9       raeburn  13378:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  13379:         if (ref($domconfig->{$role}) ne 'HASH') {
                   13380:             $domconfig->{$role} = {};
                   13381:         }
1.8       raeburn  13382:         foreach my $img (@images) {
1.402     raeburn  13383:             if ($role eq 'login') {
                   13384:                 if (($img eq 'img') || ($img eq 'logo')) {  
                   13385:                     if (defined($env{'form.login_showlogo_'.$img})) {
                   13386:                         $confhash->{$role}{'showlogo'}{$img} = 1;
                   13387:                     } else { 
                   13388:                         $confhash->{$role}{'showlogo'}{$img} = 0;
                   13389:                     }
                   13390:                 }
                   13391:                 if ($env{'form.login_alt_'.$img} ne '') {
                   13392:                     $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70      raeburn  13393:                 }
1.402     raeburn  13394:             }
1.18      albertel 13395: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   13396: 		 && !defined($domconfig->{$role}{$img})
                   13397: 		 && !$env{'form.'.$role.'_del_'.$img}
                   13398: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   13399: 		# import the old configured image from the .tab setting
                   13400: 		# if they haven't provided a new one 
                   13401: 		$domconfig->{$role}{$img} = 
                   13402: 		    $env{'form.'.$role.'_import_'.$img};
                   13403: 	    }
1.6       raeburn  13404:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  13405:                 my $error;
1.6       raeburn  13406:                 if ($configuserok eq 'ok') {
1.9       raeburn  13407:                     if ($switchserver) {
1.12      raeburn  13408:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  13409:                     } else {
                   13410:                         if ($author_ok eq 'ok') {
                   13411:                             my ($result,$logourl) = 
                   13412:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   13413:                                            $dom,$confname,$img,$width,$height);
                   13414:                             if ($result eq 'ok') {
                   13415:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  13416:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  13417:                             } else {
1.12      raeburn  13418:                                 $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  13419:                             }
                   13420:                         } else {
1.46      raeburn  13421:                             $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  13422:                         }
                   13423:                     }
                   13424:                 } else {
1.46      raeburn  13425:                     $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  13426:                 }
                   13427:                 if ($error) {
1.8       raeburn  13428:                     &Apache::lonnet::logthis($error);
1.11      albertel 13429:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  13430:                 }
                   13431:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  13432:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   13433:                     my $error;
                   13434:                     if ($configuserok eq 'ok') {
                   13435: # is confname an author?
                   13436:                         if ($switchserver eq '') {
                   13437:                             if ($author_ok eq 'ok') {
                   13438:                                 my ($result,$logourl) = 
                   13439:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   13440:                                             $dom,$confname,$img,$width,$height);
                   13441:                                 if ($result eq 'ok') {
                   13442:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 13443: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  13444:                                 }
                   13445:                             }
                   13446:                         }
                   13447:                     }
1.6       raeburn  13448:                 }
                   13449:             }
                   13450:         }
                   13451:         if (ref($domconfig) eq 'HASH') {
                   13452:             if (ref($domconfig->{$role}) eq 'HASH') {
                   13453:                 foreach my $img (@images) {
                   13454:                     if ($domconfig->{$role}{$img} ne '') {
                   13455:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   13456:                             $confhash->{$role}{$img} = '';
1.12      raeburn  13457:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  13458:                         } else {
1.9       raeburn  13459:                             if ($confhash->{$role}{$img} eq '') {
                   13460:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   13461:                             }
1.6       raeburn  13462:                         }
                   13463:                     } else {
                   13464:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   13465:                             $confhash->{$role}{$img} = '';
1.12      raeburn  13466:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  13467:                         } 
                   13468:                     }
1.402     raeburn  13469:                     if ($role eq 'login') {
                   13470:                         if (($img eq 'logo') || ($img eq 'img')) {
                   13471:                             if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   13472:                                 if ($confhash->{$role}{'showlogo'}{$img} ne 
                   13473:                                     $domconfig->{$role}{'showlogo'}{$img}) {
                   13474:                                     $changes{$role}{'showlogo'}{$img} = 1; 
                   13475:                                 }
                   13476:                             } else {
                   13477:                                 if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   13478:                                     $changes{$role}{'showlogo'}{$img} = 1;
                   13479:                                 }
1.70      raeburn  13480:                             }
1.402     raeburn  13481:                         }
                   13482:                         if ($img ne 'login') {
                   13483:                             if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
                   13484:                                 if ($confhash->{$role}{'alttext'}{$img} ne
                   13485:                                     $domconfig->{$role}{'alttext'}{$img}) {
                   13486:                                     $changes{$role}{'alttext'}{$img} = 1;
                   13487:                                 }
                   13488:                             } else {
                   13489:                                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
                   13490:                                     $changes{$role}{'alttext'}{$img} = 1;
                   13491:                                 }
1.70      raeburn  13492:                             }
                   13493:                         }
                   13494:                     }
                   13495:                 }
1.6       raeburn  13496:                 if ($domconfig->{$role}{'font'} ne '') {
                   13497:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   13498:                         $changes{$role}{'font'} = 1;
                   13499:                     }
                   13500:                 } else {
                   13501:                     if ($confhash->{$role}{'font'}) {
                   13502:                         $changes{$role}{'font'} = 1;
                   13503:                     }
                   13504:                 }
1.107     raeburn  13505:                 if ($role ne 'login') {
                   13506:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   13507:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   13508:                             $changes{$role}{'fontmenu'} = 1;
                   13509:                         }
                   13510:                     } else {
                   13511:                         if ($confhash->{$role}{'fontmenu'}) {
                   13512:                             $changes{$role}{'fontmenu'} = 1;
                   13513:                         }
1.97      tempelho 13514:                     }
                   13515:                 }
1.6       raeburn  13516:                 foreach my $item (@bgs) {
                   13517:                     if ($domconfig->{$role}{$item} ne '') {
                   13518:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13519:                             $changes{$role}{'bgs'}{$item} = 1;
                   13520:                         } 
                   13521:                     } else {
                   13522:                         if ($confhash->{$role}{$item}) {
                   13523:                             $changes{$role}{'bgs'}{$item} = 1;
                   13524:                         }
                   13525:                     }
                   13526:                 }
                   13527:                 foreach my $item (@links) {
                   13528:                     if ($domconfig->{$role}{$item} ne '') {
                   13529:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13530:                             $changes{$role}{'links'}{$item} = 1;
                   13531:                         }
                   13532:                     } else {
                   13533:                         if ($confhash->{$role}{$item}) {
                   13534:                             $changes{$role}{'links'}{$item} = 1;
                   13535:                         }
                   13536:                     }
                   13537:                 }
1.41      raeburn  13538:                 foreach my $item (@logintext) {
                   13539:                     if ($domconfig->{$role}{$item} ne '') {
                   13540:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13541:                             $changes{$role}{'logintext'}{$item} = 1;
                   13542:                         }
                   13543:                     } else {
                   13544:                         if ($confhash->{$role}{$item}) {
                   13545:                             $changes{$role}{'logintext'}{$item} = 1;
                   13546:                         }
                   13547:                     }
                   13548:                 }
1.6       raeburn  13549:             } else {
                   13550:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13551:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  13552:             }
                   13553:         } else {
                   13554:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13555:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  13556:         }
                   13557:     }
                   13558:     return ($errors,%changes);
                   13559: }
                   13560: 
1.46      raeburn  13561: sub config_check {
                   13562:     my ($dom,$confname,$servadm) = @_;
                   13563:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   13564:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   13565:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   13566:                                                    $confname,$servadm);
                   13567:     if ($configuserok eq 'ok') {
                   13568:         $switchserver = &check_switchserver($dom,$confname);
                   13569:         if ($switchserver eq '') {
                   13570:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   13571:         }
                   13572:     }
                   13573:     return ($configuserok,$author_ok,$switchserver);
                   13574: }
                   13575: 
1.6       raeburn  13576: sub default_change_checker {
1.41      raeburn  13577:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  13578:     foreach my $item (@{$links}) {
                   13579:         if ($confhash->{$role}{$item}) {
                   13580:             $changes->{$role}{'links'}{$item} = 1;
                   13581:         }
                   13582:     }
                   13583:     foreach my $item (@{$bgs}) {
                   13584:         if ($confhash->{$role}{$item}) {
                   13585:             $changes->{$role}{'bgs'}{$item} = 1;
                   13586:         }
                   13587:     }
1.41      raeburn  13588:     foreach my $item (@{$logintext}) {
                   13589:         if ($confhash->{$role}{$item}) {
                   13590:             $changes->{$role}{'logintext'}{$item} = 1;
                   13591:         }
                   13592:     }
1.6       raeburn  13593:     foreach my $img (@{$images}) {
                   13594:         if ($env{'form.'.$role.'_del_'.$img}) {
                   13595:             $confhash->{$role}{$img} = '';
1.12      raeburn  13596:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  13597:         }
1.70      raeburn  13598:         if ($role eq 'login') {
                   13599:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   13600:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   13601:             }
1.402     raeburn  13602:             if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
                   13603:                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
                   13604:                     $changes->{$role}{'alttext'}{$img} = 1;
                   13605:                 }
                   13606:             }
1.70      raeburn  13607:         }
1.6       raeburn  13608:     }
                   13609:     if ($confhash->{$role}{'font'}) {
                   13610:         $changes->{$role}{'font'} = 1;
                   13611:     }
1.48      raeburn  13612: }
1.6       raeburn  13613: 
                   13614: sub display_colorchgs {
                   13615:     my ($dom,$changes,$roles,$confhash) = @_;
                   13616:     my (%choices,$resulttext);
                   13617:     if (!grep(/^login$/,@{$roles})) {
                   13618:         $resulttext = &mt('Changes made:').'<br />';
                   13619:     }
                   13620:     foreach my $role (@{$roles}) {
                   13621:         if ($role eq 'login') {
                   13622:             %choices = &login_choices();
                   13623:         } else {
                   13624:             %choices = &color_font_choices();
                   13625:         }
                   13626:         if (ref($changes->{$role}) eq 'HASH') {
                   13627:             if ($role ne 'login') {
                   13628:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   13629:             }
                   13630:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   13631:                 if ($role ne 'login') {
                   13632:                     $resulttext .= '<ul>';
                   13633:                 }
                   13634:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   13635:                     if ($role ne 'login') {
                   13636:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   13637:                     }
                   13638:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  13639:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   13640:                             if ($confhash->{$role}{$key}{$item}) {
                   13641:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   13642:                             } else {
                   13643:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   13644:                             }
1.402     raeburn  13645:                         } elsif (($role eq 'login') && ($key eq 'alttext')) {
                   13646:                             if ($confhash->{$role}{$key}{$item} ne '') {
1.403     raeburn  13647:                                 $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402     raeburn  13648:                                                $confhash->{$role}{$key}{$item}).'</li>';
                   13649:                             } else {
                   13650:                                 $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
                   13651:                             }
1.70      raeburn  13652:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  13653:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   13654:                         } else {
1.12      raeburn  13655:                             my $newitem = $confhash->{$role}{$item};
                   13656:                             if ($key eq 'images') {
1.306     raeburn  13657:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  13658:                             }
                   13659:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  13660:                         }
                   13661:                     }
                   13662:                     if ($role ne 'login') {
                   13663:                         $resulttext .= '</ul></li>';
                   13664:                     }
                   13665:                 } else {
                   13666:                     if ($confhash->{$role}{$key} eq '') {
                   13667:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   13668:                     } else {
                   13669:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   13670:                     }
                   13671:                 }
                   13672:                 if ($role ne 'login') {
                   13673:                     $resulttext .= '</ul>';
                   13674:                 }
                   13675:             }
                   13676:         }
                   13677:     }
1.3       raeburn  13678:     return $resulttext;
1.1       raeburn  13679: }
                   13680: 
1.9       raeburn  13681: sub thumb_dimensions {
                   13682:     return ('200','50');
                   13683: }
                   13684: 
1.16      raeburn  13685: sub check_dimensions {
                   13686:     my ($inputfile) = @_;
                   13687:     my ($fullwidth,$fullheight);
                   13688:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   13689:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   13690:             my $imageinfo = <PIPE>;
                   13691:             if (!close(PIPE)) {
                   13692:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   13693:             }
                   13694:             chomp($imageinfo);
                   13695:             my ($fullsize) = 
1.21      raeburn  13696:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  13697:             if ($fullsize) {
                   13698:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   13699:             }
                   13700:         }
                   13701:     }
                   13702:     return ($fullwidth,$fullheight);
                   13703: }
                   13704: 
1.9       raeburn  13705: sub check_configuser {
                   13706:     my ($uhome,$dom,$confname,$servadm) = @_;
                   13707:     my ($configuserok,%currroles);
                   13708:     if ($uhome eq 'no_host') {
                   13709:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.361     raeburn  13710:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  13711:         $configuserok = 
                   13712:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   13713:                              $configpass,'','','','','',undef,$servadm);
                   13714:     } else {
                   13715:         $configuserok = 'ok';
                   13716:         %currroles = 
                   13717:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   13718:     }
                   13719:     return ($configuserok,%currroles);
                   13720: }
                   13721: 
                   13722: sub check_authorstatus {
                   13723:     my ($dom,$confname,%currroles) = @_;
                   13724:     my $author_ok;
1.40      raeburn  13725:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  13726:         my $start = time;
                   13727:         my $end = 0;
                   13728:         $author_ok = 
                   13729:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  13730:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  13731:     } else {
                   13732:         $author_ok = 'ok';
                   13733:     }
                   13734:     return $author_ok;
                   13735: }
                   13736: 
                   13737: sub publishlogo {
1.46      raeburn  13738:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  13739:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  13740:     if ($action eq 'upload') {
                   13741:         $fname=$env{'form.'.$formname.'.filename'};
                   13742:         chop($env{'form.'.$formname});
                   13743:     } else {
                   13744:         ($fname) = ($formname =~ /([^\/]+)$/);
                   13745:     }
1.46      raeburn  13746:     if ($savefileas ne '') {
                   13747:         $fname = $savefileas;
                   13748:     }
1.9       raeburn  13749:     $fname=&Apache::lonnet::clean_filename($fname);
                   13750: # See if there is anything left
                   13751:     unless ($fname) { return ('error: no uploaded file'); }
                   13752:     $fname="$subdir/$fname";
1.210     raeburn  13753:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  13754:     my $filepath="$docroot/priv";
                   13755:     my $relpath = "$dom/$confname";
1.9       raeburn  13756:     my ($fnamepath,$file,$fetchthumb);
                   13757:     $file=$fname;
                   13758:     if ($fname=~m|/|) {
                   13759:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   13760:     }
1.164     raeburn  13761:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  13762:     my $count;
1.164     raeburn  13763:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  13764:         $filepath.="/$parts[$count]";
                   13765:         if ((-e $filepath)!=1) {
                   13766:             mkdir($filepath,02770);
                   13767:         }
                   13768:     }
                   13769:     # Check for bad extension and disallow upload
                   13770:     if ($file=~/\.(\w+)$/ &&
                   13771:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   13772:         $output = 
1.207     bisitz   13773:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  13774:     } elsif ($file=~/\.(\w+)$/ &&
                   13775:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   13776:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   13777:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   13778:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9       raeburn  13779:     } elsif (-d "$filepath/$file") {
1.195     bisitz   13780:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  13781:     } else {
                   13782:         my $source = $filepath.'/'.$file;
                   13783:         my $logfile;
1.316     raeburn  13784:         if (!open($logfile,">>",$source.'.log')) {
1.196     raeburn  13785:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  13786:         }
                   13787:         print $logfile
                   13788: "\n================= Publish ".localtime()." ================\n".
                   13789: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   13790: # Save the file
1.316     raeburn  13791:         if (!open(FH,">",$source)) {
1.9       raeburn  13792:             &Apache::lonnet::logthis('Failed to create '.$source);
                   13793:             return (&mt('Failed to create file'));
                   13794:         }
                   13795:         if ($action eq 'upload') {
                   13796:             if (!print FH ($env{'form.'.$formname})) {
                   13797:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   13798:                 return (&mt('Failed to write file'));
                   13799:             }
                   13800:         } else {
                   13801:             my $original = &Apache::lonnet::filelocation('',$formname);
                   13802:             if(!copy($original,$source)) {
                   13803:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   13804:                 return (&mt('Failed to write file'));
                   13805:             }
                   13806:         }
                   13807:         close(FH);
                   13808:         chmod(0660, $source); # Permissions to rw-rw---.
                   13809: 
                   13810:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   13811:         my $copyfile=$targetdir.'/'.$file;
                   13812: 
                   13813:         my @parts=split(/\//,$targetdir);
                   13814:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   13815:         for (my $count=5;$count<=$#parts;$count++) {
                   13816:             $path.="/$parts[$count]";
                   13817:             if (!-e $path) {
                   13818:                 print $logfile "\nCreating directory ".$path;
                   13819:                 mkdir($path,02770);
                   13820:             }
                   13821:         }
                   13822:         my $versionresult;
                   13823:         if (-e $copyfile) {
                   13824:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   13825:         } else {
                   13826:             $versionresult = 'ok';
                   13827:         }
                   13828:         if ($versionresult eq 'ok') {
                   13829:             if (copy($source,$copyfile)) {
                   13830:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   13831:                 $output = 'ok';
                   13832:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  13833:                 push(@{$modified_urls},[$copyfile,$source]);
                   13834:                 my $metaoutput = 
                   13835:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   13836:                 unless ($registered_cleanup) {
                   13837:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13838:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13839:                     $registered_cleanup=1;
                   13840:                 }
1.9       raeburn  13841:             } else {
                   13842:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   13843:                 $output = &mt('Failed to copy file to RES space').", $!";
                   13844:             }
                   13845:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   13846:                 my $inputfile = $filepath.'/'.$file;
                   13847:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  13848:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   13849:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   13850:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   13851:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316     raeburn  13852:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   13853:                         system({$args[0]} @args);
1.16      raeburn  13854:                         chmod(0660, $filepath.'/tn-'.$file);
                   13855:                         if (-e $outfile) {
                   13856:                             my $copyfile=$targetdir.'/tn-'.$file;
                   13857:                             if (copy($outfile,$copyfile)) {
                   13858:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  13859:                                 my $thumb_metaoutput = 
                   13860:                                     &write_metadata($dom,$confname,$formname,
                   13861:                                                     $targetdir,'tn-'.$file,$logfile);
                   13862:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   13863:                                 unless ($registered_cleanup) {
                   13864:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13865:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13866:                                     $registered_cleanup=1;
                   13867:                                 }
1.267     raeburn  13868:                                 $madethumb = 1;
1.16      raeburn  13869:                             } else {
                   13870:                                 print $logfile "\nUnable to write ".$copyfile.
                   13871:                                                ':'.$!."\n";
                   13872:                             }
                   13873:                         }
1.9       raeburn  13874:                     }
                   13875:                 }
                   13876:             }
                   13877:         } else {
                   13878:             $output = $versionresult;
                   13879:         }
                   13880:     }
1.267     raeburn  13881:     return ($output,$logourl,$madethumb);
1.9       raeburn  13882: }
                   13883: 
                   13884: sub logo_versioning {
                   13885:     my ($targetdir,$file,$logfile) = @_;
                   13886:     my $target = $targetdir.'/'.$file;
                   13887:     my ($maxversion,$fn,$extn,$output);
                   13888:     $maxversion = 0;
                   13889:     if ($file =~ /^(.+)\.(\w+)$/) {
                   13890:         $fn=$1;
                   13891:         $extn=$2;
                   13892:     }
                   13893:     opendir(DIR,$targetdir);
                   13894:     while (my $filename=readdir(DIR)) {
                   13895:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   13896:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   13897:         }
                   13898:     }
                   13899:     $maxversion++;
                   13900:     print $logfile "\nCreating old version ".$maxversion."\n";
                   13901:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   13902:     if (copy($target,$copyfile)) {
                   13903:         print $logfile "Copied old target to ".$copyfile."\n";
                   13904:         $copyfile=$copyfile.'.meta';
                   13905:         if (copy($target.'.meta',$copyfile)) {
                   13906:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   13907:             $output = 'ok';
                   13908:         } else {
                   13909:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   13910:             $output = &mt('Failed to copy old meta').", $!, ";
                   13911:         }
                   13912:     } else {
                   13913:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   13914:         $output = &mt('Failed to copy old target').", $!, ";
                   13915:     }
                   13916:     return $output;
                   13917: }
                   13918: 
                   13919: sub write_metadata {
                   13920:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   13921:     my (%metadatafields,%metadatakeys,$output);
                   13922:     $metadatafields{'title'}=$formname;
                   13923:     $metadatafields{'creationdate'}=time;
                   13924:     $metadatafields{'lastrevisiondate'}=time;
                   13925:     $metadatafields{'copyright'}='public';
                   13926:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   13927:                                          $env{'user.domain'};
                   13928:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   13929:     $metadatafields{'domain'}=$dom;
                   13930:     {
                   13931:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   13932:         my $mfh;
1.316     raeburn  13933:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  13934:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  13935:                 unless ($_=~/\./) {
                   13936:                     my $unikey=$_;
                   13937:                     $unikey=~/^([A-Za-z]+)/;
                   13938:                     my $tag=$1;
                   13939:                     $tag=~tr/A-Z/a-z/;
                   13940:                     print $mfh "\n\<$tag";
                   13941:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   13942:                         my $value=$metadatafields{$unikey.'.'.$_};
                   13943:                         $value=~s/\"/\'\'/g;
                   13944:                         print $mfh ' '.$_.'="'.$value.'"';
                   13945:                     }
                   13946:                     print $mfh '>'.
                   13947:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   13948:                             .'</'.$tag.'>';
                   13949:                 }
                   13950:             }
                   13951:             $output = 'ok';
                   13952:             print $logfile "\nWrote metadata";
                   13953:             close($mfh);
                   13954:         } else {
                   13955:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  13956:             $output = &mt('Could not write metadata');
                   13957:         }
                   13958:     }
1.155     raeburn  13959:     return $output;
                   13960: }
                   13961: 
                   13962: sub notifysubscribed {
                   13963:     foreach my $targetsource (@{$modified_urls}){
                   13964:         next unless (ref($targetsource) eq 'ARRAY');
                   13965:         my ($target,$source)=@{$targetsource};
                   13966:         if ($source ne '') {
1.316     raeburn  13967:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  13968:                 print $logfh "\nCleanup phase: Notifications\n";
                   13969:                 my @subscribed=&subscribed_hosts($target);
                   13970:                 foreach my $subhost (@subscribed) {
                   13971:                     print $logfh "\nNotifying host ".$subhost.':';
                   13972:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   13973:                     print $logfh $reply;
                   13974:                 }
                   13975:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   13976:                 foreach my $subhost (@subscribedmeta) {
                   13977:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   13978:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   13979:                                                         $subhost);
                   13980:                     print $logfh $reply;
                   13981:                 }
                   13982:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  13983:                 close($logfh);
1.155     raeburn  13984:             }
                   13985:         }
                   13986:     }
                   13987:     return OK;
                   13988: }
                   13989: 
                   13990: sub subscribed_hosts {
                   13991:     my ($target) = @_;
                   13992:     my @subscribed;
1.316     raeburn  13993:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  13994:         while (my $subline=<$fh>) {
                   13995:             if ($subline =~ /^($match_lonid):/) {
                   13996:                 my $host = $1;
                   13997:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   13998:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   13999:                         push(@subscribed,$host);
                   14000:                     }
                   14001:                 }
                   14002:             }
                   14003:         }
                   14004:     }
                   14005:     return @subscribed;
1.9       raeburn  14006: }
                   14007: 
                   14008: sub check_switchserver {
                   14009:     my ($dom,$confname) = @_;
                   14010:     my ($allowed,$switchserver);
                   14011:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   14012:     if ($home eq 'no_host') {
                   14013:         $home = &Apache::lonnet::domain($dom,'primary');
                   14014:     }
                   14015:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 14016:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   14017:     if (!$allowed) {
1.180     raeburn  14018: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  14019:     }
                   14020:     return $switchserver;
                   14021: }
                   14022: 
1.1       raeburn  14023: sub modify_quotas {
1.216     raeburn  14024:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  14025:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  14026:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  14027:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   14028:         $validationfieldsref);
1.86      raeburn  14029:     if ($action eq 'quotas') {
                   14030:         $context = 'tools'; 
1.163     raeburn  14031:     } else {
1.86      raeburn  14032:         $context = $action;
                   14033:     }
                   14034:     if ($context eq 'requestcourses') {
1.325     raeburn  14035:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  14036:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  14037:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   14038:         %titles = &courserequest_titles();
                   14039:         $toolregexp = join('|',@usertools);
                   14040:         %conditions = &courserequest_conditions();
1.216     raeburn  14041:         $confname = $dom.'-domainconfig';
                   14042:         my $servadm = $r->dir_config('lonAdmEMail');
                   14043:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  14044:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   14045:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  14046:     } elsif ($context eq 'requestauthor') {
                   14047:         @usertools = ('author');
                   14048:         %titles = &authorrequest_titles();
1.86      raeburn  14049:     } else {
1.413     raeburn  14050:         @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101     raeburn  14051:         %titles = &tool_titles();
1.86      raeburn  14052:     }
1.212     raeburn  14053:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  14054:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  14055:     foreach my $key (keys(%env)) {
1.101     raeburn  14056:         if ($context eq 'requestcourses') {
                   14057:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   14058:                 my $item = $1;
                   14059:                 my $type = $2;
                   14060:                 if ($type =~ /^limit_(.+)/) {
                   14061:                     $limithash{$item}{$1} = $env{$key};
                   14062:                 } else {
                   14063:                     $confhash{$item}{$type} = $env{$key};
                   14064:                 }
                   14065:             }
1.163     raeburn  14066:         } elsif ($context eq 'requestauthor') {
                   14067:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   14068:                 $confhash{$1} = $env{$key};
                   14069:             }
1.101     raeburn  14070:         } else {
1.86      raeburn  14071:             if ($key =~ /^form\.quota_(.+)$/) {
                   14072:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  14073:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   14074:                 $confhash{'authorquota'}{$1} = $env{$key};
                   14075:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  14076:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   14077:             }
1.72      raeburn  14078:         }
                   14079:     }
1.163     raeburn  14080:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  14081:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  14082:         @approvalnotify = sort(@approvalnotify);
                   14083:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325     raeburn  14084:         my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218     raeburn  14085:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   14086:         foreach my $type (@hasuniquecode) {
                   14087:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   14088:                 $confhash{'uniquecode'}{$type} = 1;
                   14089:             }
1.216     raeburn  14090:         }
1.242     raeburn  14091:         my (%newbook,%allpos);
1.216     raeburn  14092:         if ($context eq 'requestcourses') {
1.242     raeburn  14093:             foreach my $type ('textbooks','templates') {
                   14094:                 @{$allpos{$type}} = (); 
                   14095:                 my $invalid;
                   14096:                 if ($type eq 'textbooks') {
                   14097:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   14098:                 } else {
                   14099:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   14100:                 }
                   14101:                 if ($env{'form.'.$type.'_addbook'}) {
                   14102:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   14103:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   14104:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   14105:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   14106:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   14107:                         } else {
                   14108:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   14109:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   14110:                             $position =~ s/\D+//g;
                   14111:                             if ($position ne '') {
                   14112:                                 $allpos{$type}[$position] = $newbook{$type};
                   14113:                             }
1.216     raeburn  14114:                         }
1.242     raeburn  14115:                     } else {
                   14116:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  14117:                     }
                   14118:                 }
1.242     raeburn  14119:             } 
1.216     raeburn  14120:         }
1.102     raeburn  14121:         if (ref($domconfig{$action}) eq 'HASH') {
                   14122:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   14123:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   14124:                     $changes{'notify'}{'approval'} = 1;
                   14125:                 }
                   14126:             } else {
1.144     raeburn  14127:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  14128:                     $changes{'notify'}{'approval'} = 1;
                   14129:                 }
                   14130:             }
1.218     raeburn  14131:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   14132:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14133:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   14134:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   14135:                             $changes{'uniquecode'} = 1;
                   14136:                         }
                   14137:                     }
                   14138:                     unless ($changes{'uniquecode'}) {
                   14139:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   14140:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   14141:                                 $changes{'uniquecode'} = 1;
                   14142:                             }
                   14143:                         }
                   14144:                     }
                   14145:                } else {
                   14146:                    $changes{'uniquecode'} = 1;
                   14147:                }
                   14148:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14149:                 $changes{'uniquecode'} = 1;
1.216     raeburn  14150:             }
                   14151:             if ($context eq 'requestcourses') {
1.242     raeburn  14152:                 foreach my $type ('textbooks','templates') {
                   14153:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   14154:                         my %deletions;
                   14155:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   14156:                         if (@todelete) {
                   14157:                             map { $deletions{$_} = 1; } @todelete;
                   14158:                         }
                   14159:                         my %imgdeletions;
                   14160:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   14161:                         if (@todeleteimages) {
                   14162:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14163:                         }
                   14164:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   14165:                         for (my $i=0; $i<=$maxnum; $i++) {
                   14166:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   14167:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   14168:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   14169:                                 if ($deletions{$key}) {
                   14170:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   14171:                                         #FIXME need to obsolete item in RES space
                   14172:                                     }
                   14173:                                     next;
                   14174:                                 } else {
                   14175:                                     my $newpos = $env{'form.'.$itemid};
                   14176:                                     $newpos =~ s/\D+//g;
1.243     raeburn  14177:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  14178:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  14179:                                                  ($type eq 'templates'));
1.242     raeburn  14180:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   14181:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   14182:                                             $changes{$type}{$key} = 1;
                   14183:                                         }
                   14184:                                     }
                   14185:                                     $allpos{$type}[$newpos] = $key;
                   14186:                                 }
                   14187:                                 if ($imgdeletions{$key}) {
                   14188:                                     $changes{$type}{$key} = 1;
1.216     raeburn  14189:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  14190:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   14191:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  14192:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   14193:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   14194:                                     } else {
                   14195:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   14196:                                                                                       $cdom,$cnum,$type,$configuserok,
                   14197:                                                                                       $switchserver,$author_ok);
                   14198:                                         if ($imgurl) {
                   14199:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   14200:                                             $changes{$type}{$key} = 1; 
                   14201:                                         }
                   14202:                                         if ($error) {
                   14203:                                             &Apache::lonnet::logthis($error);
                   14204:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14205:                                         }
                   14206:                                     }
1.242     raeburn  14207:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   14208:                                     $confhash{$type}{$key}{'image'} = 
                   14209:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  14210:                                 }
                   14211:                             }
                   14212:                         }
                   14213:                     }
                   14214:                 }
                   14215:             }
1.102     raeburn  14216:         } else {
1.144     raeburn  14217:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  14218:                 $changes{'notify'}{'approval'} = 1;
                   14219:             }
1.218     raeburn  14220:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  14221:                 $changes{'uniquecode'} = 1;
                   14222:             }
                   14223:         }
                   14224:         if ($context eq 'requestcourses') {
1.242     raeburn  14225:             foreach my $type ('textbooks','templates') {
                   14226:                 if ($newbook{$type}) {
                   14227:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  14228:                     foreach my $item ('subject','title','publisher','author') {
                   14229:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   14230:                                  ($type eq 'template'));
1.242     raeburn  14231:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   14232:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   14233:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   14234:                         }
                   14235:                     }
                   14236:                     if ($type eq 'textbooks') {
                   14237:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   14238:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  14239:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   14240:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   14241:                             } else {
                   14242:                                 my ($imageurl,$error) =
                   14243:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   14244:                                                             $configuserok,$switchserver,$author_ok);
                   14245:                                 if ($imageurl) {
                   14246:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   14247:                                 }
                   14248:                                 if ($error) {
                   14249:                                     &Apache::lonnet::logthis($error);
                   14250:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14251:                                 }
1.242     raeburn  14252:                             }
                   14253:                         }
1.216     raeburn  14254:                     }
                   14255:                 }
1.242     raeburn  14256:                 if (@{$allpos{$type}} > 0) {
                   14257:                     my $idx = 0;
                   14258:                     foreach my $item (@{$allpos{$type}}) {
                   14259:                         if ($item ne '') {
                   14260:                             $confhash{$type}{$item}{'order'} = $idx;
                   14261:                             if (ref($domconfig{$action}) eq 'HASH') {
                   14262:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   14263:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   14264:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   14265:                                             $changes{$type}{$item} = 1;
                   14266:                                         }
1.216     raeburn  14267:                                     }
                   14268:                                 }
                   14269:                             }
1.242     raeburn  14270:                             $idx ++;
1.216     raeburn  14271:                         }
                   14272:                     }
                   14273:                 }
                   14274:             }
1.235     raeburn  14275:             if (ref($validationitemsref) eq 'ARRAY') {
                   14276:                 foreach my $item (@{$validationitemsref}) {
                   14277:                     if ($item eq 'fields') {
                   14278:                         my @changed;
                   14279:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   14280:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   14281:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   14282:                         }
1.266     raeburn  14283:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14284:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14285:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   14286:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   14287:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   14288:                                 } else {
                   14289:                                     @changed = @{$confhash{'validation'}{$item}};
                   14290:                                 }
1.235     raeburn  14291:                             } else {
                   14292:                                 @changed = @{$confhash{'validation'}{$item}};
                   14293:                             }
                   14294:                         } else {
                   14295:                             @changed = @{$confhash{'validation'}{$item}};
                   14296:                         }
                   14297:                         if (@changed) {
                   14298:                             if ($confhash{'validation'}{$item}) {
                   14299:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   14300:                             } else {
                   14301:                                 $changes{'validation'}{$item} = &mt('None');
                   14302:                             }
                   14303:                         }
                   14304:                     } else {
                   14305:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   14306:                         if ($item eq 'markup') {
                   14307:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   14308:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   14309:                             }
                   14310:                         }
1.266     raeburn  14311:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14312:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14313:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   14314:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   14315:                                 }
                   14316:                             } else {
                   14317:                                 if ($confhash{'validation'}{$item} ne '') {
                   14318:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   14319:                                 }
1.235     raeburn  14320:                             }
                   14321:                         } else {
                   14322:                             if ($confhash{'validation'}{$item} ne '') {
                   14323:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   14324:                             }
                   14325:                         }
                   14326:                     }
                   14327:                 }
                   14328:             }
                   14329:             if ($env{'form.validationdc'}) {
                   14330:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  14331:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  14332:                 if (exists($domcoords{$newval})) {
                   14333:                     $confhash{'validation'}{'dc'} = $newval;
                   14334:                 }
                   14335:             }
                   14336:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  14337:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14338:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14339:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   14340:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   14341:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   14342:                                     $changes{'validation'}{'dc'} = &mt('None');
                   14343:                                 } else {
                   14344:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   14345:                                 }
1.235     raeburn  14346:                             }
1.266     raeburn  14347:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   14348:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  14349:                         }
                   14350:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   14351:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   14352:                     }
                   14353:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   14354:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  14355:                 }
1.266     raeburn  14356:             } else {
                   14357:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   14358:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   14359:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   14360:                             $changes{'validation'}{'dc'} = &mt('None');
                   14361:                         }
                   14362:                     }
1.235     raeburn  14363:                 }
                   14364:             }
1.102     raeburn  14365:         }
                   14366:     } else {
1.86      raeburn  14367:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  14368:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  14369:     }
1.72      raeburn  14370:     foreach my $item (@usertools) {
                   14371:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  14372:             my $unset; 
1.101     raeburn  14373:             if ($context eq 'requestcourses') {
1.104     raeburn  14374:                 $unset = '0';
                   14375:                 if ($type eq '_LC_adv') {
                   14376:                     $unset = '';
                   14377:                 }
1.101     raeburn  14378:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   14379:                     $confhash{$item}{$type} .= '=';
                   14380:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   14381:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   14382:                     }
                   14383:                 }
1.163     raeburn  14384:             } elsif ($context eq 'requestauthor') {
                   14385:                 $unset = '0';
                   14386:                 if ($type eq '_LC_adv') {
                   14387:                     $unset = '';
                   14388:                 }
1.72      raeburn  14389:             } else {
1.101     raeburn  14390:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   14391:                     $confhash{$item}{$type} = 1;
                   14392:                 } else {
                   14393:                     $confhash{$item}{$type} = 0;
                   14394:                 }
1.72      raeburn  14395:             }
1.86      raeburn  14396:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  14397:                 if ($action eq 'requestauthor') {
                   14398:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   14399:                         $changes{$type} = 1;
                   14400:                     }
                   14401:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  14402:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   14403:                         $changes{$item}{$type} = 1;
                   14404:                     }
                   14405:                 } else {
                   14406:                     if ($context eq 'requestcourses') {
1.104     raeburn  14407:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  14408:                             $changes{$item}{$type} = 1;
                   14409:                         }
                   14410:                     } else {
                   14411:                         if (!$confhash{$item}{$type}) {
                   14412:                             $changes{$item}{$type} = 1;
                   14413:                         }
                   14414:                     }
                   14415:                 }
                   14416:             } else {
                   14417:                 if ($context eq 'requestcourses') {
1.104     raeburn  14418:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  14419:                         $changes{$item}{$type} = 1;
                   14420:                     }
1.163     raeburn  14421:                 } elsif ($context eq 'requestauthor') {
                   14422:                     if ($confhash{$type} ne $unset) {
                   14423:                         $changes{$type} = 1;
                   14424:                     }
1.72      raeburn  14425:                 } else {
                   14426:                     if (!$confhash{$item}{$type}) {
                   14427:                         $changes{$item}{$type} = 1;
                   14428:                     }
                   14429:                 }
                   14430:             }
1.1       raeburn  14431:         }
                   14432:     }
1.163     raeburn  14433:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  14434:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   14435:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   14436:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   14437:                     if (exists($confhash{'defaultquota'}{$key})) {
                   14438:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   14439:                             $changes{'defaultquota'}{$key} = 1;
                   14440:                         }
                   14441:                     } else {
                   14442:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  14443:                     }
                   14444:                 }
1.86      raeburn  14445:             } else {
                   14446:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   14447:                     if (exists($confhash{'defaultquota'}{$key})) {
                   14448:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   14449:                             $changes{'defaultquota'}{$key} = 1;
                   14450:                         }
                   14451:                     } else {
                   14452:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  14453:                     }
1.1       raeburn  14454:                 }
                   14455:             }
1.197     raeburn  14456:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   14457:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   14458:                     if (exists($confhash{'authorquota'}{$key})) {
                   14459:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   14460:                             $changes{'authorquota'}{$key} = 1;
                   14461:                         }
                   14462:                     } else {
                   14463:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   14464:                     }
                   14465:                 }
                   14466:             }
1.1       raeburn  14467:         }
1.86      raeburn  14468:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   14469:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   14470:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   14471:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   14472:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   14473:                             $changes{'defaultquota'}{$key} = 1;
                   14474:                         }
                   14475:                     } else {
                   14476:                         if (!exists($domconfig{'quotas'}{$key})) {
                   14477:                             $changes{'defaultquota'}{$key} = 1;
                   14478:                         }
1.72      raeburn  14479:                     }
                   14480:                 } else {
1.86      raeburn  14481:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  14482:                 }
1.1       raeburn  14483:             }
                   14484:         }
1.197     raeburn  14485:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   14486:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   14487:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   14488:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   14489:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   14490:                             $changes{'authorquota'}{$key} = 1;
                   14491:                         }
                   14492:                     } else {
                   14493:                         $changes{'authorquota'}{$key} = 1;
                   14494:                     }
                   14495:                 } else {
                   14496:                     $changes{'authorquota'}{$key} = 1;
                   14497:                 }
                   14498:             }
                   14499:         }
1.1       raeburn  14500:     }
1.72      raeburn  14501: 
1.163     raeburn  14502:     if ($context eq 'requestauthor') {
                   14503:         $domdefaults{'requestauthor'} = \%confhash;
                   14504:     } else {
                   14505:         foreach my $key (keys(%confhash)) {
1.242     raeburn  14506:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  14507:                 $domdefaults{$key} = $confhash{$key};
                   14508:             }
1.163     raeburn  14509:         }
1.72      raeburn  14510:     }
1.163     raeburn  14511: 
1.1       raeburn  14512:     my %quotahash = (
1.86      raeburn  14513:                       $action => { %confhash }
1.1       raeburn  14514:                     );
                   14515:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   14516:                                              $dom);
                   14517:     if ($putresult eq 'ok') {
                   14518:         if (keys(%changes) > 0) {
1.72      raeburn  14519:             my $cachetime = 24*60*60;
                   14520:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  14521:             if (ref($lastactref) eq 'HASH') {
                   14522:                 $lastactref->{'domdefaults'} = 1;
                   14523:             }
1.1       raeburn  14524:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  14525:             unless (($context eq 'requestcourses') ||
1.163     raeburn  14526:                     ($context eq 'requestauthor')) {
1.86      raeburn  14527:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   14528:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   14529:                     foreach my $type (@{$types},'default') {
                   14530:                         if (defined($changes{'defaultquota'}{$type})) {
                   14531:                             my $typetitle = $usertypes->{$type};
                   14532:                             if ($type eq 'default') {
                   14533:                                 $typetitle = $othertitle;
                   14534:                             }
1.213     raeburn  14535:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  14536:                         }
                   14537:                     }
1.86      raeburn  14538:                     $resulttext .= '</ul></li>';
1.72      raeburn  14539:                 }
1.197     raeburn  14540:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   14541:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  14542:                     foreach my $type (@{$types},'default') {
                   14543:                         if (defined($changes{'authorquota'}{$type})) {
                   14544:                             my $typetitle = $usertypes->{$type};
                   14545:                             if ($type eq 'default') {
                   14546:                                 $typetitle = $othertitle;
                   14547:                             }
1.213     raeburn  14548:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  14549:                         }
                   14550:                     }
                   14551:                     $resulttext .= '</ul></li>';
                   14552:                 }
1.72      raeburn  14553:             }
1.80      raeburn  14554:             my %newenv;
1.72      raeburn  14555:             foreach my $item (@usertools) {
1.163     raeburn  14556:                 my (%haschgs,%inconf);
                   14557:                 if ($context eq 'requestauthor') {
                   14558:                     %haschgs = %changes;
1.210     raeburn  14559:                     %inconf = %confhash;
1.163     raeburn  14560:                 } else {
                   14561:                     if (ref($changes{$item}) eq 'HASH') {
                   14562:                         %haschgs = %{$changes{$item}};
                   14563:                     }
                   14564:                     if (ref($confhash{$item}) eq 'HASH') {
                   14565:                         %inconf = %{$confhash{$item}};
                   14566:                     }
                   14567:                 }
                   14568:                 if (keys(%haschgs) > 0) {
1.80      raeburn  14569:                     my $newacc = 
                   14570:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   14571:                                                           $env{'user.domain'},
1.86      raeburn  14572:                                                           $item,'reload',$context);
1.210     raeburn  14573:                     if (($context eq 'requestcourses') ||
1.163     raeburn  14574:                         ($context eq 'requestauthor')) {
1.108     raeburn  14575:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   14576:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  14577:                         }
                   14578:                     } else {
                   14579:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   14580:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   14581:                         }
1.80      raeburn  14582:                     }
1.163     raeburn  14583:                     unless ($context eq 'requestauthor') {
                   14584:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   14585:                     }
1.72      raeburn  14586:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  14587:                         if ($haschgs{$type}) {
1.72      raeburn  14588:                             my $typetitle = $usertypes->{$type};
                   14589:                             if ($type eq 'default') {
                   14590:                                 $typetitle = $othertitle;
                   14591:                             } elsif ($type eq '_LC_adv') {
                   14592:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   14593:                             }
1.163     raeburn  14594:                             if ($inconf{$type}) {
1.101     raeburn  14595:                                 if ($context eq 'requestcourses') {
                   14596:                                     my $cond;
1.163     raeburn  14597:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  14598:                                         if ($1 eq '') {
                   14599:                                             $cond = &mt('(Automatic processing of any request).');
                   14600:                                         } else {
                   14601:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   14602:                                         }
                   14603:                                     } else { 
1.163     raeburn  14604:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  14605:                                     }
                   14606:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  14607:                                 } elsif ($context eq 'requestauthor') {
                   14608:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   14609:                                                              $titles{$inconf{$type}},$typetitle);
                   14610: 
1.101     raeburn  14611:                                 } else {
                   14612:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   14613:                                 }
1.72      raeburn  14614:                             } else {
1.104     raeburn  14615:                                 if ($type eq '_LC_adv') {
1.163     raeburn  14616:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  14617:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14618:                                     } else { 
                   14619:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   14620:                                     }
                   14621:                                 } else {
                   14622:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14623:                                 }
1.72      raeburn  14624:                             }
                   14625:                         }
1.26      raeburn  14626:                     }
1.163     raeburn  14627:                     unless ($context eq 'requestauthor') {
                   14628:                         $resulttext .= '</ul></li>';
                   14629:                     }
1.26      raeburn  14630:                 }
1.1       raeburn  14631:             }
1.163     raeburn  14632:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  14633:                 if (ref($changes{'notify'}) eq 'HASH') {
                   14634:                     if ($changes{'notify'}{'approval'}) {
                   14635:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   14636:                             if ($confhash{'notify'}{'approval'}) {
                   14637:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   14638:                             } else {
1.163     raeburn  14639:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  14640:                             }
                   14641:                         }
                   14642:                     }
                   14643:                 }
                   14644:             }
1.216     raeburn  14645:             if ($action eq 'requestcourses') {
                   14646:                 my @offon = ('off','on');
                   14647:                 if ($changes{'uniquecode'}) {
1.218     raeburn  14648:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14649:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   14650:                         $resulttext .= '<li>'.
                   14651:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   14652:                                        '</li>';
                   14653:                     } else {
                   14654:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   14655:                                        '</li>';
                   14656:                     }
1.216     raeburn  14657:                 }
1.242     raeburn  14658:                 foreach my $type ('textbooks','templates') {
                   14659:                     if (ref($changes{$type}) eq 'HASH') {
                   14660:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   14661:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   14662:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   14663:                             my $coursetitle = $coursehash{'description'};
                   14664:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   14665:                             $resulttext .= '<li>';
1.243     raeburn  14666:                             foreach my $item ('subject','title','publisher','author') {
                   14667:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   14668:                                          ($type eq 'templates'));
1.242     raeburn  14669:                                 my $name = $item.':';
                   14670:                                 $name =~ s/^(\w)/\U$1/;
                   14671:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   14672:                             }
                   14673:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   14674:                             if ($type eq 'textbooks') {
                   14675:                                 if ($confhash{$type}{$key}{'image'}) {
                   14676:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   14677:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   14678:                                                    ' alt="Textbook cover" />').'<br />';
                   14679:                                 }
                   14680:                             }
                   14681:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  14682:                         }
1.242     raeburn  14683:                         $resulttext .= '</ul></li>';
1.216     raeburn  14684:                     }
                   14685:                 }
1.235     raeburn  14686:                 if (ref($changes{'validation'}) eq 'HASH') {
                   14687:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   14688:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   14689:                         foreach my $item (@{$validationitemsref}) {
                   14690:                             if (exists($changes{'validation'}{$item})) {
                   14691:                                 if ($item eq 'markup') {
                   14692:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14693:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   14694:                                 } else {
                   14695:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14696:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   14697:                                 }
                   14698:                             }
                   14699:                         }
                   14700:                         if (exists($changes{'validation'}{'dc'})) {
                   14701:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   14702:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   14703:                         }
                   14704:                     }
                   14705:                 }
1.216     raeburn  14706:             }
1.1       raeburn  14707:             $resulttext .= '</ul>';
1.80      raeburn  14708:             if (keys(%newenv)) {
                   14709:                 &Apache::lonnet::appenv(\%newenv);
                   14710:             }
1.1       raeburn  14711:         } else {
1.86      raeburn  14712:             if ($context eq 'requestcourses') {
                   14713:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  14714:             } elsif ($context eq 'requestauthor') {
                   14715:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  14716:             } else {
1.90      weissno  14717:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  14718:             }
1.1       raeburn  14719:         }
                   14720:     } else {
1.11      albertel 14721:         $resulttext = '<span class="LC_error">'.
                   14722: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  14723:     }
1.216     raeburn  14724:     if ($errors) {
                   14725:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   14726:                        '<ul>'.$errors.'</ul></p>';
                   14727:     }
1.3       raeburn  14728:     return $resulttext;
1.1       raeburn  14729: }
                   14730: 
1.216     raeburn  14731: sub process_textbook_image {
1.242     raeburn  14732:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  14733:     my $filename = $env{'form.'.$caller.'.filename'};
                   14734:     my ($error,$url);
                   14735:     my ($width,$height) = (50,50);
                   14736:     if ($configuserok eq 'ok') {
                   14737:         if ($switchserver) {
                   14738:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   14739:                          $switchserver);
                   14740:         } elsif ($author_ok eq 'ok') {
                   14741:             my ($result,$imageurl) =
                   14742:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.312     raeburn  14743:                              "$type/$cdom/$cnum/cover",$width,$height);
1.216     raeburn  14744:             if ($result eq 'ok') {
                   14745:                 $url = $imageurl;
                   14746:             } else {
                   14747:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14748:             }
                   14749:         } else {
                   14750:             $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);
                   14751:         }
                   14752:     } else {
                   14753:         $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);
                   14754:     }
                   14755:     return ($url,$error);
                   14756: }
                   14757: 
1.267     raeburn  14758: sub modify_ltitools {
                   14759:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   14760:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297     raeburn  14761:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267     raeburn  14762:     my $confname = $dom.'-domainconfig';
                   14763:     my $servadm = $r->dir_config('lonAdmEMail');
                   14764:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   14765:     my (%posslti,%possfield);
                   14766:     my @courseroles = ('cc','in','ta','ep','st');
                   14767:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   14768:     map { $posslti{$_} = 1; } @ltiroles;
                   14769:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   14770:     map { $possfield{$_} = 1; } @allfields;
                   14771:     my %lt = &ltitools_names(); 
                   14772:     if ($env{'form.ltitools_add'}) {
                   14773:         my $title = $env{'form.ltitools_add_title'};
                   14774:         $title =~ s/(`)/'/g;
                   14775:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   14776:         if ($newid) {
                   14777:             my $position = $env{'form.ltitools_add_pos'};
                   14778:             $position =~ s/\D+//g;
                   14779:             if ($position ne '') {
                   14780:                 $allpos[$position] = $newid;
                   14781:             }
                   14782:             $changes{$newid} = 1;
1.322     raeburn  14783:             foreach my $item ('title','url','key','secret','lifetime') {
1.267     raeburn  14784:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322     raeburn  14785:                 if ($item eq 'lifetime') {
                   14786:                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   14787:                 }
1.267     raeburn  14788:                 if ($env{'form.ltitools_add_'.$item}) {
1.297     raeburn  14789:                     if (($item eq 'key') || ($item eq 'secret')) {
                   14790:                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14791:                     } else {
                   14792:                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14793:                     }
1.267     raeburn  14794:                 }
                   14795:             }
                   14796:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   14797:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   14798:             }
                   14799:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   14800:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   14801:             }
1.323     raeburn  14802:             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   14803:                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   14804:             } else {
                   14805:                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   14806:             }
1.296     raeburn  14807:             foreach my $item ('width','height','linktext','explanation') {
1.267     raeburn  14808:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   14809:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296     raeburn  14810:                 if (($item eq 'width') || ($item eq 'height')) {
                   14811:                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   14812:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   14813:                     }
                   14814:                 } else {
                   14815:                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   14816:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item}; 
                   14817:                     }
1.267     raeburn  14818:                 }
                   14819:             }
                   14820:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   14821:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298     raeburn  14822:             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   14823:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267     raeburn  14824:             } else {
                   14825:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   14826:             }
                   14827:             foreach my $item ('passback','roster') {
1.319     raeburn  14828:                 if ($env{'form.ltitools_'.$item.'_add'}) {
1.267     raeburn  14829:                     $confhash{$newid}{$item} = 1;
1.319     raeburn  14830:                     if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
                   14831:                         my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
                   14832:                         $lifetime =~ s/^\s+|\s+$//g;
                   14833:                         if ($lifetime =~ /^\d+\.?\d*$/) {
                   14834:                             $confhash{$newid}{$item.'valid'} = $lifetime;
                   14835:                         }
                   14836:                     }
1.267     raeburn  14837:                 }
                   14838:             }
                   14839:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   14840:                 my ($imageurl,$error) =
1.307     raeburn  14841:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267     raeburn  14842:                                             $configuserok,$switchserver,$author_ok);
                   14843:                 if ($imageurl) {
                   14844:                     $confhash{$newid}{'image'} = $imageurl;
                   14845:                 }
                   14846:                 if ($error) {
                   14847:                     &Apache::lonnet::logthis($error);
                   14848:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14849:                 }
                   14850:             }
                   14851:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   14852:             foreach my $field (@fields) {
                   14853:                 if ($possfield{$field}) {
                   14854:                     if ($field eq 'roles') {
                   14855:                         foreach my $role (@courseroles) {
                   14856:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   14857:                             if (($choice ne '') && ($posslti{$choice})) {
                   14858:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   14859:                                 if ($role eq 'cc') {
                   14860:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   14861:                                 }
                   14862:                             }
                   14863:                         }
                   14864:                     } else {
                   14865:                         $confhash{$newid}{'fields'}{$field} = 1;
                   14866:                     }
                   14867:                 }
                   14868:             }
1.324     raeburn  14869:             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   14870:                 if ($confhash{$newid}{'fields'}{'user'}) {
                   14871:                     if ($env{'form.ltitools_userincdom_add'}) {
                   14872:                         $confhash{$newid}{'incdom'} = 1;
                   14873:                     }
                   14874:                 }
                   14875:             }
1.273     raeburn  14876:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   14877:             foreach my $item (@courseconfig) {
                   14878:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   14879:             }
1.267     raeburn  14880:             if ($env{'form.ltitools_add_custom'}) {
                   14881:                 my $name = $env{'form.ltitools_add_custom_name'};
                   14882:                 my $value = $env{'form.ltitools_add_custom_value'};
                   14883:                 $value =~ s/(`)/'/g;
                   14884:                 $name =~ s/(`)/'/g;
                   14885:                 $confhash{$newid}{'custom'}{$name} = $value;
                   14886:             }
                   14887:         } else {
                   14888:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   14889:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14890:         }
                   14891:     }
                   14892:     if (ref($domconfig{$action}) eq 'HASH') {
                   14893:         my %deletions;
                   14894:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   14895:         if (@todelete) {
                   14896:             map { $deletions{$_} = 1; } @todelete;
                   14897:         }
                   14898:         my %customadds;
                   14899:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   14900:         if (@newcustom) {
                   14901:             map { $customadds{$_} = 1; } @newcustom;
                   14902:         } 
                   14903:         my %imgdeletions;
                   14904:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   14905:         if (@todeleteimages) {
                   14906:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14907:         }
                   14908:         my $maxnum = $env{'form.ltitools_maxnum'};
                   14909:         for (my $i=0; $i<=$maxnum; $i++) {
                   14910:             my $itemid = $env{'form.ltitools_id_'.$i};
1.308     raeburn  14911:             $itemid =~ s/\D+//g;
1.267     raeburn  14912:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   14913:                 if ($deletions{$itemid}) {
                   14914:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   14915:                         #FIXME need to obsolete item in RES space
                   14916:                     }
                   14917:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   14918:                     next;
                   14919:                 } else {
                   14920:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   14921:                     $newpos =~ s/\D+//g;
1.322     raeburn  14922:                     foreach my $item ('title','url','lifetime') {
1.267     raeburn  14923:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14924:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   14925:                             $changes{$itemid} = 1;
                   14926:                         }
                   14927:                     }
1.297     raeburn  14928:                     foreach my $item ('key','secret') {
                   14929:                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14930:                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   14931:                             $changes{$itemid} = 1;
                   14932:                         }
                   14933:                     }
1.267     raeburn  14934:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   14935:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   14936:                     }
                   14937:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   14938:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   14939:                     }
1.323     raeburn  14940:                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   14941:                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   14942:                     } else {
                   14943:                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1'; 
                   14944:                     }
                   14945:                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   14946:                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   14947:                             $changes{$itemid} = 1;
                   14948:                         }
                   14949:                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   14950:                         $changes{$itemid} = 1;
                   14951:                     }
1.267     raeburn  14952:                     foreach my $size ('width','height') {
                   14953:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   14954:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   14955:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   14956:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   14957:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14958:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   14959:                                     $changes{$itemid} = 1;
                   14960:                                 }
                   14961:                             } else {
                   14962:                                 $changes{$itemid} = 1;
                   14963:                             }
1.296     raeburn  14964:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14965:                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   14966:                                 $changes{$itemid} = 1;
                   14967:                             }
                   14968:                         }
                   14969:                     }
                   14970:                     foreach my $item ('linktext','explanation') {
                   14971:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   14972:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   14973:                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   14974:                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14975:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14976:                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   14977:                                     $changes{$itemid} = 1;
                   14978:                                 }
                   14979:                             } else {
                   14980:                                 $changes{$itemid} = 1;
                   14981:                             }
                   14982:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14983:                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   14984:                                 $changes{$itemid} = 1;
                   14985:                             }
1.267     raeburn  14986:                         }
                   14987:                     }
                   14988:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   14989:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298     raeburn  14990:                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   14991:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267     raeburn  14992:                     } else {
                   14993:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   14994:                     }
                   14995:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14996:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   14997:                             $changes{$itemid} = 1;
                   14998:                         }
                   14999:                     } else {
                   15000:                         $changes{$itemid} = 1;
                   15001:                     }
                   15002:                     foreach my $extra ('passback','roster') {
                   15003:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   15004:                             $confhash{$itemid}{$extra} = 1;
1.319     raeburn  15005:                             if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338     raeburn  15006:                                 my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319     raeburn  15007:                                 $lifetime =~ s/^\s+|\s+$//g;
                   15008:                                 if ($lifetime =~ /^\d+\.?\d*$/) {
                   15009:                                     $confhash{$itemid}{$extra.'valid'} = $lifetime;
                   15010:                                 }
                   15011:                             }
1.267     raeburn  15012:                         }
                   15013:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   15014:                             $changes{$itemid} = 1;
                   15015:                         }
1.319     raeburn  15016:                         if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
                   15017:                             $changes{$itemid} = 1;
                   15018:                         }
1.267     raeburn  15019:                     }
1.273     raeburn  15020:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318     raeburn  15021:                     foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  15022:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   15023:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   15024:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   15025:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   15026:                                     $changes{$itemid} = 1;
                   15027:                                 }
                   15028:                             } else {
                   15029:                                 $changes{$itemid} = 1;
                   15030:                             }
                   15031:                         }
                   15032:                     }
1.267     raeburn  15033:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   15034:                     foreach my $field (@fields) {
                   15035:                         if ($possfield{$field}) {
                   15036:                             if ($field eq 'roles') {
                   15037:                                 foreach my $role (@courseroles) {
                   15038:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   15039:                                     if (($choice ne '') && ($posslti{$choice})) {
                   15040:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   15041:                                         if ($role eq 'cc') {
                   15042:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   15043:                                         }
                   15044:                                     }
                   15045:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   15046:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   15047:                                             $changes{$itemid} = 1;
                   15048:                                         }
                   15049:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   15050:                                         $changes{$itemid} = 1;
                   15051:                                     }
                   15052:                                 }
                   15053:                             } else {
                   15054:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   15055:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   15056:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   15057:                                         $changes{$itemid} = 1;
                   15058:                                     }
                   15059:                                 } else {
                   15060:                                     $changes{$itemid} = 1;
                   15061:                                 }
                   15062:                             }
                   15063:                         }
                   15064:                     }
1.324     raeburn  15065:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   15066:                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   15067:                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   15068:                                 $confhash{$itemid}{'incdom'} = 1;
                   15069:                             }
                   15070:                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   15071:                                 $changes{$itemid} = 1;
                   15072:                             }
                   15073:                         }
                   15074:                     }
1.267     raeburn  15075:                     $allpos[$newpos] = $itemid;
                   15076:                 }
                   15077:                 if ($imgdeletions{$itemid}) {
                   15078:                     $changes{$itemid} = 1;
                   15079:                     #FIXME need to obsolete item in RES space
                   15080:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   15081:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   15082:                                                                  $itemid,$configuserok,$switchserver,
                   15083:                                                                  $author_ok);
                   15084:                     if ($imgurl) {
                   15085:                         $confhash{$itemid}{'image'} = $imgurl;
                   15086:                         $changes{$itemid} = 1;
                   15087:                     }
                   15088:                     if ($error) {
                   15089:                         &Apache::lonnet::logthis($error);
                   15090:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15091:                     }
                   15092:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   15093:                     $confhash{$itemid}{'image'} =
                   15094:                        $domconfig{$action}{$itemid}{'image'};
                   15095:                 }
                   15096:                 if ($customadds{$i}) {
                   15097:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   15098:                     $name =~ s/(`)/'/g;
                   15099:                     $name =~ s/^\s+//;
                   15100:                     $name =~ s/\s+$//;
                   15101:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   15102:                     $value =~ s/(`)/'/g;
                   15103:                     $value =~ s/^\s+//;
                   15104:                     $value =~ s/\s+$//;
                   15105:                     if ($name ne '') {
                   15106:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   15107:                         $changes{$itemid} = 1;
                   15108:                     }
                   15109:                 }
                   15110:                 my %customdels;
                   15111:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   15112:                 if (@customdeletions) {
                   15113:                     $changes{$itemid} = 1;
                   15114:                 }
                   15115:                 map { $customdels{$_} = 1; } @customdeletions;
                   15116:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   15117:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   15118:                         unless ($customdels{$key}) {
                   15119:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   15120:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   15121:                             }
                   15122:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   15123:                                 $changes{$itemid} = 1;
                   15124:                             }
                   15125:                         }
                   15126:                     }
                   15127:                 }
                   15128:                 unless ($changes{$itemid}) {
                   15129:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   15130:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   15131:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   15132:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   15133:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   15134:                                         $changes{$itemid} = 1;
                   15135:                                         last;
                   15136:                                     }
                   15137:                                 }
                   15138:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   15139:                                 $changes{$itemid} = 1;
                   15140:                             }
                   15141:                         }
                   15142:                         last if ($changes{$itemid});
                   15143:                     }
                   15144:                 }
                   15145:             }
                   15146:         }
                   15147:     }
                   15148:     if (@allpos > 0) {
                   15149:         my $idx = 0;
                   15150:         foreach my $itemid (@allpos) {
                   15151:             if ($itemid ne '') {
                   15152:                 $confhash{$itemid}{'order'} = $idx;
                   15153:                 if (ref($domconfig{$action}) eq 'HASH') {
                   15154:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15155:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   15156:                             $changes{$itemid} = 1;
                   15157:                         }
                   15158:                     }
                   15159:                 }
                   15160:                 $idx ++;
                   15161:             }
                   15162:         }
                   15163:     }
                   15164:     my %ltitoolshash = (
                   15165:                           $action => { %confhash }
                   15166:                        );
                   15167:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   15168:                                              $dom);
                   15169:     if ($putresult eq 'ok') {
1.297     raeburn  15170:         my %ltienchash = (
                   15171:                              $action => { %encconfig }
                   15172:                          );
1.384     raeburn  15173:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267     raeburn  15174:         if (keys(%changes) > 0) {
                   15175:             my $cachetime = 24*60*60;
1.297     raeburn  15176:             my %ltiall = %confhash;
                   15177:             foreach my $id (keys(%ltiall)) {
                   15178:                 if (ref($encconfig{$id}) eq 'HASH') {
                   15179:                     foreach my $item ('key','secret') {
                   15180:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   15181:                     }
                   15182:                 }
                   15183:             }
                   15184:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267     raeburn  15185:             if (ref($lastactref) eq 'HASH') {
                   15186:                 $lastactref->{'ltitools'} = 1;
                   15187:             }
                   15188:             $resulttext = &mt('Changes made:').'<ul>';
                   15189:             my %bynum;
                   15190:             foreach my $itemid (sort(keys(%changes))) {
                   15191:                 my $position = $confhash{$itemid}{'order'};
                   15192:                 $bynum{$position} = $itemid;
                   15193:             }
                   15194:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15195:                 my $itemid = $bynum{$pos}; 
                   15196:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   15197:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   15198:                 } else {
                   15199:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   15200:                     if ($confhash{$itemid}{'image'}) {
                   15201:                         $resulttext .= '&nbsp;'.
                   15202:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   15203:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   15204:                     }
                   15205:                     $resulttext .= '</li><ul>';
                   15206:                     my $position = $pos + 1;
                   15207:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323     raeburn  15208:                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267     raeburn  15209:                         if ($confhash{$itemid}{$item} ne '') {
                   15210:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   15211:                         }
                   15212:                     }
1.297     raeburn  15213:                     if ($encconfig{$itemid}{'key'} ne '') {
                   15214:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   15215:                     }
                   15216:                     if ($encconfig{$itemid}{'secret'} ne '') {
1.267     raeburn  15217:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
1.297     raeburn  15218:                         my $num = length($encconfig{$itemid}{'secret'});
1.267     raeburn  15219:                         $resulttext .= ('*'x$num).'</li>';
                   15220:                     }
1.273     raeburn  15221:                     $resulttext .= '<li>'.&mt('Configurable in course:');
1.318     raeburn  15222:                     my @possconfig = ('label','title','target','linktext','explanation','append');
1.273     raeburn  15223:                     my $numconfig = 0; 
                   15224:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   15225:                         foreach my $item (@possconfig) {
                   15226:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   15227:                                 $numconfig ++;
1.296     raeburn  15228:                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273     raeburn  15229:                             }
                   15230:                         }
                   15231:                     }
                   15232:                     if (!$numconfig) {
1.372     raeburn  15233:                         $resulttext .= '&nbsp;'.&mt('None');
1.273     raeburn  15234:                     }
                   15235:                     $resulttext .= '</li>';
1.267     raeburn  15236:                     foreach my $item ('passback','roster') {
                   15237:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   15238:                         if ($confhash{$itemid}{$item}) {
                   15239:                             $resulttext .= &mt('Yes');
1.319     raeburn  15240:                             if ($confhash{$itemid}{$item.'valid'}) {
                   15241:                                 if ($item eq 'passback') {
                   15242:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
                   15243:                                                            $confhash{$itemid}{$item.'valid'});
                   15244:                                 } else {
                   15245:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
                   15246:                                                            $confhash{$itemid}{$item.'valid'});
                   15247:                                 }
                   15248:                             }
1.267     raeburn  15249:                         } else {
                   15250:                             $resulttext .= &mt('No');
                   15251:                         }
                   15252:                         $resulttext .= '</li>';
                   15253:                     }
                   15254:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   15255:                         my $displaylist;
                   15256:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   15257:                             $displaylist = &mt('Display target').':&nbsp;'.
                   15258:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   15259:                         }
                   15260:                         foreach my $size ('width','height') { 
                   15261:                             if ($confhash{$itemid}{'display'}{$size}) {
                   15262:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   15263:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   15264:                             }
                   15265:                         }
                   15266:                         if ($displaylist) {
                   15267:                             $displaylist =~ s/,$//;
                   15268:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   15269:                         }
1.296     raeburn  15270:                         foreach my $item ('linktext','explanation') {
                   15271:                             if ($confhash{$itemid}{'display'}{$item}) {
                   15272:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   15273:                             }
                   15274:                         }
                   15275:                     }
1.267     raeburn  15276:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   15277:                         my $fieldlist;
                   15278:                         foreach my $field (@allfields) {
                   15279:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   15280:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   15281:                             }
                   15282:                         }
                   15283:                         if ($fieldlist) {
                   15284:                             $fieldlist =~ s/,$//;
1.324     raeburn  15285:                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   15286:                                 if ($confhash{$itemid}{'incdom'}) {
                   15287:                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   15288:                                 } else {
                   15289:                                     $fieldlist .= ' ('.&mt('username').')';
                   15290:                                 }
                   15291:                             }
1.267     raeburn  15292:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   15293:                         }
                   15294:                     }
                   15295:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   15296:                         my $rolemaps;
                   15297:                         foreach my $role (@courseroles) {
                   15298:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   15299:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   15300:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   15301:                             }
                   15302:                         }
                   15303:                         if ($rolemaps) {
                   15304:                             $rolemaps =~ s/,$//; 
                   15305:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15306:                         }
                   15307:                     }
                   15308:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   15309:                         my $customlist;
                   15310:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   15311:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   15312:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   15313:                             } 
                   15314:                         }
                   15315:                         if ($customlist) {
1.317     raeburn  15316:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267     raeburn  15317:                         }
                   15318:                     } 
                   15319:                     $resulttext .= '</ul></li>';
                   15320:                 }
                   15321:             }
                   15322:             $resulttext .= '</ul>';
                   15323:         } else {
                   15324:             $resulttext = &mt('No changes made.');
                   15325:         }
                   15326:     } else {
                   15327:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15328:     }
                   15329:     if ($errors) {
                   15330:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15331:                        $errors.'</ul>';
                   15332:     }
                   15333:     return $resulttext;
                   15334: }
                   15335: 
                   15336: sub process_ltitools_image {
                   15337:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   15338:     my $filename = $env{'form.'.$caller.'.filename'};
                   15339:     my ($error,$url);
                   15340:     my ($width,$height) = (21,21);
                   15341:     if ($configuserok eq 'ok') {
                   15342:         if ($switchserver) {
                   15343:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   15344:                          $switchserver);
                   15345:         } elsif ($author_ok eq 'ok') {
                   15346:             my ($result,$imageurl,$madethumb) =
                   15347:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   15348:                              "ltitools/$itemid/icon",$width,$height);
                   15349:             if ($result eq 'ok') {
                   15350:                 if ($madethumb) {
                   15351:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   15352:                     my $imagethumb = "$path/tn-".$imagefile;
                   15353:                     $url = $imagethumb;
                   15354:                 } else {
                   15355:                     $url = $imageurl;
                   15356:                 }
                   15357:             } else {
                   15358:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   15359:             }
                   15360:         } else {
                   15361:             $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);
                   15362:         }
                   15363:     } else {
                   15364:         $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);
                   15365:     }
                   15366:     return ($url,$error);
                   15367: }
                   15368: 
                   15369: sub get_ltitools_id {
                   15370:     my ($cdom,$title) = @_;
                   15371:     # get lock on ltitools db
                   15372:     my $lockhash = {
                   15373:                       lock => $env{'user.name'}.
                   15374:                               ':'.$env{'user.domain'},
                   15375:                    };
                   15376:     my $tries = 0;
                   15377:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   15378:     my ($id,$error);
                   15379:  
                   15380:     while (($gotlock ne 'ok') && ($tries<10)) {
                   15381:         $tries ++;
                   15382:         sleep (0.1);
                   15383:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   15384:     }
                   15385:     if ($gotlock eq 'ok') {
                   15386:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   15387:         if ($currids{'lock'}) {
                   15388:             delete($currids{'lock'});
                   15389:             if (keys(%currids)) {
                   15390:                 my @curr = sort { $a <=> $b } keys(%currids);
                   15391:                 if ($curr[-1] =~ /^\d+$/) {
                   15392:                     $id = 1 + $curr[-1];
                   15393:                 }
                   15394:             } else {
                   15395:                 $id = 1;
                   15396:             }
                   15397:             if ($id) {
                   15398:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   15399:                     $error = 'nostore';
                   15400:                 }
                   15401:             } else {
                   15402:                 $error = 'nonumber';
                   15403:             }
                   15404:         }
                   15405:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   15406:     } else {
                   15407:         $error = 'nolock';
                   15408:     }
                   15409:     return ($id,$error);
                   15410: }
                   15411: 
1.372     raeburn  15412: sub modify_proctoring {
                   15413:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   15414:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15415:     my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
                   15416:     my $confname = $dom.'-domainconfig';
                   15417:     my $servadm = $r->dir_config('lonAdmEMail');
                   15418:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   15419:     my %providernames = &proctoring_providernames();
                   15420:     my $maxnum = scalar(keys(%providernames));
                   15421: 
                   15422:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   15423:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   15424:     if (ref($requref) eq 'HASH') {
                   15425:         %requserfields = %{$requref};
                   15426:     }
                   15427:     if (ref($opturef) eq 'HASH') {
                   15428:         %optuserfields = %{$opturef};
                   15429:     }
                   15430:     if (ref($defref) eq 'HASH') {
                   15431:         %defaults = %{$defref};
                   15432:     }
                   15433:     if (ref($extref) eq 'HASH') {
                   15434:         %extended = %{$extref};
                   15435:     }
                   15436:     if (ref($crsref) eq 'HASH') {
                   15437:         %crsconf = %{$crsref};
                   15438:     }
                   15439:     if (ref($rolesref) eq 'ARRAY') {
                   15440:         @courseroles = @{$rolesref};
                   15441:     }
                   15442:     if (ref($ltiref) eq 'ARRAY') {
                   15443:         @ltiroles = @{$ltiref};
                   15444:     }
                   15445: 
                   15446:     if (ref($domconfig{$action}) eq 'HASH') {
                   15447:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
                   15448:         if (@todeleteimages) {
                   15449:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   15450:         }
                   15451:     }
                   15452:     my %customadds;
                   15453:     my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
                   15454:     if (@newcustom) {
                   15455:         map { $customadds{$_} = 1; } @newcustom;
                   15456:     }
                   15457:     foreach my $provider (sort(keys(%providernames))) {
                   15458:         $confhash{$provider} = {};
                   15459:         my $pos = $env{'form.proctoring_pos_'.$provider};
                   15460:         $pos =~ s/\D+//g;
                   15461:         $allpos[$pos] = $provider;
                   15462:         my (%current,%currentenc);
                   15463:         my $showroles = 0;
                   15464:         if (ref($domconfig{$action}) eq 'HASH') {
                   15465:             if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   15466:                 %current = %{$domconfig{$action}{$provider}};
                   15467:                 foreach my $item ('key','secret') { 
                   15468:                     $currentenc{$item} = $current{$item};
                   15469:                     delete($current{$item});
                   15470:                 }
                   15471:             }
                   15472:         }
                   15473:         if ($env{'form.proctoring_available_'.$provider}) {
                   15474:             $confhash{$provider}{'available'} = 1;
                   15475:             unless ($current{'available'}) {
                   15476:                 $changes{$provider} = 1;
                   15477:             }
                   15478:         } else {
                   15479:             %{$confhash{$provider}} = %current;
                   15480:             %{$encconfhash{$provider}} = %currentenc;
                   15481:             $confhash{$provider}{'available'} = 0;
                   15482:             if ($current{'available'}) {
                   15483:                 $changes{$provider} = 1;
                   15484:             }
                   15485:         }
                   15486:         if ($confhash{$provider}{'available'}) {
                   15487:             foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
                   15488:                 my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
                   15489:                 if ($field eq 'lifetime') {
                   15490:                     if ($possval =~ /^\d+$/) {
                   15491:                         $confhash{$provider}{$field} = $possval;
                   15492:                     }
                   15493:                 } elsif ($field eq 'version') {
                   15494:                     if ($possval =~ /^\d+\.\d+$/) {
                   15495:                         $confhash{$provider}{$field} = $possval;
                   15496:                     }
                   15497:                 } elsif ($field eq 'sigmethod') {
                   15498:                     if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
                   15499:                         $confhash{$provider}{$field} = $possval;
                   15500:                     }
                   15501:                 } elsif ($field eq 'url') {
                   15502:                     $confhash{$provider}{$field} = $possval;
                   15503:                 } elsif (($field eq 'key') || ($field eq 'secret')) {
                   15504:                     $encconfhash{$provider}{$field} = $possval;
                   15505:                     unless ($currentenc{$field} eq $possval) {
                   15506:                         $changes{$provider} = 1;
                   15507:                     }
                   15508:                 }
                   15509:                 unless (($field eq 'key') || ($field eq 'secret')) {
                   15510:                     unless ($current{$field} eq $confhash{$provider}{$field}) {
                   15511:                         $changes{$provider} = 1;
                   15512:                     }
                   15513:                 }
                   15514:             }
                   15515:             if ($imgdeletions{$provider}) {
                   15516:                 $changes{$provider} = 1;
                   15517:             } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
                   15518:                 my ($imageurl,$error) =
                   15519:                     &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
                   15520:                                               $configuserok,$switchserver,$author_ok);
                   15521:                 if ($imageurl) {
                   15522:                     $confhash{$provider}{'image'} = $imageurl;
                   15523:                     $changes{$provider} = 1; 
                   15524:                 }
                   15525:                 if ($error) {
                   15526:                     &Apache::lonnet::logthis($error);
                   15527:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15528:                 }
                   15529:             } elsif (exists($current{'image'})) {
                   15530:                 $confhash{$provider}{'image'} = $current{'image'};
                   15531:             }
                   15532:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15533:                 if (@{$requserfields{$provider}} > 0) {
                   15534:                     if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15535:                         if ($env{'form.proctoring_userincdom_'.$provider}) {
                   15536:                             $confhash{$provider}{'incdom'} = 1;
                   15537:                         }
                   15538:                         unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
                   15539:                             $changes{$provider} = 1;
                   15540:                         }
                   15541:                     }
                   15542:                     if (grep(/^roles$/,@{$requserfields{$provider}})) {
                   15543:                         $showroles = 1;
                   15544:                     }
                   15545:                 }
                   15546:             }
                   15547:             $confhash{$provider}{'fields'} = [];
                   15548:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   15549:                 if (@{$optuserfields{$provider}} > 0) {
                   15550:                     my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
                   15551:                     foreach my $field (@{$optuserfields{$provider}}) {
                   15552:                         if (grep(/^\Q$field\E$/,@optfields)) {
                   15553:                             push(@{$confhash{$provider}{'fields'}},$field);
                   15554:                         }
                   15555:                     }
                   15556:                 }
                   15557:                 if (ref($current{'fields'}) eq 'ARRAY') {
                   15558:                     unless ($changes{$provider}) {
                   15559:                         my @new = sort(@{$confhash{$provider}{'fields'}});
                   15560:                         my @old = sort(@{$current{'fields'}}); 
                   15561:                         my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15562:                         if (@diffs) {
                   15563:                             $changes{$provider} = 1;
                   15564:                         }
                   15565:                     }
                   15566:                 } elsif (@{$confhash{$provider}{'fields'}}) {
                   15567:                     $changes{$provider} = 1;
                   15568:                 }
                   15569:             }
                   15570:             if (ref($defaults{$provider}) eq 'ARRAY') {  
                   15571:                 if (@{$defaults{$provider}} > 0) {
                   15572:                     my %options;
                   15573:                     if (ref($extended{$provider}) eq 'HASH') {
                   15574:                         %options = %{$extended{$provider}};
                   15575:                     }
                   15576:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
                   15577:                     foreach my $field (@{$defaults{$provider}}) {
                   15578:                         if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   15579:                             my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
                   15580:                             if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
                   15581:                                 push(@{$confhash{$provider}{'defaults'}},$poss); 
                   15582:                             }
                   15583:                         } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
                   15584:                             foreach my $inner (keys(%{$options{$field}})) {
                   15585:                                 if (ref($options{$field}{$inner}) eq 'ARRAY') {
                   15586:                                     my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15587:                                     if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
                   15588:                                         $confhash{$provider}{'defaults'}{$inner} = $poss;
                   15589:                                     }
                   15590:                                 } else {
                   15591:                                     $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15592:                                 }
                   15593:                             }
                   15594:                         } else {
                   15595:                             if (grep(/^\Q$field\E$/,@checked)) {
                   15596:                                 push(@{$confhash{$provider}{'defaults'}},$field);
                   15597:                             }
                   15598:                         }
                   15599:                     }
                   15600:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15601:                         if (ref($current{'defaults'}) eq 'ARRAY') {
                   15602:                             unless ($changes{$provider}) {
                   15603:                                 my @new = sort(@{$confhash{$provider}{'defaults'}});
                   15604:                                 my @old = sort(@{$current{'defaults'}});
                   15605:                                 my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15606:                                 if (@diffs) {
                   15607:                                     $changes{$provider} = 1; 
                   15608:                                 }
                   15609:                             }
                   15610:                         } elsif (ref($current{'defaults'}) eq 'ARRAY') {
                   15611:                             if (@{$current{'defaults'}}) {
                   15612:                                 $changes{$provider} = 1;
                   15613:                             }
                   15614:                         }
                   15615:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15616:                         if (ref($current{'defaults'}) eq 'HASH') {
                   15617:                             unless ($changes{$provider}) {
                   15618:                                 foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
                   15619:                                     unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
                   15620:                                         $changes{$provider} = 1;
                   15621:                                         last;
                   15622:                                     }
                   15623:                                 }
                   15624:                             }
                   15625:                             unless ($changes{$provider}) {
                   15626:                                 foreach my $key (keys(%{$current{'defaults'}})) {
                   15627:                                     unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
                   15628:                                         $changes{$provider} = 1;
                   15629:                                         last;
                   15630:                                     }
                   15631:                                 }
                   15632:                             }
                   15633:                         } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
                   15634:                             $changes{$provider} = 1;
                   15635:                         }
                   15636:                     }
                   15637:                 }
                   15638:             }
                   15639:             if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15640:                 if (@{$crsconf{$provider}} > 0) {
                   15641:                     $confhash{$provider}{'crsconf'} = [];
                   15642:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
                   15643:                     foreach my $crsfield (@{$crsconf{$provider}}) {
                   15644:                         if (grep(/^\Q$crsfield\E$/,@checked)) {
                   15645:                             push(@{$confhash{$provider}{'crsconf'}},$crsfield);
                   15646:                         }
                   15647:                     }
                   15648:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   15649:                         unless ($changes{$provider}) {  
                   15650:                             my @new = sort(@{$confhash{$provider}{'crsconf'}});
                   15651:                             my @old = sort(@{$current{'crsconf'}});
                   15652:                             my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15653:                             if (@diffs) {
                   15654:                                 $changes{$provider} = 1;
                   15655:                             }
                   15656:                         }
                   15657:                     } elsif (@{$confhash{$provider}{'crsconf'}}) {
                   15658:                         $changes{$provider} = 1;
                   15659:                     }
                   15660:                 }
                   15661:             }
                   15662:             if ($showroles) {
                   15663:                 $confhash{$provider}{'roles'} = {};
                   15664:                 foreach my $role (@courseroles) {
                   15665:                     my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
                   15666:                     if (grep(/^\Q$poss\E$/,@ltiroles)) {
                   15667:                         $confhash{$provider}{'roles'}{$role} = $poss;
                   15668:                     }
                   15669:                 }
                   15670:                 unless ($changes{$provider}) {
                   15671:                     if (ref($current{'roles'}) eq 'HASH') {
                   15672:                         foreach my $role (keys(%{$current{'roles'}})) {
                   15673:                             unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
                   15674:                                 $changes{$provider} = 1;
                   15675:                                 last
                   15676:                             }
                   15677:                         }
                   15678:                         unless ($changes{$provider}) {
                   15679:                             foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
                   15680:                                 unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
                   15681:                                     $changes{$provider} = 1;
                   15682:                                     last;
                   15683:                                 }
                   15684:                             }
                   15685:                         }
                   15686:                     } elsif (keys(%{$confhash{$provider}{'roles'}})) {
                   15687:                         $changes{$provider} = 1;
                   15688:                     }
                   15689:                 }
                   15690:             }
                   15691:             if (ref($current{'custom'}) eq 'HASH') {
                   15692:                 my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
                   15693:                 foreach my $key (keys(%{$current{'custom'}})) {
                   15694:                     if (grep(/^\Q$key\E$/,@customdels)) {
                   15695:                         $changes{$provider} = 1;
                   15696:                     } else {
                   15697:                         $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
                   15698:                         if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
                   15699:                             $changes{$provider} = 1;
                   15700:                         }
                   15701:                     }
                   15702:                 }
                   15703:             }
                   15704:             if ($customadds{$provider}) {
                   15705:                 my $name = $env{'form.proctoring_custom_name_'.$provider};
                   15706:                 $name =~ s/(`)/'/g;
                   15707:                 $name =~ s/^\s+//;
                   15708:                 $name =~ s/\s+$//;
                   15709:                 my $value = $env{'form.proctoring_custom_value_'.$provider};
                   15710:                 $value =~ s/(`)/'/g;
                   15711:                 $value =~ s/^\s+//;
                   15712:                 $value =~ s/\s+$//;
                   15713:                 if ($name ne '') {
                   15714:                     $confhash{$provider}{'custom'}{$name} = $value;
                   15715:                     $changes{$provider} = 1;
                   15716:                 }
                   15717:             }
                   15718:         }
                   15719:     }
                   15720:     if (@allpos > 0) {
                   15721:         my $idx = 0;
                   15722:         foreach my $provider (@allpos) {
                   15723:             if ($provider ne '') {
                   15724:                 $confhash{$provider}{'order'} = $idx;
                   15725:                 unless ($changes{$provider}) {
                   15726:                     if (ref($domconfig{$action}) eq 'HASH') {
                   15727:                         if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   15728:                             if ($domconfig{$action}{$provider}{'order'} ne $idx) {
                   15729:                                 $changes{$provider} = 1;
                   15730:                             }
                   15731:                         }
                   15732:                     }
                   15733:                 }
                   15734:                 $idx ++;
                   15735:             }
                   15736:         }
                   15737:     }
                   15738:     my %proc_hash = (
                   15739:                           $action => { %confhash }
                   15740:                        );
                   15741:     my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
                   15742:                                              $dom);
                   15743:     if ($putresult eq 'ok') {
                   15744:         my %proc_enchash = (
                   15745:                              $action => { %encconfhash }
                   15746:                          );
1.384     raeburn  15747:         &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372     raeburn  15748:         if (keys(%changes) > 0) {
                   15749:             my $cachetime = 24*60*60;
                   15750:             my %procall = %confhash;
                   15751:             foreach my $provider (keys(%procall)) {
                   15752:                 if (ref($encconfhash{$provider}) eq 'HASH') {
                   15753:                     foreach my $key ('key','secret') {
                   15754:                         $procall{$provider}{$key} = $encconfhash{$provider}{$key};
                   15755:                     }
                   15756:                 }
                   15757:             }
                   15758:             &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
                   15759:             if (ref($lastactref) eq 'HASH') {
                   15760:                 $lastactref->{'proctoring'} = 1;
                   15761:             }
                   15762:             $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
                   15763:             my %bynum;
                   15764:             foreach my $provider (sort(keys(%changes))) {
                   15765:                 my $position = $confhash{$provider}{'order'};
                   15766:                 $bynum{$position} = $provider;
                   15767:             }
                   15768:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15769:                 my $provider = $bynum{$pos};
                   15770:                 my %lt = &proctoring_titles($provider);
                   15771:                 my %fieldtitles = &proctoring_fieldtitles($provider);
                   15772:                 if (!$confhash{$provider}{'available'}) {
                   15773:                     $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
                   15774:                 } else {
                   15775:                     $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
                   15776:                     if ($confhash{$provider}{'image'}) {
                   15777:                         $resulttext .= '&nbsp;'.
                   15778:                                        '<img src="'.$confhash{$provider}{'image'}.'"'.
                   15779:                                        ' alt="'.&mt('Proctoring icon').'" />';
                   15780:                     }
                   15781:                     $resulttext .= '<ul>';
                   15782:                     my $position = $pos + 1;
                   15783:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15784:                     foreach my $key ('version','sigmethod','url','lifetime') {
                   15785:                         if ($confhash{$provider}{$key} ne '') {
                   15786:                             $resulttext .= '<li>'.$lt{$key}.':&nbsp;'.$confhash{$provider}{$key}.'</li>';
                   15787:                         }
                   15788:                     }
                   15789:                     if ($encconfhash{$provider}{'key'} ne '') {
                   15790:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfhash{$provider}{'key'}.'</li>';
                   15791:                     }
                   15792:                     if ($encconfhash{$provider}{'secret'} ne '') {
                   15793:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15794:                         my $num = length($encconfhash{$provider}{'secret'});
                   15795:                         $resulttext .= ('*'x$num).'</li>';
                   15796:                     }
                   15797:                     my (@fields,$showroles);
                   15798:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15799:                         push(@fields,@{$requserfields{$provider}});
                   15800:                     }
                   15801:                     if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
                   15802:                         push(@fields,@{$confhash{$provider}{'fields'}});
                   15803:                     } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
                   15804:                         push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
                   15805:                     }
                   15806:                     if (@fields) {
                   15807:                         if (grep(/^roles$/,@fields)) {
                   15808:                             $showroles = 1;
                   15809:                         }
                   15810:                         $resulttext .= '<li>'.$lt{'udsl'}.':&nbsp;"'.
                   15811:                                        join('", "', map { $lt{$_}; } @fields).'"</li>';
                   15812:                     }
                   15813:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15814:                         if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15815:                             if ($confhash{$provider}{'incdom'}) {
                   15816:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
                   15817:                             } else { 
                   15818:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
                   15819:                             }
                   15820:                         }
                   15821:                     }
                   15822:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15823:                         if (@{$confhash{$provider}{'defaults'}} > 0) {
                   15824:                             $resulttext .= '<li>'.$lt{'defa'};
                   15825:                             foreach my $field (@{$confhash{$provider}{'defaults'}}) {
                   15826:                                 $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15827:                             }
                   15828:                             $resulttext =~ s/,$//;
                   15829:                             $resulttext .= '</li>';
                   15830:                         }
                   15831:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15832:                         if (keys(%{$confhash{$provider}{'defaults'}})) {
                   15833:                             $resulttext .= '<li>'.$lt{'defa'}.':&nbsp;<ul>';
                   15834:                             foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
                   15835:                                 if ($confhash{$provider}{'defaults'}{$key} ne '') {
                   15836:                                     $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
                   15837:                                 }
                   15838:                             }
                   15839:                             $resulttext .= '</ul></li>';
                   15840:                         }
                   15841:                     }
                   15842:                     if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15843:                         if (@{$crsconf{$provider}} > 0) {
                   15844:                             $resulttext .= '<li>'.&mt('Configurable in course:');
                   15845:                             my $numconfig = 0;
                   15846:                             if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
                   15847:                                 if (@{$confhash{$provider}{'crsconf'}} > 0) {
                   15848:                                     foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
                   15849:                                         $numconfig ++;
                   15850:                                         if ($provider eq 'examity') {
                   15851:                                             $resulttext .= ' "'.$lt{'crs'.$field}.'",';
                   15852:                                         } else {
                   15853:                                             $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15854:                                         }
                   15855:                                     }
                   15856:                                     $resulttext =~ s/,$//;
                   15857:                                 }
                   15858:                             }
                   15859:                             if (!$numconfig) {
                   15860:                                 $resulttext .= '&nbsp;'.&mt('None');
                   15861:                             }
                   15862:                             $resulttext .= '</li>';
                   15863:                         }
                   15864:                     }
                   15865:                     if ($showroles) {
                   15866:                         if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
                   15867:                             my $rolemaps;
                   15868:                             foreach my $role (@courseroles) {
                   15869:                                 if ($confhash{$provider}{'roles'}{$role}) {
                   15870:                                     $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   15871:                                                  $confhash{$provider}{'roles'}{$role}.',';
                   15872:                                 }
                   15873:                             }
                   15874:                             if ($rolemaps) {
                   15875:                                 $rolemaps =~ s/,$//;
                   15876:                                 $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15877:                             }
                   15878:                         }
                   15879:                     }
                   15880:                     if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
                   15881:                         my $customlist;
                   15882:                         if (keys(%{$confhash{$provider}{'custom'}})) {
                   15883:                             foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
                   15884:                                 $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
                   15885:                             }
                   15886:                             $customlist =~ s/,$//;
                   15887:                         }
                   15888:                         if ($customlist) {
                   15889:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
                   15890:                         }
                   15891:                     } 
                   15892:                     $resulttext .= '</ul></li>';
                   15893:                 }
                   15894:             }
                   15895:             $resulttext .= '</ul>';
                   15896:         } else {
                   15897:             $resulttext = &mt('No changes made.');
                   15898:         }
                   15899:     } else {
                   15900:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15901:     }
                   15902:     if ($errors) {
                   15903:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15904:                        $errors.'</ul>';
                   15905:     }
                   15906:     return $resulttext;
                   15907: }
                   15908: 
                   15909: sub process_proctoring_image {
                   15910:     my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
                   15911:     my $filename = $env{'form.'.$caller.'.filename'};
                   15912:     my ($error,$url);
                   15913:     my ($width,$height) = (21,21);
                   15914:     if ($configuserok eq 'ok') {
                   15915:         if ($switchserver) {
                   15916:             $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
                   15917:                          $switchserver);
                   15918:         } elsif ($author_ok eq 'ok') {
                   15919:             my ($result,$imageurl,$madethumb) =
                   15920:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   15921:                              "proctoring/$provider/icon",$width,$height);
                   15922:             if ($result eq 'ok') {
                   15923:                 if ($madethumb) {
                   15924:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   15925:                     my $imagethumb = "$path/tn-".$imagefile;
                   15926:                     $url = $imagethumb;
                   15927:                 } else {
                   15928:                     $url = $imageurl;
                   15929:                 }
                   15930:             } else {
                   15931:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   15932:             }
                   15933:         } else {
                   15934:             $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);
                   15935:         }
                   15936:     } else {
                   15937:         $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);
                   15938:     }
                   15939:     return ($url,$error);
                   15940: }
                   15941: 
1.320     raeburn  15942: sub modify_lti {
                   15943:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   15944:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15945:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   15946:     my (%posslti,%posslticrs,%posscrstype);
                   15947:     my @courseroles = ('cc','in','ta','ep','st');
                   15948:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   15949:     my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392     raeburn  15950:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  15951:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   15952:                                official   => 'Official',
                   15953:                                unofficial => 'Unofficial',
                   15954:                                community  => 'Community',
                   15955:                                textbook   => 'Textbook',
                   15956:                                placement  => 'Placement Test',
1.392     raeburn  15957:                                lti        => 'LTI Provider',
1.320     raeburn  15958:     );
1.325     raeburn  15959:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320     raeburn  15960:     my %lt = &lti_names();
                   15961:     map { $posslti{$_} = 1; } @ltiroles;
                   15962:     map { $posslticrs{$_} = 1; } @lticourseroles;
                   15963:     map { $posscrstype{$_} = 1; } @coursetypes;
1.325     raeburn  15964: 
1.326     raeburn  15965:     my %menutitles = &ltimenu_titles();
                   15966: 
1.406     raeburn  15967:     my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
1.405     raeburn  15968:     $newltisec{'private'}{'keys'} = [];
                   15969:     $newltisec{'encrypt'} = {};
                   15970:     $newltisec{'rules'} = {};
1.406     raeburn  15971:     $newltisec{'linkprot'} = {};
1.405     raeburn  15972:     if (ref($domconfig{'ltisec'}) eq 'HASH') {
                   15973:         %currltisec = %{$domconfig{'ltisec'}};
1.406     raeburn  15974:         if (ref($currltisec{'linkprot'}) eq 'HASH') {
                   15975:             foreach my $id (keys(%{$currltisec{'linkprot'}})) {
                   15976:                 unless ($id =~ /^\d+$/) {
                   15977:                     delete($currltisec{'linkprot'}{$id});
                   15978:                 }
                   15979:             }
                   15980:         }
1.405     raeburn  15981:         if (ref($currltisec{'private'}) eq 'HASH') {
                   15982:             if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
                   15983:                 $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
                   15984:                 map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
                   15985:             }
                   15986:         }
                   15987:     }
                   15988:     foreach my $item ('crs','dom','consumers') {
                   15989:         my $formelement;
                   15990:         if ($item eq 'consumers') { 
                   15991:             $formelement = 'form.ltisec_'.$item;
                   15992:         } else {
                   15993:             $formelement = 'form.ltisec_'.$item.'linkprot';
                   15994:         }
                   15995:         if ($env{$formelement}) {
                   15996:             $newltisec{'encrypt'}{$item} = 1;
                   15997:             if (ref($currltisec{'encrypt'}) eq 'HASH') {
                   15998:                 unless ($currltisec{'encrypt'}{$item}) {
                   15999:                     $secchanges{'encrypt'} = 1;
                   16000:                 }
                   16001:             } else {
                   16002:                 $secchanges{'encrypt'} = 1;
                   16003:             }
                   16004:         } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
                   16005:             if ($currltisec{'encrypt'}{$item}) {
                   16006:                 $secchanges{'encrypt'} = 1;
                   16007:             }
                   16008:         }
                   16009:     }
                   16010:     unless (exists($currltisec{'rules'})) {
                   16011:         $currltisec{'rules'} = {};
                   16012:     }
                   16013:     &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
                   16014: 
                   16015:     my @ids=&Apache::lonnet::current_machine_ids();
                   16016:     my %servers = &Apache::lonnet::get_servers($dom,'library');
                   16017:    
                   16018:     foreach my $hostid (keys(%servers)) {
                   16019:         if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
                   16020:             my $newkey;
                   16021:             my $keyitem = 'form.ltisec_privkey_'.$hostid;
                   16022:             if (exists($env{$keyitem})) {
                   16023:                 $env{$keyitem} =~ s/(`)/'/g;
                   16024:                 if ($keyset{$hostid}) {
                   16025:                     if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
                   16026:                         if ($env{$keyitem} ne '') {
                   16027:                             $secchanges{'private'} = 1;
                   16028:                             $newkeyset{$hostid} = $env{$keyitem};
                   16029:                         }
                   16030:                     }
                   16031:                 } elsif ($env{$keyitem} ne '') {
                   16032:                     unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) { 
                   16033:                         push(@{$newltisec{'private'}{'keys'}},$hostid);
                   16034:                     }
                   16035:                     $secchanges{'private'} = 1;
                   16036:                     $newkeyset{$hostid} = $env{$keyitem};
                   16037:                 }
                   16038:             }
                   16039:         }
                   16040:     }
                   16041: 
1.406     raeburn  16042:     my (%linkprotchg,$linkprotoutput,$is_home);
                   16043:     my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
                   16044:                                                            \%linkprotchg,'domain');
                   16045:     my $home = &Apache::lonnet::domain($dom,'primary');
                   16046:     unless (($home eq 'no_host') || ($home eq '')) {
                   16047:         my @ids=&Apache::lonnet::current_machine_ids();
                   16048:         foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
                   16049:     }
                   16050: 
                   16051:     if (keys(%linkprotchg)) {
                   16052:         $secchanges{'linkprot'} = 1;
                   16053:         my %oldlinkprot;
                   16054:         if (ref($currltisec{'linkprot'}) eq 'HASH') {
                   16055:             %oldlinkprot = %{$currltisec{'linkprot'}};
                   16056:         }
                   16057:         foreach my $id (keys(%linkprotchg)) {
                   16058:             if (ref($linkprotchg{$id}) eq 'HASH') {
                   16059:                 foreach my $inner (keys(%{$linkprotchg{$id}})) {
                   16060:                     if (($inner eq 'secret') || ($inner eq 'key')) {
                   16061:                         if ($is_home) {
                   16062:                             $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
                   16063:                         }
                   16064:                     }
                   16065:                 }
                   16066:             } else {
                   16067:                 $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
                   16068:             }
                   16069:         }
                   16070:         $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
                   16071:         if (keys(%linkprotchg)) {
                   16072:             %{$newltisec{'linkprot'}} = %linkprotchg;
                   16073:         }
                   16074:     }
                   16075:     if (ref($currltisec{'linkprot'}) eq 'HASH') {
                   16076:         foreach my $id (%{$currltisec{'linkprot'}}) {
                   16077:             next if ($id !~ /^\d+$/);
                   16078:             unless (exists($linkprotchg{$id})) {
                   16079:                 if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
                   16080:                     foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
                   16081:                         if (($inner eq 'secret') || ($inner eq 'key')) {
                   16082:                             if ($is_home) {
                   16083:                                 $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
                   16084:                             }
                   16085:                         } else {
                   16086:                             $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
                   16087:                         }
                   16088:                     }
                   16089:                 } else {
                   16090:                     $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
                   16091:                 }
                   16092:             }
                   16093:         }
                   16094:     }
                   16095:     if ($proterror) {
                   16096:         $errors .= '<li>'.$proterror.'</li>';
                   16097:     }
1.320     raeburn  16098:     my (@items,%deletions,%itemids);
                   16099:     if ($env{'form.lti_add'}) {
                   16100:         my $consumer = $env{'form.lti_consumer_add'};
                   16101:         $consumer =~ s/(`)/'/g;
                   16102:         ($newid,my $error) = &get_lti_id($dom,$consumer);
                   16103:         if ($newid) {
                   16104:             $itemids{'add'} = $newid;
                   16105:             push(@items,'add');
                   16106:             $changes{$newid} = 1;
                   16107:         } else {
                   16108:             my $error = &mt('Failed to acquire unique ID for new LTI configuration');
                   16109:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   16110:         }
                   16111:     }
                   16112:     if (ref($domconfig{$action}) eq 'HASH') {
                   16113:         my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
                   16114:         if (@todelete) {
                   16115:             map { $deletions{$_} = 1; } @todelete;
                   16116:         }
                   16117:         my $maxnum = $env{'form.lti_maxnum'};
1.390     raeburn  16118:         for (my $i=0; $i<$maxnum; $i++) {
1.320     raeburn  16119:             my $itemid = $env{'form.lti_id_'.$i};
                   16120:             $itemid =~ s/\D+//g;
                   16121:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   16122:                 if ($deletions{$itemid}) {
                   16123:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
                   16124:                 } else {
1.390     raeburn  16125:                     push(@items,$i);
                   16126:                     $itemids{$i} = $itemid;
1.320     raeburn  16127:                 }
                   16128:             }
                   16129:         }
                   16130:     }
                   16131:     foreach my $idx (@items) {
                   16132:         my $itemid = $itemids{$idx};
                   16133:         next unless ($itemid);
1.390     raeburn  16134:         my $position = $env{'form.lti_pos_'.$itemid};
1.320     raeburn  16135:         $position =~ s/\D+//g;
                   16136:         if ($position ne '') {
                   16137:             $allpos[$position] = $itemid;
                   16138:         }
1.391     raeburn  16139:         foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320     raeburn  16140:             my $formitem = 'form.lti_'.$item.'_'.$idx;
                   16141:             $env{$formitem} =~ s/(`)/'/g;
                   16142:             if ($item eq 'lifetime') {
                   16143:                 $env{$formitem} =~ s/[^\d.]//g;
                   16144:             }
                   16145:             if ($env{$formitem} ne '') {
                   16146:                 if (($item eq 'key') || ($item eq 'secret')) {
                   16147:                     $encconfig{$itemid}{$item} = $env{$formitem};
                   16148:                 } else {
                   16149:                     $confhash{$itemid}{$item} = $env{$formitem};
                   16150:                     unless (($idx eq 'add') || ($changes{$itemid})) {
                   16151:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   16152:                             $changes{$itemid} = 1;
                   16153:                         }
                   16154:                     }
                   16155:                 }
                   16156:             }
                   16157:         }
                   16158:         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
                   16159:             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
                   16160:         }
1.345     raeburn  16161:         if ($confhash{$itemid}{'requser'}) {
                   16162:             if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405     raeburn  16163:                 $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345     raeburn  16164:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
                   16165:                 $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
                   16166:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
                   16167:                 my $mapuser = $env{'form.lti_customuser_'.$idx};
                   16168:                 $mapuser =~ s/(`)/'/g;
1.405     raeburn  16169:                 $mapuser =~ s/^\s+|\s+$//g;
                   16170:                 $confhash{$itemid}{'mapuser'} = $mapuser;
1.345     raeburn  16171:             }
                   16172:             my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
                   16173:             my @makeuser;
                   16174:             foreach my $ltirole (sort(@possmakeuser)) {
                   16175:                 if ($posslti{$ltirole}) {
                   16176:                     push(@makeuser,$ltirole);
                   16177:                 }
                   16178:             }
                   16179:             $confhash{$itemid}{'makeuser'} = \@makeuser;
                   16180:             if (@makeuser) {
                   16181:                 my $lcauth = $env{'form.lti_lcauth_'.$idx};
                   16182:                 if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
                   16183:                     $confhash{$itemid}{'lcauth'} = $lcauth;
                   16184:                     if ($lcauth ne 'internal') {
                   16185:                         my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
                   16186:                         $lcauthparm =~ s/^(\s+|\s+)$//g;
                   16187:                         $lcauthparm =~ s/`//g;
                   16188:                         if ($lcauthparm ne '') {
                   16189:                             $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
                   16190:                         }
                   16191:                     }
                   16192:                 } else {
                   16193:                     $confhash{$itemid}{'lcauth'} = 'lti';
                   16194:                 }
1.320     raeburn  16195:             }
1.345     raeburn  16196:             my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
                   16197:             if (@possinstdata) {
                   16198:                 foreach my $field (@possinstdata) {
                   16199:                     if (exists($fieldtitles{$field})) {
                   16200:                         push(@{$confhash{$itemid}{'instdata'}});
1.325     raeburn  16201:                     }
                   16202:                 }
                   16203:             }
1.363     raeburn  16204:             if ($env{'form.lti_callback_'.$idx}) {
                   16205:                 if ($env{'form.lti_callbackparam_'.$idx}) {
                   16206:                     my $callback = $env{'form.lti_callbackparam_'.$idx};
                   16207:                     $callback =~ s/^\s+|\s+$//g;
                   16208:                     $confhash{$itemid}{'callback'} = $callback;
                   16209:                 }
                   16210:             }
1.391     raeburn  16211:             foreach my $field ('topmenu','inlinemenu') {
1.345     raeburn  16212:                 if ($env{'form.lti_'.$field.'_'.$idx}) {
                   16213:                     $confhash{$itemid}{$field} = 1;
                   16214:                 }
1.320     raeburn  16215:             }
1.345     raeburn  16216:             if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   16217:                 $confhash{$itemid}{lcmenu} = [];
                   16218:                 my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   16219:                 foreach my $field (@possmenu) {
                   16220:                     if (exists($menutitles{$field})) {
                   16221:                         if ($field eq 'grades') {
                   16222:                             next unless ($env{'form.lti_inlinemenu_'.$idx});
                   16223:                         }
                   16224:                         push(@{$confhash{$itemid}{lcmenu}},$field);
1.326     raeburn  16225:                     }
                   16226:                 }
                   16227:             }
1.391     raeburn  16228:             if ($confhash{$itemid}{'crsinc'}) {
                   16229:                 if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
                   16230:                     ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
                   16231:                     $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
                   16232:                 } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                   16233:                     my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
                   16234:                     $mapcrs =~ s/(`)/'/g;
                   16235:                     $mapcrs =~ s/^\s+|\s+$//g;
                   16236:                     $confhash{$itemid}{'mapcrs'} = $mapcrs;
                   16237:                 }
                   16238:                 my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                   16239:                 my @crstypes;
                   16240:                 foreach my $type (sort(@posstypes)) {
                   16241:                     if ($posscrstype{$type}) {
                   16242:                         push(@crstypes,$type);
                   16243:                     }
                   16244:                 }
                   16245:                 $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392     raeburn  16246:                 if ($env{'form.lti_storecrs_'.$idx}) {
                   16247:                     $confhash{$itemid}{'storecrs'} = 1;
                   16248:                 }       
1.391     raeburn  16249:                 if ($env{'form.lti_makecrs_'.$idx}) {
                   16250:                     $confhash{$itemid}{'makecrs'} = 1;
                   16251:                 }
                   16252:                 foreach my $ltirole (@lticourseroles) {
                   16253:                     my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                   16254:                     if (grep(/^\Q$possrole\E$/,@courseroles)) {
                   16255:                         $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
                   16256:                     }
                   16257:                 }
                   16258:                 my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
                   16259:                 my @selfenroll;
                   16260:                 foreach my $type (sort(@possenroll)) {
                   16261:                     if ($posslticrs{$type}) {
                   16262:                         push(@selfenroll,$type);
                   16263:                     }
                   16264:                 }
                   16265:                 $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                   16266:                 if ($env{'form.lti_crssec_'.$idx}) {
                   16267:                     if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                   16268:                         $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                   16269:                     } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                   16270:                         my $section = $env{'form.lti_customsection_'.$idx};
                   16271:                         $section =~ s/(`)/'/g;
                   16272:                         $section =~ s/^\s+|\s+$//g;
                   16273:                         if ($section ne '') {
                   16274:                             $confhash{$itemid}{'section'} = $section;
                   16275:                         }
                   16276:                     }
                   16277:                 }
                   16278:                 foreach my $field ('passback','roster') {
                   16279:                     if ($env{'form.lti_'.$field.'_'.$idx}) {
                   16280:                         $confhash{$itemid}{$field} = 1;
                   16281:                     }
                   16282:                 }
                   16283:                 if ($env{'form.lti_passback_'.$idx}) {
                   16284:                     if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                   16285:                         $confhash{$itemid}{'passbackformat'} = '1.0';
                   16286:                     } else {
                   16287:                         $confhash{$itemid}{'passbackformat'} = '1.1';
1.337     raeburn  16288:                     }
                   16289:                 }
1.391     raeburn  16290:             }
                   16291:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   16292:                 if ($confhash{$itemid}{'crsinc'}) {
1.392     raeburn  16293:                     foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391     raeburn  16294:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320     raeburn  16295:                             $changes{$itemid} = 1;
                   16296:                         }
1.345     raeburn  16297:                     }
                   16298:                     unless ($changes{$itemid}) {
1.391     raeburn  16299:                         if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
                   16300:                             if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320     raeburn  16301:                                 $changes{$itemid} = 1;
                   16302:                             }
                   16303:                         }
1.345     raeburn  16304:                     }
1.391     raeburn  16305:                     foreach my $field ('mapcrstype','selfenroll') {
                   16306:                         unless ($changes{$itemid}) {
                   16307:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   16308:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   16309:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   16310:                                                                                    $confhash{$itemid}{$field});
                   16311:                                     if (@diffs) {
                   16312:                                         $changes{$itemid} = 1;
                   16313:                                     }
                   16314:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   16315:                                     $changes{$itemid} = 1;
                   16316:                                 }
                   16317:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   16318:                                 if (@{$confhash{$itemid}{$field}} > 0) {
1.320     raeburn  16319:                                     $changes{$itemid} = 1;
                   16320:                                 }
                   16321:                             }
1.391     raeburn  16322:                         }
                   16323:                     }
                   16324:                     unless ($changes{$itemid}) {
                   16325:                         if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
                   16326:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   16327:                                 foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
                   16328:                                     if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne 
                   16329:                                         $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345     raeburn  16330:                                         $changes{$itemid} = 1;
                   16331:                                         last;
                   16332:                                     }
                   16333:                                 }
1.391     raeburn  16334:                                 unless ($changes{$itemid}) {
                   16335:                                     foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                   16336:                                         if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
                   16337:                                             $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
                   16338:                                             $changes{$itemid} = 1;
                   16339:                                             last;
                   16340:                                         }
                   16341:                                     }
                   16342:                                 }
                   16343:                             } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
                   16344:                                 $changes{$itemid} = 1;
1.345     raeburn  16345:                             }
1.391     raeburn  16346:                         } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   16347:                             unless ($changes{$itemid}) {
                   16348:                                 if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                   16349:                                     $changes{$itemid} = 1;
                   16350:                                 }
                   16351:                             }
                   16352:                         }
                   16353:                     }
                   16354:                 }
                   16355:                 unless ($changes{$itemid}) {
                   16356:                     foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
                   16357:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345     raeburn  16358:                             $changes{$itemid} = 1;
1.320     raeburn  16359:                         }
1.391     raeburn  16360:                     }
                   16361:                     unless ($changes{$itemid}) {
                   16362:                         foreach my $field ('makeuser','lcmenu') {
                   16363:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   16364:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   16365:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   16366:                                                                                    $confhash{$itemid}{$field});
                   16367:                                     if (@diffs) {
                   16368:                                         $changes{$itemid} = 1;
                   16369:                                     }
                   16370:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   16371:                                     $changes{$itemid} = 1;
                   16372:                                 }
                   16373:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   16374:                                 if (@{$confhash{$itemid}{$field}} > 0) {
                   16375:                                     $changes{$itemid} = 1;
                   16376:                                 }
1.345     raeburn  16377:                             }
1.320     raeburn  16378:                         }
                   16379:                     }
                   16380:                 }
                   16381:             }
                   16382:         }
                   16383:     }
                   16384:     if (@allpos > 0) {
                   16385:         my $idx = 0;
                   16386:         foreach my $itemid (@allpos) {
                   16387:             if ($itemid ne '') {
                   16388:                 $confhash{$itemid}{'order'} = $idx;
                   16389:                 if (ref($domconfig{$action}) eq 'HASH') {
                   16390:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   16391:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   16392:                             $changes{$itemid} = 1;
                   16393:                         }
                   16394:                     }
                   16395:                 }
                   16396:                 $idx ++;
                   16397:             }
                   16398:         }
                   16399:     }
                   16400:     my %ltihash = (
1.405     raeburn  16401:                       $action => { %confhash }
                   16402:                   );
1.406     raeburn  16403:     my %ltienchash = (
                   16404:                          $action => { %encconfig }
                   16405:                      );
1.405     raeburn  16406:     if (keys(%secchanges)) {
                   16407:         $ltihash{'ltisec'} = \%newltisec;
1.406     raeburn  16408:         if ($secchanges{'linkprot'}) {
                   16409:             if ($is_home) {
                   16410:                 $ltienchash{'linkprot'} = \%newltienc;
                   16411:             }
                   16412:         }
1.405     raeburn  16413:     }
                   16414:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320     raeburn  16415:     if ($putresult eq 'ok') {
1.405     raeburn  16416:         my %keystore;
                   16417:         if (keys(%secchanges)) {
                   16418:             if ($secchanges{'private'}) {
                   16419:                 my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
                   16420:                 foreach my $hostid (keys(%newkeyset)) {
                   16421:                     my $storehash = {
                   16422:                                        key => $newkeyset{$hostid},
                   16423:                                        who => $env{'user.name'}.':'.$env{'user.domain'},
                   16424:                                     };
                   16425:                     $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
                   16426:                                                                     $dom,$hostid);
                   16427:                 }
                   16428:             }
1.407     raeburn  16429:             if (ref($lastactref) eq 'HASH') {
                   16430:                 if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
                   16431:                     $lastactref->{'domdefaults'} = 1;
                   16432:                 }
                   16433:             }
1.405     raeburn  16434:         }
1.384     raeburn  16435:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405     raeburn  16436:         if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
                   16437:             return &mt('No changes made.');
                   16438:         }
                   16439:         $resulttext = &mt('Changes made:').'<ul>';
                   16440:         if (keys(%secchanges) > 0) {
                   16441:             foreach my $item (keys(%secchanges)) {
                   16442:                 if ($item eq 'encrypt') {
                   16443:                     my %encrypted = (
                   16444:                               crs  => {
                   16445:                                         on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
                   16446:                                         off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
                   16447:                                       },
                   16448:                               dom => {
                   16449:                                        on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
                   16450:                                        off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
                   16451:                                      },
                   16452:                               consumers => {
                   16453:                                              on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
                   16454:                                              off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
                   16455:                                            },
                   16456:                             );
                   16457:                     foreach my $type ('crs','dom','consumers') {
                   16458:                         my $shown = $encrypted{$type}{'off'};
                   16459:                         if (ref($newltisec{$item}) eq 'HASH') {
                   16460:                             if ($newltisec{$item}{$type}) {
                   16461:                                 $shown = $encrypted{$type}{'on'}; 
                   16462:                             }
                   16463:                         }
                   16464:                         $resulttext .= '<li>'.$shown.'</li>';
                   16465:                     } 
                   16466:                 } elsif ($item eq 'rules') {
                   16467:                      my %titles = &Apache::lonlocal::texthash(
                   16468:                                       min   => 'Minimum password length',
                   16469:                                       max   => 'Maximum password length',
                   16470:                                       chars => 'Required characters',
                   16471:                      );
                   16472:                      foreach my $rule ('min','max') {
                   16473:                          if ($newltisec{rules}{$rule} eq '') {
                   16474:                              if ($rule eq 'min') {
                   16475:                                  $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
                   16476:                                                 ' '.&mt('Default of [_1] will be used',
                   16477:                                                             $Apache::lonnet::passwdmin).'</li>';
                   16478:                              } else {
                   16479:                                  $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                   16480:                              }
                   16481:                          } else {
                   16482:                              $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
                   16483:                          }
                   16484:                      }
                   16485:                      if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
                   16486:                          if (@{$newltisec{'rules'}{'chars'}} > 0) {
                   16487:                              my %rulenames = &Apache::lonlocal::texthash(
                   16488:                                                  uc => 'At least one upper case letter',
                   16489:                                                  lc => 'At least one lower case letter',
                   16490:                                                  num => 'At least one number',
                   16491:                                                  spec => 'At least one non-alphanumeric',
                   16492:                                              );
                   16493:                              my $needed = '<ul><li>'.
                   16494:                                           join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
                   16495:                                           '</li></ul>';
                   16496:                              $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   16497:                          } else {
                   16498:                              $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   16499:                          }
                   16500:                      } else {
                   16501:                          $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   16502:                      }
                   16503:                 } elsif ($item eq 'private') {
                   16504:                     if (keys(%newkeyset)) {
                   16505:                         foreach my $hostid (sort(keys(%newkeyset))) {
                   16506:                             if ($keystore{$hostid} eq 'ok') {
                   16507:                                 $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
                   16508:                             }
                   16509:                         }
                   16510:                     }
1.406     raeburn  16511:                 } elsif ($item eq 'linkprot') {
                   16512:                     $resulttext .= $linkprotoutput;
1.405     raeburn  16513:                 }
                   16514:             }
                   16515:         }
1.320     raeburn  16516:         if (keys(%changes) > 0) {
                   16517:             my $cachetime = 24*60*60;
                   16518:             my %ltiall = %confhash;
                   16519:             foreach my $id (keys(%ltiall)) {
                   16520:                 if (ref($encconfig{$id}) eq 'HASH') {
                   16521:                     foreach my $item ('key','secret') {
                   16522:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   16523:                     }
                   16524:                 }
                   16525:             }
                   16526:             &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
                   16527:             if (ref($lastactref) eq 'HASH') {
                   16528:                 $lastactref->{'lti'} = 1;
                   16529:             }
                   16530:             my %bynum;
                   16531:             foreach my $itemid (sort(keys(%changes))) {
                   16532:                 my $position = $confhash{$itemid}{'order'};
                   16533:                 $bynum{$position} = $itemid;
                   16534:             }
                   16535:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   16536:                 my $itemid = $bynum{$pos};
                   16537:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   16538:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   16539:                 } else {
1.390     raeburn  16540:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320     raeburn  16541:                     my $position = $pos + 1;
                   16542:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   16543:                     foreach my $item ('version','lifetime') {
                   16544:                         if ($confhash{$itemid}{$item} ne '') {
                   16545:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   16546:                         }
                   16547:                     }
                   16548:                     if ($encconfig{$itemid}{'key'} ne '') {
                   16549:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   16550:                     }
                   16551:                     if ($encconfig{$itemid}{'secret'} ne '') {
                   16552:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   16553:                         my $num = length($encconfig{$itemid}{'secret'});
                   16554:                         $resulttext .= ('*'x$num).'</li>';
                   16555:                     }
1.345     raeburn  16556:                     if ($confhash{$itemid}{'requser'}) {
1.391     raeburn  16557:                         if ($confhash{$itemid}{'callback'}) {
                   16558:                             $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
                   16559:                         } else {
1.392     raeburn  16560:                             $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391     raeburn  16561:                         }
1.345     raeburn  16562:                         if ($confhash{$itemid}{'mapuser'}) {
                   16563:                             my $shownmapuser;
                   16564:                             if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                   16565:                                 $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                   16566:                             } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                   16567:                                 $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                   16568:                             } else {
                   16569:                                 $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320     raeburn  16570:                             }
1.345     raeburn  16571:                             $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320     raeburn  16572:                         }
1.345     raeburn  16573:                         if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                   16574:                             if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                   16575:                                 $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                   16576:                                                           join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                   16577:                                 if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                   16578:                                     $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                   16579:                                 } else {
                   16580:                                     $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                   16581:                                                        $confhash{$itemid}{'lcauth'});
                   16582:                                     if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                   16583:                                         $resulttext .= '; '.&mt('a randomly generated password will be created');
                   16584:                                     } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                   16585:                                         if ($confhash{$itemid}{'lcauthparm'} ne '') {
                   16586:                                             $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                   16587:                                         }
                   16588:                                     } else {
                   16589:                                         $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                   16590:                                     }
                   16591:                                 }
                   16592:                                 $resulttext .= '</li>';
                   16593:                             } else {
                   16594:                                 $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                   16595:                             }
1.320     raeburn  16596:                         }
1.345     raeburn  16597:                         if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                   16598:                             if (@{$confhash{$itemid}{'instdata'}} > 0) {
                   16599:                                 $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                   16600:                                                           join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325     raeburn  16601:                             } else {
1.345     raeburn  16602:                                 $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325     raeburn  16603:                             }
1.320     raeburn  16604:                         }
1.391     raeburn  16605:                         foreach my $item ('topmenu','inlinemenu') {
1.345     raeburn  16606:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   16607:                             if ($confhash{$itemid}{$item}) {
                   16608:                                 $resulttext .= &mt('Yes');
                   16609:                             } else {
                   16610:                                 $resulttext .= &mt('No');
1.337     raeburn  16611:                             }
1.345     raeburn  16612:                             $resulttext .= '</li>';
1.320     raeburn  16613:                         }
1.345     raeburn  16614:                         if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   16615:                             if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   16616:                                 $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391     raeburn  16617:                                                join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
                   16618:                             } else {
                   16619:                                 $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
                   16620:                             }
                   16621:                         }
                   16622:                         if ($confhash{$itemid}{'crsinc'}) {
                   16623:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   16624:                                 my $rolemaps;
                   16625:                                 foreach my $role (@ltiroles) {
                   16626:                                     if ($confhash{$itemid}{'maproles'}{$role}) {
                   16627:                                         $rolemaps .= ('&nbsp;'x2).$role.'='.
                   16628:                                                      &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                   16629:                                                                                 'Course').',';
                   16630:                                     }
                   16631:                                 }
                   16632:                                 if ($rolemaps) {
                   16633:                                     $rolemaps =~ s/,$//;
                   16634:                                     $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   16635:                                 }
                   16636:                             }
                   16637:                             if ($confhash{$itemid}{'mapcrs'}) {
                   16638:                                 $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                   16639:                             }
                   16640:                             if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                   16641:                                 if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                   16642:                                     $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                   16643:                                                    join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                   16644:                                                    '</li>';
                   16645:                                 } else {
                   16646:                                     $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                   16647:                                 }
                   16648:                             }
1.392     raeburn  16649:                             if ($confhash{$itemid}{'storecrs'}) {
                   16650:                                 $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
                   16651:                             }
1.391     raeburn  16652:                             if ($confhash{$itemid}{'makecrs'}) {
                   16653:                                 $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
                   16654:                             } else {
                   16655:                                 $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
                   16656:                             }
                   16657:                             if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                   16658:                                 if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                   16659:                                     $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                   16660:                                                               join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                   16661:                                                    '</li>';
                   16662:                                 } else {
                   16663:                                     $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                   16664:                                 }
                   16665:                             }
                   16666:                             if ($confhash{$itemid}{'section'}) {
                   16667:                                 if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                   16668:                                     $resulttext .= '<li>'.&mt('User section from standard field:').
                   16669:                                                          ' (course_section_sourcedid)'.'</li>';  
                   16670:                                 } else {
                   16671:                                     $resulttext .= '<li>'.&mt('User section from:').' '.
                   16672:                                                           $confhash{$itemid}{'section'}.'</li>';
                   16673:                                 }
1.345     raeburn  16674:                             } else {
1.391     raeburn  16675:                                 $resulttext .= '<li>'.&mt('No section assignment').'</li>';
                   16676:                             }
                   16677:                             foreach my $item ('passback','roster','topmenu','inlinemenu') {
                   16678:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   16679:                                 if ($confhash{$itemid}{$item}) {
                   16680:                                     $resulttext .= &mt('Yes');
                   16681:                                     if ($item eq 'passback') {
                   16682:                                         if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                   16683:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                   16684:                                         } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                   16685:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                   16686:                                         }
                   16687:                                     }
                   16688:                                 } else {
                   16689:                                     $resulttext .= &mt('No');
                   16690:                                 }
                   16691:                                 $resulttext .= '</li>';
                   16692:                             }
                   16693:                             if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   16694:                                 if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   16695:                                     $resulttext .= '<li>'.&mt('Menu items:').' '.
                   16696:                                                    join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                   16697:                                 } else {
                   16698:                                     $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                   16699:                                 }
1.345     raeburn  16700:                             }
1.326     raeburn  16701:                         }
                   16702:                     }
1.320     raeburn  16703:                     $resulttext .= '</ul></li>';
                   16704:                 }
                   16705:             }
                   16706:         }
1.405     raeburn  16707:         $resulttext .= '</ul>';
1.320     raeburn  16708:     } else {
                   16709:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   16710:     }
                   16711:     if ($errors) {
                   16712:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   16713:                        $errors.'</ul>';
                   16714:     }
                   16715:     return $resulttext;
                   16716: }
                   16717: 
                   16718: sub get_lti_id {
                   16719:     my ($domain,$consumer) = @_;
                   16720:     # get lock on lti db
                   16721:     my $lockhash = {
                   16722:                       lock => $env{'user.name'}.
                   16723:                               ':'.$env{'user.domain'},
                   16724:                    };
                   16725:     my $tries = 0;
                   16726:     my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   16727:     my ($id,$error);
                   16728: 
                   16729:     while (($gotlock ne 'ok') && ($tries<10)) {
                   16730:         $tries ++;
                   16731:         sleep (0.1);
                   16732:         $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   16733:     }
                   16734:     if ($gotlock eq 'ok') {
                   16735:         my %currids = &Apache::lonnet::dump_dom('lti',$domain);
                   16736:         if ($currids{'lock'}) {
                   16737:             delete($currids{'lock'});
                   16738:             if (keys(%currids)) {
                   16739:                 my @curr = sort { $a <=> $b } keys(%currids);
                   16740:                 if ($curr[-1] =~ /^\d+$/) {
                   16741:                     $id = 1 + $curr[-1];
                   16742:                 }
                   16743:             } else {
                   16744:                 $id = 1;
                   16745:             }
                   16746:             if ($id) {
                   16747:                 unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
                   16748:                     $error = 'nostore';
                   16749:                 }
                   16750:             } else {
                   16751:                 $error = 'nonumber';
                   16752:             }
                   16753:         }
                   16754:         my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
                   16755:     } else {
                   16756:         $error = 'nolock';
                   16757:     }
                   16758:     return ($id,$error);
                   16759: }
                   16760: 
1.3       raeburn  16761: sub modify_autoenroll {
1.205     raeburn  16762:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  16763:     my ($resulttext,%changes);
                   16764:     my %currautoenroll;
                   16765:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   16766:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   16767:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   16768:         }
                   16769:     }
                   16770:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   16771:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  16772:                   sender => 'Sender for notification messages',
1.274     raeburn  16773:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399     raeburn  16774:                   autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  16775:     my @offon = ('off','on');
1.17      raeburn  16776:     my $sender_uname = $env{'form.sender_uname'};
                   16777:     my $sender_domain = $env{'form.sender_domain'};
                   16778:     if ($sender_domain eq '') {
                   16779:         $sender_uname = '';
                   16780:     } elsif ($sender_uname eq '') {
                   16781:         $sender_domain = '';
                   16782:     }
1.129     raeburn  16783:     my $coowners = $env{'form.autoassign_coowners'};
1.399     raeburn  16784:     my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
                   16785:     $autofailsafe =~ s{^\s+|\s+$}{}g;
                   16786:     if ($autofailsafe =~ /\D/) {
                   16787:         undef($autofailsafe);
                   16788:     }
1.274     raeburn  16789:     my $failsafe = $env{'form.autoenroll_failsafe'};
1.399     raeburn  16790:     unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
                   16791:         $failsafe = 'off';
1.400     raeburn  16792:         undef($autofailsafe);
1.274     raeburn  16793:     }
1.1       raeburn  16794:     my %autoenrollhash =  (
1.129     raeburn  16795:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   16796:                                        'sender_uname' => $sender_uname,
                   16797:                                        'sender_domain' => $sender_domain,
                   16798:                                        'co-owners' => $coowners,
1.399     raeburn  16799:                                        'autofailsafe' => $autofailsafe,
1.400     raeburn  16800:                                        'failsafe' => $failsafe,
1.1       raeburn  16801:                                 }
                   16802:                      );
1.4       raeburn  16803:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   16804:                                              $dom);
1.1       raeburn  16805:     if ($putresult eq 'ok') {
                   16806:         if (exists($currautoenroll{'run'})) {
                   16807:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   16808:                  $changes{'run'} = 1;
                   16809:              }
                   16810:         } elsif ($autorun) {
                   16811:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  16812:                  $changes{'run'} = 1;
1.1       raeburn  16813:             }
                   16814:         }
1.17      raeburn  16815:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  16816:             $changes{'sender'} = 1;
                   16817:         }
1.17      raeburn  16818:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  16819:             $changes{'sender'} = 1;
                   16820:         }
1.129     raeburn  16821:         if ($currautoenroll{'co-owners'} ne '') {
                   16822:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   16823:                 $changes{'coowners'} = 1;
                   16824:             }
                   16825:         } elsif ($coowners) {
                   16826:             $changes{'coowners'} = 1;
1.274     raeburn  16827:         }
1.399     raeburn  16828:         if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274     raeburn  16829:             $changes{'autofailsafe'} = 1;
                   16830:         }
1.399     raeburn  16831:         if ($currautoenroll{'failsafe'} ne $failsafe) {
                   16832:             $changes{'failsafe'} = 1;
                   16833:         }
1.1       raeburn  16834:         if (keys(%changes) > 0) {
                   16835:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  16836:             if ($changes{'run'}) {
1.1       raeburn  16837:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   16838:             }
                   16839:             if ($changes{'sender'}) {
1.17      raeburn  16840:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   16841:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   16842:                 } else {
                   16843:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   16844:                 }
1.1       raeburn  16845:             }
1.129     raeburn  16846:             if ($changes{'coowners'}) {
                   16847:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   16848:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16849:                 if (ref($lastactref) eq 'HASH') {
                   16850:                     $lastactref->{'domainconfig'} = 1;
                   16851:                 }
1.129     raeburn  16852:             }
1.274     raeburn  16853:             if ($changes{'autofailsafe'}) {
1.399     raeburn  16854:                 if ($autofailsafe ne '') {
                   16855:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274     raeburn  16856:                 } else {
1.399     raeburn  16857:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274     raeburn  16858:                 }
1.399     raeburn  16859:             }
                   16860:             if ($changes{'failsafe'}) {
                   16861:                 if ($failsafe eq 'off') {
                   16862:                     unless ($changes{'autofailsafe'}) {
                   16863:                         $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
                   16864:                     }
                   16865:                 } elsif ($failsafe eq 'zero') {
                   16866:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
                   16867:                 } else {
                   16868:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
                   16869:                 }
                   16870:             }
                   16871:             if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274     raeburn  16872:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   16873:                 if (ref($lastactref) eq 'HASH') {
                   16874:                     $lastactref->{'domdefaults'} = 1;
                   16875:                 }
                   16876:             }
1.1       raeburn  16877:             $resulttext .= '</ul>';
                   16878:         } else {
                   16879:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   16880:         }
                   16881:     } else {
1.11      albertel 16882:         $resulttext = '<span class="LC_error">'.
                   16883: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16884:     }
1.3       raeburn  16885:     return $resulttext;
1.1       raeburn  16886: }
                   16887: 
                   16888: sub modify_autoupdate {
1.3       raeburn  16889:     my ($dom,%domconfig) = @_;
1.1       raeburn  16890:     my ($resulttext,%currautoupdate,%fields,%changes);
                   16891:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   16892:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   16893:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   16894:         }
                   16895:     }
                   16896:     my @offon = ('off','on');
                   16897:     my %title = &Apache::lonlocal::texthash (
1.385     raeburn  16898:                     run        => 'Auto-update:',
                   16899:                     classlists => 'Updates to user information in classlists?',
                   16900:                     unexpired  => 'Skip updates for users without active or future roles?',
                   16901:                     lastactive => 'Skip updates for inactive users?',
1.1       raeburn  16902:                 );
1.44      raeburn  16903:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  16904:     my %fieldtitles = &Apache::lonlocal::texthash (
                   16905:                         id => 'Student/Employee ID',
1.20      raeburn  16906:                         permanentemail => 'E-mail address',
1.1       raeburn  16907:                         lastname => 'Last Name',
                   16908:                         firstname => 'First Name',
                   16909:                         middlename => 'Middle Name',
1.132     raeburn  16910:                         generation => 'Generation',
1.1       raeburn  16911:                       );
1.142     raeburn  16912:     $othertitle = &mt('All users');
1.1       raeburn  16913:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  16914:         $othertitle = &mt('Other users');
1.1       raeburn  16915:     }
                   16916:     foreach my $key (keys(%env)) {
                   16917:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  16918:             my ($usertype,$item) = ($1,$2);
                   16919:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   16920:                 if ($usertype eq 'default') {   
                   16921:                     push(@{$fields{$1}},$2);
                   16922:                 } elsif (ref($types) eq 'ARRAY') {
                   16923:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   16924:                         push(@{$fields{$1}},$2);
                   16925:                     }
                   16926:                 }
                   16927:             }
1.1       raeburn  16928:         }
                   16929:     }
1.131     raeburn  16930:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   16931:     @lockablenames = sort(@lockablenames);
                   16932:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   16933:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16934:         if (@changed) {
                   16935:             $changes{'lockablenames'} = 1;
                   16936:         }
                   16937:     } else {
                   16938:         if (@lockablenames) {
                   16939:             $changes{'lockablenames'} = 1;
                   16940:         }
                   16941:     }
1.1       raeburn  16942:     my %updatehash = (
                   16943:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   16944:                                       classlists => $env{'form.classlists'},
1.385     raeburn  16945:                                       unexpired  => $env{'form.unexpired'},
1.1       raeburn  16946:                                       fields => {%fields},
1.131     raeburn  16947:                                       lockablenames => \@lockablenames,
1.1       raeburn  16948:                                     }
                   16949:                      );
1.385     raeburn  16950:     my $lastactivedays;
                   16951:     if ($env{'form.lastactive'}) {
                   16952:         $lastactivedays = $env{'form.lastactivedays'};
                   16953:         $lastactivedays =~ s/^\s+|\s+$//g;
                   16954:         unless ($lastactivedays =~ /^\d+$/) {
                   16955:             undef($lastactivedays);
                   16956:             $env{'form.lastactive'} = 0;
                   16957:         }
                   16958:     }
                   16959:     $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1       raeburn  16960:     foreach my $key (keys(%currautoupdate)) {
1.385     raeburn  16961:         if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1       raeburn  16962:             if (exists($updatehash{autoupdate}{$key})) {
                   16963:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   16964:                     $changes{$key} = 1;
                   16965:                 }
                   16966:             }
                   16967:         } elsif ($key eq 'fields') {
                   16968:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  16969:                 foreach my $item (@{$types},'default') {
1.1       raeburn  16970:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   16971:                         my $change = 0;
                   16972:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   16973:                             if (!exists($fields{$item})) {
                   16974:                                 $change = 1;
1.132     raeburn  16975:                                 last;
1.1       raeburn  16976:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  16977:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  16978:                                     $change = 1;
1.132     raeburn  16979:                                     last;
1.1       raeburn  16980:                                 }
                   16981:                             }
                   16982:                         }
                   16983:                         if ($change) {
                   16984:                             push(@{$changes{$key}},$item);
                   16985:                         }
1.26      raeburn  16986:                     } 
1.1       raeburn  16987:                 }
                   16988:             }
1.131     raeburn  16989:         } elsif ($key eq 'lockablenames') {
                   16990:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   16991:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16992:                 if (@changed) {
                   16993:                     $changes{'lockablenames'} = 1;
                   16994:                 }
                   16995:             } else {
                   16996:                 if (@lockablenames) {
                   16997:                     $changes{'lockablenames'} = 1;
                   16998:                 }
                   16999:             }
                   17000:         }
                   17001:     }
                   17002:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   17003:         if (@lockablenames) {
                   17004:             $changes{'lockablenames'} = 1;
1.1       raeburn  17005:         }
                   17006:     }
1.385     raeburn  17007:     unless (grep(/^unexpired$/,keys(%currautoupdate))) {
                   17008:         if ($updatehash{'autoupdate'}{'unexpired'}) {
                   17009:             $changes{'unexpired'} = 1;
                   17010:         }
                   17011:     }
                   17012:     unless (grep(/^lastactive$/,keys(%currautoupdate))) {
                   17013:         if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
                   17014:             $changes{'lastactive'} = 1;
                   17015:         }
                   17016:     }
1.26      raeburn  17017:     foreach my $item (@{$types},'default') {
                   17018:         if (defined($fields{$item})) {
                   17019:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  17020:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   17021:                     my $change = 0;
                   17022:                     if (ref($fields{$item}) eq 'ARRAY') {
                   17023:                         foreach my $type (@{$fields{$item}}) {
                   17024:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   17025:                                 $change = 1;
                   17026:                                 last;
                   17027:                             }
                   17028:                         }
                   17029:                     }
                   17030:                     if ($change) {
                   17031:                         push(@{$changes{'fields'}},$item);
                   17032:                     }
                   17033:                 } else {
1.26      raeburn  17034:                     push(@{$changes{'fields'}},$item);
                   17035:                 }
                   17036:             } else {
                   17037:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  17038:             }
                   17039:         }
                   17040:     }
                   17041:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   17042:                                              $dom);
                   17043:     if ($putresult eq 'ok') {
                   17044:         if (keys(%changes) > 0) {
                   17045:             $resulttext = &mt('Changes made:').'<ul>';
                   17046:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  17047:                 if ($key eq 'lockablenames') {
                   17048:                     $resulttext .= '<li>';
                   17049:                     if (@lockablenames) {
                   17050:                         $usertypes->{'default'} = $othertitle;
                   17051:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   17052:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   17053:                     } else {
                   17054:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   17055:                     }
                   17056:                     $resulttext .= '</li>';
                   17057:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  17058:                     foreach my $item (@{$changes{$key}}) {
                   17059:                         my @newvalues;
                   17060:                         foreach my $type (@{$fields{$item}}) {
                   17061:                             push(@newvalues,$fieldtitles{$type});
                   17062:                         }
1.3       raeburn  17063:                         my $newvaluestr;
                   17064:                         if (@newvalues > 0) {
                   17065:                             $newvaluestr = join(', ',@newvalues);
                   17066:                         } else {
                   17067:                             $newvaluestr = &mt('none');
1.6       raeburn  17068:                         }
1.1       raeburn  17069:                         if ($item eq 'default') {
1.26      raeburn  17070:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  17071:                         } else {
1.26      raeburn  17072:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  17073:                         }
                   17074:                     }
                   17075:                 } else {
                   17076:                     my $newvalue;
                   17077:                     if ($key eq 'run') {
                   17078:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385     raeburn  17079:                     } elsif ($key eq 'lastactive') {
                   17080:                         $newvalue = $offon[$env{'form.lastactive'}];
                   17081:                         unless ($lastactivedays eq '') {
                   17082:                             $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
                   17083:                         }
1.1       raeburn  17084:                     } else {
                   17085:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  17086:                     }
1.1       raeburn  17087:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   17088:                 }
                   17089:             }
                   17090:             $resulttext .= '</ul>';
                   17091:         } else {
1.3       raeburn  17092:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  17093:         }
                   17094:     } else {
1.11      albertel 17095:         $resulttext = '<span class="LC_error">'.
                   17096: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  17097:     }
1.3       raeburn  17098:     return $resulttext;
1.1       raeburn  17099: }
                   17100: 
1.125     raeburn  17101: sub modify_autocreate {
                   17102:     my ($dom,%domconfig) = @_;
                   17103:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   17104:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   17105:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   17106:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   17107:         }
                   17108:     }
                   17109:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   17110:                  req => 'Auto-creation of validated requests for official courses',
                   17111:                  xmldc => 'Identity of course creator of courses from XML files',
                   17112:                );
                   17113:     my @types = ('xml','req');
                   17114:     foreach my $item (@types) {
                   17115:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   17116:         $newvals{$item} =~ s/\D//g;
                   17117:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   17118:     }
                   17119:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  17120:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  17121:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   17122:         $newvals{'xmldc'} = '';
                   17123:     } 
                   17124:     %autocreatehash =  (
                   17125:                         autocreate => { xml => $newvals{'xml'},
                   17126:                                         req => $newvals{'req'},
                   17127:                                       }
                   17128:                        );
                   17129:     if ($newvals{'xmldc'} ne '') {
                   17130:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   17131:     }
                   17132:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   17133:                                              $dom);
                   17134:     if ($putresult eq 'ok') {
                   17135:         my @items = @types;
                   17136:         if ($newvals{'xml'}) {
                   17137:             push(@items,'xmldc');
                   17138:         }
                   17139:         foreach my $item (@items) {
                   17140:             if (exists($currautocreate{$item})) {
                   17141:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   17142:                     $changes{$item} = 1;
                   17143:                 }
                   17144:             } elsif ($newvals{$item}) {
                   17145:                 $changes{$item} = 1;
                   17146:             }
                   17147:         }
                   17148:         if (keys(%changes) > 0) {
                   17149:             my @offon = ('off','on'); 
                   17150:             $resulttext = &mt('Changes made:').'<ul>';
                   17151:             foreach my $item (@types) {
                   17152:                 if ($changes{$item}) {
                   17153:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  17154:                     $resulttext .= '<li>'.
                   17155:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   17156:                                        '<b>','</b>').
                   17157:                                    '</li>';
1.125     raeburn  17158:                 }
                   17159:             }
                   17160:             if ($changes{'xmldc'}) {
                   17161:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   17162:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  17163:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  17164:             }
                   17165:             $resulttext .= '</ul>';
                   17166:         } else {
                   17167:             $resulttext = &mt('No changes made to auto-creation settings');
                   17168:         }
                   17169:     } else {
                   17170:         $resulttext = '<span class="LC_error">'.
                   17171:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17172:     }
                   17173:     return $resulttext;
                   17174: }
                   17175: 
1.23      raeburn  17176: sub modify_directorysrch {
1.295     raeburn  17177:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  17178:     my ($resulttext,%changes);
                   17179:     my %currdirsrch;
                   17180:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   17181:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   17182:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   17183:         }
                   17184:     }
1.277     raeburn  17185:     my %title = ( available => 'Institutional directory search available',
                   17186:                   localonly => 'Other domains can search institution',
                   17187:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  17188:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  17189:                   searchby => 'Search types',
                   17190:                   searchtypes => 'Search latitude');
                   17191:     my @offon = ('off','on');
1.24      raeburn  17192:     my @otherdoms = ('Yes','No');
1.23      raeburn  17193: 
1.25      raeburn  17194:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  17195:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   17196:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   17197: 
1.44      raeburn  17198:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  17199:     if (keys(%{$usertypes}) == 0) {
                   17200:         @cansearch = ('default');
                   17201:     } else {
                   17202:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   17203:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   17204:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   17205:                     push(@{$changes{'cansearch'}},$type);
                   17206:                 }
1.23      raeburn  17207:             }
1.26      raeburn  17208:             foreach my $type (@cansearch) {
                   17209:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   17210:                     push(@{$changes{'cansearch'}},$type);
                   17211:                 }
1.23      raeburn  17212:             }
1.26      raeburn  17213:         } else {
                   17214:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  17215:         }
                   17216:     }
                   17217: 
                   17218:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   17219:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   17220:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   17221:                 push(@{$changes{'searchby'}},$by);
                   17222:             }
                   17223:         }
                   17224:         foreach my $by (@searchby) {
                   17225:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   17226:                 push(@{$changes{'searchby'}},$by);
                   17227:             }
                   17228:         }
                   17229:     } else {
                   17230:         push(@{$changes{'searchby'}},@searchby);
                   17231:     }
1.25      raeburn  17232: 
                   17233:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   17234:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   17235:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   17236:                 push(@{$changes{'searchtypes'}},$type);
                   17237:             }
                   17238:         }
                   17239:         foreach my $type (@searchtypes) {
                   17240:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   17241:                 push(@{$changes{'searchtypes'}},$type);
                   17242:             }
                   17243:         }
                   17244:     } else {
                   17245:         if (exists($currdirsrch{'searchtypes'})) {
                   17246:             foreach my $type (@searchtypes) {  
                   17247:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   17248:                     push(@{$changes{'searchtypes'}},$type);
                   17249:                 }
                   17250:             }
                   17251:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   17252:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   17253:             }   
                   17254:         } else {
                   17255:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   17256:         }
                   17257:     }
                   17258: 
1.23      raeburn  17259:     my %dirsrch_hash =  (
                   17260:             directorysrch => { available => $env{'form.dirsrch_available'},
                   17261:                                cansearch => \@cansearch,
1.277     raeburn  17262:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   17263:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   17264:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  17265:                                searchby => \@searchby,
1.25      raeburn  17266:                                searchtypes => \@searchtypes,
1.23      raeburn  17267:                              }
                   17268:             );
                   17269:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   17270:                                              $dom);
                   17271:     if ($putresult eq 'ok') {
                   17272:         if (exists($currdirsrch{'available'})) {
                   17273:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   17274:                  $changes{'available'} = 1;
                   17275:              }
                   17276:         } else {
                   17277:             if ($env{'form.dirsrch_available'} eq '1') {
                   17278:                 $changes{'available'} = 1;
                   17279:             }
                   17280:         }
1.277     raeburn  17281:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  17282:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   17283:                 $changes{'lcavailable'} = 1;
                   17284:             }
1.277     raeburn  17285:         } else {
                   17286:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   17287:                 $changes{'lcavailable'} = 1;
                   17288:             }
                   17289:         }
1.24      raeburn  17290:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  17291:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   17292:                 $changes{'localonly'} = 1;
                   17293:             }
1.24      raeburn  17294:         } else {
1.277     raeburn  17295:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  17296:                 $changes{'localonly'} = 1;
                   17297:             }
                   17298:         }
1.277     raeburn  17299:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  17300:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   17301:                 $changes{'lclocalonly'} = 1;
                   17302:             }
1.277     raeburn  17303:         } else {
                   17304:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   17305:                 $changes{'lclocalonly'} = 1;
                   17306:             }
                   17307:         }
1.23      raeburn  17308:         if (keys(%changes) > 0) {
                   17309:             $resulttext = &mt('Changes made:').'<ul>';
                   17310:             if ($changes{'available'}) {
                   17311:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   17312:             }
1.277     raeburn  17313:             if ($changes{'lcavailable'}) {
                   17314:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   17315:             }
1.24      raeburn  17316:             if ($changes{'localonly'}) {
1.277     raeburn  17317:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  17318:             }
1.277     raeburn  17319:             if ($changes{'lclocalonly'}) {
                   17320:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  17321:             }
1.23      raeburn  17322:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   17323:                 my $chgtext;
1.26      raeburn  17324:                 if (ref($usertypes) eq 'HASH') {
                   17325:                     if (keys(%{$usertypes}) > 0) {
                   17326:                         foreach my $type (@{$types}) {
                   17327:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   17328:                                 $chgtext .= $usertypes->{$type}.'; ';
                   17329:                             }
                   17330:                         }
                   17331:                         if (grep(/^default$/,@cansearch)) {
                   17332:                             $chgtext .= $othertitle;
                   17333:                         } else {
                   17334:                             $chgtext =~ s/\; $//;
                   17335:                         }
1.210     raeburn  17336:                         $resulttext .=
1.178     raeburn  17337:                             '<li>'.
                   17338:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   17339:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   17340:                             '</li>';
1.23      raeburn  17341:                     }
                   17342:                 }
                   17343:             }
                   17344:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   17345:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   17346:                 my $chgtext;
                   17347:                 foreach my $type (@{$titleorder}) {
                   17348:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   17349:                         if (defined($searchtitles->{$type})) {
                   17350:                             $chgtext .= $searchtitles->{$type}.'; ';
                   17351:                         }
                   17352:                     }
                   17353:                 }
                   17354:                 $chgtext =~ s/\; $//;
                   17355:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   17356:             }
1.25      raeburn  17357:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   17358:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   17359:                 my $chgtext;
                   17360:                 foreach my $type (@{$srchtypeorder}) {
                   17361:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   17362:                         if (defined($srchtypes_desc->{$type})) {
                   17363:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   17364:                         }
                   17365:                     }
                   17366:                 }
                   17367:                 $chgtext =~ s/\; $//;
1.178     raeburn  17368:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  17369:             }
                   17370:             $resulttext .= '</ul>';
1.295     raeburn  17371:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   17372:             if (ref($lastactref) eq 'HASH') {
                   17373:                 $lastactref->{'directorysrch'} = 1;
                   17374:             }
1.23      raeburn  17375:         } else {
1.277     raeburn  17376:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  17377:         }
                   17378:     } else {
                   17379:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  17380:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   17381:     }
                   17382:     return $resulttext;
                   17383: }
                   17384: 
1.28      raeburn  17385: sub modify_contacts {
1.205     raeburn  17386:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  17387:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   17388:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   17389:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   17390:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   17391:         }
                   17392:     }
1.286     raeburn  17393:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  17394:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  17395:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350     raeburn  17396:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340     raeburn  17397:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   17398:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286     raeburn  17399:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  17400:     foreach my $type (@mailings) {
                   17401:         @{$newsetting{$type}} = 
                   17402:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   17403:         foreach my $item (@contacts) {
                   17404:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   17405:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   17406:             } else {
                   17407:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   17408:             }
1.289     raeburn  17409:         }
1.28      raeburn  17410:         $others{$type} = $env{'form.'.$type.'_others'};
                   17411:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  17412:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17413:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   17414:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  17415:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   17416:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   17417:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   17418:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   17419:             }
1.134     raeburn  17420:         }
1.28      raeburn  17421:     }
                   17422:     foreach my $item (@contacts) {
                   17423:         $to{$item} = $env{'form.'.$item};
                   17424:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   17425:     }
1.203     raeburn  17426:     foreach my $item (@toggles) {
                   17427:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   17428:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   17429:         }
                   17430:     }
1.340     raeburn  17431:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   17432:     foreach my $item (@lonstatus) {
                   17433:         if ($item eq 'excluded') {
                   17434:             my (%serverhomes,@excluded);
                   17435:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   17436:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   17437:             if (@possexcluded) {
                   17438:                 foreach my $id (sort(@possexcluded)) {
                   17439:                     if ($serverhomes{$id}) {
                   17440:                         push(@excluded,$id);
                   17441:                     }
                   17442:                 }
                   17443:             }
                   17444:             if (@excluded) {
                   17445:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   17446:             }
                   17447:         } elsif ($item eq 'weights') {
1.377     raeburn  17448:             foreach my $type ('E','W','N','U') {
1.340     raeburn  17449:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   17450:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   17451:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   17452:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   17453:                             $env{'form.error'.$item.'_'.$type};
                   17454:                     }
                   17455:                 }
                   17456:             }
                   17457:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   17458:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   17459:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   17460:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   17461:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   17462:                 }
                   17463:             }
                   17464:         }
                   17465:     }
1.286     raeburn  17466:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   17467:         foreach my $field (@{$fields}) {
                   17468:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   17469:                 my $value = $env{'form.helpform_'.$field};
                   17470:                 $value =~ s/^\s+|\s+$//g;
                   17471:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  17472:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  17473:                     if ($field eq 'screenshot') {
                   17474:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   17475:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  17476:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  17477:                         }
                   17478:                     }
                   17479:                 }
                   17480:             }
                   17481:         }
                   17482:     }
1.315     raeburn  17483:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   17484:     my (@statuses,%usertypeshash,@overrides);
                   17485:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   17486:         @statuses = @{$types};
                   17487:         if (ref($usertypes) eq 'HASH') {
                   17488:             %usertypeshash = %{$usertypes};
                   17489:         }
                   17490:     }
                   17491:     if (@statuses) {
                   17492:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   17493:         foreach my $type (@possoverrides) {
                   17494:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   17495:                 push(@overrides,$type);
                   17496:             }
                   17497:         }
                   17498:         if (@overrides) {
                   17499:             foreach my $type (@overrides) {
                   17500:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   17501:                 foreach my $item (@contacts) {
                   17502:                     if (grep(/^\Q$item\E$/,@standard)) {
                   17503:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   17504:                         $newsetting{'override_'.$type}{$item} = 1;
                   17505:                     } else {
                   17506:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   17507:                         $newsetting{'override_'.$type}{$item} = 0;
                   17508:                     }
                   17509:                 }
                   17510:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   17511:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   17512:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   17513:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   17514:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   17515:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   17516:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   17517:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   17518:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   17519:                 }
                   17520:             }     
                   17521:         }
                   17522:     }
1.28      raeburn  17523:     if (keys(%currsetting) > 0) {
                   17524:         foreach my $item (@contacts) {
                   17525:             if ($to{$item} ne $currsetting{$item}) {
                   17526:                 $changes{$item} = 1;
                   17527:             }
                   17528:         }
                   17529:         foreach my $type (@mailings) {
                   17530:             foreach my $item (@contacts) {
                   17531:                 if (ref($currsetting{$type}) eq 'HASH') {
                   17532:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   17533:                         push(@{$changes{$type}},$item);
                   17534:                     }
                   17535:                 } else {
                   17536:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   17537:                 }
                   17538:             }
                   17539:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   17540:                 push(@{$changes{$type}},'others');
                   17541:             }
1.289     raeburn  17542:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17543:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   17544:                     push(@{$changes{$type}},'bcc'); 
                   17545:                 }
1.286     raeburn  17546:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   17547:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   17548:                     push(@{$changes{$type}},'include');
                   17549:                 }
                   17550:             }
                   17551:         }
                   17552:         if (ref($fields) eq 'ARRAY') {
                   17553:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   17554:                 foreach my $field (@{$fields}) {
                   17555:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   17556:                         push(@{$changes{'helpform'}},$field);
                   17557:                     }
                   17558:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   17559:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   17560:                             push(@{$changes{'helpform'}},'maxsize');
                   17561:                         }
                   17562:                     }
                   17563:                 }
                   17564:             } else {
                   17565:                 foreach my $field (@{$fields}) {
                   17566:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   17567:                         push(@{$changes{'helpform'}},$field);
                   17568:                     }
                   17569:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   17570:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   17571:                             push(@{$changes{'helpform'}},'maxsize');
                   17572:                         }
                   17573:                     }
                   17574:                 }
1.134     raeburn  17575:             }
1.28      raeburn  17576:         }
1.315     raeburn  17577:         if (@statuses) {
                   17578:             if (ref($currsetting{'overrides'}) eq 'HASH') { 
                   17579:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   17580:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   17581:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   17582:                             foreach my $item (@contacts,'bcc','others','include') {
                   17583:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
                   17584:                                     push(@{$changes{'overrides'}},$key);
                   17585:                                     last;
                   17586:                                 }
                   17587:                             }
                   17588:                         } else {
                   17589:                             push(@{$changes{'overrides'}},$key);
                   17590:                         }
                   17591:                     }
                   17592:                 }
                   17593:                 foreach my $key (@overrides) {
                   17594:                     unless (exists($currsetting{'overrides'}{$key})) {
                   17595:                         push(@{$changes{'overrides'}},$key);
                   17596:                     }
                   17597:                 }
                   17598:             } else {
                   17599:                 foreach my $key (@overrides) {
                   17600:                     push(@{$changes{'overrides'}},$key); 
                   17601:                 }
                   17602:             }
                   17603:         }
1.340     raeburn  17604:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   17605:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   17606:                 if ($key eq 'excluded') {
                   17607:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   17608:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   17609:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   17610:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   17611:                             my @diffs =
                   17612:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   17613:                                                                    $currsetting{'lonstatus'}{$key});
                   17614:                             if (@diffs) {
                   17615:                                 push(@{$changes{'lonstatus'}},$key);
                   17616:                             }
                   17617:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   17618:                             push(@{$changes{'lonstatus'}},$key);
                   17619:                         }
                   17620:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   17621:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   17622:                         push(@{$changes{'lonstatus'}},$key);
                   17623:                     }
                   17624:                 } elsif ($key eq 'weights') {
                   17625:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   17626:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   17627:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  17628:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  17629:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   17630:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   17631:                                     push(@{$changes{'lonstatus'}},$key);
                   17632:                                     last;
                   17633:                                 }
                   17634:                             }
                   17635:                         } else {
1.341     raeburn  17636:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  17637:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   17638:                                     push(@{$changes{'lonstatus'}},$key);
                   17639:                                     last;
                   17640:                                 }
                   17641:                             }
                   17642:                         }
                   17643:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  17644:                         foreach my $type ('E','W','N','U') {
1.340     raeburn  17645:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   17646:                                 push(@{$changes{'lonstatus'}},$key);
                   17647:                                 last;
                   17648:                             }
                   17649:                         }
                   17650:                     }
                   17651:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   17652:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   17653:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   17654:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   17655:                                 push(@{$changes{'lonstatus'}},$key);
                   17656:                             }
                   17657:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   17658:                             push(@{$changes{'lonstatus'}},$key);
                   17659:                         }
                   17660:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   17661:                         push(@{$changes{'lonstatus'}},$key);
                   17662:                     }
                   17663:                 }
                   17664:             }
                   17665:         } else {
                   17666:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   17667:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   17668:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   17669:                         push(@{$changes{'lonstatus'}},$key);
                   17670:                     }
                   17671:                 }
                   17672:             }
                   17673:         }
1.28      raeburn  17674:     } else {
                   17675:         my %default;
                   17676:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   17677:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   17678:         $default{'errormail'} = 'adminemail';
                   17679:         $default{'packagesmail'} = 'adminemail';
                   17680:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  17681:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  17682:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  17683:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  17684:         $default{'updatesmail'} = 'adminemail';
1.350     raeburn  17685:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  17686:         foreach my $item (@contacts) {
                   17687:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  17688:                $changes{$item} = 1;
1.203     raeburn  17689:            }
1.28      raeburn  17690:         }
                   17691:         foreach my $type (@mailings) {
                   17692:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   17693:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   17694:             }
                   17695:             if ($others{$type} ne '') {
                   17696:                 push(@{$changes{$type}},'others');
1.134     raeburn  17697:             }
1.286     raeburn  17698:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17699:                 if ($bcc{$type} ne '') {
                   17700:                     push(@{$changes{$type}},'bcc');
                   17701:                 }
1.286     raeburn  17702:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   17703:                     push(@{$changes{$type}},'include');
                   17704:                 }
1.134     raeburn  17705:             }
1.28      raeburn  17706:         }
1.286     raeburn  17707:         if (ref($fields) eq 'ARRAY') {
                   17708:             foreach my $field (@{$fields}) {
                   17709:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   17710:                     push(@{$changes{'helpform'}},$field);
                   17711:                 }
                   17712:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   17713:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   17714:                         push(@{$changes{'helpform'}},'maxsize');
                   17715:                     }
                   17716:                 }
                   17717:             }
1.289     raeburn  17718:         }
1.340     raeburn  17719:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   17720:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   17721:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   17722:                     push(@{$changes{'lonstatus'}},$key);
                   17723:                 }
                   17724:             }
                   17725:         }
1.28      raeburn  17726:     }
1.203     raeburn  17727:     foreach my $item (@toggles) {
                   17728:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   17729:             $changes{$item} = 1;
                   17730:         } elsif ((!$env{'form.'.$item}) &&
                   17731:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   17732:             $changes{$item} = 1;
                   17733:         }
                   17734:     }
1.28      raeburn  17735:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   17736:                                              $dom);
                   17737:     if ($putresult eq 'ok') {
                   17738:         if (keys(%changes) > 0) {
1.205     raeburn  17739:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  17740:             if (ref($lastactref) eq 'HASH') {
                   17741:                 $lastactref->{'domainconfig'} = 1;
                   17742:             }
1.28      raeburn  17743:             my ($titles,$short_titles)  = &contact_titles();
                   17744:             $resulttext = &mt('Changes made:').'<ul>';
                   17745:             foreach my $item (@contacts) {
                   17746:                 if ($changes{$item}) {
                   17747:                     $resulttext .= '<li>'.$titles->{$item}.
                   17748:                                     &mt(' set to: ').
                   17749:                                     '<span class="LC_cusr_emph">'.
                   17750:                                     $to{$item}.'</span></li>';
                   17751:                 }
                   17752:             }
                   17753:             foreach my $type (@mailings) {
                   17754:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  17755:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  17756:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  17757:                     } else {
                   17758:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   17759:                     }
1.28      raeburn  17760:                     my @text;
                   17761:                     foreach my $item (@{$newsetting{$type}}) {
                   17762:                         push(@text,$short_titles->{$item});
                   17763:                     }
                   17764:                     if ($others{$type} ne '') {
                   17765:                         push(@text,$others{$type});
                   17766:                     }
1.286     raeburn  17767:                     if (@text) {
                   17768:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   17769:                                        join(', ',@text).'</span>';
                   17770:                     }
                   17771:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17772:                         if ($bcc{$type} ne '') {
1.286     raeburn  17773:                             my $bcctext;
                   17774:                             if (@text) {
1.289     raeburn  17775:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  17776:                             } else {
                   17777:                                 $bcctext = '(Bcc)';
                   17778:                             }
                   17779:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   17780:                         } elsif (!@text) {
                   17781:                             $resulttext .= &mt('No one');
                   17782:                         }   
1.289     raeburn  17783:                         if ($includestr{$type} ne '') {
1.286     raeburn  17784:                             if ($includeloc{$type} eq 'b') {
                   17785:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   17786:                             } elsif ($includeloc{$type} eq 's') {
                   17787:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   17788:                             }
1.134     raeburn  17789:                         }
1.286     raeburn  17790:                     } elsif (!@text) {
                   17791:                         $resulttext .= &mt('No recipients');
1.134     raeburn  17792:                     }
                   17793:                     $resulttext .= '</li>';
1.28      raeburn  17794:                 }
                   17795:             }
1.315     raeburn  17796:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   17797:                 my @deletions;
                   17798:                 foreach my $type (@{$changes{'overrides'}}) {
                   17799:                     if ($usertypeshash{$type}) {
                   17800:                         if (grep(/^\Q$type\E/,@overrides)) {
                   17801:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   17802:                                                       $usertypeshash{$type}).'<ul><li>';
                   17803:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   17804:                                 my @text;
                   17805:                                 foreach my $item (@contacts) {
                   17806:                                     if ($newsetting{'override_'.$type}{$item}) { 
                   17807:                                         push(@text,$short_titles->{$item});
                   17808:                                     }
                   17809:                                 }
                   17810:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   17811:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   17812:                                 }
                   17813:   
                   17814:                                 if (@text) {
                   17815:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   17816:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   17817:                                 }
                   17818:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   17819:                                     my $bcctext;
                   17820:                                     if (@text) {
                   17821:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   17822:                                     } else {
                   17823:                                         $bcctext = '(Bcc)';
                   17824:                                     }
                   17825:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   17826:                                 } elsif (!@text) {
                   17827:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   17828:                                 }
                   17829:                                 $resulttext .= '</li>';
                   17830:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   17831:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   17832:                                     if ($loc eq 'b') {
                   17833:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   17834:                                     } elsif ($loc eq 's') {
                   17835:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   17836:                                     }
                   17837:                                 }
                   17838:                             }
                   17839:                             $resulttext .= '</li></ul></li>';
                   17840:                         } else {
                   17841:                             push(@deletions,$usertypeshash{$type});
                   17842:                         }
                   17843:                     }
                   17844:                 }
                   17845:                 if (@deletions) {
                   17846:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   17847:                                               join(', ',@deletions)).'</li>';
                   17848:                 }
                   17849:             }
1.203     raeburn  17850:             my @offon = ('off','on');
1.340     raeburn  17851:             my $corelink = &core_link_msu();
1.203     raeburn  17852:             if ($changes{'reporterrors'}) {
                   17853:                 $resulttext .= '<li>'.
                   17854:                                &mt('E-mail error reports to [_1] set to "'.
                   17855:                                    $offon[$env{'form.reporterrors'}].'".',
1.340     raeburn  17856:                                    $corelink).
1.203     raeburn  17857:                                '</li>';
                   17858:             }
                   17859:             if ($changes{'reportupdates'}) {
                   17860:                 $resulttext .= '<li>'.
                   17861:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   17862:                                     $offon[$env{'form.reportupdates'}].'".',
1.340     raeburn  17863:                                     $corelink).
1.203     raeburn  17864:                                 '</li>';
                   17865:             }
1.340     raeburn  17866:             if ($changes{'reportstatus'}) {
                   17867:                 $resulttext .= '<li>'.
                   17868:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   17869:                                     $offon[$env{'form.reportstatus'}].'".',
                   17870:                                     $corelink).
                   17871:                                 '</li>';
                   17872:             }
                   17873:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   17874:                 $resulttext .= '<li>'.
                   17875:                                &mt('Nightly status check e-mail settings').':<ul>';
                   17876:                 my (%defval,%use_def,%shown);
                   17877:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   17878:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   17879:                 $defval{'weights'} =
1.341     raeburn  17880:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340     raeburn  17881:                 $defval{'excluded'} = &mt('None');
                   17882:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   17883:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   17884:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   17885:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   17886:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   17887:                             } elsif ($item eq 'weights') {
                   17888:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341     raeburn  17889:                                     foreach my $type ('E','W','N','U') {
1.340     raeburn  17890:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   17891:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   17892:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   17893:                                         } else {
                   17894:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   17895:                                         }
                   17896:                                         $shown{$item} .= ', ';
                   17897:                                     }
                   17898:                                     $shown{$item} =~ s/, $//;
                   17899:                                 } else {
                   17900:                                     $shown{$item} = $defval{$item};
                   17901:                                 }
                   17902:                             } elsif ($item eq 'excluded') {
                   17903:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   17904:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   17905:                                 } else {
                   17906:                                     $shown{$item} = $defval{$item};
                   17907:                                 }
                   17908:                             }
                   17909:                         } else {
                   17910:                             $shown{$item} = $defval{$item};
                   17911:                         }
                   17912:                     }
                   17913:                 } else {
                   17914:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   17915:                         $shown{$item} = $defval{$item};
                   17916:                     }
                   17917:                 }
                   17918:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   17919:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   17920:                                           $shown{$item}).'</li>';
                   17921:                 }
                   17922:                 $resulttext .= '</ul></li>';
                   17923:             }
1.286     raeburn  17924:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   17925:                 my (@optional,@required,@unused,$maxsizechg);
                   17926:                 foreach my $field (@{$changes{'helpform'}}) {
                   17927:                     if ($field eq 'maxsize') {
                   17928:                         $maxsizechg = 1;
                   17929:                         next;
                   17930:                     }
                   17931:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  17932:                         push(@optional,$field);
1.286     raeburn  17933:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   17934:                         push(@unused,$field);
                   17935:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  17936:                         push(@required,$field);
1.286     raeburn  17937:                     }
                   17938:                 }
                   17939:                 if (@optional) {
                   17940:                     $resulttext .= '<li>'.
                   17941:                                    &mt('Help form fields changed to "Optional": [_1].',
                   17942:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   17943:                                    '</li>';
                   17944:                 }
                   17945:                 if (@required) {
                   17946:                     $resulttext .= '<li>'.
                   17947:                                    &mt('Help form fields changed to "Required": [_1].',
                   17948:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   17949:                                    '</li>';
                   17950:                 }
                   17951:                 if (@unused) {
                   17952:                     $resulttext .= '<li>'.
                   17953:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   17954:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   17955:                                    '</li>';
                   17956:                 }
                   17957:                 if ($maxsizechg) {
                   17958:                     $resulttext .= '<li>'.
                   17959:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   17960:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   17961:                                    '</li>';
                   17962:                 }
                   17963:             }
1.28      raeburn  17964:             $resulttext .= '</ul>';
                   17965:         } else {
1.288     raeburn  17966:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  17967:         }
                   17968:     } else {
                   17969:         $resulttext = '<span class="LC_error">'.
                   17970:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   17971:     }
                   17972:     return $resulttext;
                   17973: }
                   17974: 
1.357     raeburn  17975: sub modify_privacy {
                   17976:     my ($dom,%domconfig) = @_;
                   17977:     my ($resulttext,%current,%changes);
                   17978:     if (ref($domconfig{'privacy'}) eq 'HASH') {
                   17979:         %current = %{$domconfig{'privacy'}};
                   17980:     }
                   17981:     my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
                   17982:     my @items = ('domain','author','course','community');
                   17983:     my %names = &Apache::lonlocal::texthash (
                   17984:                    domain => 'Assigned domain role(s)',
                   17985:                    author => 'Assigned co-author role(s)',
                   17986:                    course => 'Assigned course role(s)',
1.416     raeburn  17987:                    community => 'Assigned community role(s)',
1.357     raeburn  17988:                 );
                   17989:     my %roles = &Apache::lonlocal::texthash (
                   17990:                    domain => 'Domain role',
                   17991:                    author => 'Co-author role',
                   17992:                    course => 'Course role',
                   17993:                    community => 'Community role',
                   17994:                 );
                   17995:     my %titles = &Apache::lonlocal::texthash (
                   17996:                   approval => 'Approval for role in different domain',
                   17997:                   othdom   => 'User information available in other domain',
                   17998:                   priv     => 'Information viewable by privileged user in same domain',
                   17999:                   unpriv   => 'Information viewable by unprivileged user in same domain',
                   18000:                   instdom  => 'Other domain shares institution/provider',
                   18001:                   extdom   => 'Other domain has different institution/provider',
                   18002:                   none     => 'Not allowed',
                   18003:                   user     => 'User authorizes',
                   18004:                   domain   => 'Domain Coordinator authorizes',
                   18005:                   auto     => 'Unrestricted',
1.418     raeburn  18006:                   notify   => 'Notify when role needs authorization',
1.357     raeburn  18007:     );
                   18008:     my %fieldnames = &Apache::lonlocal::texthash (
                   18009:                         id => 'Student/Employee ID',
                   18010:                         permanentemail => 'E-mail address',
                   18011:                         lastname => 'Last Name',
                   18012:                         firstname => 'First Name',
                   18013:                         middlename => 'Middle Name',
                   18014:                         generation => 'Generation',
                   18015:     );
                   18016:     my ($othertitle,$usertypes,$types) =
                   18017:         &Apache::loncommon::sorted_inst_types($dom);
                   18018:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   18019:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   18020: 
                   18021:     my %privacyhash = (
                   18022:                        'approval' => {
                   18023:                                        instdom => {},
                   18024:                                        extdom  => {},
                   18025:                                      },
                   18026:                        'othdom'   => {},
                   18027:                        'priv'     => {},
                   18028:                        'unpriv'   => {},
                   18029:                       );
                   18030:     foreach my $item (@items) {
                   18031:         if (@instdoms > 1) {
1.416     raeburn  18032:             if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357     raeburn  18033:                 $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
                   18034:             }
                   18035:             if (ref($current{'approval'}) eq 'HASH') {
                   18036:                 if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                   18037:                     unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                   18038:                         $changes{'approval'} = 1;
                   18039:                     }
                   18040:                 }
                   18041:             } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   18042:                 $changes{'approval'} = 1;
                   18043:             }
                   18044:         }
                   18045:         if (keys(%by_location) > 0) {
                   18046:             if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   18047:                 $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
                   18048:             }
                   18049:             if (ref($current{'approval'}) eq 'HASH') {
                   18050:                 if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                   18051:                     unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                   18052:                         $changes{'approval'} = 1;
                   18053:                     }
                   18054:                 }
                   18055:             } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   18056:                 $changes{'approval'} = 1;
                   18057:             }
                   18058:         }
                   18059:         foreach my $status ('priv','unpriv') {
                   18060:             my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
                   18061:             my @newvalues;
                   18062:             foreach my $field (@possibles) {
                   18063:                 if (grep(/^\Q$field\E$/,@fields)) {
                   18064:                     $privacyhash{$status}{$item}{$field} = 1;
                   18065:                     push(@newvalues,$field);
                   18066:                 }
                   18067:             }
                   18068:             @newvalues = sort(@newvalues);
                   18069:             if (ref($current{$status}) eq 'HASH') {
                   18070:                 if (ref($current{$status}{$item}) eq 'HASH') {
                   18071:                     my @currvalues = sort(keys(%{$current{$status}{$item}}));
                   18072:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   18073:                     if (@diffs > 0) {
                   18074:                         $changes{$status} = 1;
                   18075:                     }
                   18076:                 }
                   18077:             } else {
                   18078:                 my @stdfields;
                   18079:                 foreach my $field (@fields) {
                   18080:                     if ($field eq 'id') {
                   18081:                         next if ($status eq 'unpriv');
                   18082:                         next if (($status eq 'priv') && ($item eq 'community'));
                   18083:                     }
                   18084:                     push(@stdfields,$field);
                   18085:                 }
                   18086:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   18087:                 if (@diffs > 0) {
                   18088:                     $changes{$status} = 1;
                   18089:                 }
                   18090:             }
                   18091:         }
                   18092:     }
                   18093:     if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   18094:         my @statuses;
                   18095:         if (ref($types) eq 'ARRAY') {
                   18096:             @statuses = @{$types};
                   18097:         }
                   18098:         foreach my $type (@statuses,'default') {
                   18099:             my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
                   18100:             my @newvalues;
                   18101:             foreach my $field (sort(@possfields)) {
                   18102:                 if (grep(/^\Q$field\E$/,@fields)) {
                   18103:                     $privacyhash{'othdom'}{$type}{$field} = 1;
                   18104:                     push(@newvalues,$field);
                   18105:                 }
                   18106:             }
                   18107:             @newvalues = sort(@newvalues);
                   18108:             if (ref($current{'othdom'}) eq 'HASH') {
                   18109:                 if (ref($current{'othdom'}{$type}) eq 'HASH') {
                   18110:                     my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                   18111:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   18112:                     if (@diffs > 0) {
                   18113:                         $changes{'othdom'} = 1;
                   18114:                     }
                   18115:                 }
                   18116:             } else {
                   18117:                 my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   18118:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   18119:                 if (@diffs > 0) {
                   18120:                     $changes{'othdom'} = 1;
                   18121:                 }
                   18122:             }
                   18123:         }
1.417     raeburn  18124:         my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
                   18125:         my %notify;
                   18126:         foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
                   18127:             if (exists($domcoords{$possdc})) {
                   18128:                 $notify{$possdc} = 1;
                   18129:             }
                   18130:         }
                   18131:         my $notify = join(',',sort(keys(%notify)));
                   18132:         if ($current{'notify'} ne $notify) {
                   18133:             $changes{'notify'} = 1;
                   18134:         }
                   18135:         $privacyhash{'notify'} = $notify;
1.357     raeburn  18136:     }
                   18137:     my %confighash = (
                   18138:                         privacy => \%privacyhash,
                   18139:                      );
                   18140:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   18141:     if ($putresult eq 'ok') {
                   18142:         if (keys(%changes) > 0) {
                   18143:             $resulttext = &mt('Changes made: ').'<ul>';
1.417     raeburn  18144:             foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357     raeburn  18145:                 if ($changes{$key}) {
                   18146:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   18147:                     if ($key eq 'approval') {
                   18148:                         if (keys(%{$privacyhash{$key}{instdom}})) {
                   18149:                             $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                   18150:                             foreach my $item (@items) {
                   18151:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                   18152:                             }
                   18153:                             $resulttext .= '</ul></li>';
                   18154:                         }
                   18155:                         if (keys(%{$privacyhash{$key}{extdom}})) {
                   18156:                             $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                   18157:                             foreach my $item (@items) {
                   18158:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                   18159:                             }
                   18160:                             $resulttext .= '</ul></li>';
                   18161:                         }
1.417     raeburn  18162:                     } elsif ($key eq 'notify') {
                   18163:                         if ($privacyhash{$key}) {
                   18164:                             foreach my $dc (split(/,/,$privacyhash{$key})) {
                   18165:                                 my ($dcname,$dcdom) = split(/:/,$dc);
                   18166:                                 $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
                   18167:                             }
                   18168:                         } else {
                   18169:                             $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
                   18170:                         }
1.357     raeburn  18171:                     } elsif ($key eq 'othdom') {
                   18172:                         my @statuses;
                   18173:                         if (ref($types) eq 'ARRAY') {
                   18174:                             @statuses = @{$types};
                   18175:                         }
                   18176:                         if (ref($privacyhash{$key}) eq 'HASH') {
                   18177:                             foreach my $status (@statuses,'default') {
                   18178:                                 if ($status eq 'default') {
                   18179:                                     $resulttext .= '<li>'.$othertitle.': ';
                   18180:                                 } elsif (ref($usertypes) eq 'HASH') {
                   18181:                                     $resulttext .= '<li>'.$usertypes->{$status}.': ';
                   18182:                                 } else {
                   18183:                                     next;
                   18184:                                 }
                   18185:                                 if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                   18186:                                     if (keys(%{$privacyhash{$key}{$status}})) {
                   18187:                                         $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                   18188:                                     } else {
                   18189:                                         $resulttext .= &mt('none');
                   18190:                                     }
                   18191:                                 }
                   18192:                                 $resulttext .= '</li>';
                   18193:                             }
                   18194:                         }
                   18195:                     } else {
                   18196:                         foreach my $item (@items) {
                   18197:                             if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                   18198:                                 $resulttext .= '<li>'.$names{$item}.': ';
                   18199:                                 if (keys(%{$privacyhash{$key}{$item}})) {
                   18200:                                     $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                   18201:                                 } else {
                   18202:                                     $resulttext .= &mt('none');
                   18203:                                 }
                   18204:                                 $resulttext .= '</li>';
                   18205:                             }
                   18206:                         }
                   18207:                     }
                   18208:                     $resulttext .= '</ul></li>';
                   18209:                 }
                   18210:             }
1.420   ! raeburn  18211:             $resulttext .= '</ul>'; 
1.357     raeburn  18212:         } else {
                   18213:             $resulttext = &mt('No changes made to user information settings');
                   18214:         }
                   18215:     } else {
                   18216:         $resulttext = '<span class="LC_error">'.
                   18217:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18218:     }
                   18219:     return $resulttext;
                   18220: }
                   18221: 
1.354     raeburn  18222: sub modify_passwords {
                   18223:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355     raeburn  18224:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   18225:         $updatedefaults,$updateconf);
1.354     raeburn  18226:     my $customfn = 'resetpw.html';
                   18227:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   18228:         %current = %{$domconfig{'passwords'}};
                   18229:     }
                   18230:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18231:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   18232:     if (ref($types) eq 'ARRAY') {
                   18233:         @oktypes = @{$types};
                   18234:     }
                   18235:     push(@oktypes,'default');
                   18236: 
                   18237:     my %titles = &Apache::lonlocal::texthash (
                   18238:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   18239:         intauth_check  => 'Check bcrypt cost if authenticated',
                   18240:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   18241:         permanent      => 'Permanent e-mail address',
                   18242:         critical       => 'Critical notification address',
                   18243:         notify         => 'Notification address',
                   18244:         min            => 'Minimum password length',
                   18245:         max            => 'Maximum password length',
                   18246:         chars          => 'Required characters',
                   18247:         expire         => 'Password expiration (days)',
1.356     raeburn  18248:         numsaved       => 'Number of previous passwords to save',
1.354     raeburn  18249:         reset          => 'Resetting Forgotten Password',
                   18250:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   18251:         rules          => 'Rules for LON-CAPA Passwords',
                   18252:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   18253:         username       => 'Username',
                   18254:         email          => 'E-mail address',
                   18255:     );
                   18256: 
                   18257: #
                   18258: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   18259: #
                   18260:     my (%curr_defaults,%save_defaults);
                   18261:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   18262:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   18263:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   18264:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   18265:             } else {
                   18266:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   18267:             }
                   18268:         }
                   18269:     }
                   18270:     my %staticdefaults = (
                   18271:         'resetlink'      => 2,
                   18272:         'resetcase'      => \@oktypes,
                   18273:         'resetprelink'   => 'both',
                   18274:         'resetemail'     => ['critical','notify','permanent'],
                   18275:         'intauth_cost'   => 10,
                   18276:         'intauth_check'  => 0,
                   18277:         'intauth_switch' => 0,
                   18278:     );
1.365     raeburn  18279:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354     raeburn  18280:     foreach my $type (@oktypes) {
                   18281:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   18282:     }
                   18283:     my $linklife = $env{'form.passwords_link'};
                   18284:     $linklife =~ s/^\s+|\s+$//g;
                   18285:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   18286:         $newvalues{'resetlink'} = $linklife;
                   18287:         if ($current{'resetlink'}) {
                   18288:             if ($current{'resetlink'} ne $linklife) {
                   18289:                 $changes{'reset'} = 1;
                   18290:             }
1.368     raeburn  18291:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18292:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   18293:                 $changes{'reset'} = 1;
                   18294:             }
                   18295:         }
                   18296:     } elsif ($current{'resetlink'}) {
                   18297:         $changes{'reset'} = 1;
                   18298:     }
                   18299:     my @casesens;
                   18300:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   18301:     foreach my $case (sort(@posscase)) {
                   18302:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   18303:             push(@casesens,$case);
                   18304:         }
                   18305:     }
                   18306:     $newvalues{'resetcase'} = \@casesens;
                   18307:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   18308:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   18309:         if (@diffs > 0) {
                   18310:             $changes{'reset'} = 1;
                   18311:         }
1.368     raeburn  18312:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18313:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   18314:         if (@diffs > 0) {
                   18315:             $changes{'reset'} = 1;
                   18316:         }
                   18317:     }
                   18318:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   18319:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   18320:         if (exists($current{'resetprelink'})) {
                   18321:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   18322:                 $changes{'reset'} = 1;
                   18323:             }
1.368     raeburn  18324:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18325:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   18326:                 $changes{'reset'} = 1;
                   18327:             }
                   18328:         }
                   18329:     } elsif ($current{'resetprelink'}) {
                   18330:         $changes{'reset'} = 1;
                   18331:     }
                   18332:     foreach my $type (@oktypes) {
                   18333:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   18334:         my @postlink;
                   18335:         foreach my $item (sort(@possplink)) {
                   18336:             if ($item =~ /^(email|username)$/) {
                   18337:                 push(@postlink,$item);
                   18338:             }
                   18339:         }
                   18340:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   18341:         unless ($changes{'reset'}) {
                   18342:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   18343:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   18344:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   18345:                     if (@diffs > 0) {
                   18346:                         $changes{'reset'} = 1;
                   18347:                     }
                   18348:                 } else {
                   18349:                     $changes{'reset'} = 1;
                   18350:                 }
1.368     raeburn  18351:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18352:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   18353:                 if (@diffs > 0) {
                   18354:                     $changes{'reset'} = 1;
                   18355:                 }
                   18356:             }
                   18357:         }
                   18358:     }
                   18359:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   18360:     my @resetemail;
                   18361:     foreach my $item (sort(@possemailsrc)) {
                   18362:         if ($item =~ /^(permanent|critical|notify)$/) {
                   18363:             push(@resetemail,$item);
                   18364:         }
                   18365:     }
                   18366:     $newvalues{'resetemail'} = \@resetemail;
                   18367:     unless ($changes{'reset'}) {
                   18368:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   18369:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   18370:             if (@diffs > 0) {
                   18371:                 $changes{'reset'} = 1;
                   18372:             }
1.368     raeburn  18373:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  18374:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   18375:             if (@diffs > 0) {
                   18376:                 $changes{'reset'} = 1;
                   18377:             }
                   18378:         }
                   18379:     }
                   18380:     if ($env{'form.passwords_stdtext'} == 0) {
                   18381:         $newvalues{'resetremove'} = 1;
                   18382:         unless ($current{'resetremove'}) {
                   18383:             $changes{'reset'} = 1;
                   18384:         }
                   18385:     } elsif ($current{'resetremove'}) {
                   18386:         $changes{'reset'} = 1;
                   18387:     }
                   18388:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   18389:         my $servadm = $r->dir_config('lonAdmEMail');
                   18390:         my ($configuserok,$author_ok,$switchserver) =
                   18391:             &config_check($dom,$confname,$servadm);
                   18392:         my $error;
                   18393:         if ($configuserok eq 'ok') {
                   18394:             if ($switchserver) {
                   18395:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   18396:             } else {
                   18397:                 if ($author_ok eq 'ok') {
                   18398:                     my ($result,$customurl) =
                   18399:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   18400:                                      $confname,'customtext/resetpw','','',$customfn);
                   18401:                     if ($result eq 'ok') {
                   18402:                         $newvalues{'resetcustom'} = $customurl;
                   18403:                         $changes{'reset'} = 1;
                   18404:                     } else {
                   18405:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   18406:                     }
                   18407:                 } else {
                   18408:                     $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);
                   18409:                 }
                   18410:             }
                   18411:         } else {
                   18412:             $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);
                   18413:         }
                   18414:         if ($error) {
                   18415:             &Apache::lonnet::logthis($error);
                   18416:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   18417:         }
                   18418:     } elsif ($current{'resetcustom'}) {
                   18419:         if ($env{'form.passwords_custom_del'}) {
                   18420:             $changes{'reset'} = 1;
                   18421:         } else {
                   18422:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   18423:         }
                   18424:     }
                   18425:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   18426:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   18427:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   18428:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   18429:             $changes{'intauth'} = 1;
                   18430:         }
                   18431:     } else {
                   18432:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   18433:     }
                   18434:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   18435:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   18436:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   18437:             $changes{'intauth'} = 1;
                   18438:         }
                   18439:     } else {
                   18440:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   18441:     }
                   18442:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   18443:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   18444:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   18445:             $changes{'intauth'} = 1;
                   18446:         }
                   18447:     } else {
                   18448:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   18449:     }
                   18450:     foreach my $item ('cost','check','switch') {
                   18451:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   18452:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   18453:             $updatedefaults = 1;
                   18454:         }
                   18455:     }
1.405     raeburn  18456:     &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359     raeburn  18457:     my %crsownerchg = (
                   18458:                         by => [],
                   18459:                         for => [],
                   18460:                       );
                   18461:     foreach my $item ('by','for') {
                   18462:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   18463:         foreach my $type (sort(@posstypes)) {
                   18464:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   18465:                 push(@{$crsownerchg{$item}},$type);
                   18466:             }
                   18467:         }
                   18468:     }
                   18469:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   18470:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   18471:         foreach my $item ('by','for') {
                   18472:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   18473:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   18474:                 if (@diffs > 0) {
                   18475:                     $changes{'crsownerchg'} = 1;
                   18476:                     last;
                   18477:                 }
                   18478:             }
                   18479:         }
1.368     raeburn  18480:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359     raeburn  18481:         foreach my $item ('by','for') {
                   18482:             if (@{$crsownerchg{$item}} > 0) {
                   18483:                 $changes{'crsownerchg'} = 1;
                   18484:                 last;
                   18485:             }
1.354     raeburn  18486:         }
                   18487:     }
                   18488: 
                   18489:     my %confighash = (
                   18490:                         defaults  => \%save_defaults,
                   18491:                         passwords => \%newvalues,
                   18492:                      );
                   18493:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   18494: 
                   18495:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   18496:     if ($putresult eq 'ok') {
                   18497:         if (keys(%changes) > 0) {
                   18498:             $resulttext = &mt('Changes made: ').'<ul>';
                   18499:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   18500:                 if ($changes{$key}) {
1.355     raeburn  18501:                     unless ($key eq 'intauth') {
                   18502:                         $updateconf = 1;
                   18503:                     }
1.354     raeburn  18504:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   18505:                     if ($key eq 'reset') {
                   18506:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   18507:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   18508:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   18509:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369     raeburn  18510:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   18511:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   18512:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   18513:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   18514:                             }
1.354     raeburn  18515:                         } else {
                   18516:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   18517:                         }
                   18518:                         if ($confighash{'passwords'}{'resetlink'}) {
                   18519:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   18520:                         } else {
                   18521:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   18522:                                                   &mt('Will default to 2 hours').'</li>';
                   18523:                         }
                   18524:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   18525:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   18526:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   18527:                             } else {
                   18528:                                 my $casesens;
                   18529:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   18530:                                     if ($type eq 'default') {
                   18531:                                         $casesens .= $othertitle.', ';
                   18532:                                     } elsif ($usertypes->{$type} ne '') {
                   18533:                                         $casesens .= $usertypes->{$type}.', ';
                   18534:                                     }
                   18535:                                 }
                   18536:                                 $casesens =~ s/\Q, \E$//;
                   18537:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   18538:                             }
                   18539:                         } else {
                   18540:                             $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>';
                   18541:                         }
                   18542:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   18543:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   18544:                         } else {
                   18545:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   18546:                         }
                   18547:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   18548:                             my $output;
                   18549:                             if (ref($types) eq 'ARRAY') {
                   18550:                                 foreach my $type (@{$types}) {
                   18551:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   18552:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   18553:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   18554:                                         } else {
                   18555:                                             $output .= $usertypes->{$type}.' -- '.
                   18556:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   18557:                                         }
                   18558:                                     }
                   18559:                                 }
                   18560:                             }
                   18561:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   18562:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   18563:                                     $output .= $othertitle.' -- '.&mt('none');
                   18564:                                 } else {
                   18565:                                     $output .= $othertitle.' -- '.
                   18566:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   18567:                                 }
                   18568:                             }
                   18569:                             if ($output) {
                   18570:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   18571:                             } else {
                   18572:                                 $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>';
                   18573:                             }
                   18574:                         } else {
                   18575:                             $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>';
                   18576:                         }
                   18577:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   18578:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   18579:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   18580:                             } else {
                   18581:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   18582:                             }
                   18583:                         } else {
1.379     raeburn  18584:                             $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  18585:                         }
                   18586:                         if ($confighash{'passwords'}{'resetremove'}) {
                   18587:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   18588:                         } else {
                   18589:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   18590:                         }
                   18591:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   18592:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369     raeburn  18593:                                                                             &mt('custom text'),600,500,undef,undef,
                   18594:                                                                             undef,undef,'background-color:#ffffff');
                   18595:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354     raeburn  18596:                         } else {
                   18597:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   18598:                         }
                   18599:                     } elsif ($key eq 'intauth') {
                   18600:                         foreach my $item ('cost','switch','check') {
                   18601:                             my $value = $save_defaults{$key.'_'.$item};
                   18602:                             if ($item eq 'switch') {
                   18603:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   18604:                                                      0 => 'No',
                   18605:                                                      1 => 'Yes',
                   18606:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   18607:                                                  );
                   18608:                                 if ($value =~ /^(0|1|2)$/) {
                   18609:                                     $value = $optiondesc{$value};
                   18610:                                 } else {
                   18611:                                     $value = &mt('none -- defaults to No');
                   18612:                                 }
                   18613:                             } elsif ($item eq 'check') {
                   18614:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   18615:                                                      0 => 'No',
                   18616:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   18617:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   18618:                                                  );
                   18619:                                 if ($value =~ /^(0|1|2)$/) {
                   18620:                                     $value = $optiondesc{$value};
                   18621:                                 } else {
                   18622:                                     $value = &mt('none -- defaults to No');
                   18623:                                 }
                   18624:                             }
                   18625:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   18626:                         }
                   18627:                     } elsif ($key eq 'rules') {
1.356     raeburn  18628:                         foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  18629:                             if ($confighash{'passwords'}{$rule} eq '') {
                   18630:                                 if ($rule eq 'min') {
1.356     raeburn  18631:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365     raeburn  18632:                                                    ' '.&mt('Default of [_1] will be used',
                   18633:                                                            $Apache::lonnet::passwdmin).'</li>';
1.356     raeburn  18634:                                 } else {
                   18635:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354     raeburn  18636:                                 }
                   18637:                             } else {
                   18638:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   18639:                             }
                   18640:                         }
1.370     raeburn  18641:                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   18642:                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   18643:                                 my %rulenames = &Apache::lonlocal::texthash(
                   18644:                                                      uc => 'At least one upper case letter',
                   18645:                                                      lc => 'At least one lower case letter',
                   18646:                                                      num => 'At least one number',
                   18647:                                                      spec => 'At least one non-alphanumeric',
                   18648:                                                    );
                   18649:                                 my $needed = '<ul><li>'.
                   18650:                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
                   18651:                                              '</li></ul>'; 
                   18652:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   18653:                             } else {
                   18654:                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   18655:                             }
                   18656:                         } else {
                   18657:                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   18658:                         }
1.354     raeburn  18659:                     } elsif ($key eq 'crsownerchg') {
1.359     raeburn  18660:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   18661:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   18662:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   18663:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   18664:                             } else {
                   18665:                                 my %crsownerstr;
                   18666:                                 foreach my $item ('by','for') {
                   18667:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   18668:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   18669:                                             if ($type eq 'default') {
                   18670:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   18671:                                             } elsif ($usertypes->{$type} ne '') {
                   18672:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   18673:                                             }
                   18674:                                         }
                   18675:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   18676:                                     }
                   18677:                                 }
                   18678:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   18679:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   18680:                             }
1.354     raeburn  18681:                         } else {
1.359     raeburn  18682:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354     raeburn  18683:                         }
                   18684:                     }
                   18685:                     $resulttext .= '</ul></li>';
                   18686:                 }
                   18687:             }
                   18688:             $resulttext .= '</ul>';
                   18689:         } else {
                   18690:             $resulttext = &mt('No changes made to password settings');
                   18691:         }
1.355     raeburn  18692:         my $cachetime = 24*60*60;
1.354     raeburn  18693:         if ($updatedefaults) {
                   18694:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18695:             if (ref($lastactref) eq 'HASH') {
                   18696:                 $lastactref->{'domdefaults'} = 1;
                   18697:             }
                   18698:         }
1.355     raeburn  18699:         if ($updateconf) {
                   18700:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   18701:             if (ref($lastactref) eq 'HASH') {
                   18702:                 $lastactref->{'passwdconf'} = 1;
                   18703:             }
                   18704:         }
1.354     raeburn  18705:     } else {
                   18706:         $resulttext = '<span class="LC_error">'.
                   18707:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18708:     }
                   18709:     if ($errors) {
                   18710:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   18711:                        $errors.'</ul></p>';
                   18712:     }
                   18713:     return $resulttext;
                   18714: }
                   18715: 
1.405     raeburn  18716: sub password_rule_changes {
                   18717:     my ($prefix,$newvalues,$current,$changes) = @_;
                   18718:     return unless ((ref($newvalues) eq 'HASH') &&
                   18719:                    (ref($current) eq 'HASH') &&
                   18720:                    (ref($changes) eq 'HASH'));
                   18721:     my (@rules,%staticdefaults);
                   18722:     if ($prefix eq 'passwords') {
                   18723:         @rules = ('min','max','expire','numsaved');
                   18724:     } elsif ($prefix eq 'secrets') {
                   18725:         @rules = ('min','max');
                   18726:     }
                   18727:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
                   18728:     foreach my $rule (@rules) {
                   18729:         $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
                   18730:         my $ruleok;
                   18731:         if ($rule eq 'expire') {
                   18732:             if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
                   18733:                 ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
                   18734:                 $ruleok = 1;
                   18735:             }
                   18736:         } elsif ($rule eq 'min') {
                   18737:             if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
                   18738:                 if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
                   18739:                     $ruleok = 1;
                   18740:                 }
                   18741:             }
                   18742:         } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
                   18743:                  ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
                   18744:             $ruleok = 1;
                   18745:         }
                   18746:         if ($ruleok) {
                   18747:             $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
                   18748:             if (exists($current->{$rule})) {
                   18749:                 if ($newvalues->{$rule} ne $current->{$rule}) {
                   18750:                     $changes->{'rules'} = 1;
                   18751:                 }
                   18752:             } elsif ($rule eq 'min') {
                   18753:                 if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
                   18754:                     $changes->{'rules'} = 1;
                   18755:                 }
                   18756:             } else {
                   18757:                 $changes->{'rules'} = 1;
                   18758:             }
                   18759:         } elsif (exists($current->{$rule})) {
                   18760:             $changes->{'rules'} = 1;
                   18761:         }
                   18762:     }
                   18763:     my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
                   18764:     my @chars;
                   18765:     foreach my $item (sort(@posschars)) {
                   18766:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   18767:             push(@chars,$item);
                   18768:         }
                   18769:     }
                   18770:     $newvalues->{'chars'} = \@chars;
                   18771:     unless ($changes->{'rules'}) {
                   18772:         if (ref($current->{'chars'}) eq 'ARRAY') {
                   18773:             my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
                   18774:             if (@diffs > 0) {
                   18775:                 $changes->{'rules'} = 1;
                   18776:             }
                   18777:         } else {
                   18778:             if (@chars > 0) {
                   18779:                 $changes->{'rules'} = 1;
                   18780:             }
                   18781:         }
                   18782:     }
                   18783:     return;
                   18784: }
                   18785: 
1.28      raeburn  18786: sub modify_usercreation {
1.27      raeburn  18787:     my ($dom,%domconfig) = @_;
1.224     raeburn  18788:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  18789:     my $warningmsg;
1.27      raeburn  18790:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   18791:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  18792:             if ($key eq 'cancreate') {
                   18793:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   18794:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  18795:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   18796:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18797:                         } else {
1.224     raeburn  18798:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18799:                         }
                   18800:                     }
                   18801:                 }
                   18802:             } elsif ($key eq 'email_rule') {
                   18803:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   18804:             } else {
                   18805:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   18806:             }
1.27      raeburn  18807:         }
                   18808:     }
                   18809:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  18810:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  18811:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  18812:     foreach my $item(@contexts) {
1.224     raeburn  18813:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  18814:     }
1.34      raeburn  18815:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18816:         foreach my $item (@contexts) {
1.224     raeburn  18817:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   18818:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  18819:             }
1.27      raeburn  18820:         }
1.34      raeburn  18821:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   18822:         foreach my $item (@contexts) {
1.43      raeburn  18823:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  18824:                 if ($cancreate{$item} ne 'any') {
                   18825:                     push(@{$changes{'cancreate'}},$item);
                   18826:                 }
                   18827:             } else {
                   18828:                 if ($cancreate{$item} ne 'none') {
                   18829:                     push(@{$changes{'cancreate'}},$item);
                   18830:                 }
1.27      raeburn  18831:             }
                   18832:         }
                   18833:     } else {
1.43      raeburn  18834:         foreach my $item (@contexts)  {
1.34      raeburn  18835:             push(@{$changes{'cancreate'}},$item);
                   18836:         }
1.27      raeburn  18837:     }
1.34      raeburn  18838: 
1.27      raeburn  18839:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   18840:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   18841:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   18842:                 push(@{$changes{'username_rule'}},$type);
                   18843:             }
                   18844:         }
                   18845:         foreach my $type (@username_rule) {
                   18846:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   18847:                 push(@{$changes{'username_rule'}},$type);
                   18848:             }
                   18849:         }
                   18850:     } else {
                   18851:         push(@{$changes{'username_rule'}},@username_rule);
                   18852:     }
                   18853: 
1.32      raeburn  18854:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   18855:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   18856:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   18857:                 push(@{$changes{'id_rule'}},$type);
                   18858:             }
                   18859:         }
                   18860:         foreach my $type (@id_rule) {
                   18861:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   18862:                 push(@{$changes{'id_rule'}},$type);
                   18863:             }
                   18864:         }
                   18865:     } else {
                   18866:         push(@{$changes{'id_rule'}},@id_rule);
                   18867:     }
                   18868: 
1.43      raeburn  18869:     my @authen_contexts = ('author','course','domain');
1.325     raeburn  18870:     my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  18871:     my %authhash;
1.43      raeburn  18872:     foreach my $item (@authen_contexts) {
1.28      raeburn  18873:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   18874:         foreach my $auth (@authtypes) {
                   18875:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   18876:                 $authhash{$item}{$auth} = 1;
                   18877:             } else {
                   18878:                 $authhash{$item}{$auth} = 0;
                   18879:             }
                   18880:         }
                   18881:     }
                   18882:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  18883:         foreach my $item (@authen_contexts) {
1.28      raeburn  18884:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   18885:                 foreach my $auth (@authtypes) {
                   18886:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   18887:                         push(@{$changes{'authtypes'}},$item);
                   18888:                         last;
                   18889:                     }
                   18890:                 }
                   18891:             }
                   18892:         }
                   18893:     } else {
1.43      raeburn  18894:         foreach my $item (@authen_contexts) {
1.28      raeburn  18895:             push(@{$changes{'authtypes'}},$item);
                   18896:         }
                   18897:     }
                   18898: 
1.224     raeburn  18899:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   18900:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   18901:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   18902:     $save_usercreate{'id_rule'} = \@id_rule;
                   18903:     $save_usercreate{'username_rule'} = \@username_rule,
                   18904:     $save_usercreate{'authtypes'} = \%authhash;
                   18905: 
1.27      raeburn  18906:     my %usercreation_hash =  (
1.224     raeburn  18907:         usercreation     => \%save_usercreate,
                   18908:     );
1.27      raeburn  18909: 
                   18910:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   18911:                                              $dom);
1.50      raeburn  18912: 
1.224     raeburn  18913:     if ($putresult eq 'ok') {
                   18914:         if (keys(%changes) > 0) {
                   18915:             $resulttext = &mt('Changes made:').'<ul>';
                   18916:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   18917:                 my %lt = &usercreation_types();
                   18918:                 foreach my $type (@{$changes{'cancreate'}}) {
                   18919:                     my $chgtext = $lt{$type}.', ';
                   18920:                     if ($cancreate{$type} eq 'none') {
                   18921:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   18922:                     } elsif ($cancreate{$type} eq 'any') {
                   18923:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   18924:                     } elsif ($cancreate{$type} eq 'official') {
                   18925:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   18926:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   18927:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   18928:                     }
                   18929:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   18930:                 }
                   18931:             }
                   18932:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   18933:                 my ($rules,$ruleorder) = 
                   18934:                     &Apache::lonnet::inst_userrules($dom,'username');
                   18935:                 my $chgtext = '<ul>';
                   18936:                 foreach my $type (@username_rule) {
                   18937:                     if (ref($rules->{$type}) eq 'HASH') {
                   18938:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   18939:                     }
                   18940:                 }
                   18941:                 $chgtext .= '</ul>';
                   18942:                 if (@username_rule > 0) {
                   18943:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   18944:                 } else {
                   18945:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   18946:                 }
                   18947:             }
                   18948:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   18949:                 my ($idrules,$idruleorder) = 
                   18950:                     &Apache::lonnet::inst_userrules($dom,'id');
                   18951:                 my $chgtext = '<ul>';
                   18952:                 foreach my $type (@id_rule) {
                   18953:                     if (ref($idrules->{$type}) eq 'HASH') {
                   18954:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   18955:                     }
                   18956:                 }
                   18957:                 $chgtext .= '</ul>';
                   18958:                 if (@id_rule > 0) {
                   18959:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   18960:                 } else {
                   18961:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   18962:                 }
                   18963:             }
                   18964:             my %authname = &authtype_names();
                   18965:             my %context_title = &context_names();
                   18966:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   18967:                 my $chgtext = '<ul>';
                   18968:                 foreach my $type (@{$changes{'authtypes'}}) {
                   18969:                     my @allowed;
                   18970:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   18971:                     foreach my $auth (@authtypes) {
                   18972:                         if ($authhash{$type}{$auth}) {
                   18973:                             push(@allowed,$authname{$auth});
                   18974:                         }
                   18975:                     }
                   18976:                     if (@allowed > 0) {
                   18977:                         $chgtext .= join(', ',@allowed).'</li>';
                   18978:                     } else {
                   18979:                         $chgtext .= &mt('none').'</li>';
                   18980:                     }
                   18981:                 }
                   18982:                 $chgtext .= '</ul>';
                   18983:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   18984:                 $resulttext .= '</li>';
                   18985:             }
                   18986:             $resulttext .= '</ul>';
                   18987:         } else {
                   18988:             $resulttext = &mt('No changes made to user creation settings');
                   18989:         }
                   18990:     } else {
                   18991:         $resulttext = '<span class="LC_error">'.
                   18992:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18993:     }
                   18994:     if ($warningmsg ne '') {
                   18995:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   18996:     }
                   18997:     return $resulttext;
                   18998: }
                   18999: 
                   19000: sub modify_selfcreation {
1.305     raeburn  19001:     my ($dom,$lastactref,%domconfig) = @_;
                   19002:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   19003:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   19004:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  19005:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   19006:     if (ref($typesref) eq 'ARRAY') {
                   19007:         @types = @{$typesref};
                   19008:     }
                   19009:     if (ref($usertypesref) eq 'HASH') {
                   19010:         %usertypes = %{$usertypesref};
1.228     raeburn  19011:     }
1.303     raeburn  19012:     $usertypes{'default'} = $othertitle;
1.224     raeburn  19013: #
                   19014: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   19015: #
                   19016:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   19017:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   19018:             if ($key eq 'cancreate') {
                   19019:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   19020:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   19021:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  19022:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   19023:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   19024:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   19025:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  19026:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  19027:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   19028:                         } else {
                   19029:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   19030:                         }
                   19031:                     }
                   19032:                 }
                   19033:             } elsif ($key eq 'email_rule') {
                   19034:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   19035:             } else {
                   19036:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   19037:             }
                   19038:         }
                   19039:     }
                   19040: #
                   19041: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   19042: #
                   19043:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   19044:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   19045:             if ($key eq 'selfcreate') {
                   19046:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   19047:             } else {
                   19048:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   19049:             }
                   19050:         }
                   19051:     }
1.305     raeburn  19052: #
                   19053: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   19054: #
                   19055:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   19056:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   19057:             if ($key eq 'inststatusguest') {
                   19058:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   19059:             } else {
                   19060:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   19061:             }
                   19062:         }
                   19063:     }
1.224     raeburn  19064: 
                   19065:     my @contexts = ('selfcreate');
                   19066:     @{$cancreate{'selfcreate'}} = ();
                   19067:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  19068:     if (@types) {
                   19069:         @{$cancreate{'statustocreate'}} = ();
                   19070:     }
1.236     raeburn  19071:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  19072:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  19073:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  19074:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  19075:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  19076:     my %selfcreatetypes = (
                   19077:                              sso   => 'users authenticated by institutional single sign on',
                   19078:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  19079:                              email => 'users verified by e-mail',
1.50      raeburn  19080:                           );
1.224     raeburn  19081: #
                   19082: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   19083: # is permitted.
                   19084: #
1.305     raeburn  19085:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  19086: 
1.305     raeburn  19087:     my (@statuses,%email_rule);
1.228     raeburn  19088:     foreach my $item ('login','sso','email') {
1.224     raeburn  19089:         if ($item eq 'email') {
1.236     raeburn  19090:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  19091:                 if (@types) {
                   19092:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   19093:                     foreach my $status (@poss_statuses) {
                   19094:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   19095:                             push(@statuses,$status);
                   19096:                         }
                   19097:                     }
                   19098:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   19099:                 } else {
                   19100:                     push(@statuses,'default');
                   19101:                 }
                   19102:                 if (@statuses) {
                   19103:                     my %curr_rule;
                   19104:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   19105:                         foreach my $type (@statuses) {
                   19106:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  19107:                         }
1.305     raeburn  19108:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   19109:                         foreach my $type (@statuses) {
                   19110:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   19111:                         }
                   19112:                     }
                   19113:                     push(@{$cancreate{'selfcreate'}},'email');
                   19114:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   19115:                     my %curremaildom;
                   19116:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   19117:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   19118:                     }
                   19119:                     foreach my $type (@statuses) {
                   19120:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   19121:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   19122:                         }
                   19123:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   19124:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   19125:                         }
                   19126:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   19127: #
                   19128: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   19129: #
                   19130:                             my $chosen = $1;
                   19131:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   19132:                                 my $emaildom;
                   19133:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   19134:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                   19135:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   19136:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   19137:                                         if (exists($curremaildom{$type}{$chosen})) {
                   19138:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   19139:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   19140:                                             }
                   19141:                                         } elsif ($emaildom ne '') {
                   19142:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   19143:                                         }
                   19144:                                     } elsif ($emaildom ne '') {
                   19145:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   19146:                                     } 
                   19147:                                 }
                   19148:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   19149:                             } elsif ($chosen eq 'custom') {
                   19150:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   19151:                                 $email_rule{$type} = [];
                   19152:                                 if (ref($emailrules) eq 'HASH') {
                   19153:                                     foreach my $rule (@possemail_rules) {
                   19154:                                         if (exists($emailrules->{$rule})) {
                   19155:                                             push(@{$email_rule{$type}},$rule);
                   19156:                                         }
                   19157:                                     }
                   19158:                                 }
                   19159:                                 if (@{$email_rule{$type}}) {
                   19160:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   19161:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   19162:                                         if (@{$curr_rule{$type}} > 0) {
                   19163:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   19164:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   19165:                                                     push(@{$changes{'email_rule'}},$type);
                   19166:                                                 }
                   19167:                                             }
                   19168:                                         }
                   19169:                                         foreach my $type (@{$email_rule{$type}}) {
                   19170:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   19171:                                                 push(@{$changes{'email_rule'}},$type);
                   19172:                                             }
                   19173:                                         }
                   19174:                                     } else {
                   19175:                                         push(@{$changes{'email_rule'}},$type);
                   19176:                                     }
                   19177:                                 }
                   19178:                             } else {
                   19179:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   19180:                             }
                   19181:                         }
                   19182:                     }
                   19183:                     if (@types) {
                   19184:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19185:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   19186:                             if (@changed) {
                   19187:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   19188:                             }
                   19189:                         } else {
                   19190:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   19191:                         }
                   19192:                     }
                   19193:                 } else {
                   19194:                     delete($env{'form.cancreate_email'});
                   19195:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19196:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   19197:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   19198:                         }
                   19199:                     }
                   19200:                 }
                   19201:             } else {
                   19202:                 $save_inststatus{'inststatusguest'} = [];
                   19203:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19204:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   19205:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  19206:                     }
                   19207:                 }
1.224     raeburn  19208:             }
                   19209:         } else {
                   19210:             if ($env{'form.cancreate_'.$item}) {
                   19211:                 push(@{$cancreate{'selfcreate'}},$item);
                   19212:             }
                   19213:         }
                   19214:     }
1.305     raeburn  19215:     my (%userinfo,%savecaptcha);
1.224     raeburn  19216:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   19217: #
1.228     raeburn  19218: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   19219: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  19220: #
1.236     raeburn  19221: 
1.244     raeburn  19222:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  19223:         push(@contexts,'emailusername');
1.305     raeburn  19224:         if (@statuses) {
                   19225:             foreach my $type (@statuses) {
1.228     raeburn  19226:                 if (ref($infofields) eq 'ARRAY') {
                   19227:                     foreach my $field (@{$infofields}) {
                   19228:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   19229:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   19230:                         }
                   19231:                     }
1.224     raeburn  19232:                 }
                   19233:             }
                   19234:         }
                   19235: #
                   19236: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  19237: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  19238: #
                   19239: 
                   19240:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   19241:         @approvalnotify = sort(@approvalnotify);
                   19242:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   19243:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   19244:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   19245:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   19246:                     push(@{$changes{'cancreate'}},'notify');
                   19247:                 }
                   19248:             } else {
                   19249:                 if ($cancreate{'notify'}{'approval'}) {
                   19250:                     push(@{$changes{'cancreate'}},'notify');
                   19251:                 }
                   19252:             }
                   19253:         } elsif ($cancreate{'notify'}{'approval'}) {
                   19254:             push(@{$changes{'cancreate'}},'notify');
                   19255:         }
                   19256: 
                   19257:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   19258:     }
                   19259: #  
1.236     raeburn  19260: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  19261: # institutional log-in.
                   19262: #
                   19263:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   19264:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   19265:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   19266:             $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.').' '.
                   19267:                           &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.');
                   19268:         }
                   19269:     }
                   19270:     my @fields = ('lastname','firstname','middlename','generation',
                   19271:                   'permanentemail','id');
1.240     raeburn  19272:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  19273:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19274: #
                   19275: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   19276: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   19277: # may self-create accounts 
                   19278: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   19279: # which the user may supply, if institutional data is unavailable.
                   19280: #
                   19281:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  19282:         if (@types) {
1.305     raeburn  19283:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   19284:             push(@contexts,'statustocreate');
1.303     raeburn  19285:             foreach my $type (@types) {
1.224     raeburn  19286:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   19287:                 foreach my $field (@fields) {
                   19288:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   19289:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   19290:                     } else {
                   19291:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   19292:                     }
                   19293:                 }
                   19294:             }
                   19295:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  19296:                 foreach my $type (@types) {
1.224     raeburn  19297:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   19298:                         foreach my $field (@fields) {
                   19299:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   19300:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   19301:                                 push(@{$changes{'selfcreate'}},$type);
                   19302:                                 last;
                   19303:                             }
                   19304:                         }
                   19305:                     }
                   19306:                 }
                   19307:             } else {
1.303     raeburn  19308:                 foreach my $type (@types) {
1.224     raeburn  19309:                     push(@{$changes{'selfcreate'}},$type);
                   19310:                 }
                   19311:             }
                   19312:         }
1.240     raeburn  19313:         foreach my $field (@shibfields) {
                   19314:             if ($env{'form.shibenv_'.$field} ne '') {
                   19315:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   19316:             }
                   19317:         }
                   19318:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   19319:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   19320:                 foreach my $field (@shibfields) {
                   19321:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   19322:                         push(@{$changes{'cancreate'}},'shibenv');
                   19323:                     }
                   19324:                 }
                   19325:             } else {
                   19326:                 foreach my $field (@shibfields) {
                   19327:                     if ($env{'form.shibenv_'.$field}) {
                   19328:                         push(@{$changes{'cancreate'}},'shibenv');
                   19329:                         last;
                   19330:                     }
                   19331:                 }
                   19332:             }
                   19333:         }
1.224     raeburn  19334:     }
                   19335:     foreach my $item (@contexts) {
                   19336:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   19337:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   19338:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   19339:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   19340:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19341:                             push(@{$changes{'cancreate'}},$item);
                   19342:                         }
                   19343:                     }
                   19344:                 }
                   19345:             }
                   19346:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   19347:                 foreach my $type (@{$cancreate{$item}}) {
                   19348:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   19349:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19350:                             push(@{$changes{'cancreate'}},$item);
                   19351:                         }
                   19352:                     }
                   19353:                 }
                   19354:             }
                   19355:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   19356:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  19357:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   19358:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   19359:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   19360:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  19361:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19362:                                     push(@{$changes{'cancreate'}},$item);
                   19363:                                 }
                   19364:                             }
                   19365:                         }
1.305     raeburn  19366:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   19367:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  19368:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19369:                                 push(@{$changes{'cancreate'}},$item);
                   19370:                             }
1.224     raeburn  19371:                         }
                   19372:                     }
                   19373:                 }
1.305     raeburn  19374:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   19375:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   19376:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   19377:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   19378:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  19379:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19380:                                         push(@{$changes{'cancreate'}},$item);
                   19381:                                     }
                   19382:                                 }
                   19383:                             } else {
                   19384:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19385:                                     push(@{$changes{'cancreate'}},$item);
                   19386:                                 }
                   19387:                             }
                   19388:                         }
1.305     raeburn  19389:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   19390:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  19391:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19392:                                 push(@{$changes{'cancreate'}},$item);
                   19393:                             }
1.224     raeburn  19394:                         }
                   19395:                     }
                   19396:                 }
                   19397:             }
                   19398:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   19399:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   19400:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   19401:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19402:                         push(@{$changes{'cancreate'}},$item);
                   19403:                     }
                   19404:                 }
1.305     raeburn  19405:             }
                   19406:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   19407:             if (ref($cancreate{$item}) eq 'HASH') {
                   19408:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19409:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  19410:                 }
                   19411:             }
                   19412:         } elsif ($item eq 'emailusername') {
1.228     raeburn  19413:             if (ref($cancreate{$item}) eq 'HASH') {
                   19414:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   19415:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   19416:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   19417:                             if ($cancreate{$item}{$type}{$field}) {
                   19418:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   19419:                                     push(@{$changes{'cancreate'}},$item);
                   19420:                                 }
                   19421:                                 last;
                   19422:                             }
                   19423:                         }
                   19424:                     }
                   19425:                 }
1.224     raeburn  19426:             }
                   19427:         }
                   19428:     }
                   19429: #
                   19430: # Populate %save_usercreate hash with updates to self-creation configuration.
                   19431: #
                   19432:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   19433:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  19434:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  19435:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   19436:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   19437:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   19438:     }
1.236     raeburn  19439:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   19440:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   19441:     }
1.303     raeburn  19442:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   19443:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   19444:     }
1.305     raeburn  19445:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   19446:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   19447:     }
1.303     raeburn  19448:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   19449:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   19450:     }
1.224     raeburn  19451:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   19452:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   19453:     }
1.240     raeburn  19454:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   19455:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   19456:     }
1.224     raeburn  19457:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  19458:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  19459: 
                   19460:     my %userconfig_hash = (
                   19461:             usercreation     => \%save_usercreate,
                   19462:             usermodification => \%save_usermodify,
1.305     raeburn  19463:             inststatus       => \%save_inststatus,
1.224     raeburn  19464:     );
1.305     raeburn  19465: 
1.224     raeburn  19466:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   19467:                                              $dom);
                   19468: #
1.305     raeburn  19469: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  19470: #
1.27      raeburn  19471:     if ($putresult eq 'ok') {
                   19472:         if (keys(%changes) > 0) {
                   19473:             $resulttext = &mt('Changes made:').'<ul>';
                   19474:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  19475:                 my %lt = &selfcreation_types();
1.34      raeburn  19476:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  19477:                     my $chgtext = '';
1.45      raeburn  19478:                     if ($type eq 'selfcreate') {
1.50      raeburn  19479:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  19480:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  19481:                         } else {
1.224     raeburn  19482:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   19483:                                         '<ul>';
1.50      raeburn  19484:                             foreach my $case (@{$cancreate{$type}}) {
                   19485:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   19486:                             }
                   19487:                             $chgtext .= '</ul>';
1.100     raeburn  19488:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   19489:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   19490:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   19491:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  19492:                                             $chgtext .= '<span class="LC_warning">'.
                   19493:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   19494:                                                         '</span><br />';
                   19495:                                         }
                   19496:                                     }
                   19497:                                 }
                   19498:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  19499:                                     if (!@statuses) {
                   19500:                                         $chgtext .= '<span class="LC_warning">'.
                   19501:                                                     &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.").
                   19502:                                                     '</span><br />';
1.303     raeburn  19503: 
1.100     raeburn  19504:                                     }
                   19505:                                 }
                   19506:                             }
1.43      raeburn  19507:                         }
1.240     raeburn  19508:                     } elsif ($type eq 'shibenv') {
                   19509:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  19510:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  19511:                         } else {
                   19512:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   19513:                                         '<ul>';
                   19514:                             foreach my $field (@shibfields) {
                   19515:                                 next if ($cancreate{$type}{$field} eq '');
                   19516:                                 if ($field eq 'inststatus') {
                   19517:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   19518:                                 } else {
                   19519:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   19520:                                 }
                   19521:                             }
                   19522:                             $chgtext .= '</ul>';
1.303     raeburn  19523:                         }
1.93      raeburn  19524:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  19525:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   19526:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   19527:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   19528:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  19529:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  19530:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  19531:                                         $chgtext .= '<br />'.
                   19532:                                                     '<span class="LC_warning">'.
                   19533:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   19534:                                                     '</span>';
                   19535:                                     }
1.303     raeburn  19536:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  19537:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  19538:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   19539:                                     } else {
                   19540:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   19541:                                     }
                   19542:                                     $chgtext .= '<ul>';
                   19543:                                     foreach my $case (@{$cancreate{$type}}) {
                   19544:                                         if ($case eq 'default') {
                   19545:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   19546:                                         } else {
1.303     raeburn  19547:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  19548:                                         }
                   19549:                                     }
1.100     raeburn  19550:                                     $chgtext .= '</ul>';
                   19551:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  19552:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  19553:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   19554:                                                     '</span>';
1.100     raeburn  19555:                                     }
                   19556:                                 }
                   19557:                             } else {
                   19558:                                 if (@{$cancreate{$type}} == 0) {
                   19559:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   19560:                                 } else {
                   19561:                                     $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  19562:                                 }
                   19563:                             }
1.303     raeburn  19564:                             $chgtext .= '<br />';
1.93      raeburn  19565:                         }
1.236     raeburn  19566:                     } elsif ($type eq 'selfcreateprocessing') {
                   19567:                         my %choices = &Apache::lonlocal::texthash (
                   19568:                                                                     automatic => 'Automatic approval',
                   19569:                                                                     approval  => 'Queued for approval',
                   19570:                                                                   );
1.305     raeburn  19571:                         if (@types) {
                   19572:                             if (@statuses) {
1.303     raeburn  19573:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
1.309     raeburn  19574:                                             '<ul>';
1.305     raeburn  19575:                                 foreach my $status (@statuses) {
                   19576:                                     if ($status eq 'default') {
                   19577:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  19578:                                     } else {
1.305     raeburn  19579:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  19580:                                     }
                   19581:                                 }
                   19582:                                 $chgtext .= '</ul>';
                   19583:                             }
                   19584:                         } else {
                   19585:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   19586:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   19587:                         }
                   19588:                     } elsif ($type eq 'emailverified') {
                   19589:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  19590:                                                                     all   => 'Same as e-mail',
                   19591:                                                                     first => 'Omit @domain',
                   19592:                                                                     free  => 'Free to choose',
1.303     raeburn  19593:                                                                   );
1.305     raeburn  19594:                         if (@types) {
                   19595:                             if (@statuses) {
1.303     raeburn  19596:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   19597:                                             '<ul>';
1.305     raeburn  19598:                                 foreach my $status (@statuses) {
1.362     raeburn  19599:                                     if ($status eq 'default') {
1.305     raeburn  19600:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  19601:                                     } else {
1.305     raeburn  19602:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  19603:                                     }
                   19604:                                 }
                   19605:                                 $chgtext .= '</ul>';
                   19606:                             }
                   19607:                         } else {
1.305     raeburn  19608:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  19609:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  19610:                         }
1.305     raeburn  19611:                     } elsif ($type eq 'emailoptions') {
                   19612:                         my %options = &Apache::lonlocal::texthash (
                   19613:                                                                     any     => 'Any e-mail',
                   19614:                                                                     inst    => 'Institutional only',
                   19615:                                                                     noninst => 'Non-institutional only',
                   19616:                                                                     custom  => 'Custom restrictions',
                   19617:                                                                   );
                   19618:                         if (@types) {
                   19619:                             if (@statuses) {
                   19620:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   19621:                                             '<ul>';
                   19622:                                 foreach my $status (@statuses) {
                   19623:                                     if ($type eq 'default') {
                   19624:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   19625:                                     } else {
                   19626:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  19627:                                     }
                   19628:                                 }
1.305     raeburn  19629:                                 $chgtext .= '</ul>';
                   19630:                             }
                   19631:                         } else {
                   19632:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   19633:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   19634:                             } else {
                   19635:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   19636:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  19637:                             }
1.305     raeburn  19638:                         }
                   19639:                     } elsif ($type eq 'emaildomain') {
                   19640:                         my $output;
                   19641:                         if (@statuses) {
                   19642:                             foreach my $type (@statuses) {
                   19643:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   19644:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   19645:                                         if ($type eq 'default') {
                   19646:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19647:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   19648:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19649:                                             } else {
                   19650:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   19651:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   19652:                                             }
1.303     raeburn  19653:                                         } else {
1.305     raeburn  19654:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19655:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   19656:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19657:                                             } else {
                   19658:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   19659:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                   19660:                                             }
1.303     raeburn  19661:                                         }
1.305     raeburn  19662:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   19663:                                         if ($type eq 'default') {
                   19664:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19665:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   19666:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19667:                                             } else {
                   19668:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   19669:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   19670:                                             }
1.303     raeburn  19671:                                         } else {
1.305     raeburn  19672:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   19673:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   19674:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   19675:                                             } else {
                   19676:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   19677:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                   19678:                                             }
1.303     raeburn  19679:                                         }
                   19680:                                     }
                   19681:                                 }
                   19682:                             }
1.305     raeburn  19683:                         }
                   19684:                         if ($output ne '') {
                   19685:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   19686:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  19687:                         }
1.165     raeburn  19688:                     } elsif ($type eq 'captcha') {
1.224     raeburn  19689:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  19690:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   19691:                         } else {
                   19692:                             my %captchas = &captcha_phrases();
1.224     raeburn  19693:                             if ($captchas{$savecaptcha{$type}}) {
                   19694:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  19695:                             } else {
1.210     raeburn  19696:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  19697:                             }
                   19698:                         }
                   19699:                     } elsif ($type eq 'recaptchakeys') {
                   19700:                         my ($privkey,$pubkey);
1.224     raeburn  19701:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   19702:                             $pubkey = $savecaptcha{$type}{'public'};
                   19703:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  19704:                         }
                   19705:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   19706:                         if (!$pubkey) {
                   19707:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   19708:                         } else {
                   19709:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   19710:                         }
                   19711:                         if (!$privkey) {
                   19712:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   19713:                         } else {
                   19714:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   19715:                         }
                   19716:                         $chgtext .= '</ul>';
1.269     raeburn  19717:                     } elsif ($type eq 'recaptchaversion') {
                   19718:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  19719:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  19720:                         }
1.224     raeburn  19721:                     } elsif ($type eq 'emailusername') {
                   19722:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  19723:                             if (@statuses) {
                   19724:                                 foreach my $type (@statuses) {
1.228     raeburn  19725:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   19726:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  19727:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  19728:                                                     '<ul>';
                   19729:                                             foreach my $field (@{$infofields}) {
                   19730:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   19731:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   19732:                                                 }
                   19733:                                             }
1.245     raeburn  19734:                                             $chgtext .= '</ul>';
                   19735:                                         } else {
1.303     raeburn  19736:                                             $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  19737:                                         }
                   19738:                                     } else {
1.303     raeburn  19739:                                         $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  19740:                                     }
                   19741:                                 }
                   19742:                             }
                   19743:                         }
                   19744:                     } elsif ($type eq 'notify') {
1.303     raeburn  19745:                         my $numapprove = 0;
1.224     raeburn  19746:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   19747:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   19748:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  19749:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   19750:                                     $numapprove ++;
1.224     raeburn  19751:                                 }
                   19752:                             }
1.43      raeburn  19753:                         }
1.303     raeburn  19754:                         unless ($numapprove) {
                   19755:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   19756:                         }
1.34      raeburn  19757:                     }
1.224     raeburn  19758:                     if ($chgtext) {
                   19759:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  19760:                     }
                   19761:                 }
                   19762:             }
1.305     raeburn  19763:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  19764:                 my ($emailrules,$emailruleorder) =
                   19765:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  19766:                 foreach my $type (@{$changes{'email_rule'}}) {
                   19767:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   19768:                         my $chgtext = '<ul>';
                   19769:                         foreach my $rule (@{$email_rule{$type}}) {
                   19770:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   19771:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   19772:                             }
                   19773:                         }
                   19774:                         $chgtext .= '</ul>';
1.310     raeburn  19775:                         my $typename;
1.305     raeburn  19776:                         if (@types) {
                   19777:                             if ($type eq 'default') {
                   19778:                                 $typename = $othertitle;
                   19779:                             } else {
                   19780:                                 $typename = $usertypes{$type};
                   19781:                             } 
                   19782:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   19783:                         }
                   19784:                         if (@{$email_rule{$type}} > 0) {
                   19785:                             $resulttext .= '<li>'.
                   19786:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   19787:                                                $usertypes{$type}).
                   19788:                                            $chgtext.
                   19789:                                            '</li>';
                   19790:                         } else {
                   19791:                             $resulttext .= '<li>'.
1.310     raeburn  19792:                                            &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  19793:                                            '</li>'.
1.310     raeburn  19794:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  19795:                         }
1.43      raeburn  19796:                     }
                   19797:                 }
1.305     raeburn  19798:             }
                   19799:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   19800:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19801:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   19802:                         my $chgtext = '<ul>';
                   19803:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   19804:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   19805:                         }
                   19806:                         $chgtext .= '</ul>';
                   19807:                         $resulttext .= '<li>'.
                   19808:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   19809:                                           $chgtext.
                   19810:                                        '</li>';
                   19811:                     } else {
                   19812:                         $resulttext .= '<li>'.
                   19813:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   19814:                                        '</li>';
                   19815:                     }
1.43      raeburn  19816:                 }
                   19817:             }
1.224     raeburn  19818:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   19819:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   19820:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19821:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   19822:                     my $typename = $type;
1.303     raeburn  19823:                     if (keys(%usertypes) > 0) {
                   19824:                         if ($usertypes{$type} ne '') {
                   19825:                             $typename = $usertypes{$type};
1.224     raeburn  19826:                         }
                   19827:                     }
                   19828:                     my @modifiable;
                   19829:                     $resulttext .= '<li>'.
                   19830:                                     &mt('Self-creation of account by users with status: [_1]',
                   19831:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   19832:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   19833:                     foreach my $field (@fields) {
                   19834:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   19835:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  19836:                         }
                   19837:                     }
1.224     raeburn  19838:                     if (@modifiable > 0) {
                   19839:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  19840:                     } else {
1.224     raeburn  19841:                         $resulttext .= &mt('none');
1.43      raeburn  19842:                     }
1.224     raeburn  19843:                     $resulttext .= '</li>';
1.28      raeburn  19844:                 }
1.224     raeburn  19845:                 $resulttext .= '</ul></li>';
1.28      raeburn  19846:             }
1.27      raeburn  19847:             $resulttext .= '</ul>';
1.305     raeburn  19848:             my $cachetime = 24*60*60;
                   19849:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   19850:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   19851:             if (ref($lastactref) eq 'HASH') {
                   19852:                 $lastactref->{'domdefaults'} = 1;
                   19853:             }
1.27      raeburn  19854:         } else {
1.224     raeburn  19855:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  19856:         }
                   19857:     } else {
                   19858:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  19859:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19860:     }
1.43      raeburn  19861:     if ($warningmsg ne '') {
                   19862:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   19863:     }
1.23      raeburn  19864:     return $resulttext;
                   19865: }
                   19866: 
1.165     raeburn  19867: sub process_captcha {
1.369     raeburn  19868:     my ($container,$changes,$newsettings,$currsettings) = @_;
                   19869:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165     raeburn  19870:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   19871:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   19872:         $newsettings->{'captcha'} = 'original';
                   19873:     }
1.369     raeburn  19874:     my %current;
                   19875:     if (ref($currsettings) eq 'HASH') {
                   19876:         %current = %{$currsettings};
                   19877:     }
                   19878:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  19879:         if ($container eq 'cancreate') {
1.169     raeburn  19880:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19881:                 push(@{$changes->{'cancreate'}},'captcha');
                   19882:             } elsif (!defined($changes->{'cancreate'})) {
                   19883:                 $changes->{'cancreate'} = ['captcha'];
                   19884:             }
1.368     raeburn  19885:         } elsif ($container eq 'passwords') {
                   19886:             $changes->{'reset'} = 1;
1.169     raeburn  19887:         } else {
                   19888:             $changes->{'captcha'} = 1;
1.165     raeburn  19889:         }
                   19890:     }
1.269     raeburn  19891:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  19892:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   19893:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   19894:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  19895:         $newpub =~ s/[^\w\-]//g;
                   19896:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  19897:         $newsettings->{'recaptchakeys'} = {
                   19898:                                              public  => $newpub,
                   19899:                                              private => $newpriv,
                   19900:                                           };
1.269     raeburn  19901:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   19902:         $newversion =~ s/\D//g;
                   19903:         if ($newversion ne '2') {
                   19904:             $newversion = 1;
                   19905:         }
                   19906:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  19907:     }
1.369     raeburn  19908:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   19909:         $currpub = $current{'recaptchakeys'}{'public'};
                   19910:         $currpriv = $current{'recaptchakeys'}{'private'};
1.179     raeburn  19911:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   19912:             $newsettings->{'recaptchakeys'} = {
                   19913:                                                  public  => '',
                   19914:                                                  private => '',
                   19915:                                               }
                   19916:         }
1.165     raeburn  19917:     }
1.369     raeburn  19918:     if ($current{'captcha'} eq 'recaptcha') {
                   19919:         $currversion = $current{'recaptchaversion'};
1.269     raeburn  19920:         if ($currversion ne '2') {
                   19921:             $currversion = 1;
                   19922:         }
                   19923:     }
                   19924:     if ($currversion ne $newversion) {
                   19925:         if ($container eq 'cancreate') {
                   19926:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19927:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   19928:             } elsif (!defined($changes->{'cancreate'})) {
                   19929:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   19930:             }
1.368     raeburn  19931:         } elsif ($container eq 'passwords') {
                   19932:             $changes->{'reset'} = 1;
1.269     raeburn  19933:         } else {
                   19934:             $changes->{'recaptchaversion'} = 1;
                   19935:         }
                   19936:     }
1.165     raeburn  19937:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  19938:         if ($container eq 'cancreate') {
                   19939:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19940:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   19941:             } elsif (!defined($changes->{'cancreate'})) {
                   19942:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   19943:             }
1.368     raeburn  19944:         } elsif ($container eq 'passwords') {
                   19945:             $changes->{'reset'} = 1;
1.169     raeburn  19946:         } else {
1.210     raeburn  19947:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  19948:         }
                   19949:     }
                   19950:     return;
                   19951: }
                   19952: 
1.33      raeburn  19953: sub modify_usermodification {
                   19954:     my ($dom,%domconfig) = @_;
1.224     raeburn  19955:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  19956:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   19957:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  19958:             if ($key eq 'selfcreate') {
                   19959:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   19960:             } else {  
                   19961:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   19962:             }
1.33      raeburn  19963:         }
                   19964:     }
1.224     raeburn  19965:     my @contexts = ('author','course');
1.33      raeburn  19966:     my %context_title = (
                   19967:                            author => 'In author context',
                   19968:                            course => 'In course context',
                   19969:                         );
                   19970:     my @fields = ('lastname','firstname','middlename','generation',
                   19971:                   'permanentemail','id');
                   19972:     my %roles = (
                   19973:                   author => ['ca','aa'],
                   19974:                   course => ['st','ep','ta','in','cr'],
                   19975:                 );
                   19976:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19977:     foreach my $context (@contexts) {
                   19978:         foreach my $role (@{$roles{$context}}) {
                   19979:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   19980:             foreach my $item (@fields) {
                   19981:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   19982:                     $modifyhash{$context}{$role}{$item} = 1;
                   19983:                 } else {
                   19984:                     $modifyhash{$context}{$role}{$item} = 0;
                   19985:                 }
                   19986:             }
                   19987:         }
                   19988:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   19989:             foreach my $role (@{$roles{$context}}) {
                   19990:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   19991:                     foreach my $field (@fields) {
                   19992:                         if ($modifyhash{$context}{$role}{$field} ne 
                   19993:                                 $curr_usermodification{$context}{$role}{$field}) {
                   19994:                             push(@{$changes{$context}},$role);
                   19995:                             last;
                   19996:                         }
                   19997:                     }
                   19998:                 }
                   19999:             }
                   20000:         } else {
                   20001:             foreach my $context (@contexts) {
                   20002:                 foreach my $role (@{$roles{$context}}) {
                   20003:                     push(@{$changes{$context}},$role);
                   20004:                 }
                   20005:             }
                   20006:         }
                   20007:     }
                   20008:     my %usermodification_hash =  (
                   20009:                                    usermodification => \%modifyhash,
                   20010:                                  );
                   20011:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   20012:                                              \%usermodification_hash,$dom);
                   20013:     if ($putresult eq 'ok') {
                   20014:         if (keys(%changes) > 0) {
                   20015:             $resulttext = &mt('Changes made: ').'<ul>';
                   20016:             foreach my $context (@contexts) {
                   20017:                 if (ref($changes{$context}) eq 'ARRAY') {
                   20018:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   20019:                     if (ref($changes{$context}) eq 'ARRAY') {
                   20020:                         foreach my $role (@{$changes{$context}}) {
                   20021:                             my $rolename;
1.224     raeburn  20022:                             if ($role eq 'cr') {
                   20023:                                 $rolename = &mt('Custom');
1.33      raeburn  20024:                             } else {
1.224     raeburn  20025:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  20026:                             }
                   20027:                             my @modifiable;
1.224     raeburn  20028:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  20029:                             foreach my $field (@fields) {
                   20030:                                 if ($modifyhash{$context}{$role}{$field}) {
                   20031:                                     push(@modifiable,$fieldtitles{$field});
                   20032:                                 }
                   20033:                             }
                   20034:                             if (@modifiable > 0) {
                   20035:                                 $resulttext .= join(', ',@modifiable);
                   20036:                             } else {
                   20037:                                 $resulttext .= &mt('none'); 
                   20038:                             }
                   20039:                             $resulttext .= '</li>';
                   20040:                         }
                   20041:                         $resulttext .= '</ul></li>';
                   20042:                     }
                   20043:                 }
                   20044:             }
                   20045:             $resulttext .= '</ul>';
                   20046:         } else {
                   20047:             $resulttext = &mt('No changes made to user modification settings');
                   20048:         }
                   20049:     } else {
                   20050:         $resulttext = '<span class="LC_error">'.
                   20051:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   20052:     }
                   20053:     return $resulttext;
                   20054: }
                   20055: 
1.43      raeburn  20056: sub modify_defaults {
1.212     raeburn  20057:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  20058:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  20059:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  20060:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354     raeburn  20061:                  'portal_def');
1.325     raeburn  20062:     my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43      raeburn  20063:     foreach my $item (@items) {
                   20064:         $newvalues{$item} = $env{'form.'.$item};
                   20065:         if ($item eq 'auth_def') {
                   20066:             if ($newvalues{$item} ne '') {
                   20067:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   20068:                     push(@errors,$item);
                   20069:                 }
                   20070:             }
                   20071:         } elsif ($item eq 'lang_def') {
                   20072:             if ($newvalues{$item} ne '') {
                   20073:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   20074:                     my $langcode = $1;
1.103     raeburn  20075:                     if ($langcode ne 'x_chef') {
                   20076:                         if (code2language($langcode) eq '') {
                   20077:                             push(@errors,$item);
                   20078:                         }
1.43      raeburn  20079:                     }
                   20080:                 } else {
                   20081:                     push(@errors,$item);
                   20082:                 }
                   20083:             }
1.54      raeburn  20084:         } elsif ($item eq 'timezone_def') {
                   20085:             if ($newvalues{$item} ne '') {
1.62      raeburn  20086:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  20087:                     push(@errors,$item);   
                   20088:                 }
                   20089:             }
1.68      raeburn  20090:         } elsif ($item eq 'datelocale_def') {
                   20091:             if ($newvalues{$item} ne '') {
                   20092:                 my @datelocale_ids = DateTime::Locale->ids();
                   20093:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   20094:                     push(@errors,$item);
                   20095:                 }
                   20096:             }
1.141     raeburn  20097:         } elsif ($item eq 'portal_def') {
                   20098:             if ($newvalues{$item} ne '') {
1.414     raeburn  20099:                 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])\/?$/) {
                   20100:                     foreach my $field ('email','web') {
                   20101:                         if ($env{'form.'.$item.'_'.$field}) {
                   20102:                             $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
                   20103:                         }
                   20104:                     }
                   20105:                 } else {
1.141     raeburn  20106:                     push(@errors,$item);
                   20107:                 }
                   20108:             }
1.43      raeburn  20109:         }
                   20110:         if (grep(/^\Q$item\E$/,@errors)) {
                   20111:             $newvalues{$item} = $domdefaults{$item};
1.414     raeburn  20112:             if ($item eq 'portal_def') {
                   20113:                 if ($domdefaults{$item}) {
                   20114:                     foreach my $field ('email','web') {
                   20115:                         if (exists($domdefaults{$item.'_'.$field})) {
                   20116:                             $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
                   20117:                         }
                   20118:                     }
                   20119:                 }
                   20120:             }
1.43      raeburn  20121:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   20122:             $changes{$item} = 1;
                   20123:         }
1.414     raeburn  20124:         if ($item eq 'portal_def') {
                   20125:             unless (grep(/^\Q$item\E$/,@errors)) {
                   20126:                 if ($newvalues{$item} eq '') { 
                   20127:                     foreach my $field ('email','web') {
                   20128:                         if (exists($domdefaults{$item.'_'.$field})) {
                   20129:                             delete($domdefaults{$item.'_'.$field});
                   20130:                         }
                   20131:                     }
                   20132:                 } else {
                   20133:                     unless ($changes{$item}) {
                   20134:                         foreach my $field ('email','web') {
                   20135:                             if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
                   20136:                                 $changes{$item} = 1;
                   20137:                                 last;
                   20138:                             }
                   20139:                         }
                   20140:                     }
                   20141:                     foreach my $field ('email','web') {
                   20142:                         if ($newvalues{$item.'_'.$field}) {
                   20143:                             $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
                   20144:                         } elsif (exists($domdefaults{$item.'_'.$field})) {
                   20145:                             delete($domdefaults{$item.'_'.$field});
                   20146:                         }
                   20147:                     }
                   20148:                 }
                   20149:             }
                   20150:         }
1.72      raeburn  20151:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  20152:     }
1.354     raeburn  20153:     my %staticdefaults = (
                   20154:                            'intauth_cost'   => 10,
                   20155:                            'intauth_check'  => 0,
                   20156:                            'intauth_switch' => 0,
                   20157:                          );
                   20158:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   20159:         if (exists($domdefaults{$item})) {
                   20160:             $newvalues{$item} = $domdefaults{$item};
                   20161:         } else {
                   20162:             $newvalues{$item} = $staticdefaults{$item};
                   20163:         }
                   20164:     }
1.409     raeburn  20165:     my ($unamemaprules,$ruleorder);
                   20166:     my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
                   20167:     if (@possunamemaprules) {
                   20168:         ($unamemaprules,$ruleorder) =
                   20169:             &Apache::lonnet::inst_userrules($dom,'unamemap');
                   20170:         if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   20171:             if (@{$ruleorder} > 0) {
                   20172:                 my %possrules;
                   20173:                 map { $possrules{$_} = 1; } @possunamemaprules;
                   20174:                 foreach my $rule (@{$ruleorder}) {
                   20175:                     if ($possrules{$rule}) {
                   20176:                         push(@{$newvalues{'unamemap_rule'}},$rule);
                   20177:                     }
                   20178:                 }
                   20179:             }
                   20180:         }
                   20181:     }
                   20182:     if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
                   20183:         if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   20184:             my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
                   20185:                                                                $newvalues{'unamemap_rule'});
                   20186:             if (@rulediffs) {
                   20187:                 $changes{'unamemap_rule'} = 1;
                   20188:                 $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
                   20189:             }
                   20190:         } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
                   20191:             $changes{'unamemap_rule'} = 1;
                   20192:             delete($domdefaults{'unamemap_rule'});
                   20193:         }
                   20194:     } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   20195:         if (@{$newvalues{'unamemap_rule'}} > 0) {
                   20196:             $changes{'unamemap_rule'} = 1;
                   20197:             $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
                   20198:         }
                   20199:     }
1.43      raeburn  20200:     my %defaults_hash = (
1.72      raeburn  20201:                          defaults => \%newvalues,
                   20202:                         );
1.43      raeburn  20203:     my $title = &defaults_titles();
1.236     raeburn  20204: 
                   20205:     my $currinststatus;
                   20206:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   20207:         $currinststatus = $domconfig{'inststatus'};
                   20208:     } else {
                   20209:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   20210:         $currinststatus = {
                   20211:                              inststatustypes => $usertypes,
                   20212:                              inststatusorder => $types,
                   20213:                              inststatusguest => [],
                   20214:                           };
                   20215:     }
                   20216:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   20217:     my @allpos;
                   20218:     my %alltypes;
1.305     raeburn  20219:     my @inststatusguest;
                   20220:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   20221:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   20222:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   20223:                 push(@inststatusguest,$type);
                   20224:             }
                   20225:         }
                   20226:     }
                   20227:     my ($currtitles,$currorder);
1.236     raeburn  20228:     if (ref($currinststatus) eq 'HASH') {
                   20229:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   20230:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   20231:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   20232:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   20233:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   20234:                     }
                   20235:                 }
                   20236:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   20237:                     my $position = $env{'form.inststatus_pos_'.$type};
                   20238:                     $position =~ s/\D+//g;
                   20239:                     $allpos[$position] = $type;
                   20240:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   20241:                     $alltypes{$type} =~ s/`//g;
                   20242:                 }
                   20243:             }
                   20244:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   20245:             $currtitles =~ s/,$//;
                   20246:         }
                   20247:     }
                   20248:     if ($env{'form.addinststatus'}) {
                   20249:         my $newtype = $env{'form.addinststatus'};
                   20250:         $newtype =~ s/\W//g;
                   20251:         unless (exists($alltypes{$newtype})) {
                   20252:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   20253:             $alltypes{$newtype} =~ s/`//g; 
                   20254:             my $position = $env{'form.addinststatus_pos'};
                   20255:             $position =~ s/\D+//g;
                   20256:             if ($position ne '') {
                   20257:                 $allpos[$position] = $newtype;
                   20258:             }
                   20259:         }
                   20260:     }
1.305     raeburn  20261:     my @orderedstatus;
1.236     raeburn  20262:     foreach my $type (@allpos) {
                   20263:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   20264:             push(@orderedstatus,$type);
                   20265:         }
                   20266:     }
                   20267:     foreach my $type (keys(%alltypes)) {
                   20268:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   20269:             delete($alltypes{$type});
                   20270:         }
                   20271:     }
                   20272:     $defaults_hash{'inststatus'} = {
                   20273:                                      inststatustypes => \%alltypes,
                   20274:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  20275:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  20276:                                    };
                   20277:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   20278:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   20279:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   20280:         }
                   20281:     }
                   20282:     if ($currorder ne join(',',@orderedstatus)) {
                   20283:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   20284:     }
                   20285:     my $newtitles;
                   20286:     foreach my $item (@orderedstatus) {
                   20287:         $newtitles .= $alltypes{$item}.',';
                   20288:     }
                   20289:     $newtitles =~ s/,$//;
                   20290:     if ($currtitles ne $newtitles) {
                   20291:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   20292:     }
1.43      raeburn  20293:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   20294:                                              $dom);
                   20295:     if ($putresult eq 'ok') {
                   20296:         if (keys(%changes) > 0) {
                   20297:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  20298:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  20299:             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";
                   20300:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  20301:                 if ($item eq 'inststatus') {
                   20302:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  20303:                         if (@orderedstatus) {
1.236     raeburn  20304:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   20305:                             foreach my $type (@orderedstatus) { 
                   20306:                                 $resulttext .= $alltypes{$type}.', ';
                   20307:                             }
                   20308:                             $resulttext =~ s/, $//;
                   20309:                             $resulttext .= '</li>';
1.305     raeburn  20310:                         } else {
                   20311:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
1.236     raeburn  20312:                         }
                   20313:                     }
1.409     raeburn  20314:                 } elsif ($item eq 'unamemap_rule') {
                   20315:                     if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   20316:                         my @rulenames;
                   20317:                         if (ref($unamemaprules) eq 'HASH') {
                   20318:                             foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
                   20319:                                 if (ref($unamemaprules->{$rule}) eq 'HASH') {
                   20320:                                     push(@rulenames,$unamemaprules->{$rule}->{'name'});
                   20321:                                 }
                   20322:                             }
                   20323:                         }
                   20324:                         if (@rulenames) {
                   20325:                             $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
                   20326:                                                      '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
                   20327:                                            '</li>';
                   20328:                         } else {
                   20329:                             $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
                   20330:                         }
                   20331:                     } else {
                   20332:                         $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
                   20333:                     }
1.236     raeburn  20334:                 } else {
                   20335:                     my $value = $env{'form.'.$item};
                   20336:                     if ($value eq '') {
                   20337:                         $value = &mt('none');
                   20338:                     } elsif ($item eq 'auth_def') {
                   20339:                         my %authnames = &authtype_names();
                   20340:                         my %shortauth = (
                   20341:                                           internal   => 'int',
                   20342:                                           krb4       => 'krb4',
                   20343:                                           krb5       => 'krb5',
                   20344:                                           localauth  => 'loc',
1.325     raeburn  20345:                                           lti        => 'lti',
1.236     raeburn  20346:                         );
                   20347:                         $value = $authnames{$shortauth{$value}};
                   20348:                     }
                   20349:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414     raeburn  20350:                     $mailmsgtext .= "$title->{$item} set to $value\n";
                   20351:                     if ($item eq 'portal_def') {
                   20352:                         if ($env{'form.'.$item} ne '') {
                   20353:                             foreach my $field ('email','web') {
                   20354:                                 $value = $env{'form.'.$item.'_'.$field};
                   20355:                                 if ($value) {
                   20356:                                     $value = &mt('Yes');
                   20357:                                 } else {
                   20358:                                     $value = &mt('No');
                   20359:                                 }
                   20360:                                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
                   20361:                             }
                   20362:                         }
                   20363:                     }
1.43      raeburn  20364:                 }
                   20365:             }
                   20366:             $resulttext .= '</ul>';
                   20367:             $mailmsgtext .= "\n";
                   20368:             my $cachetime = 24*60*60;
1.72      raeburn  20369:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  20370:             if (ref($lastactref) eq 'HASH') {
                   20371:                 $lastactref->{'domdefaults'} = 1;
                   20372:             }
1.68      raeburn  20373:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  20374:                 my $notify = 1;
                   20375:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   20376:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   20377:                         $notify = 0;
                   20378:                     }
                   20379:                 }
                   20380:                 if ($notify) {
                   20381:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   20382:                                                "LON-CAPA Domain Settings Change - $dom",
                   20383:                                                $mailmsgtext);
                   20384:                 }
1.54      raeburn  20385:             }
1.43      raeburn  20386:         } else {
1.54      raeburn  20387:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  20388:         }
                   20389:     } else {
                   20390:         $resulttext = '<span class="LC_error">'.
                   20391:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   20392:     }
                   20393:     if (@errors > 0) {
                   20394:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   20395:         foreach my $item (@errors) {
                   20396:             $resulttext .= ' "'.$title->{$item}.'",';
                   20397:         }
                   20398:         $resulttext =~ s/,$//;
                   20399:     }
                   20400:     return $resulttext;
                   20401: }
                   20402: 
1.46      raeburn  20403: sub modify_scantron {
1.205     raeburn  20404:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  20405:     my ($resulttext,%confhash,%changes,$errors);
                   20406:     my $custom = 'custom.tab';
                   20407:     my $default = 'default.tab';
                   20408:     my $servadm = $r->dir_config('lonAdmEMail');
1.346     raeburn  20409:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  20410:         &config_check($dom,$confname,$servadm);
                   20411:     if ($env{'form.scantronformat.filename'} ne '') {
                   20412:         my $error;
                   20413:         if ($configuserok eq 'ok') {
                   20414:             if ($switchserver) {
1.130     raeburn  20415:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  20416:             } else {
                   20417:                 if ($author_ok eq 'ok') {
                   20418:                     my ($result,$scantronurl) =
                   20419:                         &publishlogo($r,'upload','scantronformat',$dom,
                   20420:                                      $confname,'scantron','','',$custom);
                   20421:                     if ($result eq 'ok') {
                   20422:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  20423:                         $changes{'scantronformat'} = 1;
1.46      raeburn  20424:                     } else {
                   20425:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   20426:                     }
                   20427:                 } else {
                   20428:                     $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);
                   20429:                 }
                   20430:             }
                   20431:         } else {
                   20432:             $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);
                   20433:         }
                   20434:         if ($error) {
                   20435:             &Apache::lonnet::logthis($error);
                   20436:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   20437:         }
                   20438:     }
1.48      raeburn  20439:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   20440:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   20441:             if ($env{'form.scantronformat_del'}) {
                   20442:                 $confhash{'scantron'}{'scantronformat'} = '';
                   20443:                 $changes{'scantronformat'} = 1;
1.347     raeburn  20444:             } else {
                   20445:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46      raeburn  20446:             }
                   20447:         }
                   20448:     }
1.347     raeburn  20449:     my @options = ('hdr','pad','rem');
1.346     raeburn  20450:     my @fields = &scantroncsv_fields();
                   20451:     my %titles = &scantronconfig_titles();
1.347     raeburn  20452:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346     raeburn  20453:     my ($newdat,$currdat,%newcol,%currcol);
                   20454:     if (grep(/^dat$/,@formats)) {
                   20455:         $confhash{'scantron'}{config}{dat} = 1;
                   20456:         $newdat = 1;
                   20457:     } else {
                   20458:         $newdat = 0;
                   20459:     }
                   20460:     if (grep(/^csv$/,@formats)) {
                   20461:         my %bynum;
                   20462:         foreach my $field (@fields) {
                   20463:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   20464:                 my $posscol = $1;
                   20465:                 if (($posscol < 20) && (!$bynum{$posscol})) {
1.347     raeburn  20466:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346     raeburn  20467:                     $bynum{$posscol} = $field;
                   20468:                     $newcol{$field} = $posscol;
                   20469:                 }
                   20470:             }
                   20471:         }
1.347     raeburn  20472:         if (keys(%newcol)) {
                   20473:             foreach my $option (@options) {
                   20474:                 if ($env{'form.scantroncsv_'.$option}) {
                   20475:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   20476:                 }
                   20477:             }
                   20478:         }
1.346     raeburn  20479:     }
                   20480:     $currdat = 1;
                   20481:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   20482:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347     raeburn  20483:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346     raeburn  20484:                 $currdat = 0;
                   20485:             }
                   20486:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  20487:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   20488:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   20489:                 }
1.346     raeburn  20490:             }
                   20491:         }
                   20492:     }
                   20493:     if ($currdat != $newdat) {
                   20494:         $changes{'config'} = 1;
                   20495:     } else {
                   20496:         foreach my $field (@fields) {
                   20497:             if ($currcol{$field} ne '') {
                   20498:                 if ($currcol{$field} ne $newcol{$field}) {
                   20499:                     $changes{'config'} = 1;
                   20500:                     last;
1.347     raeburn  20501:                 }
1.346     raeburn  20502:             } elsif ($newcol{$field} ne '') {
                   20503:                 $changes{'config'} = 1;
                   20504:                 last;
                   20505:             }
                   20506:         }
                   20507:     }
1.46      raeburn  20508:     if (keys(%confhash) > 0) {
                   20509:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   20510:                                                  $dom);
                   20511:         if ($putresult eq 'ok') {
                   20512:             if (keys(%changes) > 0) {
1.48      raeburn  20513:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   20514:                     $resulttext = &mt('Changes made:').'<ul>';
1.346     raeburn  20515:                     if ($changes{'scantronformat'}) {
                   20516:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   20517:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   20518:                         } else {
                   20519:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   20520:                         }
                   20521:                     }
1.347     raeburn  20522:                     if ($changes{'config'}) {
1.346     raeburn  20523:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   20524:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   20525:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   20526:                             }
                   20527:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  20528:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   20529:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   20530:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   20531:                                         foreach my $field (@fields) {
                   20532:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   20533:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   20534:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   20535:                                             }
                   20536:                                         }
                   20537:                                         $resulttext .= '</ul></li>';
                   20538:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   20539:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   20540:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   20541:                                                 foreach my $option (@options) {
                   20542:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   20543:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   20544:                                                     }
                   20545:                                                 }
                   20546:                                                 $resulttext .= '</ul></li>';
                   20547:                                             }
1.346     raeburn  20548:                                         }
                   20549:                                     }
                   20550:                                 }
                   20551:                             }
                   20552:                         } else {
                   20553:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   20554:                         }
1.46      raeburn  20555:                     }
1.48      raeburn  20556:                     $resulttext .= '</ul>';
                   20557:                 } else {
1.130     raeburn  20558:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  20559:                 }
                   20560:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  20561:                 if (ref($lastactref) eq 'HASH') {
                   20562:                     $lastactref->{'domainconfig'} = 1;
                   20563:                 }
1.46      raeburn  20564:             } else {
1.346     raeburn  20565:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  20566:             }
                   20567:         } else {
                   20568:             $resulttext = '<span class="LC_error">'.
                   20569:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   20570:         }
                   20571:     } else {
1.130     raeburn  20572:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  20573:     }
                   20574:     if ($errors) {
1.353     raeburn  20575:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   20576:                        $errors.'</ul></p>';
1.46      raeburn  20577:     }
                   20578:     return $resulttext;
                   20579: }
                   20580: 
1.48      raeburn  20581: sub modify_coursecategories {
1.239     raeburn  20582:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  20583:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   20584:         $cathash);
1.48      raeburn  20585:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  20586:     my @catitems = ('unauth','auth');
                   20587:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  20588:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  20589:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   20590:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   20591:             $changes{'togglecats'} = 1;
                   20592:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   20593:         }
                   20594:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   20595:             $changes{'categorize'} = 1;
                   20596:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   20597:         }
1.120     raeburn  20598:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   20599:             $changes{'togglecatscomm'} = 1;
                   20600:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   20601:         }
                   20602:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   20603:             $changes{'categorizecomm'} = 1;
                   20604:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  20605: 
                   20606:         }
                   20607:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   20608:             $changes{'togglecatsplace'} = 1;
                   20609:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   20610:         }
                   20611:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   20612:             $changes{'categorizeplace'} = 1;
                   20613:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  20614:         }
1.238     raeburn  20615:         foreach my $item (@catitems) {
                   20616:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   20617:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   20618:                     $changes{$item} = 1;
                   20619:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   20620:                 }
                   20621:             }
                   20622:         }
1.57      raeburn  20623:     } else {
                   20624:         $changes{'togglecats'} = 1;
                   20625:         $changes{'categorize'} = 1;
1.124     raeburn  20626:         $changes{'togglecatscomm'} = 1;
                   20627:         $changes{'categorizecomm'} = 1;
1.272     raeburn  20628:         $changes{'togglecatsplace'} = 1;
                   20629:         $changes{'categorizeplace'} = 1;
1.87      raeburn  20630:         $domconfig{'coursecategories'} = {
                   20631:                                              togglecats => $env{'form.togglecats'},
                   20632:                                              categorize => $env{'form.categorize'},
1.124     raeburn  20633:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   20634:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  20635:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   20636:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  20637:                                          };
1.238     raeburn  20638:         foreach my $item (@catitems) {
                   20639:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   20640:                 $changes{$item} = 1;
                   20641:             }
                   20642:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   20643:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   20644:             }
                   20645:         }
1.57      raeburn  20646:     }
                   20647:     if (ref($cathash) eq 'HASH') {
                   20648:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  20649:             push (@deletecategory,'instcode::0');
                   20650:         }
1.120     raeburn  20651:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   20652:             push(@deletecategory,'communities::0');
                   20653:         }
1.272     raeburn  20654:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   20655:             push(@deletecategory,'placement::0');
                   20656:         }
1.48      raeburn  20657:     }
1.57      raeburn  20658:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   20659:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  20660:         if (@deletecategory > 0) {
                   20661:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  20662:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  20663:             foreach my $item (@deletecategory) {
1.57      raeburn  20664:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   20665:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  20666:                     $deletions{$item} = 1;
1.57      raeburn  20667:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  20668:                 }
                   20669:             }
                   20670:         }
1.57      raeburn  20671:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  20672:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  20673:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  20674:                 $reorderings{$item} = 1;
1.57      raeburn  20675:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  20676:             }
                   20677:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   20678:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   20679:                 my $newdepth = $depth+1;
                   20680:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  20681:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  20682:                 $adds{$newitem} = 1; 
                   20683:             }
                   20684:             if ($env{'form.subcat_'.$item} ne '') {
                   20685:                 my $newcat = $env{'form.subcat_'.$item};
                   20686:                 my $newdepth = $depth+1;
                   20687:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  20688:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  20689:                 $adds{$newitem} = 1;
                   20690:             }
                   20691:         }
                   20692:     }
                   20693:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  20694:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  20695:             my $newitem = 'instcode::0';
1.57      raeburn  20696:             if ($cathash->{$newitem} eq '') {  
                   20697:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  20698:                 $adds{$newitem} = 1;
                   20699:             }
                   20700:         } else {
                   20701:             my $newitem = 'instcode::0';
1.57      raeburn  20702:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  20703:             $adds{$newitem} = 1;
                   20704:         }
                   20705:     }
1.120     raeburn  20706:     if ($env{'form.communities'} eq '1') {
                   20707:         if (ref($cathash) eq 'HASH') {
                   20708:             my $newitem = 'communities::0';
                   20709:             if ($cathash->{$newitem} eq '') {
                   20710:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   20711:                 $adds{$newitem} = 1;
                   20712:             }
                   20713:         } else {
                   20714:             my $newitem = 'communities::0';
                   20715:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   20716:             $adds{$newitem} = 1;
                   20717:         }
                   20718:     }
1.272     raeburn  20719:     if ($env{'form.placement'} eq '1') {
                   20720:         if (ref($cathash) eq 'HASH') {
                   20721:             my $newitem = 'placement::0';
                   20722:             if ($cathash->{$newitem} eq '') {
                   20723:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   20724:                 $adds{$newitem} = 1;
                   20725:             }
                   20726:         } else {
                   20727:             my $newitem = 'placement::0';
                   20728:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   20729:             $adds{$newitem} = 1;
                   20730:         }
                   20731:     }
1.48      raeburn  20732:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  20733:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  20734:             ($env{'form.addcategory_name'} ne 'communities') &&
                   20735:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  20736:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   20737:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   20738:             $adds{$newitem} = 1;
                   20739:         }
1.48      raeburn  20740:     }
1.57      raeburn  20741:     my $putresult;
1.48      raeburn  20742:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   20743:         if (keys(%deletions) > 0) {
                   20744:             foreach my $key (keys(%deletions)) {
                   20745:                 if ($predelallitems{$key} ne '') {
                   20746:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   20747:                 }
                   20748:             }
                   20749:         }
                   20750:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  20751:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  20752:         if (ref($chkcats[0]) eq 'ARRAY') {
                   20753:             my $depth = 0;
                   20754:             my $chg = 0;
                   20755:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   20756:                 my $name = $chkcats[0][$i];
                   20757:                 my $item;
                   20758:                 if ($name eq '') {
                   20759:                     $chg ++;
                   20760:                 } else {
                   20761:                     $item = &escape($name).'::0';
                   20762:                     if ($chg) {
1.57      raeburn  20763:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  20764:                     }
                   20765:                     $depth ++; 
1.57      raeburn  20766:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  20767:                     $depth --;
                   20768:                 }
                   20769:             }
                   20770:         }
1.57      raeburn  20771:     }
                   20772:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   20773:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  20774:         if ($putresult eq 'ok') {
1.57      raeburn  20775:             my %title = (
1.120     raeburn  20776:                          togglecats     => 'Show/Hide a course in catalog',
                   20777:                          categorize     => 'Assign a category to a course',
                   20778:                          togglecatscomm => 'Show/Hide a community in catalog',
                   20779:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  20780:                         );
                   20781:             my %level = (
1.120     raeburn  20782:                          dom  => 'set in Domain ("Modify Course/Community")',
                   20783:                          crs  => 'set in Course ("Course Configuration")',
                   20784:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  20785:                          none     => 'No catalog',
                   20786:                          std      => 'Standard catalog',
                   20787:                          domonly  => 'Domain-only catalog',
                   20788:                          codesrch => 'Code search form',
1.57      raeburn  20789:                         );
1.48      raeburn  20790:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  20791:             if ($changes{'togglecats'}) {
                   20792:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   20793:             }
                   20794:             if ($changes{'categorize'}) {
                   20795:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  20796:             }
1.120     raeburn  20797:             if ($changes{'togglecatscomm'}) {
                   20798:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   20799:             }
                   20800:             if ($changes{'categorizecomm'}) {
                   20801:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   20802:             }
1.238     raeburn  20803:             if ($changes{'unauth'}) {
                   20804:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   20805:             }
                   20806:             if ($changes{'auth'}) {
                   20807:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   20808:             }
1.57      raeburn  20809:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   20810:                 my $cathash;
                   20811:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   20812:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   20813:                 } else {
                   20814:                     $cathash = {};
                   20815:                 } 
                   20816:                 my (@cats,@trails,%allitems);
                   20817:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   20818:                 if (keys(%deletions) > 0) {
                   20819:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   20820:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   20821:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   20822:                     }
                   20823:                     $resulttext .= '</ul></li>';
                   20824:                 }
                   20825:                 if (keys(%reorderings) > 0) {
                   20826:                     my %sort_by_trail;
                   20827:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   20828:                     foreach my $key (keys(%reorderings)) {
                   20829:                         if ($allitems{$key} ne '') {
                   20830:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   20831:                         }
1.48      raeburn  20832:                     }
1.57      raeburn  20833:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   20834:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   20835:                     }
                   20836:                     $resulttext .= '</ul></li>';
1.48      raeburn  20837:                 }
1.57      raeburn  20838:                 if (keys(%adds) > 0) {
                   20839:                     my %sort_by_trail;
                   20840:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   20841:                     foreach my $key (keys(%adds)) {
                   20842:                         if ($allitems{$key} ne '') {
                   20843:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   20844:                         }
                   20845:                     }
                   20846:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   20847:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  20848:                     }
1.57      raeburn  20849:                     $resulttext .= '</ul></li>';
1.48      raeburn  20850:                 }
1.364     raeburn  20851:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   20852:                 if (ref($lastactref) eq 'HASH') {
                   20853:                     $lastactref->{'cats'} = 1;
                   20854:                 }
1.48      raeburn  20855:             }
                   20856:             $resulttext .= '</ul>';
1.239     raeburn  20857:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  20858:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   20859:                 if ($changes{'auth'}) {
                   20860:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   20861:                 }
                   20862:                 if ($changes{'unauth'}) {
                   20863:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   20864:                 }
                   20865:                 my $cachetime = 24*60*60;
                   20866:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  20867:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  20868:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  20869:                 }
                   20870:             }
1.48      raeburn  20871:         } else {
                   20872:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  20873:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  20874:         }
                   20875:     } else {
1.120     raeburn  20876:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  20877:     }
                   20878:     return $resulttext;
                   20879: }
                   20880: 
1.69      raeburn  20881: sub modify_serverstatuses {
                   20882:     my ($dom,%domconfig) = @_;
                   20883:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   20884:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   20885:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   20886:     }
                   20887:     my @pages = &serverstatus_pages();
                   20888:     foreach my $type (@pages) {
                   20889:         $newserverstatus{$type}{'namedusers'} = '';
                   20890:         $newserverstatus{$type}{'machines'} = '';
                   20891:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   20892:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   20893:             my @okusers;
                   20894:             foreach my $user (@users) {
                   20895:                 my ($uname,$udom) = split(/:/,$user);
                   20896:                 if (($udom =~ /^$match_domain$/) &&   
                   20897:                     (&Apache::lonnet::domain($udom)) &&
                   20898:                     ($uname =~ /^$match_username$/)) {
                   20899:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   20900:                         push(@okusers,$user);
                   20901:                     }
                   20902:                 }
                   20903:             }
                   20904:             if (@okusers > 0) {
                   20905:                  @okusers = sort(@okusers);
                   20906:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   20907:             }
                   20908:         }
                   20909:         if (defined($env{'form.'.$type.'_machines'})) {
                   20910:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   20911:             my @okmachines;
                   20912:             foreach my $ip (@machines) {
                   20913:                 my @parts = split(/\./,$ip);
                   20914:                 next if (@parts < 4);
                   20915:                 my $badip = 0;
                   20916:                 for (my $i=0; $i<4; $i++) {
                   20917:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   20918:                         $badip = 1;
                   20919:                         last;
                   20920:                     }
                   20921:                 }
                   20922:                 if (!$badip) {
                   20923:                     push(@okmachines,$ip);     
                   20924:                 }
                   20925:             }
                   20926:             @okmachines = sort(@okmachines);
                   20927:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   20928:         }
                   20929:     }
                   20930:     my %serverstatushash =  (
                   20931:                                 serverstatuses => \%newserverstatus,
                   20932:                             );
                   20933:     foreach my $type (@pages) {
1.83      raeburn  20934:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  20935:             my (@current,@new);
1.83      raeburn  20936:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  20937:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   20938:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   20939:                 }
                   20940:             }
                   20941:             if ($newserverstatus{$type}{$setting} ne '') {
                   20942:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  20943:             }
                   20944:             if (@current > 0) {
                   20945:                 if (@new > 0) {
                   20946:                     foreach my $item (@current) {
                   20947:                         if (!grep(/^\Q$item\E$/,@new)) {
                   20948:                             $changes{$type}{$setting} = 1;
1.82      raeburn  20949:                             last;
                   20950:                         }
                   20951:                     }
1.84      raeburn  20952:                     foreach my $item (@new) {
                   20953:                         if (!grep(/^\Q$item\E$/,@current)) {
                   20954:                             $changes{$type}{$setting} = 1;
                   20955:                             last;
1.82      raeburn  20956:                         }
                   20957:                     }
                   20958:                 } else {
1.83      raeburn  20959:                     $changes{$type}{$setting} = 1;
1.69      raeburn  20960:                 }
1.83      raeburn  20961:             } elsif (@new > 0) {
                   20962:                 $changes{$type}{$setting} = 1;
1.69      raeburn  20963:             }
                   20964:         }
                   20965:     }
                   20966:     if (keys(%changes) > 0) {
1.81      raeburn  20967:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  20968:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   20969:                                                  \%serverstatushash,$dom);
                   20970:         if ($putresult eq 'ok') {
                   20971:             $resulttext .= &mt('Changes made:').'<ul>';
                   20972:             foreach my $type (@pages) {
1.84      raeburn  20973:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  20974:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  20975:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  20976:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   20977:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   20978:                         } else {
                   20979:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   20980:                         }
1.84      raeburn  20981:                     }
                   20982:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  20983:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   20984:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   20985:                         } else {
                   20986:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   20987:                         }
                   20988: 
                   20989:                     }
                   20990:                     $resulttext .= '</ul></li>';
                   20991:                 }
                   20992:             }
                   20993:             $resulttext .= '</ul>';
                   20994:         } else {
                   20995:             $resulttext = '<span class="LC_error">'.
                   20996:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   20997: 
                   20998:         }
                   20999:     } else {
                   21000:         $resulttext = &mt('No changes made to access to server status pages');
                   21001:     }
                   21002:     return $resulttext;
                   21003: }
                   21004: 
1.118     jms      21005: sub modify_helpsettings {
1.285     raeburn  21006:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  21007:     my ($resulttext,$errors,%changes,%helphash);
                   21008:     my %defaultchecked = ('submitbugs' => 'on');
                   21009:     my @offon = ('off','on');
1.118     jms      21010:     my @toggles = ('submitbugs');
1.285     raeburn  21011:     my %current = ('submitbugs' => '',
                   21012:                    'adhoc'      => {},
                   21013:                   );
1.118     jms      21014:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  21015:         %current = %{$domconfig{'helpsettings'}};
                   21016:     }
1.285     raeburn  21017:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  21018:     foreach my $item (@toggles) {
                   21019:         if ($defaultchecked{$item} eq 'on') { 
                   21020:             if ($current{$item} eq '') {
                   21021:                 if ($env{'form.'.$item} eq '0') {
                   21022:                     $changes{$item} = 1;
                   21023:                 }
                   21024:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   21025:                 $changes{$item} = 1;
                   21026:             }
                   21027:         } elsif ($defaultchecked{$item} eq 'off') {
                   21028:             if ($current{$item} eq '') {
                   21029:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  21030:                     $changes{$item} = 1;
                   21031:                 }
1.282     raeburn  21032:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   21033:                 $changes{$item} = 1;
                   21034:             }
                   21035:         }
                   21036:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   21037:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   21038:         }
                   21039:     }
1.285     raeburn  21040:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  21041:     my $confname = $dom.'-domainconfig';
                   21042:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  21043:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   21044:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  21045:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  21046:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  21047:     my %lt = &Apache::lonlocal::texthash(
                   21048:                     s      => 'system',
                   21049:                     d      => 'domain',
                   21050:                     order  => 'Display order',
                   21051:                     access => 'Role usage',
1.291     raeburn  21052:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  21053:                     dh     => 'All with domain helpdesk role',
                   21054:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  21055:                     none   => 'None',
                   21056:                     status => 'Determined based on institutional status',
                   21057:                     inc    => 'Include all, but exclude specific personnel',
                   21058:                     exc    => 'Exclude all, but include specific personnel',
                   21059:     );
                   21060:     for (my $num=0; $num<=$maxnum; $num++) {
                   21061:         my ($prefix,$identifier,$rolename,%curr);
                   21062:         if ($num == $maxnum) {
                   21063:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   21064:             $identifier = 'custhelp'.$num;
                   21065:             $prefix = 'helproles_'.$num;
                   21066:             $rolename = $env{'form.custhelpname'.$num};
                   21067:             $rolename=~s/[^A-Za-z0-9]//gs;
                   21068:             next if ($rolename eq '');
                   21069:             next if (exists($existing{'rolesdef_'.$rolename}));
                   21070:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   21071:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   21072:                                                      $newprivs{'c'},$confname,$dom);
                   21073:             if ($result ne 'ok') {
                   21074:                 $errors .= '<li><span class="LC_error">'.
                   21075:                            &mt('An error occurred storing the new custom role: [_1]',
                   21076:                            $result).'</span></li>';
                   21077:                 next;
                   21078:             } else {
                   21079:                 $changedprivs{$rolename} = \%newprivs;
                   21080:                 $newrole = $rolename;
                   21081:             }
                   21082:         } else {
                   21083:             $prefix = 'helproles_'.$num;
                   21084:             $rolename = $env{'form.'.$prefix};
                   21085:             next if ($rolename eq '');
                   21086:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   21087:             $identifier = 'custhelp'.$num;
                   21088:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   21089:             my %currprivs;
1.289     raeburn  21090:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  21091:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   21092:             foreach my $level ('c','d','s') {
                   21093:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   21094:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   21095:                                                              $newprivs{'c'},$confname,$dom);
                   21096:                     if ($result ne 'ok') {
                   21097:                         $errors .= '<li><span class="LC_error">'.
                   21098:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   21099:                                        $rolename,$result).'</span></li>';
                   21100:                     } else {
                   21101:                         $changedprivs{$rolename} = \%newprivs;
                   21102:                     }
                   21103:                     last;
                   21104:                 }
                   21105:             }
                   21106:             if (ref($current{'adhoc'}) eq 'HASH') {
                   21107:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   21108:                     %curr = %{$current{'adhoc'}{$rolename}};
                   21109:                 }
                   21110:             }
                   21111:         }
                   21112:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   21113:         $newpos =~ s/\D+//g;
                   21114:         $allpos[$newpos] = $rolename;
                   21115:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   21116:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   21117:         if ($curr{'desc'}) {
                   21118:             if ($curr{'desc'} ne $newdesc) {
                   21119:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   21120:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   21121:             }
                   21122:         } elsif ($newdesc ne '') {
                   21123:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   21124:             $newsettings{$rolename}{'desc'} = $newdesc;
                   21125:         }
                   21126:         my $access = $env{'form.'.$prefix.'_access'};
                   21127:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   21128:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   21129:             if ($access eq 'status') {
                   21130:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   21131:                 if (scalar(@statuses) == 0) {
1.289     raeburn  21132:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  21133:                 } else {
                   21134:                     my (@shownstatus,$numtypes);
                   21135:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   21136:                     if (ref($types) eq 'ARRAY') {
                   21137:                         $numtypes = scalar(@{$types});
                   21138:                         foreach my $type (sort(@statuses)) {
                   21139:                             if ($type eq 'default') {
                   21140:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   21141:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   21142:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   21143:                                 push(@shownstatus,$usertypes->{$type});
                   21144:                             }
                   21145:                         }
                   21146:                     }
                   21147:                     if (grep(/^default$/,@statuses)) {
                   21148:                         push(@shownstatus,$othertitle);
                   21149:                     }
                   21150:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   21151:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   21152:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   21153:                     } else {
                   21154:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   21155:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   21156:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   21157:                             if (@diffs) {
                   21158:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   21159:                             }
                   21160:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   21161:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  21162:                         }
1.166     raeburn  21163:                     }
                   21164:                 }
1.285     raeburn  21165:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   21166:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   21167:                 my @newspecstaff;
                   21168:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   21169:                 foreach my $person (sort(@personnel)) {
                   21170:                     if ($domhelpdesk{$person}) {
                   21171:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   21172:                     }
                   21173:                 }
                   21174:                 if (ref($curr{$access}) eq 'ARRAY') {
                   21175:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   21176:                     if (@diffs) {
                   21177:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   21178:                     }
                   21179:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   21180:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   21181:                 }
                   21182:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   21183:                     my ($uname,$udom) = split(/:/,$person);
                   21184:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   21185:                 }
                   21186:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  21187:             }
1.285     raeburn  21188:         } else {
                   21189:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   21190:         }
                   21191:         unless ($curr{'access'} eq $access) {
                   21192:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   21193:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  21194:         }
                   21195:     }
1.285     raeburn  21196:     if (@allpos > 0) {
                   21197:         my $idx = 0;
                   21198:         foreach my $rolename (@allpos) {
                   21199:             if ($rolename ne '') {
                   21200:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   21201:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   21202:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   21203:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   21204:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  21205:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  21206:                         }
                   21207:                     }
1.282     raeburn  21208:                 }
1.285     raeburn  21209:                 $idx ++;
1.166     raeburn  21210:             }
                   21211:         }
1.118     jms      21212:     }
1.123     jms      21213:     my $putresult;
                   21214:     if (keys(%changes) > 0) {
1.166     raeburn  21215:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  21216:         if ($putresult eq 'ok') {
1.285     raeburn  21217:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   21218:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   21219:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   21220:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   21221:                 }
                   21222:             }
                   21223:             my $cachetime = 24*60*60;
                   21224:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21225:             if (ref($lastactref) eq 'HASH') {
                   21226:                 $lastactref->{'domdefaults'} = 1;
                   21227:             }
                   21228:         } else {
                   21229:             $errors .= '<li><span class="LC_error">'.
                   21230:                        &mt('An error occurred storing the settings: [_1]',
                   21231:                            $putresult).'</span></li>';
                   21232:         }
                   21233:     }
                   21234:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   21235:         $resulttext = &mt('Changes made:').'<ul>';
                   21236:         my (%shownprivs,@levelorder);
                   21237:         @levelorder = ('c','d','s');
                   21238:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  21239:             foreach my $item (sort(keys(%changes))) {
                   21240:                 if ($item eq 'submitbugs') {
                   21241:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   21242:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   21243:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  21244:                 } elsif ($item eq 'customrole') {
                   21245:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  21246:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   21247:                         my %keytext = &Apache::lonlocal::texthash(
                   21248:                                                                    order  => 'Order',
                   21249:                                                                    desc   => 'Role description',
                   21250:                                                                    access => 'Role usage',
1.300     droeschl 21251:                                                                    status => 'Allowed institutional types',
1.285     raeburn  21252:                                                                    exc    => 'Allowed personnel',
                   21253:                                                                    inc    => 'Disallowed personnel',
                   21254:                         );
1.282     raeburn  21255:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  21256:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   21257:                                 if ($role eq $newrole) {
                   21258:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   21259:                                                               $role).'<ul>';
                   21260:                                 } else {
                   21261:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   21262:                                                               $role).'<ul>';
                   21263:                                 }
                   21264:                                 foreach my $key (@keyorder) {
                   21265:                                     if ($changes{'customrole'}{$role}{$key}) {
                   21266:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   21267:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   21268:                                                        '</li>';
                   21269:                                     }
                   21270:                                 }
                   21271:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   21272:                                     $shownprivs{$role} = 1;
                   21273:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   21274:                                     foreach my $level (@levelorder) {
                   21275:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   21276:                                             next if ($item eq '');
                   21277:                                             my ($priv) = split(/\&/,$item,2);
                   21278:                                             if (&Apache::lonnet::plaintext($priv)) {
                   21279:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   21280:                                                 unless ($level eq 'c') {
                   21281:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   21282:                                                 }
                   21283:                                                 $resulttext .= '</li>';
                   21284:                                             }
                   21285:                                         }
                   21286:                                     }
                   21287:                                     $resulttext .= '</ul>';
                   21288:                                 }
                   21289:                                 $resulttext .= '</ul></li>';
                   21290:                             }
                   21291:                         }
                   21292:                     }
                   21293:                 }
                   21294:             }
                   21295:         }
                   21296:         if (keys(%changedprivs)) {
                   21297:             foreach my $role (sort(keys(%changedprivs))) {
                   21298:                 unless ($shownprivs{$role}) {
                   21299:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   21300:                                               $role).'<ul>'.
                   21301:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   21302:                     foreach my $level (@levelorder) {
                   21303:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   21304:                             next if ($item eq '');
                   21305:                             my ($priv) = split(/\&/,$item,2);
                   21306:                             if (&Apache::lonnet::plaintext($priv)) {
                   21307:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   21308:                                 unless ($level eq 'c') {
                   21309:                                     $resulttext .= ' ('.$lt{$level}.')';
                   21310:                                 }
                   21311:                                 $resulttext .= '</li>';
                   21312:                             }
1.282     raeburn  21313:                         }
                   21314:                     }
1.285     raeburn  21315:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  21316:                 }
                   21317:             }
                   21318:         }
1.285     raeburn  21319:         $resulttext .= '</ul>';
                   21320:     } else {
                   21321:         $resulttext = &mt('No changes made to help settings');
1.118     jms      21322:     }
                   21323:     if ($errors) {
1.168     raeburn  21324:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  21325:                                     $errors.'</ul>';
1.118     jms      21326:     }
                   21327:     return $resulttext;
                   21328: }
                   21329: 
1.121     raeburn  21330: sub modify_coursedefaults {
1.212     raeburn  21331:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  21332:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  21333:     my %defaultchecked = (
                   21334:                            'canuse_pdfforms' => 'off',
                   21335:                            'uselcmath'       => 'on',
1.398     raeburn  21336:                            'usejsme'         => 'on',
                   21337:                            'inline_chem'     => 'on',
1.404     raeburn  21338:                            'ltiauth'         => 'off',
1.257     raeburn  21339:                          );
1.404     raeburn  21340:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198     raeburn  21341:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  21342:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   21343:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   21344:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  21345:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  21346:     my %staticdefaults = (
                   21347:                            anonsurvey_threshold => 10,
                   21348:                            uploadquota          => 500,
1.257     raeburn  21349:                            postsubmit           => 60,
1.276     raeburn  21350:                            mysqltables          => 172800,
1.198     raeburn  21351:                          );
1.314     raeburn  21352:     my %texoptions = (
                   21353:                         MathJax  => 'MathJax',
                   21354:                         mimetex  => &mt('Convert to Images'),
                   21355:                         tth      => &mt('TeX to HTML'),
                   21356:                      );
1.121     raeburn  21357:     $defaultshash{'coursedefaults'} = {};
                   21358: 
                   21359:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   21360:         if ($domconfig{'coursedefaults'} eq '') {
                   21361:             $domconfig{'coursedefaults'} = {};
                   21362:         }
                   21363:     }
                   21364: 
                   21365:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   21366:         foreach my $item (@toggles) {
                   21367:             if ($defaultchecked{$item} eq 'on') {
                   21368:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   21369:                     ($env{'form.'.$item} eq '0')) {
                   21370:                     $changes{$item} = 1;
1.192     raeburn  21371:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  21372:                     $changes{$item} = 1;
                   21373:                 }
                   21374:             } elsif ($defaultchecked{$item} eq 'off') {
                   21375:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   21376:                     ($env{'form.'.$item} eq '1')) {
                   21377:                     $changes{$item} = 1;
                   21378:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   21379:                     $changes{$item} = 1;
                   21380:                 }
                   21381:             }
                   21382:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   21383:         }
1.198     raeburn  21384:         foreach my $item (@numbers) {
                   21385:             my ($currdef,$newdef);
1.208     raeburn  21386:             $newdef = $env{'form.'.$item};
1.198     raeburn  21387:             if ($item eq 'anonsurvey_threshold') {
                   21388:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   21389:                 $newdef =~ s/\D//g;
                   21390:                 if ($newdef eq '' || $newdef < 1) {
                   21391:                     $newdef = 1;
                   21392:                 }
                   21393:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   21394:             } else {
1.276     raeburn  21395:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   21396:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   21397:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  21398:                 }
                   21399:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  21400:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  21401:             }
                   21402:             if ($currdef ne $newdef) {
                   21403:                 if ($item eq 'anonsurvey_threshold') {
                   21404:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   21405:                         $changes{$item} = 1;
                   21406:                     }
1.276     raeburn  21407:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289     raeburn  21408:                     my $setting = $1;
1.276     raeburn  21409:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   21410:                         $changes{$setting} = 1;
1.198     raeburn  21411:                     }
                   21412:                 }
1.139     raeburn  21413:             }
                   21414:         }
1.314     raeburn  21415:         my $texengine;
                   21416:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   21417:             $texengine = $env{'form.texengine'};
1.349     raeburn  21418:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   21419:             if ($currdef eq '') {
                   21420:                 unless ($texengine eq $Apache::lonnet::deftex) {
1.314     raeburn  21421:                     $changes{'texengine'} = 1;
                   21422:                 }
1.349     raeburn  21423:             } elsif ($currdef ne $texengine) {
1.314     raeburn  21424:                 $changes{'texengine'} = 1;
                   21425:             }
                   21426:         }
                   21427:         if ($texengine ne '') {
                   21428:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   21429:         }
1.264     raeburn  21430:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   21431:         my @currclonecode;
                   21432:         if (ref($currclone) eq 'HASH') {
                   21433:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   21434:                 @currclonecode = @{$currclone->{'instcode'}};
                   21435:             }
                   21436:         }
                   21437:         my $newclone;
1.289     raeburn  21438:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  21439:             $newclone = $env{'form.canclone'};
                   21440:         }
                   21441:         if ($newclone eq 'instcode') {
                   21442:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   21443:             my (%codedefaults,@code_order,@clonecode);
                   21444:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   21445:                                                     \@code_order);
                   21446:             foreach my $item (@code_order) {
                   21447:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   21448:                     push(@clonecode,$item);
                   21449:                 }
                   21450:             }
                   21451:             if (@clonecode) {
                   21452:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   21453:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   21454:                 if (@diffs) {
                   21455:                     $changes{'canclone'} = 1;
                   21456:                 }
                   21457:             } else {
                   21458:                 $newclone eq '';
                   21459:             }
                   21460:         } elsif ($newclone ne '') {
1.289     raeburn  21461:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   21462:         }
1.264     raeburn  21463:         if ($newclone ne $currclone) {
                   21464:             $changes{'canclone'} = 1;
                   21465:         }
1.257     raeburn  21466:         my %credits;
                   21467:         foreach my $type (@types) {
                   21468:             unless ($type eq 'community') {
                   21469:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   21470:                 $credits{$type} =~ s/[^\d.]+//g;
                   21471:             }
                   21472:         }
                   21473:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   21474:             ($env{'form.coursecredits'} eq '1')) {
                   21475:             $changes{'coursecredits'} = 1;
                   21476:             foreach my $type (keys(%credits)) {
                   21477:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   21478:             }
                   21479:         } else {
1.289     raeburn  21480:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  21481:                 foreach my $type (@types) {
                   21482:                     unless ($type eq 'community') {
1.289     raeburn  21483:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  21484:                             $changes{'coursecredits'} = 1;
                   21485:                         }
                   21486:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   21487:                     }
                   21488:                 }
                   21489:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   21490:                 foreach my $type (@types) {
                   21491:                     unless ($type eq 'community') {
                   21492:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   21493:                             $changes{'coursecredits'} = 1;
                   21494:                             last;
                   21495:                         }
                   21496:                     }
                   21497:                 }
                   21498:             }
                   21499:         }
                   21500:         if ($env{'form.postsubmit'} eq '1') {
                   21501:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   21502:             my %currtimeout;
                   21503:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   21504:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   21505:                     $changes{'postsubmit'} = 1;
                   21506:                 }
                   21507:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   21508:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   21509:                 }
                   21510:             } else {
                   21511:                 $changes{'postsubmit'} = 1;
                   21512:             }
                   21513:             foreach my $type (@types) {
                   21514:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   21515:                 $timeout =~ s/\D//g;
                   21516:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   21517:                     $timeout = '';
                   21518:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   21519:                     $timeout = '0';
                   21520:                 }
                   21521:                 unless ($timeout eq '') {
                   21522:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   21523:                 }
                   21524:                 if (exists($currtimeout{$type})) {
                   21525:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  21526:                         $changes{'postsubmit'} = 1;
1.257     raeburn  21527:                     }
                   21528:                 } elsif ($timeout ne '') {
                   21529:                     $changes{'postsubmit'} = 1;
                   21530:                 }
                   21531:             }
                   21532:         } else {
                   21533:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   21534:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   21535:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   21536:                     $changes{'postsubmit'} = 1;
                   21537:                 }
                   21538:             } else {
                   21539:                 $changes{'postsubmit'} = 1;
                   21540:             }
1.192     raeburn  21541:         }
1.121     raeburn  21542:     }
                   21543:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21544:                                              $dom);
                   21545:     if ($putresult eq 'ok') {
                   21546:         if (keys(%changes) > 0) {
1.213     raeburn  21547:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  21548:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  21549:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398     raeburn  21550:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.404     raeburn  21551:                 ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
                   21552:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.257     raeburn  21553:                     if ($changes{$item}) {
                   21554:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   21555:                     }
1.289     raeburn  21556:                 }
1.192     raeburn  21557:                 if ($changes{'coursecredits'}) {
                   21558:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  21559:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   21560:                             $domdefaults{$type.'credits'} =
                   21561:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   21562:                         }
                   21563:                     }
                   21564:                 }
                   21565:                 if ($changes{'postsubmit'}) {
                   21566:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   21567:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   21568:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   21569:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   21570:                                 $domdefaults{$type.'postsubtimeout'} =
                   21571:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   21572:                             }
                   21573:                         }
1.192     raeburn  21574:                     }
                   21575:                 }
1.198     raeburn  21576:                 if ($changes{'uploadquota'}) {
                   21577:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   21578:                         foreach my $type (@types) {
                   21579:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   21580:                         }
                   21581:                     }
                   21582:                 }
1.264     raeburn  21583:                 if ($changes{'canclone'}) {
                   21584:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   21585:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   21586:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   21587:                             if (@clonecodes) {
                   21588:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   21589:                             }
                   21590:                         }
                   21591:                     } else {
                   21592:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   21593:                     }
                   21594:                 }
1.121     raeburn  21595:                 my $cachetime = 24*60*60;
                   21596:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  21597:                 if (ref($lastactref) eq 'HASH') {
                   21598:                     $lastactref->{'domdefaults'} = 1;
                   21599:                 }
1.121     raeburn  21600:             }
                   21601:             $resulttext = &mt('Changes made:').'<ul>';
                   21602:             foreach my $item (sort(keys(%changes))) {
                   21603:                 if ($item eq 'canuse_pdfforms') {
                   21604:                     if ($env{'form.'.$item} eq '1') {
                   21605:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   21606:                     } else {
                   21607:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   21608:                     }
1.257     raeburn  21609:                 } elsif ($item eq 'uselcmath') {
                   21610:                     if ($env{'form.'.$item} eq '1') {
                   21611:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   21612:                     } else {
                   21613:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   21614:                     }
                   21615:                 } elsif ($item eq 'usejsme') {
                   21616:                     if ($env{'form.'.$item} eq '1') {
                   21617:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   21618:                     } else {
1.289     raeburn  21619:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  21620:                     }
1.398     raeburn  21621:                 } elsif ($item eq 'inline_chem') {
                   21622:                     if ($env{'form.'.$item} eq '1') {
                   21623:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
                   21624:                     } else {
                   21625:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
                   21626:                     }
1.314     raeburn  21627:                 } elsif ($item eq 'texengine') {
                   21628:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   21629:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   21630:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   21631:                     }
1.139     raeburn  21632:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  21633:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  21634:                 } elsif ($item eq 'uploadquota') {
                   21635:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   21636:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   21637:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   21638:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  21639:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  21640:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  21641:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   21642:                                        '</ul>'.
                   21643:                                        '</li>';
                   21644:                     } else {
                   21645:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   21646:                     }
1.276     raeburn  21647:                 } elsif ($item eq 'mysqltables') {
                   21648:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   21649:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   21650:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   21651:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   21652:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   21653:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   21654:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   21655:                                        '</ul>'.
                   21656:                                        '</li>';
                   21657:                     } else {
                   21658:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   21659:                     }
1.257     raeburn  21660:                 } elsif ($item eq 'postsubmit') {
                   21661:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   21662:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   21663:                     } else {
                   21664:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  21665:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  21666:                             $resulttext .= &mt('durations:').'<ul>';
                   21667:                             foreach my $type (@types) {
                   21668:                                 $resulttext .= '<li>';
                   21669:                                 my $timeout;
                   21670:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   21671:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   21672:                                 }
                   21673:                                 my $display;
                   21674:                                 if ($timeout eq '0') {
                   21675:                                     $display = &mt('unlimited');
                   21676:                                 } elsif ($timeout eq '') {
                   21677:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   21678:                                 } else {
                   21679:                                     $display = &mt('[quant,_1,second]',$timeout);
                   21680:                                 }
                   21681:                                 if ($type eq 'community') {
                   21682:                                     $resulttext .= &mt('Communities');
                   21683:                                 } elsif ($type eq 'official') {
                   21684:                                     $resulttext .= &mt('Official courses');
                   21685:                                 } elsif ($type eq 'unofficial') {
                   21686:                                     $resulttext .= &mt('Unofficial courses');
                   21687:                                 } elsif ($type eq 'textbook') {
                   21688:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  21689:                                 } elsif ($type eq 'placement') {
                   21690:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  21691:                                 }
                   21692:                                 $resulttext .= ' -- '.$display.'</li>';
                   21693:                             }
                   21694:                             $resulttext .= '</ul>';
                   21695:                         }
1.289     raeburn  21696:                         $resulttext .= '</li>';
1.257     raeburn  21697:                     }
1.192     raeburn  21698:                 } elsif ($item eq 'coursecredits') {
                   21699:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   21700:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  21701:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   21702:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  21703:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   21704:                         } else {
                   21705:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   21706:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   21707:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  21708:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  21709:                                            '</ul>'.
                   21710:                                            '</li>';
                   21711:                         }
                   21712:                     } else {
                   21713:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   21714:                     }
1.264     raeburn  21715:                 } elsif ($item eq 'canclone') {
                   21716:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   21717:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   21718:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   21719:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   21720:                         }
                   21721:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   21722:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   21723:                     } else {
1.289     raeburn  21724:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  21725:                     }
1.404     raeburn  21726:                 } elsif ($item eq 'ltiauth') {
                   21727:                     if ($env{'form.'.$item} eq '1') {
                   21728:                         $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
                   21729:                     } else {
                   21730:                         $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
                   21731:                     }
1.140     raeburn  21732:                 }
1.121     raeburn  21733:             }
                   21734:             $resulttext .= '</ul>';
                   21735:         } else {
                   21736:             $resulttext = &mt('No changes made to course defaults');
                   21737:         }
                   21738:     } else {
                   21739:         $resulttext = '<span class="LC_error">'.
                   21740:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   21741:     }
                   21742:     return $resulttext;
                   21743: }
                   21744: 
1.231     raeburn  21745: sub modify_selfenrollment {
                   21746:     my ($dom,$lastactref,%domconfig) = @_;
                   21747:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  21748:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  21749:     my %titles = &tool_titles();
1.232     raeburn  21750:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   21751:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  21752:     $ordered{'default'} = ['types','registered','approval','limit'];
                   21753: 
                   21754:     my (%roles,%shown,%toplevel);
                   21755:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   21756: 
                   21757:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   21758:         if ($domconfig{'selfenrollment'} eq '') {
                   21759:             $domconfig{'selfenrollment'} = {};
                   21760:         }
                   21761:     }
                   21762:     %toplevel = (
                   21763:                   admin      => 'Configuration Rights',
                   21764:                   default    => 'Default settings',
                   21765:                   validation => 'Validation of self-enrollment requests',
                   21766:                 );
1.233     raeburn  21767:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  21768: 
                   21769:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   21770:         foreach my $item (@{$ordered{'admin'}}) {
                   21771:             foreach my $type (@types) {
                   21772:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   21773:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   21774:                 } else {
                   21775:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   21776:                 }
                   21777:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   21778:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   21779:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   21780:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   21781:                             push(@{$changes{'admin'}{$type}},$item);
                   21782:                         }
                   21783:                     } else {
                   21784:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   21785:                             push(@{$changes{'admin'}{$type}},$item);
                   21786:                         }
                   21787:                     }
                   21788:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   21789:                     push(@{$changes{'admin'}{$type}},$item);
                   21790:                 }
                   21791:             }
                   21792:         }
                   21793:     }
                   21794: 
                   21795:     foreach my $item (@{$ordered{'default'}}) {
                   21796:         foreach my $type (@types) {
                   21797:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   21798:             if ($item eq 'types') {
                   21799:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   21800:                     $value = '';
                   21801:                 }
                   21802:             } elsif ($item eq 'registered') {
                   21803:                 unless ($value eq '1') {
                   21804:                     $value = 0;
                   21805:                 }
                   21806:             } elsif ($item eq 'approval') {
                   21807:                 unless ($value =~ /^[012]$/) {
                   21808:                     $value = 0;
                   21809:                 }
                   21810:             } else {
                   21811:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   21812:                     $value = 'none';
                   21813:                 }
                   21814:             }
                   21815:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   21816:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   21817:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   21818:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   21819:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   21820:                          push(@{$changes{'default'}{$type}},$item);
                   21821:                     }
                   21822:                 } else {
                   21823:                     push(@{$changes{'default'}{$type}},$item);
                   21824:                 }
                   21825:             } else {
                   21826:                 push(@{$changes{'default'}{$type}},$item);
                   21827:             }
                   21828:             if ($item eq 'limit') {
                   21829:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   21830:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   21831:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   21832:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   21833:                     }
                   21834:                 } else {
                   21835:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   21836:                 }
                   21837:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   21838:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   21839:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   21840:                          push(@{$changes{'default'}{$type}},'cap');
                   21841:                     }
                   21842:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   21843:                     push(@{$changes{'default'}{$type}},'cap');
                   21844:                 }
                   21845:             }
                   21846:         }
                   21847:     }
                   21848: 
                   21849:     foreach my $item (@{$itemsref}) {
                   21850:         if ($item eq 'fields') {
                   21851:             my @changed;
                   21852:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   21853:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   21854:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   21855:             }
                   21856:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   21857:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   21858:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   21859:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   21860:                 } else {
                   21861:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   21862:                 }
                   21863:             } else {
                   21864:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   21865:             }
                   21866:             if (@changed) {
                   21867:                 if ($selfenrollhash{'validation'}{$item}) { 
                   21868:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   21869:                 } else {
                   21870:                     $changes{'validation'}{$item} = &mt('None');
                   21871:                 }
                   21872:             }
                   21873:         } else {
                   21874:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   21875:             if ($item eq 'markup') {
                   21876:                if ($env{'form.selfenroll_validation_'.$item}) {
                   21877:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   21878:                }
                   21879:             }
                   21880:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   21881:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   21882:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   21883:                 }
                   21884:             }
                   21885:         }
                   21886:     }
                   21887: 
                   21888:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   21889:                                              $dom);
                   21890:     if ($putresult eq 'ok') {
                   21891:         if (keys(%changes) > 0) {
                   21892:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   21893:             $resulttext = &mt('Changes made:').'<ul>';
                   21894:             foreach my $key ('admin','default','validation') {
                   21895:                 if (ref($changes{$key}) eq 'HASH') {
                   21896:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   21897:                     if ($key eq 'validation') {
                   21898:                         foreach my $item (@{$itemsref}) {
                   21899:                             if (exists($changes{$key}{$item})) {
                   21900:                                 if ($item eq 'markup') {
                   21901:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   21902:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   21903:                                 } else {  
                   21904:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   21905:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   21906:                                 }
                   21907:                             }
                   21908:                         }
                   21909:                     } else {
                   21910:                         foreach my $type (@types) {
                   21911:                             if ($type eq 'community') {
                   21912:                                 $roles{'1'} = &mt('Community personnel');
                   21913:                             } else {
                   21914:                                 $roles{'1'} = &mt('Course personnel');
                   21915:                             }
                   21916:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  21917:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   21918:                                     if ($key eq 'admin') {
                   21919:                                         my @mgrdc = ();
                   21920:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   21921:                                             foreach my $item (@{$ordered{'admin'}}) {
                   21922:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   21923:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   21924:                                                         push(@mgrdc,$item);
                   21925:                                                     }
                   21926:                                                 }
                   21927:                                             }
                   21928:                                             if (@mgrdc) {
                   21929:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   21930:                                             } else {
                   21931:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   21932:                                             }
                   21933:                                         }
                   21934:                                     } else {
                   21935:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   21936:                                             foreach my $item (@{$ordered{$key}}) {
                   21937:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   21938:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   21939:                                                         $selfenrollhash{$key}{$type}{$item};
                   21940:                                                 }
                   21941:                                             }
                   21942:                                         }
                   21943:                                     }
                   21944:                                 }
1.231     raeburn  21945:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   21946:                                 foreach my $item (@{$ordered{$key}}) {
                   21947:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   21948:                                         $resulttext .= '<li>';
                   21949:                                         if ($key eq 'admin') {
                   21950:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   21951:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   21952:                                         } else {
                   21953:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   21954:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   21955:                                         }
                   21956:                                         $resulttext .= '</li>';
                   21957:                                     }
                   21958:                                 }
                   21959:                                 $resulttext .= '</ul></li>';
                   21960:                             }
                   21961:                         }
                   21962:                         $resulttext .= '</ul></li>'; 
                   21963:                     }
                   21964:                 }
1.305     raeburn  21965:             }
                   21966:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   21967:                 my $cachetime = 24*60*60;
                   21968:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21969:                 if (ref($lastactref) eq 'HASH') {
                   21970:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  21971:                 }
1.231     raeburn  21972:             }
                   21973:             $resulttext .= '</ul>';
                   21974:         } else {
                   21975:             $resulttext = &mt('No changes made to self-enrollment settings');
                   21976:         }
                   21977:     } else {
                   21978:         $resulttext = '<span class="LC_error">'.
                   21979:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   21980:     }
                   21981:     return $resulttext;
                   21982: }
                   21983: 
1.373     raeburn  21984: sub modify_wafproxy {
                   21985:     my ($dom,$action,$lastactref,%domconfig) = @_;
                   21986:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  21987:     my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
                   21988:         %wafproxy,%changes,%expirecache,%expiresaml);
1.373     raeburn  21989:     foreach my $server (sort(keys(%servers))) {
                   21990:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   21991:         if ($serverhome eq $server) {
                   21992:             my $serverdom = &Apache::lonnet::host_domain($server);
                   21993:             if ($serverdom eq $dom) {
                   21994:                 $canset{$server} = 1;
                   21995:             }
                   21996:         }
                   21997:     }
1.381     raeburn  21998:     if (ref($domconfig{'wafproxy'}) eq 'HASH') {
                   21999:         %{$values{$dom}} = ();
                   22000:         if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
                   22001:             %curralias = %{$domconfig{'wafproxy'}{'alias'}};
                   22002:         }
1.388     raeburn  22003:         if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
                   22004:             %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
                   22005:         }
1.382     raeburn  22006:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381     raeburn  22007:             $currvalue{$item} = $domconfig{'wafproxy'}{$item};
                   22008:         }
                   22009:     }
1.373     raeburn  22010:     my $output;
                   22011:     if (keys(%canset)) {
                   22012:         %{$wafproxy{'alias'}} = ();
1.388     raeburn  22013:         %{$wafproxy{'saml'}} = ();
1.373     raeburn  22014:         foreach my $key (sort(keys(%canset))) {
1.381     raeburn  22015:             if ($env{'form.wafproxy_'.$dom}) {
                   22016:                 $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
                   22017:                 $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
                   22018:                 if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
                   22019:                     $changes{'alias'} = 1;
                   22020:                 }
1.388     raeburn  22021:                 if ($env{'form.wafproxy_alias_saml_'.$key}) {
                   22022:                     $wafproxy{'saml'}{$key} = 1;
                   22023:                 }
                   22024:                 if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
                   22025:                     $changes{'saml'} = 1;
                   22026:                 }
1.381     raeburn  22027:             } else {
                   22028:                 $wafproxy{'alias'}{$key} = '';
1.388     raeburn  22029:                 $wafproxy{'saml'}{$key} = '';
1.381     raeburn  22030:                 if ($curralias{$key}) {
                   22031:                     $changes{'alias'} = 1;
                   22032:                 }
1.388     raeburn  22033:                 if ($currsaml{$key}) {
                   22034:                     $changes{'saml'} = 1;
                   22035:                 }
1.373     raeburn  22036:             }
                   22037:             if ($wafproxy{'alias'}{$key} eq '') {
                   22038:                 if ($curralias{$key}) {
                   22039:                     $expirecache{$key} = 1;
                   22040:                 }
                   22041:                 delete($wafproxy{'alias'}{$key});
                   22042:             }
1.388     raeburn  22043:             if ($wafproxy{'saml'}{$key} eq '') {
                   22044:                 if ($currsaml{$key}) {
                   22045:                     $expiresaml{$key} = 1;
                   22046:                 }
                   22047:                 delete($wafproxy{'saml'}{$key});
                   22048:             }
1.373     raeburn  22049:         }
                   22050:         unless (keys(%{$wafproxy{'alias'}})) {
                   22051:             delete($wafproxy{'alias'});
                   22052:         }
1.388     raeburn  22053:         unless (keys(%{$wafproxy{'saml'}})) {
                   22054:             delete($wafproxy{'saml'});
                   22055:         }
                   22056:         # Localization for values in %warn occurs in &mt() calls separately.
1.373     raeburn  22057:         my %warn = (
                   22058:                      trusted => 'trusted IP range(s)',
1.381     raeburn  22059:                      vpnint => 'internal IP range(s) for VPN sessions(s)',
                   22060:                      vpnext => 'IP range(s) for backend WAF connections',
1.373     raeburn  22061:                    );
1.382     raeburn  22062:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  22063:             my $possible = $env{'form.wafproxy_'.$item};
                   22064:             $possible =~ s/^\s+|\s+$//g;
                   22065:             if ($possible ne '') {
1.381     raeburn  22066:                 if ($item eq 'remoteip') {
                   22067:                     if ($possible =~ /^[mhn]$/) {
                   22068:                         $wafproxy{$item} = $possible;
                   22069:                     }
                   22070:                 } elsif ($item eq 'ipheader') {
                   22071:                     if ($wafproxy{'remoteip'} eq 'h') {
                   22072:                         $wafproxy{$item} = $possible;
                   22073:                     }
1.382     raeburn  22074:                 } elsif ($item eq 'sslopt') {
                   22075:                     if ($possible =~ /^0|1$/) {
                   22076:                         $wafproxy{$item} = $possible;
                   22077:                     }
1.373     raeburn  22078:                 } else {
                   22079:                     my (@ok,$count);
1.381     raeburn  22080:                     if (($item eq 'vpnint') || ($item eq 'vpnext')) {
                   22081:                         unless ($env{'form.wafproxy_vpnaccess'}) {
                   22082:                             $possible = '';
                   22083:                         }
                   22084:                     } elsif ($item eq 'trusted') {
                   22085:                         unless ($wafproxy{'remoteip'} eq 'h') {
                   22086:                             $possible = '';
                   22087:                         }
                   22088:                     }
                   22089:                     unless ($possible eq '') {
                   22090:                         $possible =~ s/[\r\n]+/\s/g;
                   22091:                         $possible =~ s/\s*-\s*/-/g;
                   22092:                         $possible =~ s/\s+/,/g;
1.393     raeburn  22093:                         $possible =~ s/,+/,/g;
1.381     raeburn  22094:                     }
1.373     raeburn  22095:                     $count = 0;
1.381     raeburn  22096:                     if ($possible ne '') {
1.373     raeburn  22097:                         foreach my $poss (split(/\,/,$possible)) {
                   22098:                             $count ++;
1.393     raeburn  22099:                             $poss = &validate_ip_pattern($poss);
                   22100:                             if ($poss ne '') {
1.373     raeburn  22101:                                 push(@ok,$poss);
                   22102:                             }
                   22103:                         }
                   22104:                         my $diff = $count - scalar(@ok);
                   22105:                         if ($diff) {
                   22106:                             push(@warnings,'<li>'.
                   22107:                                  &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
                   22108:                                      $diff,$warn{$item}).
                   22109:                                  '</li>');
                   22110:                         }
1.393     raeburn  22111:                         if (@ok) {
                   22112:                             my @cidr_list;
                   22113:                             foreach my $item (@ok) {
                   22114:                                 @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   22115:                             }
                   22116:                             $wafproxy{$item} = join(',',@cidr_list);
                   22117:                         }
1.373     raeburn  22118:                     }
                   22119:                 }
1.381     raeburn  22120:                 if ($wafproxy{$item} ne $currvalue{$item}) {
1.373     raeburn  22121:                     $changes{$item} = 1;
                   22122:                 }
1.381     raeburn  22123:             } elsif ($currvalue{$item}) {
                   22124:                 $changes{$item} = 1;
                   22125:             } 
                   22126:         }
                   22127:     } else {
                   22128:         if (keys(%curralias)) {
                   22129:             $changes{'alias'} = 1;
1.388     raeburn  22130:         }
                   22131:         if (keys(%currsaml)) {
                   22132:             $changes{'saml'} = 1;
1.381     raeburn  22133:         } 
                   22134:         if (keys(%currvalue)) {
                   22135:             foreach my $key (keys(%currvalue)) {
                   22136:                 $changes{$key} = 1;
1.373     raeburn  22137:             }
                   22138:         }
                   22139:     }
                   22140:     if (keys(%changes)) {
                   22141:         my %defaultshash = (
                   22142:                               wafproxy => \%wafproxy,
                   22143:                            ); 
                   22144:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22145:                                                  $dom);
                   22146:         if ($putresult eq 'ok') {
                   22147:             my $cachetime = 24*60*60;
                   22148:             my (%domdefaults,$updatedomdefs);
1.382     raeburn  22149:             foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  22150:                 if ($changes{$item}) {
                   22151:                     unless ($updatedomdefs) {
                   22152:                         %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   22153:                         $updatedomdefs = 1;
                   22154:                     }
                   22155:                     if ($wafproxy{$item}) {
                   22156:                         $domdefaults{'waf_'.$item} = $wafproxy{$item};
                   22157:                     } elsif (exists($domdefaults{'waf_'.$item})) {
                   22158:                         delete($domdefaults{'waf_'.$item});
                   22159:                     } 
                   22160:                 }
                   22161:             }
                   22162:             if ($updatedomdefs) {
                   22163:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   22164:                 if (ref($lastactref) eq 'HASH') {
                   22165:                     $lastactref->{'domdefaults'} = 1;
                   22166:                 }
                   22167:             }
                   22168:             if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
                   22169:                 my %updates = %expirecache;
                   22170:                 foreach my $key (keys(%expirecache)) {
                   22171:                     &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
                   22172:                 }
                   22173:                 if (ref($wafproxy{'alias'}) eq 'HASH') {
                   22174:                     my $cachetime = 24*60*60;
                   22175:                     foreach my $key (keys(%{$wafproxy{'alias'}})) {
                   22176:                         $updates{$key} = 1;
                   22177:                         &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
                   22178:                                                       $cachetime);
                   22179:                     }
                   22180:                 }
                   22181:                 if (ref($lastactref) eq 'HASH') {
                   22182:                     $lastactref->{'proxyalias'} = \%updates;
                   22183:                 }
                   22184:             }
1.388     raeburn  22185:             if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
                   22186:                 my %samlupdates = %expiresaml;
                   22187:                 foreach my $key (keys(%expiresaml)) {
                   22188:                     &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
                   22189:                 }
                   22190:                 if (ref($wafproxy{'saml'}) eq 'HASH') {
                   22191:                     my $cachetime = 24*60*60;
                   22192:                     foreach my $key (keys(%{$wafproxy{'saml'}})) {
                   22193:                         $samlupdates{$key} = 1;
                   22194:                         &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
                   22195:                                                       $cachetime);
                   22196:                     }
                   22197:                 }
                   22198:                 if (ref($lastactref) eq 'HASH') {
                   22199:                     $lastactref->{'proxysaml'} = \%samlupdates;
                   22200:                 }
                   22201:             }
1.373     raeburn  22202:             $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401     raeburn  22203:             foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  22204:                 if ($changes{$item}) {
                   22205:                     if ($item eq 'alias') {
                   22206:                         my $numaliased = 0;
                   22207:                         if (ref($wafproxy{'alias'}) eq 'HASH') {
                   22208:                             my $shown;
                   22209:                             if (keys(%{$wafproxy{'alias'}})) {
                   22210:                                 foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
                   22211:                                     $shown .= '<li>'.&mt('[_1] aliased by [_2]',
                   22212:                                                          &Apache::lonnet::hostname($server),
                   22213:                                                          $wafproxy{'alias'}{$server}).'</li>';
                   22214:                                     $numaliased ++;
                   22215:                                 }
                   22216:                                 if ($numaliased) {
                   22217:                                     $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
                   22218:                                                           '<ul>'.$shown.'</ul>').'</li>';
                   22219:                                 }
                   22220:                             }
                   22221:                         }
                   22222:                         unless ($numaliased) {
                   22223:                             $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
                   22224:                         }
1.388     raeburn  22225:                     } elsif ($item eq 'saml') {
                   22226:                         my $shown; 
                   22227:                         if (ref($wafproxy{'saml'}) eq 'HASH') {
                   22228:                             if (keys(%{$wafproxy{'saml'}})) {
                   22229:                                 $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
                   22230:                             }
                   22231:                         }
                   22232:                         if ($shown) {
1.396     raeburn  22233:                             $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388     raeburn  22234:                                                   $shown).'</li>';
                   22235:                         } else {
1.396     raeburn  22236:                             $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388     raeburn  22237:                         }
1.373     raeburn  22238:                     } else {
1.381     raeburn  22239:                         if ($item eq 'remoteip') {
                   22240:                             my %ip_methods = &remoteip_methods();
                   22241:                             if ($wafproxy{$item} =~ /^[mh]$/) {
                   22242:                                 $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
                   22243:                                                       $ip_methods{$wafproxy{$item}}).'</li>';
                   22244:                             } else {
                   22245:                                 if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
                   22246:                                     $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
                   22247:                                                '</li>';
                   22248:                                 } else {
                   22249:                                     $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
                   22250:                                 }
                   22251:                             }
                   22252:                         } elsif ($item eq 'ipheader') {
1.373     raeburn  22253:                             if ($wafproxy{$item}) {
1.381     raeburn  22254:                                 $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373     raeburn  22255:                                                       $wafproxy{$item}).'</li>';
                   22256:                             } else {
1.381     raeburn  22257:                                 $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373     raeburn  22258:                             }
                   22259:                         } elsif ($item eq 'trusted') {
                   22260:                             if ($wafproxy{$item}) {
1.381     raeburn  22261:                                 $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373     raeburn  22262:                                                       $wafproxy{$item}).'</li>';
                   22263:                             } else {
                   22264:                                 $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
                   22265:                             }
1.381     raeburn  22266:                         } elsif ($item eq 'vpnint') {
                   22267:                             if ($wafproxy{$item}) {
                   22268:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
                   22269:                                                        $wafproxy{$item}).'</li>';
                   22270:                             } else {
                   22271:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
                   22272:                             }
                   22273:                         } elsif ($item eq 'vpnext') {
1.373     raeburn  22274:                             if ($wafproxy{$item}) {
1.381     raeburn  22275:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373     raeburn  22276:                                                        $wafproxy{$item}).'</li>';
                   22277:                             } else {
1.381     raeburn  22278:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373     raeburn  22279:                             }
1.382     raeburn  22280:                         } elsif ($item eq 'sslopt') {
                   22281:                             if ($wafproxy{$item}) {
                   22282:                                 $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>';
                   22283:                             } else {
                   22284:                                 $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>';
                   22285:                             }
1.373     raeburn  22286:                         }
                   22287:                     }
                   22288:                 }
                   22289:             }
1.420   ! raeburn  22290:             $output .= '</ul>';
1.373     raeburn  22291:         } else {
                   22292:             $output = '<span class="LC_error">'.
                   22293:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   22294:         }
                   22295:     } elsif (keys(%canset)) {
                   22296:         $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
                   22297:     }
                   22298:     if (@warnings) {
                   22299:         $output .= '<br />'.&mt('Warnings:').'<ul>'.
                   22300:                        join("\n",@warnings).'</ul>';
                   22301:     }
                   22302:     return $output;
                   22303: }
                   22304: 
                   22305: sub validate_ip_pattern {
                   22306:     my ($pattern) = @_;
                   22307:     if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
                   22308:         my ($start,$end) = ($1,$2);
                   22309:         if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393     raeburn  22310:             if (($start !~ m{/}) && ($end !~ m{/})) {
                   22311:                 return $start.'-'.$end;
                   22312:             }
                   22313:         }
                   22314:     } elsif ($pattern ne '') {
                   22315:         $pattern = &Net::CIDR::cidrvalidate($pattern);
                   22316:         if ($pattern ne '') {
                   22317:             return $pattern;
1.373     raeburn  22318:         }
                   22319:     }
1.393     raeburn  22320:     return;
1.373     raeburn  22321: }
                   22322: 
1.137     raeburn  22323: sub modify_usersessions {
1.212     raeburn  22324:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  22325:     my @hostingtypes = ('version','excludedomain','includedomain');
                   22326:     my @offloadtypes = ('primary','default');
                   22327:     my %types = (
                   22328:                   remote => \@hostingtypes,
                   22329:                   hosted => \@hostingtypes,
                   22330:                   spares => \@offloadtypes,
                   22331:                 );
                   22332:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  22333:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  22334:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   22335:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  22336:     my @locations = sort(keys(%by_location));
1.137     raeburn  22337:     my (%defaultshash,%changes);
                   22338:     foreach my $prefix (@prefixes) {
                   22339:         $defaultshash{'usersessions'}{$prefix} = {};
                   22340:     }
1.212     raeburn  22341:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  22342:     my $resulttext;
1.138     raeburn  22343:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  22344:     foreach my $prefix (@prefixes) {
1.145     raeburn  22345:         next if ($prefix eq 'spares');
                   22346:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  22347:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   22348:             if ($type eq 'version') {
                   22349:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   22350:                 my $okvalue;
                   22351:                 if ($value ne '') {
                   22352:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   22353:                         $okvalue = $value;
                   22354:                     }
                   22355:                 }
                   22356:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   22357:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   22358:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   22359:                             if ($inuse == 0) {
                   22360:                                 $changes{$prefix}{$type} = 1;
                   22361:                             } else {
                   22362:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   22363:                                     $changes{$prefix}{$type} = 1;
                   22364:                                 }
                   22365:                                 if ($okvalue ne '') {
                   22366:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22367:                                 } 
                   22368:                             }
                   22369:                         } else {
                   22370:                             if (($inuse == 1) && ($okvalue ne '')) {
                   22371:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22372:                                 $changes{$prefix}{$type} = 1;
                   22373:                             }
                   22374:                         }
                   22375:                     } else {
                   22376:                         if (($inuse == 1) && ($okvalue ne '')) {
                   22377:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22378:                             $changes{$prefix}{$type} = 1;
                   22379:                         }
                   22380:                     }
                   22381:                 } else {
                   22382:                     if (($inuse == 1) && ($okvalue ne '')) {
                   22383:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   22384:                         $changes{$prefix}{$type} = 1;
                   22385:                     }
                   22386:                 }
                   22387:             } else {
                   22388:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   22389:                 my @okvals;
                   22390:                 foreach my $val (@vals) {
1.138     raeburn  22391:                     if ($val =~ /:/) {
                   22392:                         my @items = split(/:/,$val);
                   22393:                         foreach my $item (@items) {
                   22394:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   22395:                                 push(@okvals,$item);
                   22396:                             }
                   22397:                         }
                   22398:                     } else {
                   22399:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   22400:                             push(@okvals,$val);
                   22401:                         }
1.137     raeburn  22402:                     }
                   22403:                 }
                   22404:                 @okvals = sort(@okvals);
                   22405:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   22406:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   22407:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   22408:                             if ($inuse == 0) {
                   22409:                                 $changes{$prefix}{$type} = 1; 
                   22410:                             } else {
                   22411:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22412:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   22413:                                 if (@changed > 0) {
                   22414:                                     $changes{$prefix}{$type} = 1;
                   22415:                                 }
                   22416:                             }
                   22417:                         } else {
                   22418:                             if ($inuse == 1) {
                   22419:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22420:                                 $changes{$prefix}{$type} = 1;
                   22421:                             }
                   22422:                         } 
                   22423:                     } else {
                   22424:                         if ($inuse == 1) {
                   22425:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22426:                             $changes{$prefix}{$type} = 1;
                   22427:                         }
                   22428:                     }
                   22429:                 } else {
                   22430:                     if ($inuse == 1) {
                   22431:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   22432:                         $changes{$prefix}{$type} = 1;
                   22433:                     }
                   22434:                 }
                   22435:             }
                   22436:         }
                   22437:     }
1.145     raeburn  22438: 
                   22439:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  22440:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  22441:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   22442:     my $savespares;
                   22443: 
                   22444:     foreach my $lonhost (sort(keys(%servers))) {
                   22445:         my $serverhomeID =
                   22446:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  22447:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  22448:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   22449:         my %spareschg;
                   22450:         foreach my $type (@{$types{'spares'}}) {
                   22451:             my @okspares;
                   22452:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   22453:             foreach my $server (@checked) {
1.152     raeburn  22454:                 if (&Apache::lonnet::hostname($server) ne '') {
                   22455:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   22456:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   22457:                             push(@okspares,$server);
                   22458:                         }
1.145     raeburn  22459:                     }
                   22460:                 }
                   22461:             }
                   22462:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   22463:             my $newspare;
1.152     raeburn  22464:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   22465:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  22466:                     $newspare = $new;
                   22467:                 }
                   22468:             }
1.152     raeburn  22469:             my @spares;
                   22470:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   22471:                 @spares = sort(@okspares,$newspare);
                   22472:             } else {
                   22473:                 @spares = sort(@okspares);
                   22474:             }
                   22475:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  22476:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   22477:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  22478:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  22479:                     if (@diffs > 0) {
                   22480:                         $spareschg{$type} = 1;
                   22481:                     }
                   22482:                 }
                   22483:             }
                   22484:         }
                   22485:         if (keys(%spareschg) > 0) {
                   22486:             $changes{'spares'}{$lonhost} = \%spareschg;
                   22487:         }
                   22488:     }
1.261     raeburn  22489:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371     raeburn  22490:     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261     raeburn  22491:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   22492:     my @okoffload;
                   22493:     if (@offloadnow) {
                   22494:         foreach my $server (@offloadnow) {
                   22495:             if (&Apache::lonnet::hostname($server) ne '') {
                   22496:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   22497:                     push(@okoffload,$server);
                   22498:                 }
                   22499:             }
                   22500:         }
                   22501:         if (@okoffload) {
                   22502:             foreach my $lonhost (@okoffload) {
                   22503:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   22504:             }
                   22505:         }
                   22506:     }
1.371     raeburn  22507:     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   22508:     my @okoffloadoth;
                   22509:     if (@offloadoth) {
                   22510:         foreach my $server (@offloadoth) {
                   22511:             if (&Apache::lonnet::hostname($server) ne '') {
                   22512:                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   22513:                     push(@okoffloadoth,$server);
                   22514:                 }
                   22515:             }
                   22516:         }
                   22517:         if (@okoffloadoth) {
                   22518:             foreach my $lonhost (@okoffloadoth) {
                   22519:                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   22520:             }
                   22521:         }
                   22522:     }
1.145     raeburn  22523:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   22524:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   22525:             if (ref($changes{'spares'}) eq 'HASH') {
                   22526:                 if (keys(%{$changes{'spares'}}) > 0) {
                   22527:                     $savespares = 1;
                   22528:                 }
                   22529:             }
                   22530:         } else {
                   22531:             $savespares = 1;
                   22532:         }
1.371     raeburn  22533:         foreach my $offload ('offloadnow','offloadoth') {
                   22534:             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   22535:                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   22536:                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   22537:                         $changes{$offload} = 1;
                   22538:                         last;
                   22539:                     }
1.261     raeburn  22540:                 }
1.371     raeburn  22541:                 unless ($changes{$offload}) {
                   22542:                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   22543:                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   22544:                             $changes{$offload} = 1;
                   22545:                             last;
                   22546:                         }
1.261     raeburn  22547:                     }
                   22548:                 }
1.371     raeburn  22549:             } else {
                   22550:                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   22551:                      $changes{'offloadnow'} = 1;
                   22552:                 }
                   22553:                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   22554:                     $changes{'offloadoth'} = 1;
                   22555:                 }
                   22556:             } 
                   22557:         }
                   22558:     } else {
                   22559:         if (@okoffload) {
1.261     raeburn  22560:             $changes{'offloadnow'} = 1;
                   22561:         }
1.371     raeburn  22562:         if (@okoffloadoth) {
                   22563:             $changes{'offloadoth'} = 1;
                   22564:         }
1.145     raeburn  22565:     }
1.147     raeburn  22566:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   22567:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  22568:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22569:                                                  $dom);
                   22570:         if ($putresult eq 'ok') {
                   22571:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   22572:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   22573:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   22574:                 }
                   22575:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   22576:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   22577:                 }
1.261     raeburn  22578:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   22579:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   22580:                 }
1.371     raeburn  22581:                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   22582:                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   22583:                 }
1.137     raeburn  22584:             }
                   22585:             my $cachetime = 24*60*60;
                   22586:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  22587:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  22588:             if (ref($lastactref) eq 'HASH') {
                   22589:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  22590:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  22591:             }
1.147     raeburn  22592:             if (keys(%changes) > 0) {
                   22593:                 my %lt = &usersession_titles();
                   22594:                 $resulttext = &mt('Changes made:').'<ul>';
                   22595:                 foreach my $prefix (@prefixes) {
                   22596:                     if (ref($changes{$prefix}) eq 'HASH') {
                   22597:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   22598:                         if ($prefix eq 'spares') {
                   22599:                             if (ref($changes{$prefix}) eq 'HASH') {
                   22600:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   22601:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  22602:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  22603:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   22604:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  22605:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   22606:                                         foreach my $type (@{$types{$prefix}}) {
                   22607:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   22608:                                                 my $offloadto = &mt('None');
                   22609:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   22610:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   22611:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   22612:                                                     }
1.145     raeburn  22613:                                                 }
1.147     raeburn  22614:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  22615:                                             }
1.137     raeburn  22616:                                         }
                   22617:                                     }
1.147     raeburn  22618:                                     $resulttext .= '</li>';
1.137     raeburn  22619:                                 }
                   22620:                             }
1.147     raeburn  22621:                         } else {
                   22622:                             foreach my $type (@{$types{$prefix}}) {
                   22623:                                 if (defined($changes{$prefix}{$type})) {
1.344     raeburn  22624:                                     my ($newvalue,$notinuse);
1.147     raeburn  22625:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   22626:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   22627:                                             if ($type eq 'version') {
                   22628:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344     raeburn  22629:                                             } else {
                   22630:                                                 if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   22631:                                                     if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   22632:                                                         $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   22633:                                                     }
                   22634:                                                 } else {
                   22635:                                                     $notinuse = 1;
1.147     raeburn  22636:                                                 }
1.145     raeburn  22637:                                             }
                   22638:                                         }
                   22639:                                     }
1.147     raeburn  22640:                                     if ($newvalue eq '') {
                   22641:                                         if ($type eq 'version') {
                   22642:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344     raeburn  22643:                                         } elsif ($notinuse) {
                   22644:                                             $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147     raeburn  22645:                                         } else {
                   22646:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   22647:                                         }
1.145     raeburn  22648:                                     } else {
1.147     raeburn  22649:                                         if ($type eq 'version') {
1.344     raeburn  22650:                                             $newvalue .= ' '.&mt('(or later)');
1.147     raeburn  22651:                                         }
                   22652:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  22653:                                     }
1.137     raeburn  22654:                                 }
                   22655:                             }
                   22656:                         }
1.147     raeburn  22657:                         $resulttext .= '</ul>';
1.137     raeburn  22658:                     }
                   22659:                 }
1.261     raeburn  22660:                 if ($changes{'offloadnow'}) {
                   22661:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   22662:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371     raeburn  22663:                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261     raeburn  22664:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   22665:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   22666:                             }
                   22667:                             $resulttext .= '</ul>';
                   22668:                         } else {
1.371     raeburn  22669:                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   22670:                         }
                   22671:                     } else {
                   22672:                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   22673:                     }
                   22674:                 }
                   22675:                 if ($changes{'offloadoth'}) {
                   22676:                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   22677:                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   22678:                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   22679:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   22680:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   22681:                             }
                   22682:                             $resulttext .= '</ul>';
                   22683:                         } else {
                   22684:                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261     raeburn  22685:                         }
                   22686:                     } else {
1.371     raeburn  22687:                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261     raeburn  22688:                     }
                   22689:                 }
1.147     raeburn  22690:                 $resulttext .= '</ul>';
                   22691:             } else {
                   22692:                 $resulttext = $nochgmsg;
1.137     raeburn  22693:             }
                   22694:         } else {
                   22695:             $resulttext = '<span class="LC_error">'.
                   22696:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   22697:         }
                   22698:     } else {
1.147     raeburn  22699:         $resulttext = $nochgmsg;
1.137     raeburn  22700:     }
                   22701:     return $resulttext;
                   22702: }
                   22703: 
1.275     raeburn  22704: sub modify_ssl {
                   22705:     my ($dom,$lastactref,%domconfig) = @_;
                   22706:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   22707:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   22708:     my @locations = sort(keys(%by_location));
                   22709:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   22710:     my (%defaultshash,%changes);
                   22711:     my $action = 'ssl';
1.293     raeburn  22712:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  22713:     foreach my $prefix (@prefixes) {
                   22714:         $defaultshash{$action}{$prefix} = {};
                   22715:     }
                   22716:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   22717:     my $resulttext;
                   22718:     my %iphost = &Apache::lonnet::get_iphost();
                   22719:     my @reptypes = ('certreq','nocertreq');
                   22720:     my @connecttypes = ('dom','intdom','other');
                   22721:     my %types = (
1.293     raeburn  22722:                   connto      => \@connecttypes,
                   22723:                   connfrom    => \@connecttypes,
                   22724:                   replication => \@reptypes,
1.275     raeburn  22725:                 );
                   22726:     foreach my $prefix (sort(keys(%types))) {
                   22727:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  22728:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  22729:                 my $value = 'yes';
                   22730:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   22731:                     $value = $env{'form.'.$prefix.'_'.$type};
                   22732:                 }
1.335     raeburn  22733:                 if (ref($domconfig{$action}) eq 'HASH') {
                   22734:                     if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   22735:                         if ($domconfig{$action}{$prefix}{$type} ne '') {
                   22736:                             if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   22737:                                 $changes{$prefix}{$type} = 1;
                   22738:                             }
                   22739:                             $defaultshash{$action}{$prefix}{$type} = $value;
                   22740:                         } else {
                   22741:                             $defaultshash{$action}{$prefix}{$type} = $value;
1.275     raeburn  22742:                             $changes{$prefix}{$type} = 1;
                   22743:                         }
                   22744:                     } else {
                   22745:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   22746:                         $changes{$prefix}{$type} = 1;
                   22747:                     }
                   22748:                 } else {
                   22749:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   22750:                     $changes{$prefix}{$type} = 1;
                   22751:                 }
                   22752:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   22753:                     delete($changes{$prefix}{$type});
                   22754:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   22755:                     delete($changes{$prefix}{$type});
                   22756:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   22757:                     delete($changes{$prefix}{$type});
                   22758:                 }
                   22759:             } elsif ($prefix eq 'replication') {
                   22760:                 if (@locations > 0) {
                   22761:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   22762:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   22763:                     my @okvals;
                   22764:                     foreach my $val (@vals) {
                   22765:                         if ($val =~ /:/) {
                   22766:                             my @items = split(/:/,$val);
                   22767:                             foreach my $item (@items) {
                   22768:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   22769:                                     push(@okvals,$item);
                   22770:                                 }
                   22771:                             }
                   22772:                         } else {
                   22773:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   22774:                                 push(@okvals,$val);
                   22775:                             }
                   22776:                         }
                   22777:                     }
                   22778:                     @okvals = sort(@okvals);
                   22779:                     if (ref($domconfig{$action}) eq 'HASH') {
                   22780:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   22781:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   22782:                                 if ($inuse == 0) {
                   22783:                                     $changes{$prefix}{$type} = 1;
                   22784:                                 } else {
                   22785:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22786:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   22787:                                     if (@changed > 0) {
                   22788:                                         $changes{$prefix}{$type} = 1;
                   22789:                                     }
                   22790:                                 }
                   22791:                             } else {
                   22792:                                 if ($inuse == 1) {
                   22793:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22794:                                     $changes{$prefix}{$type} = 1;
                   22795:                                 }
                   22796:                             }
                   22797:                         } else {
                   22798:                             if ($inuse == 1) {
                   22799:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22800:                                 $changes{$prefix}{$type} = 1;
                   22801:                             }
                   22802:                         }
                   22803:                     } else {
                   22804:                         if ($inuse == 1) {
                   22805:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   22806:                             $changes{$prefix}{$type} = 1;
                   22807:                         }
                   22808:                     }
                   22809:                 }
                   22810:             }
                   22811:         }
                   22812:     }
1.336     raeburn  22813:     if (keys(%changes)) {
                   22814:         foreach my $prefix (keys(%changes)) {
                   22815:             if (ref($changes{$prefix}) eq 'HASH') {
                   22816:                 if (scalar(keys(%{$changes{$prefix}})) == 0) {
                   22817:                     delete($changes{$prefix});
                   22818:                 }
                   22819:             } else {
                   22820:                 delete($changes{$prefix});
                   22821:             }
                   22822:         }
                   22823:     }
1.275     raeburn  22824:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   22825:     if (keys(%changes) > 0) {
                   22826:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22827:                                                  $dom);
                   22828:         if ($putresult eq 'ok') {
                   22829:             if (ref($defaultshash{$action}) eq 'HASH') {
                   22830:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   22831:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   22832:                 }
1.293     raeburn  22833:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335     raeburn  22834:                     $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293     raeburn  22835:                 }
                   22836:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335     raeburn  22837:                     $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275     raeburn  22838:                 }
                   22839:             }
                   22840:             my $cachetime = 24*60*60;
                   22841:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   22842:             if (ref($lastactref) eq 'HASH') {
                   22843:                 $lastactref->{'domdefaults'} = 1;
                   22844:             }
                   22845:             if (keys(%changes) > 0) {
                   22846:                 my %titles = &ssl_titles();
                   22847:                 $resulttext = &mt('Changes made:').'<ul>';
                   22848:                 foreach my $prefix (@prefixes) {
                   22849:                     if (ref($changes{$prefix}) eq 'HASH') {
                   22850:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   22851:                         foreach my $type (@{$types{$prefix}}) {
                   22852:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  22853:                                 my ($newvalue,$notinuse);
1.275     raeburn  22854:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   22855:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  22856:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  22857:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344     raeburn  22858:                                         } else {
                   22859:                                             if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   22860:                                                 if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   22861:                                                     $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   22862:                                                 }
                   22863:                                             } else {
                   22864:                                                 $notinuse = 1;
1.275     raeburn  22865:                                             }
                   22866:                                         }
                   22867:                                     }
1.344     raeburn  22868:                                     if ($notinuse) {
                   22869:                                         $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                   22870:                                     } elsif ($newvalue eq '') {
1.275     raeburn  22871:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   22872:                                     } else {
                   22873:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   22874:                                     }
                   22875:                                 }
                   22876:                             }
                   22877:                         }
                   22878:                         $resulttext .= '</ul>';
                   22879:                     }
                   22880:                 }
                   22881:             } else {
                   22882:                 $resulttext = $nochgmsg;
                   22883:             }
                   22884:         } else {
                   22885:             $resulttext = '<span class="LC_error">'.
                   22886:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   22887:         }
                   22888:     } else {
                   22889:         $resulttext = $nochgmsg;
                   22890:     }
                   22891:     return $resulttext;
                   22892: }
                   22893: 
1.279     raeburn  22894: sub modify_trust {
                   22895:     my ($dom,$lastactref,%domconfig) = @_;
                   22896:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   22897:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   22898:     my @locations = sort(keys(%by_location));
                   22899:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   22900:     my @types = ('exc','inc');
                   22901:     my (%defaultshash,%changes);
                   22902:     foreach my $prefix (@prefixes) {
                   22903:         $defaultshash{'trust'}{$prefix} = {};
                   22904:     }
                   22905:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   22906:     my $resulttext;
                   22907:     foreach my $prefix (@prefixes) {
                   22908:         foreach my $type (@types) {
                   22909:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   22910:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   22911:             my @okvals;
                   22912:             foreach my $val (@vals) {
                   22913:                 if ($val =~ /:/) {
                   22914:                     my @items = split(/:/,$val);
                   22915:                     foreach my $item (@items) {
                   22916:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   22917:                             push(@okvals,$item);
                   22918:                         }
                   22919:                     }
                   22920:                 } else {
                   22921:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   22922:                         push(@okvals,$val);
                   22923:                     }
                   22924:                 }
                   22925:             }
                   22926:             @okvals = sort(@okvals);
                   22927:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   22928:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   22929:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   22930:                         if ($inuse == 0) {
                   22931:                             $changes{$prefix}{$type} = 1;
                   22932:                         } else {
                   22933:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22934:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   22935:                             if (@changed > 0) {
                   22936:                                 $changes{$prefix}{$type} = 1;
                   22937:                             }
                   22938:                         }
                   22939:                     } else {
                   22940:                         if ($inuse == 1) {
                   22941:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22942:                             $changes{$prefix}{$type} = 1;
                   22943:                         }
                   22944:                     }
                   22945:                 } else {
                   22946:                     if ($inuse == 1) {
                   22947:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22948:                         $changes{$prefix}{$type} = 1;
                   22949:                     }
                   22950:                 }
                   22951:             } else {
                   22952:                 if ($inuse == 1) {
                   22953:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22954:                     $changes{$prefix}{$type} = 1;
                   22955:                 }
                   22956:             }
                   22957:         }
                   22958:     }
                   22959:     my $nochgmsg = &mt('No changes made to trust settings.');
                   22960:     if (keys(%changes) > 0) {
                   22961:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22962:                                                  $dom);
                   22963:         if ($putresult eq 'ok') {
                   22964:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   22965:                 foreach my $prefix (@prefixes) {
                   22966:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   22967:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   22968:                     }
                   22969:                 }
                   22970:             }
                   22971:             my $cachetime = 24*60*60;
                   22972:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410     raeburn  22973:             &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279     raeburn  22974:             if (ref($lastactref) eq 'HASH') {
                   22975:                 $lastactref->{'domdefaults'} = 1;
1.410     raeburn  22976:                 $lastactref->{'trust'} = 1;
1.279     raeburn  22977:             }
                   22978:             if (keys(%changes) > 0) {
                   22979:                 my %lt = &trust_titles();
                   22980:                 $resulttext = &mt('Changes made:').'<ul>';
                   22981:                 foreach my $prefix (@prefixes) {
                   22982:                     if (ref($changes{$prefix}) eq 'HASH') {
                   22983:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   22984:                         foreach my $type (@types) {
                   22985:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  22986:                                 my ($newvalue,$notinuse);
1.279     raeburn  22987:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   22988:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   22989:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   22990:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   22991:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   22992:                                             }
1.344     raeburn  22993:                                         } else {
                   22994:                                             $notinuse = 1;
1.279     raeburn  22995:                                         }
                   22996:                                     }
                   22997:                                 }
1.344     raeburn  22998:                                 if ($notinuse) {
                   22999:                                     $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                   23000:                                 } elsif ($newvalue eq '') {
1.279     raeburn  23001:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   23002:                                 } else {
                   23003:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   23004:                                 }
                   23005:                             }
                   23006:                         }
                   23007:                         $resulttext .= '</ul>';
                   23008:                     }
                   23009:                 }
                   23010:                 $resulttext .= '</ul>';
                   23011:             } else {
                   23012:                 $resulttext = $nochgmsg;
                   23013:             }
                   23014:         } else {
                   23015:             $resulttext = '<span class="LC_error">'.
                   23016:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   23017:         }
                   23018:     } else {
                   23019:         $resulttext = $nochgmsg;
                   23020:     }
                   23021:     return $resulttext;
                   23022: }
                   23023: 
1.150     raeburn  23024: sub modify_loadbalancing {
                   23025:     my ($dom,%domconfig) = @_;
                   23026:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   23027:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   23028:     my ($othertitle,$usertypes,$types) =
                   23029:         &Apache::loncommon::sorted_inst_types($dom);
                   23030:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  23031:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  23032:     my @sparestypes = ('primary','default');
                   23033:     my %typetitles = &sparestype_titles();
                   23034:     my $resulttext;
1.342     raeburn  23035:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  23036:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   23037:         %existing = %{$domconfig{'loadbalancing'}};
                   23038:     }
                   23039:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  23040:                               \%currtargets,\%currrules,\%currcookies);
1.171     raeburn  23041:     my ($saveloadbalancing,%defaultshash,%changes);
                   23042:     my ($alltypes,$othertypes,$titles) =
                   23043:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   23044:     my %ruletitles = &offloadtype_text();
                   23045:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   23046:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   23047:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   23048:         if ($balancer eq '') {
                   23049:             next;
                   23050:         }
1.210     raeburn  23051:         if (!exists($servers{$balancer})) {
1.171     raeburn  23052:             if (exists($currbalancer{$balancer})) {
                   23053:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  23054:             }
1.171     raeburn  23055:             next;
                   23056:         }
                   23057:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   23058:             push(@{$changes{'delete'}},$balancer);
                   23059:             next;
                   23060:         }
                   23061:         if (!exists($currbalancer{$balancer})) {
                   23062:             push(@{$changes{'add'}},$balancer);
                   23063:         }
                   23064:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   23065:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   23066:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   23067:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   23068:             $saveloadbalancing = 1;
                   23069:         }
                   23070:         foreach my $sparetype (@sparestypes) {
                   23071:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   23072:             my @offloadto;
                   23073:             foreach my $target (@targets) {
                   23074:                 if (($servers{$target}) && ($target ne $balancer)) {
                   23075:                     if ($sparetype eq 'default') {
                   23076:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   23077:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  23078:                         }
                   23079:                     }
1.171     raeburn  23080:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   23081:                         push(@offloadto,$target);
                   23082:                     }
1.150     raeburn  23083:                 }
                   23084:             }
1.284     raeburn  23085:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   23086:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   23087:                     push(@offloadto,$balancer);
                   23088:                 }
                   23089:             }
                   23090:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  23091:         }
1.342     raeburn  23092:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   23093:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   23094:             if (exists($currbalancer{$balancer})) { 
                   23095:                 unless ($currcookies{$balancer}) {
                   23096:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   23097:                 }
                   23098:             }
                   23099:         } elsif (exists($currbalancer{$balancer})) {
                   23100:             if ($currcookies{$balancer}) {
                   23101:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   23102:             }
                   23103:         }
1.171     raeburn  23104:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  23105:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  23106:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   23107:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  23108:                     if (@targetdiffs > 0) {
1.171     raeburn  23109:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  23110:                     }
1.171     raeburn  23111:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23112:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   23113:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  23114:                     }
                   23115:                 }
                   23116:             }
                   23117:         } else {
1.171     raeburn  23118:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  23119:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  23120:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23121:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   23122:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   23123:                         }
1.150     raeburn  23124:                     }
                   23125:                 }
1.210     raeburn  23126:             }
1.150     raeburn  23127:         }
                   23128:         my $ishomedom;
1.171     raeburn  23129:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   23130:             $ishomedom = 1;
1.150     raeburn  23131:         }
                   23132:         if (ref($alltypes) eq 'ARRAY') {
                   23133:             foreach my $type (@{$alltypes}) {
                   23134:                 my $rule;
1.210     raeburn  23135:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  23136:                          (!$ishomedom)) {
1.171     raeburn  23137:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   23138:                 }
                   23139:                 if ($rule eq 'specific') {
1.255     raeburn  23140:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  23141:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  23142:                         $rule = $specifiedhost;
                   23143:                     }
1.150     raeburn  23144:                 }
1.171     raeburn  23145:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   23146:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   23147:                     if ($rule ne $currrules{$balancer}{$type}) {
                   23148:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  23149:                     }
                   23150:                 } elsif ($rule ne '') {
1.171     raeburn  23151:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  23152:                 }
                   23153:             }
                   23154:         }
1.171     raeburn  23155:     }
                   23156:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   23157:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   23158:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   23159:             $defaultshash{'loadbalancing'} = {};
                   23160:         }
                   23161:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   23162:                                                  \%defaultshash,$dom);
                   23163:         if ($putresult eq 'ok') {
                   23164:             if (keys(%changes) > 0) {
1.252     raeburn  23165:                 my %toupdate;
1.171     raeburn  23166:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   23167:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   23168:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  23169:                         $toupdate{$balancer} = 1;
1.150     raeburn  23170:                     }
1.171     raeburn  23171:                 }
                   23172:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  23173:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  23174:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  23175:                         $toupdate{$balancer} = 1;
1.171     raeburn  23176:                     }
                   23177:                 }
                   23178:                 if (ref($changes{'curr'}) eq 'HASH') {
                   23179:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  23180:                         $toupdate{$balancer} = 1;
1.171     raeburn  23181:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   23182:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   23183:                                 my %offloadstr;
                   23184:                                 foreach my $sparetype (@sparestypes) {
                   23185:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23186:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   23187:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   23188:                                         }
                   23189:                                     }
1.150     raeburn  23190:                                 }
1.171     raeburn  23191:                                 if (keys(%offloadstr) == 0) {
                   23192:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  23193:                                 } else {
1.171     raeburn  23194:                                     my $showoffload;
                   23195:                                     foreach my $sparetype (@sparestypes) {
                   23196:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   23197:                                         if (defined($offloadstr{$sparetype})) {
                   23198:                                             $showoffload .= $offloadstr{$sparetype};
                   23199:                                         } else {
                   23200:                                             $showoffload .= &mt('None');
                   23201:                                         }
                   23202:                                         $showoffload .= ('&nbsp;'x3);
                   23203:                                     }
                   23204:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  23205:                                 }
                   23206:                             }
                   23207:                         }
1.171     raeburn  23208:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   23209:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   23210:                                 foreach my $type (@{$alltypes}) {
                   23211:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   23212:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   23213:                                         my $balancetext;
                   23214:                                         if ($rule eq '') {
                   23215:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  23216:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  23217:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  23218:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  23219:                                                 foreach my $sparetype (@sparestypes) {
                   23220:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   23221:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   23222:                                                     }
                   23223:                                                 }
1.253     raeburn  23224:                                                 foreach my $item (@{$alltypes}) {
                   23225:                                                     next if ($item =~  /^_LC_ipchange/);
                   23226:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   23227:                                                     if ($hasrule eq 'homeserver') {
                   23228:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   23229:                                                     } else {
                   23230:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   23231:                                                             if ($servers{$hasrule}) {
                   23232:                                                                 $toupdate{$hasrule} = 1;
                   23233:                                                             }
                   23234:                                                         }
                   23235:                                                     }
                   23236:                                                 }
1.254     raeburn  23237:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   23238:                                                     $balancetext =  $ruletitles{$rule};
                   23239:                                                 } else {
                   23240:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   23241:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   23242:                                                     if ($receiver) {
                   23243:                                                         $toupdate{$receiver};
                   23244:                                                     }
                   23245:                                                 }
                   23246:                                             } else {
                   23247:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  23248:                                             }
1.171     raeburn  23249:                                         } else {
                   23250:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   23251:                                         }
1.210     raeburn  23252:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  23253:                                     }
                   23254:                                 }
                   23255:                             }
                   23256:                         }
1.342     raeburn  23257:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389     raeburn  23258:                             if ($currcookies{$balancer}) {
                   23259:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
                   23260:                                                           $balancer).'</li>';
                   23261:                             } else {
                   23262:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   23263:                                                           $balancer).'</li>';
                   23264:                             }
1.342     raeburn  23265:                         }
1.375     raeburn  23266:                     }
                   23267:                 }
                   23268:                 if (keys(%toupdate)) {
                   23269:                     my %thismachine;
                   23270:                     my $updatedhere;
                   23271:                     my $cachetime = 60*60*24;
                   23272:                     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   23273:                     foreach my $lonhost (keys(%toupdate)) {
                   23274:                         if ($thismachine{$lonhost}) {
                   23275:                             unless ($updatedhere) {
                   23276:                                 &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   23277:                                                               $defaultshash{'loadbalancing'},
                   23278:                                                               $cachetime);
                   23279:                                 $updatedhere = 1;
1.252     raeburn  23280:                             }
1.375     raeburn  23281:                         } else {
                   23282:                             my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   23283:                             &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252     raeburn  23284:                         }
1.150     raeburn  23285:                     }
1.171     raeburn  23286:                 }
                   23287:                 if ($resulttext ne '') {
                   23288:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  23289:                 } else {
                   23290:                     $resulttext = $nochgmsg;
                   23291:                 }
                   23292:             } else {
1.171     raeburn  23293:                 $resulttext = $nochgmsg;
1.150     raeburn  23294:             }
                   23295:         } else {
1.171     raeburn  23296:             $resulttext = '<span class="LC_error">'.
                   23297:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  23298:         }
                   23299:     } else {
1.171     raeburn  23300:         $resulttext = $nochgmsg;
1.150     raeburn  23301:     }
                   23302:     return $resulttext;
                   23303: }
                   23304: 
1.48      raeburn  23305: sub recurse_check {
                   23306:     my ($chkcats,$categories,$depth,$name) = @_;
                   23307:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   23308:         my $chg = 0;
                   23309:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   23310:             my $category = $chkcats->[$depth]{$name}[$j];
                   23311:             my $item;
                   23312:             if ($category eq '') {
                   23313:                 $chg ++;
                   23314:             } else {
                   23315:                 my $deeper = $depth + 1;
                   23316:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   23317:                 if ($chg) {
                   23318:                     $categories->{$item} -= $chg;
                   23319:                 }
                   23320:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   23321:                 $deeper --;
                   23322:             }
                   23323:         }
                   23324:     }
                   23325:     return;
                   23326: }
                   23327: 
                   23328: sub recurse_cat_deletes {
                   23329:     my ($item,$coursecategories,$deletions) = @_;
                   23330:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   23331:     my $subdepth = $depth + 1;
                   23332:     if (ref($coursecategories) eq 'HASH') {
                   23333:         foreach my $subitem (keys(%{$coursecategories})) {
                   23334:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   23335:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   23336:                 delete($coursecategories->{$subitem});
                   23337:                 $deletions->{$subitem} = 1;
                   23338:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  23339:             }
1.48      raeburn  23340:         }
                   23341:     }
                   23342:     return;
                   23343: }
                   23344: 
1.125     raeburn  23345: sub active_dc_picker {
1.191     raeburn  23346:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  23347:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  23348:     my @domcoord = keys(%domcoords);
                   23349:     if (keys(%currhash)) {
                   23350:         foreach my $dc (keys(%currhash)) {
                   23351:             unless (exists($domcoords{$dc})) {
                   23352:                 push(@domcoord,$dc);
                   23353:             }
                   23354:         }
                   23355:     }
                   23356:     @domcoord = sort(@domcoord);
1.210     raeburn  23357:     my $numdcs = scalar(@domcoord);
1.191     raeburn  23358:     my $rows = 0;
                   23359:     my $table;
1.125     raeburn  23360:     if ($numdcs > 1) {
1.191     raeburn  23361:         $table = '<table>';
                   23362:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  23363:             my $rem = $i%($numinrow);
                   23364:             if ($rem == 0) {
                   23365:                 if ($i > 0) {
1.191     raeburn  23366:                     $table .= '</tr>';
1.125     raeburn  23367:                 }
1.191     raeburn  23368:                 $table .= '<tr>';
                   23369:                 $rows ++;
1.125     raeburn  23370:             }
1.191     raeburn  23371:             my $check = '';
                   23372:             if ($inputtype eq 'radio') {
                   23373:                 if (keys(%currhash) == 0) {
                   23374:                     if (!$i) {
                   23375:                         $check = ' checked="checked"';
                   23376:                     }
                   23377:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   23378:                     $check = ' checked="checked"';
                   23379:                 }
                   23380:             } else {
                   23381:                 if (exists($currhash{$domcoord[$i]})) {
                   23382:                     $check = ' checked="checked"';
1.125     raeburn  23383:                 }
                   23384:             }
1.191     raeburn  23385:             if ($i == @domcoord - 1) {
1.125     raeburn  23386:                 my $colsleft = $numinrow - $rem;
                   23387:                 if ($colsleft > 1) {
1.191     raeburn  23388:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  23389:                 } else {
1.191     raeburn  23390:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  23391:                 }
                   23392:             } else {
1.191     raeburn  23393:                 $table .= '<td class="LC_left_item">';
                   23394:             }
                   23395:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   23396:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   23397:             $table .= '<span class="LC_nobreak"><label>'.
                   23398:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   23399:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   23400:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  23401:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  23402:             }
1.219     raeburn  23403:             $table .= '</label></span></td>';
1.191     raeburn  23404:         }
                   23405:         $table .= '</tr></table>';
                   23406:     } elsif ($numdcs == 1) {
1.219     raeburn  23407:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   23408:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  23409:         if ($inputtype eq 'radio') {
1.247     raeburn  23410:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  23411:             if ($user ne $dcname.':'.$dcdom) {
                   23412:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   23413:             }
1.191     raeburn  23414:         } else {
                   23415:             my $check;
                   23416:             if (exists($currhash{$domcoord[0]})) {
                   23417:                 $check = ' checked="checked"';
1.125     raeburn  23418:             }
1.247     raeburn  23419:             $table = '<span class="LC_nobreak"><label>'.
                   23420:                      '<input type="checkbox" name="'.$name.'" '.
                   23421:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  23422:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  23423:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  23424:             }
1.220     raeburn  23425:             $table .= '</label></span>';
1.191     raeburn  23426:             $rows ++;
1.125     raeburn  23427:         }
                   23428:     }
1.191     raeburn  23429:     return ($numdcs,$table,$rows);
1.125     raeburn  23430: }
                   23431: 
1.137     raeburn  23432: sub usersession_titles {
                   23433:     return &Apache::lonlocal::texthash(
                   23434:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   23435:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  23436:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  23437:                version => 'LON-CAPA version requirement',
1.138     raeburn  23438:                excludedomain => 'Allow all, but exclude specific domains',
                   23439:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  23440:                primary => 'Primary (checked first)',
1.154     raeburn  23441:                default => 'Default',
1.137     raeburn  23442:            );
                   23443: }
                   23444: 
1.152     raeburn  23445: sub id_for_thisdom {
                   23446:     my (%servers) = @_;
                   23447:     my %altids;
                   23448:     foreach my $server (keys(%servers)) {
                   23449:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   23450:         if ($serverhome ne $server) {
                   23451:             $altids{$serverhome} = $server;
                   23452:         }
                   23453:     }
                   23454:     return %altids;
                   23455: }
                   23456: 
1.150     raeburn  23457: sub count_servers {
                   23458:     my ($currbalancer,%servers) = @_;
                   23459:     my (@spares,$numspares);
                   23460:     foreach my $lonhost (sort(keys(%servers))) {
                   23461:         next if ($currbalancer eq $lonhost);
                   23462:         push(@spares,$lonhost);
                   23463:     }
                   23464:     if ($currbalancer) {
                   23465:         $numspares = scalar(@spares);
                   23466:     } else {
                   23467:         $numspares = scalar(@spares) - 1;
                   23468:     }
                   23469:     return ($numspares,@spares);
                   23470: }
                   23471: 
                   23472: sub lonbalance_targets_js {
1.171     raeburn  23473:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  23474:     my $select = &mt('Select');
                   23475:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   23476:     if (ref($servers) eq 'HASH') {
                   23477:         $alltargets = join("','",sort(keys(%{$servers})));
                   23478:         my @homedoms;
                   23479:         foreach my $server (sort(keys(%{$servers}))) {
                   23480:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   23481:                 push(@homedoms,'1');
                   23482:             } else {
                   23483:                 push(@homedoms,'0');
                   23484:             }
                   23485:         }
                   23486:         $allishome = join("','",@homedoms);
                   23487:     }
                   23488:     if (ref($types) eq 'ARRAY') {
                   23489:         if (@{$types} > 0) {
                   23490:             @alltypes = @{$types};
                   23491:         }
                   23492:     }
                   23493:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   23494:     $allinsttypes = join("','",@alltypes);
1.342     raeburn  23495:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  23496:     if (ref($settings) eq 'HASH') {
                   23497:         %existing = %{$settings};
                   23498:     }
                   23499:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342     raeburn  23500:                               \%currtargets,\%currrules,\%currcookies);
1.210     raeburn  23501:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  23502:     return <<"END";
                   23503: 
                   23504: <script type="text/javascript">
                   23505: // <![CDATA[
                   23506: 
1.171     raeburn  23507: currBalancers = new Array('$balancers');
                   23508: 
                   23509: function toggleTargets(balnum) {
                   23510:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   23511:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   23512:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   23513:     var prevbalancer = prevhostitem.value;
                   23514:     var baltotal = document.getElementById('loadbalancing_total').value;
                   23515:     prevhostitem.value = balancer;
                   23516:     if (prevbalancer != '') {
                   23517:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   23518:         if (prevIdx != -1) {
                   23519:             currBalancers.splice(prevIdx,1);
                   23520:         }
                   23521:     }
1.150     raeburn  23522:     if (balancer == '') {
1.171     raeburn  23523:         hideSpares(balnum);
1.150     raeburn  23524:     } else {
1.171     raeburn  23525:         var currIdx = currBalancers.indexOf(balancer);
                   23526:         if (currIdx == -1) {
                   23527:             currBalancers.push(balancer);
                   23528:         }
1.150     raeburn  23529:         var homedoms = new Array('$allishome');
1.171     raeburn  23530:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   23531:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  23532:     }
1.171     raeburn  23533:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  23534:     return;
                   23535: }
                   23536: 
1.171     raeburn  23537: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  23538:     var alltargets = new Array('$alltargets');
                   23539:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  23540:     var offloadtypes = new Array('primary','default');
                   23541: 
1.171     raeburn  23542:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   23543:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  23544:  
1.151     raeburn  23545:     for (var i=0; i<offloadtypes.length; i++) {
                   23546:         var count = 0;
                   23547:         for (var j=0; j<alltargets.length; j++) {
                   23548:             if (alltargets[j] != balancer) {
1.171     raeburn  23549:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   23550:                 item.value = alltargets[j];
                   23551:                 item.style.textAlign='left';
                   23552:                 item.style.textFace='normal';
                   23553:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   23554:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   23555:                     item.disabled = '';
                   23556:                 } else {
                   23557:                     item.disabled = 'disabled';
                   23558:                     item.checked = false;
                   23559:                 }
1.151     raeburn  23560:                 count ++;
                   23561:             }
1.150     raeburn  23562:         }
                   23563:     }
1.151     raeburn  23564:     for (var k=0; k<insttypes.length; k++) {
                   23565:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  23566:             if (ishomedom == 1) {
1.171     raeburn  23567:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   23568:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  23569:             } else {
1.171     raeburn  23570:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   23571:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  23572:             }
                   23573:         } else {
1.171     raeburn  23574:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   23575:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  23576:         }
1.151     raeburn  23577:         if ((insttypes[k] != '_LC_external') && 
                   23578:             ((insttypes[k] != '_LC_internetdom') ||
                   23579:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  23580:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   23581:             item.options.length = 0;
                   23582:             item.options[0] = new Option("","",true,true);
1.210     raeburn  23583:             var idx = 0;
1.151     raeburn  23584:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  23585:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   23586:                     idx ++;
                   23587:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  23588:                 }
                   23589:             }
                   23590:         }
                   23591:     }
                   23592:     return;
                   23593: }
                   23594: 
1.171     raeburn  23595: function hideSpares(balnum) {
1.150     raeburn  23596:     var alltargets = new Array('$alltargets');
                   23597:     var insttypes = new Array('$allinsttypes');
                   23598:     var offloadtypes = new Array('primary','default');
                   23599: 
1.171     raeburn  23600:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   23601:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  23602: 
                   23603:     var total = alltargets.length - 1;
                   23604:     for (var i=0; i<offloadtypes; i++) {
                   23605:         for (var j=0; j<total; j++) {
1.171     raeburn  23606:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   23607:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   23608:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  23609:         }
1.150     raeburn  23610:     }
                   23611:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  23612:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   23613:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  23614:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  23615:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   23616:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  23617:         }
                   23618:     }
                   23619:     return;
                   23620: }
                   23621: 
1.171     raeburn  23622: function checkOffloads(item,balnum,type) {
1.150     raeburn  23623:     var alltargets = new Array('$alltargets');
                   23624:     var offloadtypes = new Array('primary','default');
                   23625:     if (item.checked) {
                   23626:         var total = alltargets.length - 1;
                   23627:         var other;
                   23628:         if (type == offloadtypes[0]) {
1.151     raeburn  23629:             other = offloadtypes[1];
1.150     raeburn  23630:         } else {
1.151     raeburn  23631:             other = offloadtypes[0];
1.150     raeburn  23632:         }
                   23633:         for (var i=0; i<total; i++) {
1.171     raeburn  23634:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  23635:             if (server == item.value) {
1.171     raeburn  23636:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   23637:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  23638:                 }
                   23639:             }
                   23640:         }
                   23641:     }
                   23642:     return;
                   23643: }
                   23644: 
1.171     raeburn  23645: function singleServerToggle(balnum,type) {
                   23646:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  23647:     if (offloadtoSelIdx == 0) {
1.171     raeburn  23648:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   23649:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  23650: 
                   23651:     } else {
1.171     raeburn  23652:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   23653:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  23654:     }
                   23655:     return;
                   23656: }
                   23657: 
1.171     raeburn  23658: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  23659:     if (type == '_LC_external') {
1.171     raeburn  23660:         return;
1.150     raeburn  23661:     }
1.171     raeburn  23662:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  23663:     for (var i=0; i<typesRules.length; i++) {
                   23664:         if (formname.elements[typesRules[i]].checked) {
                   23665:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  23666:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   23667:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  23668:             } else {
1.171     raeburn  23669:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   23670:             }
                   23671:         }
                   23672:     }
                   23673:     return;
                   23674: }
                   23675: 
                   23676: function balancerDeleteChange(balnum) {
                   23677:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   23678:     var baltotal = document.getElementById('loadbalancing_total').value;
                   23679:     var addtarget;
                   23680:     var removetarget;
                   23681:     var action = 'delete';
                   23682:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   23683:         var lonhost = hostitem.value;
                   23684:         var currIdx = currBalancers.indexOf(lonhost);
                   23685:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   23686:             if (currIdx != -1) {
                   23687:                 currBalancers.splice(currIdx,1);
                   23688:             }
                   23689:             addtarget = lonhost;
                   23690:         } else {
                   23691:             if (currIdx == -1) {
                   23692:                 currBalancers.push(lonhost);
                   23693:             }
                   23694:             removetarget = lonhost;
                   23695:             action = 'undelete';
                   23696:         }
                   23697:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   23698:     }
                   23699:     return;
                   23700: }
                   23701: 
                   23702: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   23703:     if (baltotal > 1) {
                   23704:         var offloadtypes = new Array('primary','default');
                   23705:         var alltargets = new Array('$alltargets');
                   23706:         var insttypes = new Array('$allinsttypes');
                   23707:         for (var i=0; i<baltotal; i++) {
                   23708:             if (i != balnum) {
                   23709:                 for (var j=0; j<offloadtypes.length; j++) {
                   23710:                     var total = alltargets.length - 1;
                   23711:                     for (var k=0; k<total; k++) {
                   23712:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   23713:                         var server = serveritem.value;
                   23714:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   23715:                             if (server == addtarget) {
                   23716:                                 serveritem.disabled = '';
                   23717:                             }
                   23718:                         }
                   23719:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   23720:                             if (server == removetarget) {
                   23721:                                 serveritem.disabled = 'disabled';
                   23722:                                 serveritem.checked = false;
                   23723:                             }
                   23724:                         }
                   23725:                     }
                   23726:                 }
                   23727:                 for (var j=0; j<insttypes.length; j++) {
                   23728:                     if (insttypes[j] != '_LC_external') {
                   23729:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   23730:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   23731:                             var currSel = singleserver.selectedIndex;
                   23732:                             var currVal = singleserver.options[currSel].value;
                   23733:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   23734:                                 var numoptions = singleserver.options.length;
                   23735:                                 var needsnew = 1;
                   23736:                                 for (var k=0; k<numoptions; k++) {
                   23737:                                     if (singleserver.options[k] == addtarget) {
                   23738:                                         needsnew = 0;
                   23739:                                         break;
                   23740:                                     }
                   23741:                                 }
                   23742:                                 if (needsnew == 1) {
                   23743:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   23744:                                 }
                   23745:                             }
                   23746:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   23747:                                 singleserver.options.length = 0;
                   23748:                                 if ((currVal) && (currVal != removetarget)) {
                   23749:                                     singleserver.options[0] = new Option("","",false,false);
                   23750:                                 } else {
                   23751:                                     singleserver.options[0] = new Option("","",true,true);
                   23752:                                 }
                   23753:                                 var idx = 0;
                   23754:                                 for (var m=0; m<alltargets.length; m++) {
                   23755:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   23756:                                         idx ++;
                   23757:                                         if (currVal == alltargets[m]) {
                   23758:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   23759:                                         } else {
                   23760:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   23761:                                         }
                   23762:                                     }
                   23763:                                 }
                   23764:                             }
                   23765:                         }
                   23766:                     }
                   23767:                 }
1.150     raeburn  23768:             }
                   23769:         }
                   23770:     }
                   23771:     return;
                   23772: }
                   23773: 
1.152     raeburn  23774: // ]]>
                   23775: </script>
                   23776: 
                   23777: END
                   23778: }
                   23779: 
1.372     raeburn  23780: 
1.152     raeburn  23781: sub new_spares_js {
                   23782:     my @sparestypes = ('primary','default');
                   23783:     my $types = join("','",@sparestypes);
                   23784:     my $select = &mt('Select');
                   23785:     return <<"END";
                   23786: 
                   23787: <script type="text/javascript">
                   23788: // <![CDATA[
                   23789: 
                   23790: function updateNewSpares(formname,lonhost) {
                   23791:     var types = new Array('$types');
                   23792:     var include = new Array();
                   23793:     var exclude = new Array();
                   23794:     for (var i=0; i<types.length; i++) {
                   23795:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   23796:         for (var j=0; j<spareboxes.length; j++) {
                   23797:             if (formname.elements[spareboxes[j]].checked) {
                   23798:                 exclude.push(formname.elements[spareboxes[j]].value);
                   23799:             } else {
                   23800:                 include.push(formname.elements[spareboxes[j]].value);
                   23801:             }
                   23802:         }
                   23803:     }
                   23804:     for (var i=0; i<types.length; i++) {
                   23805:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   23806:         var selIdx = newSpare.selectedIndex;
                   23807:         var currnew = newSpare.options[selIdx].value;
                   23808:         var okSpares = new Array();
                   23809:         for (var j=0; j<newSpare.options.length; j++) {
                   23810:             var possible = newSpare.options[j].value;
                   23811:             if (possible != '') {
                   23812:                 if (exclude.indexOf(possible) == -1) {
                   23813:                     okSpares.push(possible);
                   23814:                 } else {
                   23815:                     if (currnew == possible) {
                   23816:                         selIdx = 0;
                   23817:                     }
                   23818:                 }
                   23819:             }
                   23820:         }
                   23821:         for (var k=0; k<include.length; k++) {
                   23822:             if (okSpares.indexOf(include[k]) == -1) {
                   23823:                 okSpares.push(include[k]);
                   23824:             }
                   23825:         }
                   23826:         okSpares.sort();
                   23827:         newSpare.options.length = 0;
                   23828:         if (selIdx == 0) {
                   23829:             newSpare.options[0] = new Option("$select","",true,true);
                   23830:         } else {
                   23831:             newSpare.options[0] = new Option("$select","",false,false);
                   23832:         }
                   23833:         for (var m=0; m<okSpares.length; m++) {
                   23834:             var idx = m+1;
                   23835:             var selThis = 0;
                   23836:             if (selIdx != 0) {
                   23837:                 if (okSpares[m] == currnew) {
                   23838:                     selThis = 1;
                   23839:                 }
                   23840:             }
                   23841:             if (selThis == 1) {
                   23842:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   23843:             } else {
                   23844:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   23845:             }
                   23846:         }
                   23847:     }
                   23848:     return;
                   23849: }
                   23850: 
                   23851: function checkNewSpares(lonhost,type) {
                   23852:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   23853:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
1.372     raeburn  23854:     if (chosen != '') {
1.152     raeburn  23855:         var othertype;
                   23856:         var othernewSpare;
                   23857:         if (type == 'primary') {
                   23858:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   23859:         }
                   23860:         if (type == 'default') {
                   23861:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   23862:         }
                   23863:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   23864:             othernewSpare.selectedIndex = 0;
                   23865:         }
                   23866:     }
                   23867:     return;
                   23868: }
                   23869: 
                   23870: // ]]>
                   23871: </script>
                   23872: 
                   23873: END
                   23874: 
                   23875: }
                   23876: 
                   23877: sub common_domprefs_js {
                   23878:     return <<"END";
                   23879: 
                   23880: <script type="text/javascript">
                   23881: // <![CDATA[
                   23882: 
1.150     raeburn  23883: function getIndicesByName(formname,item) {
1.152     raeburn  23884:     var group = new Array();
1.150     raeburn  23885:     for (var i=0;i<formname.elements.length;i++) {
                   23886:         if (formname.elements[i].name == item) {
1.152     raeburn  23887:             group.push(formname.elements[i].id);
1.150     raeburn  23888:         }
                   23889:     }
1.152     raeburn  23890:     return group;
1.150     raeburn  23891: }
                   23892: 
                   23893: // ]]>
                   23894: </script>
                   23895: 
                   23896: END
1.152     raeburn  23897: 
1.150     raeburn  23898: }
                   23899: 
1.165     raeburn  23900: sub recaptcha_js {
                   23901:     my %lt = &captcha_phrases();
                   23902:     return <<"END";
                   23903: 
                   23904: <script type="text/javascript">
                   23905: // <![CDATA[
                   23906: 
                   23907: function updateCaptcha(caller,context) {
                   23908:     var privitem;
                   23909:     var pubitem;
                   23910:     var privtext;
                   23911:     var pubtext;
1.269     raeburn  23912:     var versionitem;
                   23913:     var versiontext;
1.165     raeburn  23914:     if (document.getElementById(context+'_recaptchapub')) {
                   23915:         pubitem = document.getElementById(context+'_recaptchapub');
                   23916:     } else {
                   23917:         return;
                   23918:     }
                   23919:     if (document.getElementById(context+'_recaptchapriv')) {
                   23920:         privitem = document.getElementById(context+'_recaptchapriv');
                   23921:     } else {
                   23922:         return;
                   23923:     }
                   23924:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   23925:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   23926:     } else {
                   23927:         return;
                   23928:     }
                   23929:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   23930:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   23931:     } else {
                   23932:         return;
                   23933:     }
1.269     raeburn  23934:     if (document.getElementById(context+'_recaptchaversion')) {
                   23935:         versionitem = document.getElementById(context+'_recaptchaversion');
                   23936:     } else {
                   23937:         return;
                   23938:     }
                   23939:     if (document.getElementById(context+'_recaptchavertxt')) {
                   23940:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   23941:     } else {
                   23942:         return;
                   23943:     }
1.165     raeburn  23944:     if (caller.checked) {
                   23945:         if (caller.value == 'recaptcha') {
                   23946:             pubitem.type = 'text';
                   23947:             privitem.type = 'text';
                   23948:             pubitem.size = '40';
                   23949:             privitem.size = '40';
                   23950:             pubtext.innerHTML = "$lt{'pub'}";
                   23951:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  23952:             versionitem.type = 'text';
                   23953:             versionitem.size = '3';
1.289     raeburn  23954:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  23955:         } else {
                   23956:             pubitem.type = 'hidden';
                   23957:             privitem.type = 'hidden';
1.269     raeburn  23958:             versionitem.type = 'hidden';
1.165     raeburn  23959:             pubtext.innerHTML = '';
                   23960:             privtext.innerHTML = '';
1.269     raeburn  23961:             versiontext.innerHTML = '';
1.165     raeburn  23962:         }
                   23963:     }
                   23964:     return;
                   23965: }
                   23966: 
                   23967: // ]]>
                   23968: </script>
                   23969: 
                   23970: END
                   23971: 
                   23972: }
                   23973: 
1.236     raeburn  23974: sub toggle_display_js {
1.192     raeburn  23975:     return <<"END";
                   23976: 
                   23977: <script type="text/javascript">
                   23978: // <![CDATA[
                   23979: 
1.236     raeburn  23980: function toggleDisplay(domForm,caller) {
                   23981:     if (document.getElementById(caller)) {
                   23982:         var divitem = document.getElementById(caller);
                   23983:         var optionsElement = domForm.coursecredits;
1.264     raeburn  23984:         var checkval = 1;
                   23985:         var dispval = 'block';
1.303     raeburn  23986:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  23987:         if (caller == 'emailoptions') {
1.372     raeburn  23988:             optionsElement = domForm.cancreate_email;
1.236     raeburn  23989:         }
1.257     raeburn  23990:         if (caller == 'studentsubmission') {
                   23991:             optionsElement = domForm.postsubmit;
                   23992:         }
1.264     raeburn  23993:         if (caller == 'cloneinstcode') {
                   23994:             optionsElement = domForm.canclone;
                   23995:             checkval = 'instcode';
                   23996:         }
1.303     raeburn  23997:         if (selfcreateRegExp.test(caller)) {
                   23998:             optionsElement = domForm.elements[caller];
                   23999:             checkval = 'other';
                   24000:             dispval = 'inline'
                   24001:         }
1.236     raeburn  24002:         if (optionsElement.length) {
1.192     raeburn  24003:             var currval;
1.236     raeburn  24004:             for (var i=0; i<optionsElement.length; i++) {
                   24005:                 if (optionsElement[i].checked) {
                   24006:                    currval = optionsElement[i].value;
1.192     raeburn  24007:                 }
                   24008:             }
1.264     raeburn  24009:             if (currval == checkval) {
                   24010:                 divitem.style.display = dispval;
1.192     raeburn  24011:             } else {
1.236     raeburn  24012:                 divitem.style.display = 'none';
1.192     raeburn  24013:             }
                   24014:         }
                   24015:     }
                   24016:     return;
                   24017: }
                   24018: 
                   24019: // ]]>
                   24020: </script>
                   24021: 
                   24022: END
                   24023: 
                   24024: }
                   24025: 
1.165     raeburn  24026: sub captcha_phrases {
                   24027:     return &Apache::lonlocal::texthash (
                   24028:                  priv => 'Private key',
                   24029:                  pub  => 'Public key',
                   24030:                  original  => 'original (CAPTCHA)',
                   24031:                  recaptcha => 'successor (ReCAPTCHA)',
                   24032:                  notused   => 'unused',
1.289     raeburn  24033:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  24034:     );
                   24035: }
                   24036: 
1.205     raeburn  24037: sub devalidate_remote_domconfs {
1.212     raeburn  24038:     my ($dom,$cachekeys) = @_;
                   24039:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  24040:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   24041:     my %thismachine;
                   24042:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355     raeburn  24043:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394     raeburn  24044:                       'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410     raeburn  24045:                       'ipaccess','trust');
1.386     raeburn  24046:     my %cache_by_lonhost;
                   24047:     if (exists($cachekeys->{'samllanding'})) {
                   24048:         if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
                   24049:             my %landing = %{$cachekeys->{'samllanding'}};
                   24050:             my %domservers = &Apache::lonnet::get_servers($dom);
                   24051:             if (keys(%domservers)) {
                   24052:                 foreach my $server (keys(%domservers)) {
                   24053:                     my @cached;
                   24054:                     next if ($thismachine{$server});
                   24055:                     if ($landing{$server}) {
                   24056:                         push(@cached,&escape('samllanding').':'.&escape($server));
                   24057:                     }
                   24058:                     if (@cached) {
                   24059:                         $cache_by_lonhost{$server} = \@cached;
                   24060:                     }
                   24061:                 }
                   24062:             }
                   24063:         }
                   24064:     }
1.260     raeburn  24065:     if (keys(%servers)) {
1.205     raeburn  24066:         foreach my $server (keys(%servers)) {
                   24067:             next if ($thismachine{$server});
1.212     raeburn  24068:             my @cached;
                   24069:             foreach my $name (@posscached) {
                   24070:                 if ($cachekeys->{$name}) {
1.388     raeburn  24071:                     if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386     raeburn  24072:                         if (ref($cachekeys->{$name}) eq 'HASH') {
1.373     raeburn  24073:                             foreach my $key (keys(%{$cachekeys->{$name}})) {
                   24074:                                 push(@cached,&escape($name).':'.&escape($key));
                   24075:                             }
                   24076:                         }
                   24077:                     } else {
                   24078:                         push(@cached,&escape($name).':'.&escape($dom));
                   24079:                     }
1.212     raeburn  24080:                 }
                   24081:             }
1.386     raeburn  24082:             if ((exists($cache_by_lonhost{$server})) &&
                   24083:                 (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
                   24084:                 push(@cached,@{$cache_by_lonhost{$server}});
                   24085:             }
1.212     raeburn  24086:             if (@cached) {
                   24087:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   24088:             }
1.205     raeburn  24089:         }
                   24090:     }
                   24091:     return;
                   24092: }
                   24093: 
1.3       raeburn  24094: 1;

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