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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.401   ! raeburn     4: # $Id: domainprefs.pm,v 1.400 2021/12/28 03:26:44 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.69      raeburn   170: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   171: use LONCAPA::Enrollment;
1.81      raeburn   172: use LONCAPA::lonauthcgi();
1.275     raeburn   173: use LONCAPA::SSL;
1.9       raeburn   174: use File::Copy;
1.43      raeburn   175: use Locale::Language;
1.62      raeburn   176: use DateTime::TimeZone;
1.68      raeburn   177: use DateTime::Locale;
1.267     raeburn   178: use Time::HiRes qw( sleep );
1.373     raeburn   179: use Net::CIDR;
1.1       raeburn   180: 
1.155     raeburn   181: my $registered_cleanup;
                    182: my $modified_urls;
                    183: 
1.1       raeburn   184: sub handler {
                    185:     my $r=shift;
                    186:     if ($r->header_only) {
                    187:         &Apache::loncommon::content_type($r,'text/html');
                    188:         $r->send_http_header;
                    189:         return OK;
                    190:     }
                    191: 
1.91      raeburn   192:     my $context = 'domain';
1.1       raeburn   193:     my $dom = $env{'request.role.domain'};
1.5       albertel  194:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   195:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    196:         &Apache::loncommon::content_type($r,'text/html');
                    197:         $r->send_http_header;
                    198:     } else {
                    199:         $env{'user.error.msg'}=
                    200:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    201:         return HTTP_NOT_ACCEPTABLE;
                    202:     }
1.155     raeburn   203: 
                    204:     $registered_cleanup=0;
                    205:     @{$modified_urls}=();
                    206: 
1.1       raeburn   207:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    208:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   209:                                             ['phase','actions']);
1.30      raeburn   210:     my $phase = 'pickactions';
1.3       raeburn   211:     if ( exists($env{'form.phase'}) ) {
                    212:         $phase = $env{'form.phase'};
                    213:     }
1.150     raeburn   214:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   215:     my %domconfig =
1.6       raeburn   216:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   217:                 'quotas','autoenroll','autoupdate','autocreate',
                    218:                 'directorysrch','usercreation','usermodification',
                    219:                 'contacts','defaults','scantron','coursecategories',
                    220:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   221:                 'coursedefaults','usersessions','loadbalancing',
1.267     raeburn   222:                 'requestauthor','selfenrollment','inststatus',
1.372     raeburn   223:                 'ltitools','ssl','trust','lti','privacy','passwords',
1.394     raeburn   224:                 'proctoring','wafproxy','ipaccess'],$dom);
1.320     raeburn   225:     my %encconfig =
1.384     raeburn   226:         &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring'],$dom,undef,1);
1.297     raeburn   227:     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    228:         if (ref($encconfig{'ltitools'}) eq 'HASH') {
                    229:             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320     raeburn   230:                 if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
                    231:                     (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297     raeburn   232:                     foreach my $item ('key','secret') {
                    233:                         $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
                    234:                     }
                    235:                 }
                    236:             }
                    237:         }
                    238:     }
1.320     raeburn   239:     if (ref($domconfig{'lti'}) eq 'HASH') {
                    240:         if (ref($encconfig{'lti'}) eq 'HASH') {
                    241:             foreach my $id (keys(%{$domconfig{'lti'}})) {
                    242:                 if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
                    243:                     (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
                    244:                     foreach my $item ('key','secret') {
                    245:                         $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
                    246:                     }
                    247:                 }
                    248:             }
                    249:         }
                    250:     }
1.372     raeburn   251:     if (ref($domconfig{'proctoring'}) eq 'HASH') {
                    252:         if (ref($encconfig{'proctoring'}) eq 'HASH') {
                    253:             foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
                    254:                 if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
                    255:                     (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
                    256:                     foreach my $item ('key','secret') {
                    257:                         $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
                    258:                     }
                    259:                 }
                    260:             }
                    261:         }
                    262:     }
1.394     raeburn   263:     my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
                    264:                        'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373     raeburn   265:                        'contacts','privacy','usercreation','selfcreation',
1.374     raeburn   266:                        'usermodification','scantron','requestcourses','requestauthor',
1.373     raeburn   267:                        'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372     raeburn   268:                        'ltitools','proctoring','selfenrollment','usersessions','ssl',
                    269:                        'trust','lti');
1.171     raeburn   270:     my %existing;
                    271:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    272:         %existing = %{$domconfig{'loadbalancing'}};
                    273:     }
                    274:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   275:         push(@prefs_order,'loadbalancing');
                    276:     }
1.30      raeburn   277:     my %prefs = (
                    278:         'rolecolors' =>
                    279:                    { text => 'Default color schemes',
1.67      raeburn   280:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   281:                      header => [{col1 => 'Student Settings',
                    282:                                  col2 => '',},
                    283:                                 {col1 => 'Coordinator Settings',
                    284:                                  col2 => '',},
                    285:                                 {col1 => 'Author Settings',
                    286:                                  col2 => '',},
                    287:                                 {col1 => 'Administrator Settings',
                    288:                                  col2 => '',}],
1.230     raeburn   289:                       print => \&print_rolecolors,
                    290:                       modify => \&modify_rolecolors,
1.30      raeburn   291:                     },
1.110     raeburn   292:         'login' =>
1.30      raeburn   293:                     { text => 'Log-in page options',
1.67      raeburn   294:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   295:                       header => [{col1 => 'Log-in Page Items',
                    296:                                   col2 => '',},
                    297:                                  {col1 => 'Log-in Help',
1.256     raeburn   298:                                   col2 => 'Value'},
                    299:                                  {col1 => 'Custom HTML in document head',
1.386     raeburn   300:                                   col2 => 'Value'},
                    301:                                  {col1 => 'SSO',
                    302:                                   col2 => 'Dual login: SSO and non-SSO options'},
                    303:                                 ],
1.230     raeburn   304:                       print => \&print_login,
                    305:                       modify => \&modify_login,
1.30      raeburn   306:                     },
1.43      raeburn   307:         'defaults' => 
1.236     raeburn   308:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   309:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   310:                       header => [{col1 => 'Setting',
1.236     raeburn   311:                                   col2 => 'Value'},
                    312:                                  {col1 => 'Institutional user types',
1.305     raeburn   313:                                   col2 => 'Name displayed'}],
1.230     raeburn   314:                       print => \&print_defaults,
                    315:                       modify => \&modify_defaults,
1.43      raeburn   316:                     },
1.381     raeburn   317:         'wafproxy' =>
                    318:                     { text => 'Web Application Firewall/Reverse Proxy',
1.373     raeburn   319:                       help => 'Domain_Configuration_WAF_Proxy',
1.381     raeburn   320:                       header => [{col1 => 'Domain(s)',
                    321:                                   col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373     raeburn   322:                                  },
1.381     raeburn   323:                                  {col1 => 'Domain(s)',
                    324:                                   col2 => 'WAF Configuration',}],
1.373     raeburn   325:                       print => \&print_wafproxy,
1.381     raeburn   326:                       modify => \&modify_wafproxy,
1.373     raeburn   327:                     },
1.354     raeburn   328:         'passwords' =>
                    329:                     { text => 'Passwords (Internal authentication)',
                    330:                       help => 'Domain_Configuration_Passwords',
                    331:                       header => [{col1 => 'Resetting Forgotten Password',
                    332:                                   col2 => 'Settings'},
                    333:                                  {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                    334:                                   col2 => 'Settings'},
                    335:                                  {col1 => 'Rules for LON-CAPA Passwords',
                    336:                                   col2 => 'Settings'},
                    337:                                  {col1 => 'Course Owner Changing Student Passwords',
                    338:                                   col2 => 'Settings'}],
                    339:                       print => \&print_passwords,
                    340:                       modify => \&modify_passwords,
                    341:                     },
1.30      raeburn   342:         'quotas' => 
1.197     raeburn   343:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   344:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   345:                       header => [{col1 => 'User affiliation',
1.72      raeburn   346:                                   col2 => 'Available tools',
1.213     raeburn   347:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230     raeburn   348:                       print => \&print_quotas,
                    349:                       modify => \&modify_quotas,
1.30      raeburn   350:                     },
                    351:         'autoenroll' =>
                    352:                    { text => 'Auto-enrollment settings',
1.67      raeburn   353:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   354:                      header => [{col1 => 'Configuration setting',
                    355:                                  col2 => 'Value(s)'}],
1.230     raeburn   356:                      print => \&print_autoenroll,
                    357:                      modify => \&modify_autoenroll,
1.30      raeburn   358:                    },
                    359:         'autoupdate' => 
                    360:                    { text => 'Auto-update settings',
1.67      raeburn   361:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   362:                      header => [{col1 => 'Setting',
                    363:                                  col2 => 'Value',},
1.131     raeburn   364:                                 {col1 => 'Setting',
                    365:                                  col2 => 'Affiliation'},
1.43      raeburn   366:                                 {col1 => 'User population',
1.227     bisitz    367:                                  col2 => 'Updatable user data'}],
1.230     raeburn   368:                      print => \&print_autoupdate,
                    369:                      modify => \&modify_autoupdate,
1.30      raeburn   370:                   },
1.125     raeburn   371:         'autocreate' => 
                    372:                   { text => 'Auto-course creation settings',
                    373:                      help => 'Domain_Configuration_Auto_Creation',
                    374:                      header => [{col1 => 'Configuration Setting',
                    375:                                  col2 => 'Value',}],
1.230     raeburn   376:                      print => \&print_autocreate,
                    377:                      modify => \&modify_autocreate,
1.125     raeburn   378:                   },
1.30      raeburn   379:         'directorysrch' => 
1.277     raeburn   380:                   { text => 'Directory searches',
1.67      raeburn   381:                     help => 'Domain_Configuration_InstDirectory_Search',
1.277     raeburn   382:                     header => [{col1 => 'Institutional Directory Setting',
                    383:                                 col2 => 'Value',},
                    384:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   385:                                 col2 => 'Value',}],
1.230     raeburn   386:                     print => \&print_directorysrch,
                    387:                     modify => \&modify_directorysrch,
1.30      raeburn   388:                   },
                    389:         'contacts' =>
1.286     raeburn   390:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   391:                     help => 'Domain_Configuration_Contact_Info',
1.286     raeburn   392:                     header => [{col1 => 'Default e-mail addresses',
                    393:                                 col2 => 'Value',},
                    394:                                {col1 => 'Recipient(s) for notifications',
                    395:                                 col2 => 'Value',},
1.340     raeburn   396:                                {col1 => 'Nightly status check e-mail',
                    397:                                 col2 => 'Settings',},
1.286     raeburn   398:                                {col1 => 'Ask helpdesk form settings',
                    399:                                 col2 => 'Value',},],
1.230     raeburn   400:                     print => \&print_contacts,
                    401:                     modify => \&modify_contacts,
1.30      raeburn   402:                   },
                    403:         'usercreation' => 
                    404:                   { text => 'User creation',
1.67      raeburn   405:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   406:                     header => [{col1 => 'Format rule type',
                    407:                                 col2 => 'Format rules in force'},
1.34      raeburn   408:                                {col1 => 'User account creation',
                    409:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   410:                                {col1 => 'Context',
1.43      raeburn   411:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   412:                     print => \&print_usercreation,
                    413:                     modify => \&modify_usercreation,
1.30      raeburn   414:                   },
1.224     raeburn   415:         'selfcreation' => 
                    416:                   { text => 'Users self-creating accounts',
                    417:                     help => 'Domain_Configuration_Self_Creation', 
                    418:                     header => [{col1 => 'Self-creation with institutional username',
                    419:                                 col2 => 'Enabled?'},
                    420:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    421:                                 col2 => 'Information user can enter'},
1.303     raeburn   422:                                {col1 => 'Self-creation with e-mail verification',
1.224     raeburn   423:                                 col2 => 'Settings'}],
1.230     raeburn   424:                     print => \&print_selfcreation,
                    425:                     modify => \&modify_selfcreation,
1.224     raeburn   426:                   },
1.69      raeburn   427:         'usermodification' =>
1.33      raeburn   428:                   { text => 'User modification',
1.67      raeburn   429:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   430:                     header => [{col1 => 'Target user has role',
1.227     bisitz    431:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   432:                                {col1 => 'Target user has role',
1.227     bisitz    433:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   434:                     print => \&print_usermodification,
                    435:                     modify => \&modify_usermodification,
1.33      raeburn   436:                   },
1.69      raeburn   437:         'scantron' =>
1.346     raeburn   438:                   { text => 'Bubblesheet format',
1.67      raeburn   439:                     help => 'Domain_Configuration_Scantron_Format',
1.346     raeburn   440:                     header => [ {col1 => 'Bubblesheet format file',
                    441:                                  col2 => ''},
                    442:                                 {col1 => 'Bubblesheet data upload formats',
                    443:                                  col2 => 'Settings'}],
1.230     raeburn   444:                     print => \&print_scantron,
                    445:                     modify => \&modify_scantron,
1.46      raeburn   446:                   },
1.86      raeburn   447:         'requestcourses' => 
                    448:                  {text => 'Request creation of courses',
                    449:                   help => 'Domain_Configuration_Request_Courses',
                    450:                   header => [{col1 => 'User affiliation',
1.102     raeburn   451:                               col2 => 'Availability/Processing of requests',},
                    452:                              {col1 => 'Setting',
1.216     raeburn   453:                               col2 => 'Value'},
                    454:                              {col1 => 'Available textbooks',
1.235     raeburn   455:                               col2 => ''},
1.242     raeburn   456:                              {col1 => 'Available templates',
                    457:                               col2 => ''},
1.235     raeburn   458:                              {col1 => 'Validation (not official courses)',
                    459:                               col2 => 'Value'},],
1.230     raeburn   460:                   print => \&print_quotas,
                    461:                   modify => \&modify_quotas,
1.86      raeburn   462:                  },
1.163     raeburn   463:         'requestauthor' =>
1.223     bisitz    464:                  {text => 'Request Authoring Space',
1.163     raeburn   465:                   help => 'Domain_Configuration_Request_Author',
                    466:                   header => [{col1 => 'User affiliation',
                    467:                               col2 => 'Availability/Processing of requests',},
                    468:                              {col1 => 'Setting',
                    469:                               col2 => 'Value'}],
1.230     raeburn   470:                   print => \&print_quotas,
                    471:                   modify => \&modify_quotas,
1.163     raeburn   472:                  },
1.69      raeburn   473:         'coursecategories' =>
1.120     raeburn   474:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   475:                     help => 'Domain_Configuration_Cataloging_Courses',
1.238     raeburn   476:                     header => [{col1 => 'Catalog type/availability',
                    477:                                 col2 => '',},
                    478:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   479:                                 col2 => '',},
                    480:                                {col1 => 'Categories',
                    481:                                 col2 => '',
                    482:                                }],
1.230     raeburn   483:                     print => \&print_coursecategories,
                    484:                     modify => \&modify_coursecategories,
1.69      raeburn   485:                   },
                    486:         'serverstatuses' =>
1.77      raeburn   487:                  {text   => 'Access to server status pages',
1.69      raeburn   488:                   help   => 'Domain_Configuration_Server_Status',
                    489:                   header => [{col1 => 'Status Page',
                    490:                               col2 => 'Other named users',
                    491:                               col3 => 'Specific IPs',
                    492:                             }],
1.230     raeburn   493:                   print => \&print_serverstatuses,
                    494:                   modify => \&modify_serverstatuses,
1.69      raeburn   495:                  },
1.118     jms       496:         'helpsettings' =>
1.282     raeburn   497:                  {text   => 'Support settings',
1.118     jms       498:                   help   => 'Domain_Configuration_Help_Settings',
1.282     raeburn   499:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    500:                               col2 => 'Value'},
                    501:                              {col1 => 'Helpdesk Roles',
                    502:                               col2 => 'Settings'},],
1.230     raeburn   503:                   print  => \&print_helpsettings,
                    504:                   modify => \&modify_helpsettings,
1.118     jms       505:                  },
1.121     raeburn   506:         'coursedefaults' => 
                    507:                  {text => 'Course/Community defaults',
                    508:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   509:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    510:                               col2 => 'Value',},
                    511:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    512:                               col2 => 'Value',},],
1.230     raeburn   513:                   print => \&print_coursedefaults,
                    514:                   modify => \&modify_coursedefaults,
1.121     raeburn   515:                  },
1.231     raeburn   516:         'selfenrollment' => 
                    517:                  {text   => 'Self-enrollment in Course/Community',
                    518:                   help   => 'Domain_Configuration_Selfenrollment',
                    519:                   header => [{col1 => 'Configuration Rights',
                    520:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    521:                              {col1 => 'Defaults',
                    522:                               col2 => 'Value'},
                    523:                              {col1 => 'Self-enrollment validation (optional)',
                    524:                               col2 => 'Value'},],
                    525:                   print => \&print_selfenrollment,
                    526:                   modify => \&modify_selfenrollment,
                    527:                  },
1.120     raeburn   528:         'privacy' => 
1.357     raeburn   529:                  {text   => 'Availability of User Information',
1.120     raeburn   530:                   help   => 'Domain_Configuration_User_Privacy',
1.357     raeburn   531:                   header => [{col1 => 'Role assigned in different domain',
                    532:                               col2 => 'Approval options'},
                    533:                              {col1 => 'Role assigned in different domain to user of type',
                    534:                               col2 => 'User information available in that domain'},
                    535:                              {col1 => "Role assigned in user's domain",
                    536:                               col2 => 'Information viewable by privileged user'},
                    537:                              {col1 => "Role assigned in user's domain",
                    538:                               col2 => 'Information viewable by unprivileged user'}],
1.230     raeburn   539:                   print => \&print_privacy,
                    540:                   modify => \&modify_privacy,
1.120     raeburn   541:                  },
1.141     raeburn   542:         'usersessions' =>
1.145     raeburn   543:                  {text  => 'User session hosting/offloading',
1.137     raeburn   544:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   545:                   header => [{col1 => 'Domain server',
                    546:                               col2 => 'Servers to offload sessions to when busy'},
                    547:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   548:                               col2 => 'Rules'},
                    549:                              {col1 => "Hosting domain's own users elsewhere",
                    550:                               col2 => 'Rules'}],
1.230     raeburn   551:                   print => \&print_usersessions,
                    552:                   modify => \&modify_usersessions,
1.137     raeburn   553:                  },
1.279     raeburn   554:         'loadbalancing' =>
1.185     raeburn   555:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   556:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   557:                   header => [{col1 => 'Balancers',
1.150     raeburn   558:                               col2 => 'Default destinations',
1.183     bisitz    559:                               col3 => 'User affiliation',
1.150     raeburn   560:                               col4 => 'Overrides'},
                    561:                             ],
1.230     raeburn   562:                   print => \&print_loadbalancing,
                    563:                   modify => \&modify_loadbalancing,
1.150     raeburn   564:                  },
1.279     raeburn   565:         'ltitools' => 
1.267     raeburn   566:                  {text => 'External Tools (LTI)',
1.296     raeburn   567:                   help => 'Domain_Configuration_LTI_Tools',
1.267     raeburn   568:                   header => [{col1 => 'Setting',
                    569:                               col2 => 'Value',}],
                    570:                   print => \&print_ltitools,
                    571:                   modify => \&modify_ltitools,
                    572:                  },
1.372     raeburn   573:         'proctoring' =>
                    574:                  {text => 'Remote Proctoring Integration',
                    575:                   help => 'Domain_Configuration_Proctoring',
                    576:                   header => [{col1 => 'Name',
                    577:                               col2 => 'Configuration'}],
                    578:                   print => \&print_proctoring,
                    579:                   modify => \&modify_proctoring,
                    580:                  },
1.279     raeburn   581:         'ssl' =>
1.275     raeburn   582:                  {text  => 'LON-CAPA Network (SSL)',
                    583:                   help  => 'Domain_Configuration_Network_SSL',
                    584:                   header => [{col1 => 'Server',
                    585:                               col2 => 'Certificate Status'},
                    586:                              {col1 => 'Connections to other servers',
                    587:                               col2 => 'Rules'},
1.293     raeburn   588:                              {col1 => 'Connections from other servers',
                    589:                               col2 => 'Rules'},
1.275     raeburn   590:                              {col1 => "Replicating domain's published content",
                    591:                               col2 => 'Rules'}],
                    592:                   print => \&print_ssl,
                    593:                   modify => \&modify_ssl,
                    594:                  },
1.279     raeburn   595:         'trust' =>
                    596:                  {text   => 'Trust Settings',
                    597:                   help   => 'Domain_Configuration_Trust',
                    598:                   header => [{col1 => "Access to this domain's content by others",
                    599:                               col2 => 'Rules'},
                    600:                              {col1 => "Access to other domain's content by this domain",
                    601:                               col2 => 'Rules'},
                    602:                              {col1 => "Enrollment in this domain's courses by others",
                    603:                               col2 => 'Rules',},
                    604:                              {col1 => "Co-author roles in this domain for others",
                    605:                               col2 => 'Rules',},
                    606:                              {col1 => "Co-author roles for this domain's users elsewhere",
                    607:                               col2 => 'Rules',},
                    608:                              {col1 => "Domain roles in this domain assignable to others",
                    609:                               col2 => 'Rules'},
                    610:                              {col1 => "Course catalog for this domain displayed elsewhere",
                    611:                               col2 => 'Rules'},
                    612:                              {col1 => "Requests for creation of courses in this domain by others",
                    613:                               col2 => 'Rules'},
                    614:                              {col1 => "Users in other domains can send messages to this domain",
                    615:                               col2 => 'Rules'},],
                    616:                   print => \&print_trust,
                    617:                   modify => \&modify_trust,
                    618:                  },
1.320     raeburn   619:           'lti' =>
                    620:                  {text => 'LTI Provider',
                    621:                   help => 'Domain_Configuration_LTI_Provider',
                    622:                   header => [{col1 => 'Setting',
                    623:                               col2 => 'Value',}],
                    624:                   print => \&print_lti,
                    625:                   modify => \&modify_lti,
                    626:                  },
1.394     raeburn   627:            'ipaccess' =>
                    628:                        {text => 'IP-based access control',
                    629:                         help => 'Domain_Configuration_IP_Access',
                    630:                         header => [{col1 => 'Setting',
                    631:                                     col2 => 'Value'},],
                    632:                         print  => \&print_ipaccess,
                    633:                         modify => \&modify_ipaccess,
                    634:                        },
1.3       raeburn   635:     );
1.110     raeburn   636:     if (keys(%servers) > 1) {
                    637:         $prefs{'login'}  = { text   => 'Log-in page options',
                    638:                              help   => 'Domain_Configuration_Login_Page',
                    639:                             header => [{col1 => 'Log-in Service',
                    640:                                         col2 => 'Server Setting',},
                    641:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   642:                                         col2 => ''},
                    643:                                        {col1 => 'Log-in Help',
1.256     raeburn   644:                                         col2 => 'Value'},
                    645:                                        {col1 => 'Custom HTML in document head',
1.386     raeburn   646:                                         col2 => 'Value'},
                    647:                                        {col1 => 'SSO',
                    648:                                         col2 => 'Dual login: SSO and non-SSO options'},
                    649:                                       ],
1.230     raeburn   650:                             print => \&print_login,
                    651:                             modify => \&modify_login,
1.110     raeburn   652:                            };
                    653:     }
1.174     foxr      654: 
1.6       raeburn   655:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   656:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   657:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   658:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   659:       text=>"Settings to display/modify"});
1.9       raeburn   660:     my $confname = $dom.'-domainconfig';
1.174     foxr      661: 
1.3       raeburn   662:     if ($phase eq 'process') {
1.212     raeburn   663:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    664:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   665:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   666:             $r->rflush();
1.212     raeburn   667:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   668:         }
1.30      raeburn   669:     } elsif ($phase eq 'display') {
1.192     raeburn   670:         my $js = &recaptcha_js().
1.236     raeburn   671:                  &toggle_display_js();
1.171     raeburn   672:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   673:             my ($othertitle,$usertypes,$types) =
                    674:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   675:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    676:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   677:                    &new_spares_js().
                    678:                    &common_domprefs_js().
                    679:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   680:         }
1.216     raeburn   681:         if (grep(/^requestcourses$/,@actions)) {
                    682:             my $javascript_validations;
                    683:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    684:             $js .= <<END;
                    685: <script type="text/javascript">
                    686: $javascript_validations
                    687: </script>
                    688: $coursebrowserjs
                    689: END
1.394     raeburn   690:         } elsif (grep(/^ipaccess$/,@actions)) {
                    691:             $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216     raeburn   692:         }
1.305     raeburn   693:         if (grep(/^selfcreation$/,@actions)) {
                    694:             $js .= &selfcreate_javascript();
                    695:         }
1.286     raeburn   696:         if (grep(/^contacts$/,@actions)) {
                    697:             $js .= &contacts_javascript();
                    698:         }
1.346     raeburn   699:         if (grep(/^scantron$/,@actions)) {
                    700:             $js .= &scantron_javascript();
                    701:         }
1.150     raeburn   702:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   703:     } else {
1.180     raeburn   704: # check if domconfig user exists for the domain.
                    705:         my $servadm = $r->dir_config('lonAdmEMail');
                    706:         my ($configuserok,$author_ok,$switchserver) =
                    707:             &config_check($dom,$confname,$servadm);
                    708:         unless ($configuserok eq 'ok') {
1.181     raeburn   709:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    710:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   711:                           $confname).
1.181     raeburn   712:                       '<br />'
                    713:             );
1.180     raeburn   714:             if ($switchserver) {
1.181     raeburn   715:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    716:                           '<br />'.
                    717:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    718:                           '<br />'.
                    719:                           &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).
                    720:                           '<br />'.
                    721:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    722:                 );
                    723:             } else {
                    724:                 $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.').
                    725:                           '<br />'.
                    726:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    727:                 );
1.180     raeburn   728:             }
                    729:             $r->print(&Apache::loncommon::end_page());
                    730:             return OK;
                    731:         }
1.21      raeburn   732:         if (keys(%domconfig) == 0) {
                    733:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   734:             my @ids=&Apache::lonnet::current_machine_ids();
                    735:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   736:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   737:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   738:                 my $custom_img_count = 0;
                    739:                 foreach my $img (@loginimages) {
                    740:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    741:                         $custom_img_count ++;
                    742:                     }
                    743:                 }
                    744:                 foreach my $role (@roles) {
                    745:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    746:                         $custom_img_count ++;
                    747:                     }
                    748:                 }
                    749:                 if ($custom_img_count > 0) {
1.94      raeburn   750:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   751:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   752:                     $r->print(
                    753:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    754:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    755:     &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 />'.
                    756:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    757:                     if ($switch_server) {
1.30      raeburn   758:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   759:                     }
1.91      raeburn   760:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   761:                     return OK;
                    762:                 }
                    763:             }
                    764:         }
1.91      raeburn   765:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   766:     }
                    767:     return OK;
                    768: }
                    769: 
                    770: sub process_changes {
1.205     raeburn   771:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   772:     my %domconfig;
                    773:     if (ref($values) eq 'HASH') {
                    774:         %domconfig = %{$values};
                    775:     }
1.3       raeburn   776:     my $output;
                    777:     if ($action eq 'login') {
1.205     raeburn   778:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   779:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   780:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   781:                                      $lastactref,%domconfig);
1.3       raeburn   782:     } elsif ($action eq 'quotas') {
1.216     raeburn   783:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   784:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   785:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   786:     } elsif ($action eq 'autoupdate') {
                    787:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   788:     } elsif ($action eq 'autocreate') {
                    789:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   790:     } elsif ($action eq 'directorysrch') {
1.295     raeburn   791:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   792:     } elsif ($action eq 'usercreation') {
1.28      raeburn   793:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   794:     } elsif ($action eq 'selfcreation') {
1.305     raeburn   795:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   796:     } elsif ($action eq 'usermodification') {
                    797:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   798:     } elsif ($action eq 'contacts') {
1.205     raeburn   799:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   800:     } elsif ($action eq 'defaults') {
1.212     raeburn   801:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   802:     } elsif ($action eq 'scantron') {
1.205     raeburn   803:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   804:     } elsif ($action eq 'coursecategories') {
1.239     raeburn   805:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   806:     } elsif ($action eq 'serverstatuses') {
                    807:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   808:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   809:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   810:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   811:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       812:     } elsif ($action eq 'helpsettings') {
1.285     raeburn   813:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121     raeburn   814:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   815:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   816:     } elsif ($action eq 'selfenrollment') {
                    817:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   818:     } elsif ($action eq 'usersessions') {
1.212     raeburn   819:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   820:     } elsif ($action eq 'loadbalancing') {
                    821:         $output = &modify_loadbalancing($dom,%domconfig);
1.267     raeburn   822:     } elsif ($action eq 'ltitools') {
                    823:         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372     raeburn   824:     } elsif ($action eq 'proctoring') {
                    825:         $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275     raeburn   826:     } elsif ($action eq 'ssl') {
                    827:         $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279     raeburn   828:     } elsif ($action eq 'trust') {
                    829:         $output = &modify_trust($dom,$lastactref,%domconfig);
1.320     raeburn   830:     } elsif ($action eq 'lti') {
                    831:         $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357     raeburn   832:     } elsif ($action eq 'privacy') {
                    833:         $output = &modify_privacy($dom,%domconfig);
1.354     raeburn   834:     } elsif ($action eq 'passwords') {
                    835:         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373     raeburn   836:     } elsif ($action eq 'wafproxy') {
                    837:         $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394     raeburn   838:     } elsif ($action eq 'ipaccess') {
                    839:         $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3       raeburn   840:     }
                    841:     return $output;
                    842: }
                    843: 
                    844: sub print_config_box {
1.9       raeburn   845:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   846:     my $rowtotal = 0;
1.49      raeburn   847:     my $output;
                    848:     if ($action eq 'coursecategories') {
                    849:         $output = &coursecategories_javascript($settings);
1.236     raeburn   850:     } elsif ($action eq 'defaults') {
                    851:         $output = &defaults_javascript($settings); 
1.354     raeburn   852:     } elsif ($action eq 'passwords') {
                    853:         $output = &passwords_javascript();
1.282     raeburn   854:     } elsif ($action eq 'helpsettings') {
                    855:         my (%privs,%levelscurrent);
                    856:         my %full=();
                    857:         my %levels=(
                    858:                      course => {},
                    859:                      domain => {},
                    860:                      system => {},
                    861:                    );
                    862:         my $context = 'domain';
                    863:         my $crstype = 'Course';
                    864:         my $formname = 'display';
                    865:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    866:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    867:         $output =
                    868:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, 
                    869:                                                       \@templateroles);
1.334     raeburn   870:     } elsif ($action eq 'ltitools') {
                    871:         $output .= &ltitools_javascript($settings);
                    872:     } elsif ($action eq 'lti') {
                    873:         $output .= &lti_javascript($settings);
1.372     raeburn   874:     } elsif ($action eq 'proctoring') {
                    875:         $output .= &proctoring_javascript($settings);
1.381     raeburn   876:     } elsif ($action eq 'wafproxy') {
                    877:         $output .= &wafproxy_javascript($dom);
1.385     raeburn   878:     } elsif ($action eq 'autoupdate') {
                    879:         $output .= &autoupdate_javascript();
1.399     raeburn   880:     } elsif ($action eq 'autoenroll') {
                    881:         $output .= &autoenroll_javascript();
1.386     raeburn   882:     } elsif ($action eq 'login') {
                    883:         $output .= &saml_javascript();
1.394     raeburn   884:     } elsif ($action eq 'ipaccess') {
                    885:         $output .= &ipaccess_javascript($settings);
1.91      raeburn   886:     }
1.236     raeburn   887:     $output .=
1.30      raeburn   888:          '<table class="LC_nested_outer">
1.3       raeburn   889:           <tr>
1.306     raeburn   890:            <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66      raeburn   891:            &mt($item->{text}).'&nbsp;'.
                    892:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    893:           '</tr>';
1.30      raeburn   894:     $rowtotal ++;
1.110     raeburn   895:     my $numheaders = 1;
                    896:     if (ref($item->{'header'}) eq 'ARRAY') {
                    897:         $numheaders = scalar(@{$item->{'header'}});
                    898:     }
                    899:     if ($numheaders > 1) {
1.64      raeburn   900:         my $colspan = '';
1.145     raeburn   901:         my $rightcolspan = '';
1.369     raeburn   902:         my $leftnobr = '';
1.238     raeburn   903:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   904:             ($action eq 'directorysrch') ||
1.386     raeburn   905:             (($action eq 'login') && ($numheaders < 5))) {
1.64      raeburn   906:             $colspan = ' colspan="2"';
                    907:         }
1.145     raeburn   908:         if ($action eq 'usersessions') {
                    909:             $rightcolspan = ' colspan="3"'; 
                    910:         }
1.369     raeburn   911:         if ($action eq 'passwords') {
                    912:             $leftnobr = ' LC_nobreak';
                    913:         }
1.30      raeburn   914:         $output .= '
1.3       raeburn   915:           <tr>
                    916:            <td>
                    917:             <table class="LC_nested">
                    918:              <tr class="LC_info_row">
1.369     raeburn   919:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   920:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   921:              </tr>';
1.69      raeburn   922:         $rowtotal ++;
1.230     raeburn   923:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   924:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   925:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286     raeburn   926:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373     raeburn   927:             ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230     raeburn   928:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354     raeburn   929:         } elsif ($action eq 'passwords') {
                    930:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   931:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   932:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346     raeburn   933:         } elsif ($action eq 'scantron') {
                    934:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   935:         } elsif ($action eq 'login') {
1.386     raeburn   936:             if ($numheaders == 5) {
1.168     raeburn   937:                 $colspan = ' colspan="2"';
                    938:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    939:             } else {
                    940:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    941:             }
1.230     raeburn   942:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   943:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       944:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   945:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   946:         }
1.30      raeburn   947:         $output .= '
1.6       raeburn   948:            </table>
                    949:           </td>
                    950:          </tr>
                    951:          <tr>
                    952:            <td>
                    953:             <table class="LC_nested">
                    954:              <tr class="LC_info_row">
1.230     raeburn   955:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    956:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   957:              </tr>';
                    958:             $rowtotal ++;
1.230     raeburn   959:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    960:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn   961:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.357     raeburn   962:             ($action eq 'trust') || ($action eq 'contacts') ||
                    963:             ($action eq 'privacy') || ($action eq 'passwords')) {
1.238     raeburn   964:             if ($action eq 'coursecategories') {
                    965:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    966:                 $colspan = ' colspan="2"';
1.279     raeburn   967:             } elsif ($action eq 'trust') {
                    968:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354     raeburn   969:             } elsif ($action eq 'passwords') {
                    970:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238     raeburn   971:             } else {
                    972:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    973:             }
1.279     raeburn   974:             if ($action eq 'trust') {
                    975:                 $output .= '
                    976:             </table>
                    977:           </td>
                    978:          </tr>';
                    979:                 my @trusthdrs = qw(2 3 4 5 6 7);
                    980:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                    981:                 for (my $i=0; $i<@trusthdrs; $i++) {
                    982:                     $output .= '
                    983:          <tr>
                    984:            <td>
                    985:             <table class="LC_nested">
                    986:              <tr class="LC_info_row">
                    987:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                    988:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                    989:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                    990:             </table>
                    991:           </td>
                    992:          </tr>';
                    993:                 }
                    994:                 $output .= '
                    995:          <tr>
                    996:            <td>
                    997:             <table class="LC_nested">
                    998:              <tr class="LC_info_row">
                    999:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                   1000:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                   1001:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1002:             } else {
                   1003:                 $output .= '
1.63      raeburn  1004:            </table>
                   1005:           </td>
                   1006:          </tr>
                   1007:          <tr>
                   1008:            <td>
                   1009:             <table class="LC_nested">
                   1010:              <tr class="LC_info_row">
                   1011:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn  1012:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn  1013:              </tr>'."\n";
1.279     raeburn  1014:                 if ($action eq 'coursecategories') {
                   1015:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357     raeburn  1016:                 } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354     raeburn  1017:                     if ($action eq 'passwords') {
                   1018:                         $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                   1019:                     } else {
                   1020:                         $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                   1021:                     }
                   1022:                     $output .= '
1.340     raeburn  1023:              </tr>
                   1024:             </table>
                   1025:            </td>
                   1026:           </tr>
                   1027:           <tr>
                   1028:            <td>
                   1029:             <table class="LC_nested">
                   1030:              <tr class="LC_info_row">
1.369     raeburn  1031:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354     raeburn  1032:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
                   1033:                     if ($action eq 'passwords') {
                   1034:                         $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                   1035:                     } else {
                   1036:                         $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1037:                     }
                   1038:                     $output .= '
1.340     raeburn  1039:             </table>
                   1040:           </td>
                   1041:          </tr>
                   1042:          <tr>';
1.279     raeburn  1043:                 } else {
                   1044:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1045:                 }
1.238     raeburn  1046:             }
1.63      raeburn  1047:             $rowtotal ++;
1.236     raeburn  1048:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282     raeburn  1049:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373     raeburn  1050:                  ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230     raeburn  1051:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346     raeburn  1052:         } elsif ($action eq 'scantron') {
                   1053:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293     raeburn  1054:         } elsif ($action eq 'ssl') {
                   1055:             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
                   1056:             </table>
                   1057:           </td>
                   1058:          </tr>
                   1059:          <tr>
                   1060:            <td>
                   1061:             <table class="LC_nested">
                   1062:              <tr class="LC_info_row">
                   1063:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1064:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                   1065:                            $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
                   1066:             </table>
                   1067:           </td>
                   1068:          </tr>
                   1069:          <tr>
                   1070:            <td>
                   1071:             <table class="LC_nested">
                   1072:              <tr class="LC_info_row">
                   1073:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1074:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                   1075:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn  1076:         } elsif ($action eq 'login') {
1.386     raeburn  1077:             if ($numheaders == 5) {
1.168     raeburn  1078:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1079:            </table>
                   1080:           </td>
                   1081:          </tr>
                   1082:          <tr>
                   1083:            <td>
                   1084:             <table class="LC_nested">
                   1085:              <tr class="LC_info_row">
                   1086:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn  1087:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn  1088:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1089:                 $rowtotal ++;
                   1090:             } else {
                   1091:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1092:             }
1.256     raeburn  1093:             $output .= '
                   1094:            </table>
                   1095:           </td>
                   1096:          </tr>
                   1097:          <tr>
                   1098:            <td>
                   1099:             <table class="LC_nested">
                   1100:              <tr class="LC_info_row">';
1.386     raeburn  1101:             if ($numheaders == 5) {
1.256     raeburn  1102:                 $output .= '
                   1103:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1104:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1105:              </tr>';
                   1106:             } else {
                   1107:                 $output .= '
                   1108:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1109:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                   1110:              </tr>';
                   1111:             }
                   1112:             $rowtotal ++;
1.386     raeburn  1113:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1114:            </table>
                   1115:           </td>
                   1116:          </tr>
                   1117:          <tr>
                   1118:            <td>
                   1119:             <table class="LC_nested">
                   1120:              <tr class="LC_info_row">';
                   1121:             if ($numheaders == 5) {
                   1122:                 $output .= '
                   1123:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1124:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
                   1125:              </tr>';
                   1126:             } else {
                   1127:                 $output .= '
                   1128:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1129:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1130:              </tr>';
                   1131:             }
                   1132:             $rowtotal ++;
                   1133:             $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn  1134:         } elsif ($action eq 'requestcourses') {
1.247     raeburn  1135:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                   1136:             $rowtotal ++;
                   1137:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn  1138:            </table>
                   1139:           </td>
                   1140:          </tr>
                   1141:          <tr>
                   1142:            <td>
                   1143:             <table class="LC_nested">
                   1144:              <tr class="LC_info_row">
                   1145:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1146:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn  1147:                        &textbookcourses_javascript($settings).
                   1148:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                   1149:             </table>
                   1150:            </td>
                   1151:           </tr>
                   1152:          <tr>
                   1153:            <td>
                   1154:             <table class="LC_nested">
                   1155:              <tr class="LC_info_row">
                   1156:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1157:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                   1158:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn  1159:             </table>
                   1160:            </td>
                   1161:           </tr>
                   1162:           <tr>
                   1163:            <td>
                   1164:             <table class="LC_nested">
                   1165:              <tr class="LC_info_row">
1.306     raeburn  1166:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1167:               <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn  1168:              </tr>'.
                   1169:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn  1170:         } elsif ($action eq 'requestauthor') {
                   1171:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn  1172:             $rowtotal ++;
1.122     jms      1173:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1174:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn  1175:            </table>
                   1176:           </td>
                   1177:          </tr>
                   1178:          <tr>
                   1179:            <td>
                   1180:             <table class="LC_nested">
                   1181:              <tr class="LC_info_row">
1.306     raeburn  1182:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69      raeburn  1183:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306     raeburn  1184:               <td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1185:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1186:              </tr>'.
1.30      raeburn  1187:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1188:            </table>
                   1189:           </td>
                   1190:          </tr>
                   1191:          <tr>
                   1192:            <td>
                   1193:             <table class="LC_nested">
                   1194:              <tr class="LC_info_row">
1.59      bisitz   1195:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1196:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1197:              </tr>'.
1.30      raeburn  1198:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1199:             $rowtotal += 2;
1.6       raeburn  1200:         }
1.3       raeburn  1201:     } else {
1.30      raeburn  1202:         $output .= '
1.3       raeburn  1203:           <tr>
                   1204:            <td>
                   1205:             <table class="LC_nested">
1.30      raeburn  1206:              <tr class="LC_info_row">';
1.277     raeburn  1207:         if ($action eq 'login') {
1.30      raeburn  1208:             $output .= '  
1.59      bisitz   1209:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1210:         } elsif ($action eq 'serverstatuses') {
                   1211:             $output .= '
1.306     raeburn  1212:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69      raeburn  1213:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1214: 
1.6       raeburn  1215:         } else {
1.30      raeburn  1216:             $output .= '
1.306     raeburn  1217:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1218:         }
1.72      raeburn  1219:         if (defined($item->{'header'}->[0]->{'col3'})) {
1.306     raeburn  1220:             $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72      raeburn  1221:                        &mt($item->{'header'}->[0]->{'col2'});
                   1222:             if ($action eq 'serverstatuses') {
                   1223:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1224:             } 
1.69      raeburn  1225:         } else {
1.306     raeburn  1226:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1227:                        &mt($item->{'header'}->[0]->{'col2'});
                   1228:         }
                   1229:         $output .= '</td>';
                   1230:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1231:             if (defined($item->{'header'}->[0]->{'col4'})) {
1.306     raeburn  1232:                 $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150     raeburn  1233:                             &mt($item->{'header'}->[0]->{'col3'});
                   1234:             } else {
1.306     raeburn  1235:                 $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1236:                            &mt($item->{'header'}->[0]->{'col3'});
                   1237:             }
1.69      raeburn  1238:             if ($action eq 'serverstatuses') {
                   1239:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1240:             }
                   1241:             $output .= '</td>';
1.6       raeburn  1242:         }
1.150     raeburn  1243:         if ($item->{'header'}->[0]->{'col4'}) {
1.306     raeburn  1244:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1245:                        &mt($item->{'header'}->[0]->{'col4'});
                   1246:         }
1.69      raeburn  1247:         $output .= '</tr>';
1.48      raeburn  1248:         $rowtotal ++;
1.168     raeburn  1249:         if ($action eq 'quotas') {
1.86      raeburn  1250:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1251:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.286     raeburn  1252:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
1.372     raeburn  1253:                  ($action eq 'ltitools') || ($action eq 'lti') ||
1.394     raeburn  1254:                  ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230     raeburn  1255:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1256:         }
1.3       raeburn  1257:     }
1.30      raeburn  1258:     $output .= '
1.3       raeburn  1259:    </table>
                   1260:   </td>
                   1261:  </tr>
1.30      raeburn  1262: </table><br />';
                   1263:     return ($output,$rowtotal);
1.1       raeburn  1264: }
                   1265: 
1.3       raeburn  1266: sub print_login {
1.168     raeburn  1267:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386     raeburn  1268:     my ($css_class,$datatable,$switchserver,%lt);
1.6       raeburn  1269:     my %choices = &login_choices();
1.386     raeburn  1270:     if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
                   1271:         %lt = &login_file_options();
                   1272:         $switchserver = &check_switchserver($dom,$confname);
                   1273:     }
1.168     raeburn  1274:     if ($caller eq 'service') {
1.149     raeburn  1275:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1276:         my $choice = $choices{'disallowlogin'};
                   1277:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1278:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306     raeburn  1279:                       '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1280:                       '<th>'.$choices{'server'}.'</th>'.
                   1281:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1282:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1283:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1284:         my %disallowed;
                   1285:         if (ref($settings) eq 'HASH') {
                   1286:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1287:                %disallowed = %{$settings->{'loginvia'}};
                   1288:             }
                   1289:         }
                   1290:         foreach my $lonhost (sort(keys(%servers))) {
                   1291:             my $direct = 'selected="selected"';
1.128     raeburn  1292:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1293:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1294:                     $direct = '';
                   1295:                 }
1.110     raeburn  1296:             }
1.115     raeburn  1297:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1298:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1299:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1300:                           '</option>';
1.184     raeburn  1301:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1302:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1303:                 my $selected = '';
1.128     raeburn  1304:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1305:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1306:                         $selected = 'selected="selected"';
                   1307:                     }
1.110     raeburn  1308:                 }
                   1309:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1310:                               $servers{$hostid}.'</option>';
                   1311:             }
1.128     raeburn  1312:             $datatable .= '</select></td>'.
                   1313:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1314:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1315:                 my $pathname = $path;
                   1316:                 if ($path eq 'custom') {
                   1317:                     $pathname = &mt('Custom Path').' ->';
                   1318:                 }
                   1319:                 my $selected = '';
                   1320:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1321:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1322:                         $selected = 'selected="selected"';
                   1323:                     }
                   1324:                 } elsif ($path eq '') {
                   1325:                     $selected = 'selected="selected"';
                   1326:                 }
                   1327:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1328:             }
                   1329:             $datatable .= '</select></td>';
                   1330:             my ($custom,$exempt);
                   1331:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1332:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1333:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1334:             }
                   1335:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1336:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1337:                           '</tr>';
1.110     raeburn  1338:         }
                   1339:         $datatable .= '</table></td></tr>';
                   1340:         return $datatable;
1.168     raeburn  1341:     } elsif ($caller eq 'page') {
                   1342:         my %defaultchecked = ( 
                   1343:                                'coursecatalog' => 'on',
1.188     raeburn  1344:                                'helpdesk'      => 'on',
1.168     raeburn  1345:                                'adminmail'     => 'off',
                   1346:                                'newuser'       => 'off',
                   1347:                              );
1.188     raeburn  1348:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1349:         my (%checkedon,%checkedoff);
1.42      raeburn  1350:         foreach my $item (@toggles) {
1.168     raeburn  1351:             if ($defaultchecked{$item} eq 'on') { 
                   1352:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1353:                 $checkedoff{$item} = ' ';
1.168     raeburn  1354:             } elsif ($defaultchecked{$item} eq 'off') {
                   1355:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1356:                 $checkedon{$item} = ' ';
                   1357:             }
1.1       raeburn  1358:         }
1.168     raeburn  1359:         my @images = ('img','logo','domlogo','login');
                   1360:         my @logintext = ('textcol','bgcol');
                   1361:         my @bgs = ('pgbg','mainbg','sidebg');
                   1362:         my @links = ('link','alink','vlink');
                   1363:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1364:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1365:         my (%is_custom,%designs);
                   1366:         my %defaults = (
                   1367:                        font => $defaultdesign{'login.font'},
                   1368:                        );
1.6       raeburn  1369:         foreach my $item (@images) {
1.168     raeburn  1370:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1371:             $defaults{'showlogo'}{$item} = 1;
                   1372:         }
                   1373:         foreach my $item (@bgs) {
                   1374:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1375:         }
1.41      raeburn  1376:         foreach my $item (@logintext) {
1.168     raeburn  1377:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1378:         }
1.168     raeburn  1379:         foreach my $item (@links) {
                   1380:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1381:         }
1.168     raeburn  1382:         if (ref($settings) eq 'HASH') {
                   1383:             foreach my $item (@toggles) {
                   1384:                 if ($settings->{$item} eq '1') {
                   1385:                     $checkedon{$item} =  ' checked="checked" ';
                   1386:                     $checkedoff{$item} = ' ';
                   1387:                 } elsif ($settings->{$item} eq '0') {
                   1388:                     $checkedoff{$item} =  ' checked="checked" ';
                   1389:                     $checkedon{$item} = ' ';
                   1390:                 }
                   1391:             }
                   1392:             foreach my $item (@images) {
                   1393:                 if (defined($settings->{$item})) {
                   1394:                     $designs{$item} = $settings->{$item};
                   1395:                     $is_custom{$item} = 1;
                   1396:                 }
                   1397:                 if (defined($settings->{'showlogo'}{$item})) {
                   1398:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1399:                 }
                   1400:             }
                   1401:             foreach my $item (@logintext) {
                   1402:                 if ($settings->{$item} ne '') {
                   1403:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1404:                     $is_custom{$item} = 1;
                   1405:                 }
                   1406:             }
                   1407:             if ($settings->{'font'} ne '') {
                   1408:                 $designs{'font'} = $settings->{'font'};
                   1409:                 $is_custom{'font'} = 1;
                   1410:             }
                   1411:             foreach my $item (@bgs) {
                   1412:                 if ($settings->{$item} ne '') {
                   1413:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1414:                     $is_custom{$item} = 1;
                   1415:                 }
                   1416:             }
                   1417:             foreach my $item (@links) {
                   1418:                 if ($settings->{$item} ne '') {
                   1419:                     $designs{'links'}{$item} = $settings->{$item};
                   1420:                     $is_custom{$item} = 1;
                   1421:                 }
                   1422:             }
                   1423:         } else {
                   1424:             if ($designhash{$dom.'.login.font'} ne '') {
                   1425:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1426:                 $is_custom{'font'} = 1;
                   1427:             }
                   1428:             foreach my $item (@images) {
                   1429:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1430:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1431:                     $is_custom{$item} = 1;
                   1432:                 }
                   1433:             }
                   1434:             foreach my $item (@bgs) {
                   1435:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1436:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1437:                     $is_custom{$item} = 1;
                   1438:                 }
1.6       raeburn  1439:             }
1.168     raeburn  1440:             foreach my $item (@links) {
                   1441:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1442:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1443:                     $is_custom{$item} = 1;
                   1444:                 }
1.6       raeburn  1445:             }
                   1446:         }
1.168     raeburn  1447:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1448:                                                       logo => 'Institution Logo',
                   1449:                                                       domlogo => 'Domain Logo',
                   1450:                                                       login => 'Login box');
                   1451:         my $itemcount = 1;
                   1452:         foreach my $item (@toggles) {
                   1453:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1454:             $datatable .=  
                   1455:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1456:                 '</td><td>'.
                   1457:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1458:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1459:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1460:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1461:                 '</tr>';
                   1462:             $itemcount ++;
1.6       raeburn  1463:         }
1.168     raeburn  1464:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1465:         $datatable .= '</tr></table></td></tr>';
                   1466:     } elsif ($caller eq 'help') {
1.386     raeburn  1467:         my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168     raeburn  1468:         my $itemcount = 1;
                   1469:         $defaulturl = '/adm/loginproblems.html';
                   1470:         $defaulttype = 'default';
                   1471:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1472:         my @currlangs;
                   1473:         if (ref($settings) eq 'HASH') {
                   1474:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1475:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1476:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1477:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1478:                     $type{$key} = 'custom';
                   1479:                     unless ($key eq 'nolang') {
                   1480:                         push(@currlangs,$key);
                   1481:                     }
                   1482:                 }
                   1483:             } elsif ($settings->{'helpurl'} ne '') {
                   1484:                 $type{'nolang'} = 'custom';
                   1485:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1486:             }
                   1487:         }
1.168     raeburn  1488:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1489:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1490:             $datatable .= '<tr'.$css_class.'>';
                   1491:             if ($url{$lang} eq '') {
                   1492:                 $url{$lang} = $defaulturl;
                   1493:             }
                   1494:             if ($type{$lang} eq '') {
                   1495:                 $type{$lang} = $defaulttype;
                   1496:             }
                   1497:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1498:             if ($lang eq 'nolang') {
                   1499:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1500:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1501:             } else {
                   1502:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1503:                                   $langchoices{$lang},
                   1504:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1505:             }
                   1506:             $datatable .= '</span></td>'."\n".
                   1507:                           '<td class="LC_left_item">';
                   1508:             if ($type{$lang} eq 'custom') {
                   1509:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1510:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1511:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1512:             } else {
                   1513:                 $datatable .= $lt{'upl'};
                   1514:             }
                   1515:             $datatable .='<br />';
                   1516:             if ($switchserver) {
                   1517:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1518:             } else {
                   1519:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1520:             }
1.168     raeburn  1521:             $datatable .= '</td></tr>';
                   1522:             $itemcount ++;
1.6       raeburn  1523:         }
1.168     raeburn  1524:         my @addlangs;
                   1525:         foreach my $lang (sort(keys(%langchoices))) {
                   1526:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1527:             push(@addlangs,$lang);
                   1528:         }
                   1529:         if (@addlangs > 0) {
                   1530:             my %toadd;
                   1531:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1532:             $toadd{''} = &mt('Select');
                   1533:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1534:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1535:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1536:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1537:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1538:             if ($switchserver) {
                   1539:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1540:             } else {
                   1541:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1542:             }
1.168     raeburn  1543:             $datatable .= '</td></tr>';
1.169     raeburn  1544:             $itemcount ++;
1.6       raeburn  1545:         }
1.169     raeburn  1546:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1547:     } elsif ($caller eq 'headtag') {
                   1548:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1549:         my $choice = $choices{'headtag'};
                   1550:         $css_class = ' class="LC_odd_row"';
                   1551:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1552:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1553:                       '<th>'.$choices{'current'}.'</th>'.
                   1554:                       '<th>'.$choices{'action'}.'</th>'.
                   1555:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1556:         my (%currurls,%currexempt);
                   1557:         if (ref($settings) eq 'HASH') {
                   1558:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1559:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1560:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1561:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1562:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1563:                     }
                   1564:                 }
                   1565:             }
                   1566:         }
                   1567:         foreach my $lonhost (sort(keys(%domservers))) {
                   1568:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1569:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1570:             if ($currurls{$lonhost}) {
                   1571:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1572:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1573:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1574:                               '">'.$lt{'curr'}.'</a></td>'.
                   1575:                               '<td><span class="LC_nobreak"><label>'.
                   1576:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1577:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1578:             } else {
                   1579:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1580:             }
                   1581:             $datatable .='<br />';
                   1582:             if ($switchserver) {
                   1583:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1584:             } else {
                   1585:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1586:             }
1.330     raeburn  1587:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256     raeburn  1588:         }
                   1589:         $datatable .= '</table></td></tr>';
1.386     raeburn  1590:     } elsif ($caller eq 'saml') {
                   1591:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1592:         $datatable .= '<tr><td colspan="3" style="text-align: left">'.
                   1593:                       '<table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1594:                       '<th>'.$choices{'samllanding'}.'</th>'.
                   1595:                       '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
                   1596:         my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
                   1597:         foreach my $lonhost (keys(%domservers)) {
                   1598:             $samlurl{$lonhost} = '/adm/sso';
                   1599:             $styleon{$lonhost} = 'display:none';
                   1600:             $styleoff{$lonhost} = '';
                   1601:         }
                   1602:         if (ref($settings->{'saml'}) eq 'HASH') {
                   1603:             foreach my $lonhost (keys(%{$settings->{'saml'}})) {
                   1604:                 if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
                   1605:                     $saml{$lonhost} = 1;
                   1606:                     $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
                   1607:                     $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
                   1608:                     $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                   1609:                     $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                   1610:                     $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
                   1611:                     $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                   1612:                     $styleon{$lonhost} = '';
                   1613:                     $styleoff{$lonhost} = 'display:none';
                   1614:                 } else {
                   1615:                     $styleon{$lonhost} = 'display:none';
                   1616:                     $styleoff{$lonhost} = '';
                   1617:                 }
                   1618:             }
                   1619:         }
                   1620:         my $itemcount = 1;
                   1621:         foreach my $lonhost (sort(keys(%domservers))) {
                   1622:             my $samlon = ' ';
                   1623:             my $samloff = ' checked="checked" ';
                   1624:             if ($saml{$lonhost}) {
                   1625:                 $samlon = $samloff;
                   1626:                 $samloff = ' ';
                   1627:             }
                   1628:             my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1629:             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
                   1630:                           '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
                   1631:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
                   1632:                           &mt('No').'</label>'.('&nbsp;'x2).
                   1633:                           '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
                   1634:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
                   1635:                           &mt('Yes').'</label></span></td>'.
                   1636:                           '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
                   1637:                           '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
                   1638:                           '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
                   1639:                           '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
                   1640:                           '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
                   1641:                           '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
                   1642:                           '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
                   1643:                           $samltext{$lonhost}.'" /></td><td>';
                   1644:             if ($samlimg{$lonhost}) {
                   1645:                 $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
                   1646:                               '<span class="LC_nobreak"><label>'.
                   1647:                               '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
                   1648:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1649:             } else {
                   1650:                 $datatable .= $lt{'upl'};
                   1651:             }
                   1652:             $datatable .='<br />';
                   1653:             if ($switchserver) {
                   1654:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1655:             } else {
                   1656:                 $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
                   1657:             }
                   1658:             $datatable .= '</td>'.
                   1659:                           '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
                   1660:                           'value="'.$samlalt{$lonhost}.'" /></td>'.
                   1661:                           '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
                   1662:                           'value="'.$samlurl{$lonhost}.'" /></td>'.
                   1663:                           '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
                   1664:                           $samltitle{$lonhost}.'</textarea></td>'.
                   1665:                           '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
                   1666:                           'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                   1667:                           '</table></td>'.
                   1668:                           '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%">&nbsp;</td></tr>';
                   1669:            $itemcount ++;
                   1670:         }
                   1671:         $datatable .= '</table></td></tr>';
1.1       raeburn  1672:     }
1.6       raeburn  1673:     return $datatable;
                   1674: }
                   1675: 
                   1676: sub login_choices {
                   1677:     my %choices =
                   1678:         &Apache::lonlocal::texthash (
1.116     bisitz   1679:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1680:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1681:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1682:             disallowlogin => "Login page requests redirected",
                   1683:             hostid        => "Server",
1.128     raeburn  1684:             server        => "Redirect to:",
                   1685:             serverpath    => "Path",
                   1686:             custompath    => "Custom", 
                   1687:             exempt        => "Exempt IP(s)",
1.110     raeburn  1688:             directlogin   => "No redirect",
                   1689:             newuser       => "Link to create a user account",
                   1690:             img           => "Header",
                   1691:             logo          => "Main Logo",
                   1692:             domlogo       => "Domain Logo",
                   1693:             login         => "Log-in Header", 
                   1694:             textcol       => "Text color",
                   1695:             bgcol         => "Box color",
                   1696:             bgs           => "Background colors",
                   1697:             links         => "Link colors",
                   1698:             font          => "Font color",
                   1699:             pgbg          => "Header",
                   1700:             mainbg        => "Page",
                   1701:             sidebg        => "Login box",
                   1702:             link          => "Link",
                   1703:             alink         => "Active link",
                   1704:             vlink         => "Visited link",
1.256     raeburn  1705:             headtag       => "Custom markup",
                   1706:             action        => "Action",
                   1707:             current       => "Current",
1.386     raeburn  1708:             samllanding   => "Dual login?",
                   1709:             samloptions   => "Options",
1.6       raeburn  1710:         );
                   1711:     return %choices;
                   1712: }
                   1713: 
1.386     raeburn  1714: sub login_file_options {
                   1715:       return &Apache::lonlocal::texthash(
                   1716:                                            del     => 'Delete?',
                   1717:                                            rep     => 'Replace:',
                   1718:                                            upl     => 'Upload:',
                   1719:                                            curr    => 'View contents',
                   1720:                                            default => 'Default',
                   1721:                                            custom  => 'Custom',
                   1722:                                            none    => 'None',
                   1723:       );
                   1724: }
                   1725: 
1.394     raeburn  1726: sub print_ipaccess {
                   1727:     my ($dom,$settings,$rowtotal) = @_;
                   1728:     my $css_class;
                   1729:     my $itemcount = 0;
                   1730:     my $datatable;
                   1731:     my %ordered;
                   1732:     if (ref($settings) eq 'HASH') {
                   1733:         foreach my $item (keys(%{$settings})) {
                   1734:             if (ref($settings->{$item}) eq 'HASH') {
                   1735:                 my $num = $settings->{$item}{'order'};
                   1736:                 if ($num eq '') {
                   1737:                     $num = scalar(keys(%{$settings}));
                   1738:                 }
                   1739:                 $ordered{$num} = $item;
                   1740:             }
                   1741:         }
                   1742:     }
                   1743:     my $maxnum = scalar(keys(%ordered));
                   1744:     if (keys(%ordered)) {
                   1745:         my @items = sort { $a <=> $b } keys(%ordered);
                   1746:         for (my $i=0; $i<@items; $i++) {
                   1747:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1748:             my $item = $ordered{$items[$i]};
                   1749:             my ($name,$ipranges,%commblocks,%courses);
                   1750:             if (ref($settings->{$item}) eq 'HASH') {
                   1751:                 $name = $settings->{$item}->{'name'};
                   1752:                 $ipranges = $settings->{$item}->{'ip'};
                   1753:                 if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
                   1754:                     %commblocks = %{$settings->{$item}->{'commblocks'}};
                   1755:                 }
                   1756:                 if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
                   1757:                     %courses = %{$settings->{$item}->{'courses'}};
                   1758:                 }
                   1759:             }
                   1760:             my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
                   1761:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   1762:                          .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
                   1763:             for (my $k=0; $k<=$maxnum; $k++) {
                   1764:                 my $vpos = $k+1;
                   1765:                 my $selstr;
                   1766:                 if ($k == $i) {
                   1767:                     $selstr = ' selected="selected" ';
                   1768:                 }
                   1769:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1770:             }
                   1771:             $datatable .= '</select>'.('&nbsp;'x2).
                   1772:                 '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
                   1773:                 &mt('Delete?').'</label></span></td>'.
                   1774:                 '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
                   1775:                 &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
                   1776:                 '</td></tr>';
                   1777:             $itemcount ++;
                   1778:         }
                   1779:     }
                   1780:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1781:     my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
                   1782:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   1783:                   '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
                   1784:                   '<select name="ipaccess_pos_add"'.$chgstr.'>';
                   1785:     for (my $k=0; $k<$maxnum+1; $k++) {
                   1786:         my $vpos = $k+1;
                   1787:         my $selstr;
                   1788:         if ($k == $maxnum) {
                   1789:             $selstr = ' selected="selected" ';
                   1790:         }
                   1791:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1792:     }
                   1793:     $datatable .= '</select>&nbsp;'."\n".
                   1794:                   '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   1795:                   '<td colspan="2">'.
                   1796:                   &ipaccess_options('add',$itemcount,$dom).
                   1797:                   '</td>'."\n".
                   1798:                   '</tr>'."\n";
                   1799:     $$rowtotal ++;
                   1800:     return $datatable;
                   1801: }
                   1802: 
                   1803: sub ipaccess_options {
                   1804:     my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
                   1805:     my (%currblocks,%currcourses,$output);
                   1806:     if (ref($blocksref) eq 'HASH') {
                   1807:         %currblocks = %{$blocksref};
                   1808:     }
                   1809:     if (ref($coursesref) eq 'HASH') {
                   1810:         %currcourses = %{$coursesref};
                   1811:     }
                   1812:     $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
                   1813:               '<span class="LC_nobreak">'.&mt('Name').':&nbsp;'.
                   1814:               '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
                   1815:               '</span></fieldset>'.
                   1816:               '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
                   1817:               &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   1818:               &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
                   1819:               '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
                   1820:               $ipranges.'</textarea></fieldset>'.
                   1821:               '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
                   1822:               &blocker_checkboxes($num,$blocksref).'</fieldset>'.
                   1823:               '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
                   1824:               '<table>';
                   1825:     foreach my $cid (sort(keys(%currcourses))) {
                   1826:         my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   1827:         $output .= '<tr><td><span class="LC_nobreak">'.
                   1828:                    '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
                   1829:                    &mt('Delete?').'&nbsp;<span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
                   1830:                    ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
                   1831:     }
                   1832:     $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').':&nbsp;'.
                   1833:                '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
                   1834:                 &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
                   1835:                '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
                   1836:                '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
                   1837:                '</span></td></tr></table>'."\n".
                   1838:                '</fieldset>';
                   1839:     return $output;
                   1840: }
                   1841: 
                   1842: sub blocker_checkboxes {
                   1843:     my ($num,$blocks) = @_;
                   1844:     my ($typeorder,$types) = &commblocktype_text();
                   1845:     my $numinrow = 6;
                   1846:     my $output = '<table>';
                   1847:     for (my $i=0; $i<@{$typeorder}; $i++) {
                   1848:         my $block = $typeorder->[$i];
                   1849:         my $blockstatus;
                   1850:         if (ref($blocks) eq 'HASH') {
                   1851:             if ($blocks->{$block} eq 'on') {
                   1852:                 $blockstatus = 'checked="checked"';
                   1853:             }
                   1854:         }
                   1855:         my $rem = $i%($numinrow);
                   1856:         if ($rem == 0) {
                   1857:             if ($i > 0) {
                   1858:                 $output .= '</tr>';
                   1859:             }
                   1860:             $output .= '<tr>';
                   1861:         }
                   1862:         if ($i == scalar(@{$typeorder})-1) {
                   1863:             my $colsleft = $numinrow-$rem;
                   1864:             if ($colsleft > 1) {
                   1865:                 $output .= '<td colspan="'.$colsleft.'">';
                   1866:             } else {
                   1867:                 $output .= '<td>';
                   1868:             }
                   1869:         } else {
                   1870:             $output .= '<td>';
                   1871:         }
                   1872:         my $item = 'ipaccess_block_'.$num;
                   1873:         if ($blockstatus) {
                   1874:             $blockstatus = ' '.$blockstatus;
                   1875:         }
                   1876:         $output .= '<span class="LC_nobreak"><label>'."\n".
                   1877:                    '<input type="checkbox" name="'.$item.'"'.
                   1878:                    $blockstatus.' value="'.$block.'"'.' />'.
                   1879:                    $types->{$block}.'</label></span>'."\n".
                   1880:                    '<br /></td>';
                   1881:     }
                   1882:     $output .= '</tr></table>';
                   1883:     return $output;
                   1884: }
                   1885: 
                   1886: sub commblocktype_text {
                   1887:     my %types = &Apache::lonlocal::texthash(
                   1888:         'com' => 'Messaging',
                   1889:         'chat' => 'Chat Room',
                   1890:         'boards' => 'Discussion',
                   1891:         'port' => 'Portfolio',
                   1892:         'groups' => 'Groups',
                   1893:         'blogs' => 'Blogs',
                   1894:         'about' => 'User Information',
                   1895:         'printout' => 'Printouts',
                   1896:         'passwd' => 'Change Password',
                   1897:         'grades' => 'Gradebook',
1.397     raeburn  1898:         'search' => 'Course search',
                   1899:         'wishlist' => 'Stored links',
                   1900:         'annotate' => 'Annotations',
1.394     raeburn  1901:     );
1.397     raeburn  1902:     my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394     raeburn  1903:     return ($typeorder,\%types);
                   1904: }
                   1905: 
1.6       raeburn  1906: sub print_rolecolors {
1.30      raeburn  1907:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1908:     my %choices = &color_font_choices();
                   1909:     my @bgs = ('pgbg','tabbg','sidebg');
                   1910:     my @links = ('link','alink','vlink');
                   1911:     my @images = ('img');
                   1912:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1913:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1914:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1915:     my (%is_custom,%designs);
1.200     raeburn  1916:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1917:     if (ref($settings) eq 'HASH') {
                   1918:         if (ref($settings->{$role}) eq 'HASH') {
                   1919:             if ($settings->{$role}->{'img'} ne '') {
                   1920:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1921:                 $is_custom{'img'} = 1;
                   1922:             }
                   1923:             if ($settings->{$role}->{'font'} ne '') {
                   1924:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1925:                 $is_custom{'font'} = 1;
                   1926:             }
1.97      tempelho 1927:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1928:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1929:                 $is_custom{'fontmenu'} = 1;
                   1930:             }
1.6       raeburn  1931:             foreach my $item (@bgs) {
                   1932:                 if ($settings->{$role}->{$item} ne '') {
                   1933:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1934:                     $is_custom{$item} = 1;
                   1935:                 }
                   1936:             }
                   1937:             foreach my $item (@links) {
                   1938:                 if ($settings->{$role}->{$item} ne '') {
                   1939:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1940:                     $is_custom{$item} = 1;
                   1941:                 }
                   1942:             }
                   1943:         }
                   1944:     } else {
                   1945:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1946:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1947:             $is_custom{'img'} = 1;
                   1948:         }
1.97      tempelho 1949:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1950:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1951:             $is_custom{'fontmenu'} = 1; 
                   1952:         }
1.6       raeburn  1953:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1954:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1955:             $is_custom{'font'} = 1;
                   1956:         }
                   1957:         foreach my $item (@bgs) {
                   1958:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1959:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1960:                 $is_custom{$item} = 1;
                   1961:             
                   1962:             }
                   1963:         }
                   1964:         foreach my $item (@links) {
                   1965:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1966:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1967:                 $is_custom{$item} = 1;
                   1968:             }
                   1969:         }
                   1970:     }
                   1971:     my $itemcount = 1;
1.30      raeburn  1972:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1973:     $datatable .= '</tr></table></td></tr>';
                   1974:     return $datatable;
                   1975: }
                   1976: 
1.200     raeburn  1977: sub role_defaults {
                   1978:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1979:     my %defaults;
                   1980:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1981:         return %defaults;
                   1982:     }
                   1983:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1984:     if ($role eq 'login') {
                   1985:         %defaults = (
                   1986:                        font => $defaultdesign{$role.'.font'},
                   1987:                     );
                   1988:         if (ref($logintext) eq 'ARRAY') {
                   1989:             foreach my $item (@{$logintext}) {
                   1990:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1991:             }
                   1992:         }
                   1993:         foreach my $item (@{$images}) {
                   1994:             $defaults{'showlogo'}{$item} = 1;
                   1995:         }
                   1996:     } else {
                   1997:         %defaults = (
                   1998:                        img => $defaultdesign{$role.'.img'},
                   1999:                        font => $defaultdesign{$role.'.font'},
                   2000:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   2001:                     );
                   2002:     }
                   2003:     foreach my $item (@{$bgs}) {
                   2004:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   2005:     }
                   2006:     foreach my $item (@{$links}) {
                   2007:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   2008:     }
                   2009:     foreach my $item (@{$images}) {
                   2010:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   2011:     }
                   2012:     return %defaults;
                   2013: }
                   2014: 
1.6       raeburn  2015: sub display_color_options {
1.9       raeburn  2016:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   2017:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  2018:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  2019:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  2020:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  2021:         '<td>'.$choices->{'font'}.'</td>';
                   2022:     if (!$is_custom->{'font'}) {
1.329     raeburn  2023:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  2024:     } else {
                   2025:         $datatable .= '<td>&nbsp;</td>';
                   2026:     }
1.174     foxr     2027:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   2028: 
1.8       raeburn  2029:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2030:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  2031:                   ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2032:                   '&nbsp;</span></td></tr>';
1.107     raeburn  2033:     unless ($role eq 'login') { 
                   2034:         $datatable .= '<tr'.$css_class.'>'.
                   2035:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   2036:         if (!$is_custom->{'fontmenu'}) {
1.329     raeburn  2037:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  2038:         } else {
                   2039:             $datatable .= '<td>&nbsp;</td>';
                   2040:         }
1.202     raeburn  2041: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     2042: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  2043:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2044:                       '<input class="colorchooser" type="text" size="10" name="'
                   2045: 		      .$role.'_fontmenu"'.
                   2046:                       ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2047:                       '&nbsp;</span></td></tr>';
1.97      tempelho 2048:     }
1.9       raeburn  2049:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  2050:     foreach my $img (@{$images}) {
1.18      albertel 2051: 	$itemcount ++;
1.6       raeburn  2052:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  2053:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  2054:                       '<td>'.$choices->{$img};
1.41      raeburn  2055:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  2056:         if ($role eq 'login') {
                   2057:             if ($img eq 'login') {
                   2058:                 $login_hdr_pick =
1.135     bisitz   2059:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  2060:                 $logincolors =
                   2061:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  2062:                                        $designs,$defaults);
1.70      raeburn  2063:             } elsif ($img ne 'domlogo') {
                   2064:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   2065:             }
                   2066:         }
                   2067:         $datatable .= '</td>';
1.6       raeburn  2068:         if ($designs->{$img} ne '') {
                   2069:             $imgfile = $designs->{$img};
1.18      albertel 2070: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  2071:         } else {
                   2072:             $imgfile = $defaults->{$img};
                   2073:         }
                   2074:         if ($imgfile) {
1.9       raeburn  2075:             my ($showfile,$fullsize);
                   2076:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  2077:                 my $urldir = $1;
                   2078:                 my $filename = $2;
                   2079:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   2080:                 if (@info) {
                   2081:                     my $thumbfile = 'tn-'.$filename;
                   2082:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   2083:                     if (@thumb) {
                   2084:                         $showfile = $urldir.'/'.$thumbfile;
                   2085:                     } else {
                   2086:                         $showfile = $imgfile;
                   2087:                     }
                   2088:                 } else {
                   2089:                     $showfile = '';
                   2090:                 }
                   2091:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  2092:                 $showfile = $imgfile;
1.6       raeburn  2093:                 my $imgdir = $1;
                   2094:                 my $filename = $2;
1.159     raeburn  2095:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  2096:                     $showfile = "/$imgdir/tn-".$filename;
                   2097:                 } else {
1.159     raeburn  2098:                     my $input = $londocroot.$imgfile;
                   2099:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  2100:                     if (!-e $output) {
1.9       raeburn  2101:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  2102:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   2103:                         if ($fullwidth ne '' && $fullheight ne '') {
                   2104:                             if ($fullwidth > $width && $fullheight > $height) { 
                   2105:                                 my $size = $width.'x'.$height;
1.316     raeburn  2106:                                 my @args = ('convert','-sample',$size,$input,$output);
                   2107:                                 system({$args[0]} @args);
1.159     raeburn  2108:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  2109:                             }
                   2110:                         }
1.6       raeburn  2111:                     }
                   2112:                 }
1.16      raeburn  2113:             }
1.6       raeburn  2114:             if ($showfile) {
1.40      raeburn  2115:                 if ($showfile =~ m{^/(adm|res)/}) {
                   2116:                     if ($showfile =~ m{^/res/}) {
                   2117:                         my $local_showfile =
                   2118:                             &Apache::lonnet::filelocation('',$showfile);
                   2119:                         &Apache::lonnet::repcopy($local_showfile);
                   2120:                     }
                   2121:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   2122:                 }
                   2123:                 if ($imgfile) {
                   2124:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   2125:                         if ($imgfile =~ m{^/res/}) {
                   2126:                             my $local_imgfile =
                   2127:                                 &Apache::lonnet::filelocation('',$imgfile);
                   2128:                             &Apache::lonnet::repcopy($local_imgfile);
                   2129:                         }
                   2130:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   2131:                     } else {
                   2132:                         $fullsize = $imgfile;
                   2133:                     }
                   2134:                 }
1.41      raeburn  2135:                 $datatable .= '<td>';
                   2136:                 if ($img eq 'login') {
1.135     bisitz   2137:                     $datatable .= $login_hdr_pick;
                   2138:                 } 
1.41      raeburn  2139:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   2140:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  2141:             } else {
1.201     raeburn  2142:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2143:                               &mt('Upload:').'<br />';
1.6       raeburn  2144:             }
                   2145:         } else {
1.201     raeburn  2146:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2147:                           &mt('Upload:').'<br />';
1.6       raeburn  2148:         }
1.9       raeburn  2149:         if ($switchserver) {
                   2150:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2151:         } else {
1.135     bisitz   2152:             if ($img ne 'login') { # suppress file selection for Log-in header
                   2153:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   2154:             }
1.9       raeburn  2155:         }
                   2156:         $datatable .= '</td></tr>';
1.6       raeburn  2157:     }
                   2158:     $itemcount ++;
                   2159:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2160:     $datatable .= '<tr'.$css_class.'>'.
                   2161:                   '<td>'.$choices->{'bgs'}.'</td>';
                   2162:     my $bgs_def;
                   2163:     foreach my $item (@{$bgs}) {
                   2164:         if (!$is_custom->{$item}) {
1.329     raeburn  2165:             $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  2166:         }
                   2167:     }
                   2168:     if ($bgs_def) {
1.8       raeburn  2169:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  2170:     } else {
                   2171:         $datatable .= '<td>&nbsp;</td>';
                   2172:     }
                   2173:     $datatable .= '<td class="LC_right_item">'.
                   2174:                   '<table border="0"><tr>';
1.174     foxr     2175: 
1.6       raeburn  2176:     foreach my $item (@{$bgs}) {
1.306     raeburn  2177:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     2178: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  2179:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     2180:             $datatable .= '&nbsp;';
1.6       raeburn  2181:         }
1.174     foxr     2182:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  2183:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  2184:     }
                   2185:     $datatable .= '</tr></table></td></tr>';
                   2186:     $itemcount ++;
                   2187:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2188:     $datatable .= '<tr'.$css_class.'>'.
                   2189:                   '<td>'.$choices->{'links'}.'</td>';
                   2190:     my $links_def;
                   2191:     foreach my $item (@{$links}) {
                   2192:         if (!$is_custom->{$item}) {
1.329     raeburn  2193:             $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  2194:         }
                   2195:     }
                   2196:     if ($links_def) {
1.8       raeburn  2197:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  2198:     } else {
                   2199:         $datatable .= '<td>&nbsp;</td>';
                   2200:     }
                   2201:     $datatable .= '<td class="LC_right_item">'.
                   2202:                   '<table border="0"><tr>';
                   2203:     foreach my $item (@{$links}) {
1.234     raeburn  2204: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  2205:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  2206:         if ($designs->{'links'}{$item}) {
1.174     foxr     2207:             $datatable.='&nbsp;';
1.6       raeburn  2208:         }
1.174     foxr     2209:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  2210:                       '" /></td>';
                   2211:     }
1.30      raeburn  2212:     $$rowtotal += $itemcount;
1.3       raeburn  2213:     return $datatable;
                   2214: }
                   2215: 
1.70      raeburn  2216: sub logo_display_options {
                   2217:     my ($img,$defaults,$designs) = @_;
                   2218:     my $checkedon;
                   2219:     if (ref($defaults) eq 'HASH') {
                   2220:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   2221:             if ($defaults->{'showlogo'}{$img}) {
                   2222:                 $checkedon = 'checked="checked" ';     
                   2223:             }
                   2224:         } 
                   2225:     }
                   2226:     if (ref($designs) eq 'HASH') {
                   2227:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   2228:             if (defined($designs->{'showlogo'}{$img})) {
                   2229:                 if ($designs->{'showlogo'}{$img} == 0) {
                   2230:                     $checkedon = '';
                   2231:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   2232:                     $checkedon = 'checked="checked" ';
                   2233:                 }
                   2234:             }
                   2235:         }
                   2236:     }
                   2237:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   2238:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   2239:            &mt('show').'</label>'."\n";
                   2240: }
                   2241: 
1.41      raeburn  2242: sub login_header_options  {
1.135     bisitz   2243:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   2244:     my $output = '';
1.41      raeburn  2245:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   2246:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  2247:         if (!$is_custom->{'textcol'}) {
                   2248:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   2249:                        '&nbsp;&nbsp;&nbsp;';
                   2250:         }
                   2251:         if (!$is_custom->{'bgcol'}) {
                   2252:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   2253:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   2254:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   2255:         }
                   2256:         $output .= '<br />';
                   2257:     }
                   2258:     $output .='<br />';
                   2259:     return $output;
                   2260: }
                   2261: 
                   2262: sub login_text_colors {
1.201     raeburn  2263:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  2264:     my $color_menu = '<table border="0"><tr>';
                   2265:     foreach my $item (@{$logintext}) {
1.306     raeburn  2266:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  2267:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   2268:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   2269:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  2270:     }
                   2271:     $color_menu .= '</tr></table><br />';
                   2272:     return $color_menu;
                   2273: }
                   2274: 
                   2275: sub image_changes {
                   2276:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   2277:     my $output;
1.135     bisitz   2278:     if ($img eq 'login') {
1.331     raeburn  2279:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   2280:     } elsif (!$is_custom) {
1.70      raeburn  2281:         if ($img ne 'domlogo') {
1.331     raeburn  2282:             $output = &mt('Default image:').'<br />';
1.41      raeburn  2283:         } else {
1.331     raeburn  2284:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  2285:         }
                   2286:     }
1.331     raeburn  2287:     if ($img ne 'login') {
1.135     bisitz   2288:         if ($img_import) {
                   2289:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   2290:         }
                   2291:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   2292:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   2293:         if ($is_custom) {
                   2294:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   2295:                        '<input type="checkbox" name="'.
                   2296:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   2297:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   2298:         } else {
1.306     raeburn  2299:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   2300:         }
1.41      raeburn  2301:     }
                   2302:     return $output;
                   2303: }
                   2304: 
1.3       raeburn  2305: sub print_quotas {
1.86      raeburn  2306:     my ($dom,$settings,$rowtotal,$action) = @_;
                   2307:     my $context;
                   2308:     if ($action eq 'quotas') {
                   2309:         $context = 'tools';
                   2310:     } else {
                   2311:         $context = $action;
                   2312:     }
1.197     raeburn  2313:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  2314:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  2315:     my $typecount = 0;
1.101     raeburn  2316:     my ($css_class,%titles);
1.86      raeburn  2317:     if ($context eq 'requestcourses') {
1.325     raeburn  2318:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  2319:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  2320:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   2321:         %titles = &courserequest_titles();
1.163     raeburn  2322:     } elsif ($context eq 'requestauthor') {
                   2323:         @usertools = ('author');
                   2324:         @options = ('norequest','approval','automatic');
1.210     raeburn  2325:         %titles = &authorrequest_titles();
1.86      raeburn  2326:     } else {
1.162     raeburn  2327:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  2328:         %titles = &tool_titles();
1.86      raeburn  2329:     }
1.26      raeburn  2330:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  2331:         foreach my $type (@{$types}) {
1.197     raeburn  2332:             my ($currdefquota,$currauthorquota);
1.163     raeburn  2333:             unless (($context eq 'requestcourses') ||
                   2334:                     ($context eq 'requestauthor')) {
1.86      raeburn  2335:                 if (ref($settings) eq 'HASH') {
                   2336:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  2337:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  2338:                     } else {
                   2339:                         $currdefquota = $settings->{$type};
                   2340:                     }
1.197     raeburn  2341:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   2342:                         $currauthorquota = $settings->{authorquota}->{$type};
                   2343:                     }
1.78      raeburn  2344:                 }
1.72      raeburn  2345:             }
1.3       raeburn  2346:             if (defined($usertypes->{$type})) {
                   2347:                 $typecount ++;
                   2348:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  2349:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  2350:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  2351:                               '<td class="LC_left_item">';
1.101     raeburn  2352:                 if ($context eq 'requestcourses') {
                   2353:                     $datatable .= '<table><tr>';
                   2354:                 }
                   2355:                 my %cell;  
1.72      raeburn  2356:                 foreach my $item (@usertools) {
1.101     raeburn  2357:                     if ($context eq 'requestcourses') {
                   2358:                         my ($curroption,$currlimit);
                   2359:                         if (ref($settings) eq 'HASH') {
                   2360:                             if (ref($settings->{$item}) eq 'HASH') {
                   2361:                                 $curroption = $settings->{$item}->{$type};
                   2362:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2363:                                     $currlimit = $1; 
                   2364:                                 }
                   2365:                             }
                   2366:                         }
                   2367:                         if (!$curroption) {
                   2368:                             $curroption = 'norequest';
                   2369:                         }
                   2370:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2371:                         foreach my $option (@options) {
                   2372:                             my $val = $option;
                   2373:                             if ($option eq 'norequest') {
                   2374:                                 $val = 0;  
                   2375:                             }
                   2376:                             if ($option eq 'validate') {
                   2377:                                 my $canvalidate = 0;
                   2378:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2379:                                     if ($validations{$item}{$type}) {
                   2380:                                         $canvalidate = 1;
                   2381:                                     }
                   2382:                                 }
                   2383:                                 next if (!$canvalidate);
                   2384:                             }
                   2385:                             my $checked = '';
                   2386:                             if ($option eq $curroption) {
                   2387:                                 $checked = ' checked="checked"';
                   2388:                             } elsif ($option eq 'autolimit') {
                   2389:                                 if ($curroption =~ /^autolimit/) {
                   2390:                                     $checked = ' checked="checked"';
                   2391:                                 }                       
                   2392:                             } 
                   2393:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2394:                                   '<input type="radio" name="crsreq_'.$item.
                   2395:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2396:                                   $titles{$option}.'</label>';
1.101     raeburn  2397:                             if ($option eq 'autolimit') {
1.127     raeburn  2398:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2399:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2400:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2401:                             }
1.127     raeburn  2402:                             $cell{$item} .= '</span> ';
1.103     raeburn  2403:                             if ($option eq 'autolimit') {
1.127     raeburn  2404:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2405:                             }
1.101     raeburn  2406:                         }
1.163     raeburn  2407:                     } elsif ($context eq 'requestauthor') {
                   2408:                         my $curroption;
                   2409:                         if (ref($settings) eq 'HASH') {
                   2410:                             $curroption = $settings->{$type};
                   2411:                         }
                   2412:                         if (!$curroption) {
                   2413:                             $curroption = 'norequest';
                   2414:                         }
                   2415:                         foreach my $option (@options) {
                   2416:                             my $val = $option;
                   2417:                             if ($option eq 'norequest') {
                   2418:                                 $val = 0;
                   2419:                             }
                   2420:                             my $checked = '';
                   2421:                             if ($option eq $curroption) {
                   2422:                                 $checked = ' checked="checked"';
                   2423:                             }
                   2424:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2425:                                   '<input type="radio" name="authorreq_'.$type.
                   2426:                                   '" value="'.$val.'"'.$checked.' />'.
                   2427:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2428:                         }
1.101     raeburn  2429:                     } else {
                   2430:                         my $checked = 'checked="checked" ';
                   2431:                         if (ref($settings) eq 'HASH') {
                   2432:                             if (ref($settings->{$item}) eq 'HASH') {
                   2433:                                 if ($settings->{$item}->{$type} == 0) {
                   2434:                                     $checked = '';
                   2435:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2436:                                     $checked =  'checked="checked" ';
                   2437:                                 }
1.78      raeburn  2438:                             }
1.72      raeburn  2439:                         }
1.101     raeburn  2440:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2441:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2442:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2443:                                       '</label></span>&nbsp; ';
1.72      raeburn  2444:                     }
1.101     raeburn  2445:                 }
                   2446:                 if ($context eq 'requestcourses') {
                   2447:                     $datatable .= '</tr><tr>';
                   2448:                     foreach my $item (@usertools) {
1.106     raeburn  2449:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2450:                     }
                   2451:                     $datatable .= '</tr></table>';
1.72      raeburn  2452:                 }
1.86      raeburn  2453:                 $datatable .= '</td>';
1.163     raeburn  2454:                 unless (($context eq 'requestcourses') ||
                   2455:                         ($context eq 'requestauthor')) {
1.86      raeburn  2456:                     $datatable .= 
1.197     raeburn  2457:                               '<td class="LC_right_item">'.
                   2458:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2459:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2460:                               '" value="'.$currdefquota.
1.197     raeburn  2461:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2462:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2463:                               '<input type="text" name="authorquota_'.$type.
                   2464:                               '" value="'.$currauthorquota.
                   2465:                               '" size="5" /></span></td>';
1.86      raeburn  2466:                 }
                   2467:                 $datatable .= '</tr>';
1.3       raeburn  2468:             }
                   2469:         }
                   2470:     }
1.163     raeburn  2471:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2472:         $defaultquota = '20';
1.197     raeburn  2473:         $authorquota = '500';
1.86      raeburn  2474:         if (ref($settings) eq 'HASH') {
                   2475:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2476:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2477:             } elsif (defined($settings->{'default'})) {
                   2478:                 $defaultquota = $settings->{'default'};
                   2479:             }
1.197     raeburn  2480:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2481:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2482:             }
1.3       raeburn  2483:         }
                   2484:     }
                   2485:     $typecount ++;
                   2486:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2487:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2488:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2489:                   '<td class="LC_left_item">';
1.101     raeburn  2490:     if ($context eq 'requestcourses') {
                   2491:         $datatable .= '<table><tr>';
                   2492:     }
                   2493:     my %defcell;
1.72      raeburn  2494:     foreach my $item (@usertools) {
1.101     raeburn  2495:         if ($context eq 'requestcourses') {
                   2496:             my ($curroption,$currlimit);
                   2497:             if (ref($settings) eq 'HASH') {
                   2498:                 if (ref($settings->{$item}) eq 'HASH') {
                   2499:                     $curroption = $settings->{$item}->{'default'};
                   2500:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2501:                         $currlimit = $1;
                   2502:                     }
                   2503:                 }
                   2504:             }
                   2505:             if (!$curroption) {
                   2506:                 $curroption = 'norequest';
                   2507:             }
                   2508:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2509:             foreach my $option (@options) {
                   2510:                 my $val = $option;
                   2511:                 if ($option eq 'norequest') {
                   2512:                     $val = 0;
                   2513:                 }
                   2514:                 if ($option eq 'validate') {
                   2515:                     my $canvalidate = 0;
                   2516:                     if (ref($validations{$item}) eq 'HASH') {
                   2517:                         if ($validations{$item}{'default'}) {
                   2518:                             $canvalidate = 1;
                   2519:                         }
                   2520:                     }
                   2521:                     next if (!$canvalidate);
                   2522:                 }
                   2523:                 my $checked = '';
                   2524:                 if ($option eq $curroption) {
                   2525:                     $checked = ' checked="checked"';
                   2526:                 } elsif ($option eq 'autolimit') {
                   2527:                     if ($curroption =~ /^autolimit/) {
                   2528:                         $checked = ' checked="checked"';
                   2529:                     }
                   2530:                 }
                   2531:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2532:                                   '<input type="radio" name="crsreq_'.$item.
                   2533:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2534:                                   $titles{$option}.'</label>';
                   2535:                 if ($option eq 'autolimit') {
1.127     raeburn  2536:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2537:                                        $item.'_limit_default" size="1" '.
                   2538:                                        'value="'.$currlimit.'" />';
                   2539:                 }
1.127     raeburn  2540:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2541:                 if ($option eq 'autolimit') {
1.127     raeburn  2542:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2543:                 }
1.101     raeburn  2544:             }
1.163     raeburn  2545:         } elsif ($context eq 'requestauthor') {
                   2546:             my $curroption;
                   2547:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2548:                 $curroption = $settings->{'default'};
1.163     raeburn  2549:             }
                   2550:             if (!$curroption) {
                   2551:                 $curroption = 'norequest';
                   2552:             }
                   2553:             foreach my $option (@options) {
                   2554:                 my $val = $option;
                   2555:                 if ($option eq 'norequest') {
                   2556:                     $val = 0;
                   2557:                 }
                   2558:                 my $checked = '';
                   2559:                 if ($option eq $curroption) {
                   2560:                     $checked = ' checked="checked"';
                   2561:                 }
                   2562:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2563:                               '<input type="radio" name="authorreq_default"'.
                   2564:                               ' value="'.$val.'"'.$checked.' />'.
                   2565:                               $titles{$option}.'</label></span>&nbsp; ';
                   2566:             }
1.101     raeburn  2567:         } else {
                   2568:             my $checked = 'checked="checked" ';
                   2569:             if (ref($settings) eq 'HASH') {
                   2570:                 if (ref($settings->{$item}) eq 'HASH') {
                   2571:                     if ($settings->{$item}->{'default'} == 0) {
                   2572:                         $checked = '';
                   2573:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2574:                         $checked = 'checked="checked" ';
                   2575:                     }
1.78      raeburn  2576:                 }
1.72      raeburn  2577:             }
1.101     raeburn  2578:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2579:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2580:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2581:                           '</label></span>&nbsp; ';
                   2582:         }
                   2583:     }
                   2584:     if ($context eq 'requestcourses') {
                   2585:         $datatable .= '</tr><tr>';
                   2586:         foreach my $item (@usertools) {
1.106     raeburn  2587:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2588:         }
1.101     raeburn  2589:         $datatable .= '</tr></table>';
1.72      raeburn  2590:     }
1.86      raeburn  2591:     $datatable .= '</td>';
1.163     raeburn  2592:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2593:         $datatable .= '<td class="LC_right_item">'.
                   2594:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2595:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2596:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2597:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2598:                       '<input type="text" name="authorquota" value="'.
                   2599:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2600:     }
                   2601:     $datatable .= '</tr>';
1.72      raeburn  2602:     $typecount ++;
                   2603:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2604:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2605:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2606:     if ($context eq 'requestcourses') {
1.109     raeburn  2607:         $datatable .= &mt('(overrides affiliation, if set)').
                   2608:                       '</td>'.
                   2609:                       '<td class="LC_left_item">'.
                   2610:                       '<table><tr>';
1.101     raeburn  2611:     } else {
1.109     raeburn  2612:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2613:                       '</td>'.
                   2614:                       '<td class="LC_left_item" colspan="2">'.
                   2615:                       '<br />';
1.101     raeburn  2616:     }
                   2617:     my %advcell;
1.72      raeburn  2618:     foreach my $item (@usertools) {
1.101     raeburn  2619:         if ($context eq 'requestcourses') {
                   2620:             my ($curroption,$currlimit);
                   2621:             if (ref($settings) eq 'HASH') {
                   2622:                 if (ref($settings->{$item}) eq 'HASH') {
                   2623:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2624:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2625:                         $currlimit = $1;
                   2626:                     }
                   2627:                 }
                   2628:             }
                   2629:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2630:             my $checked = '';
                   2631:             if ($curroption eq '') {
                   2632:                 $checked = ' checked="checked"';
                   2633:             }
                   2634:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2635:                                '<input type="radio" name="crsreq_'.$item.
                   2636:                                '__LC_adv" value=""'.$checked.' />'.
                   2637:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2638:             foreach my $option (@options) {
                   2639:                 my $val = $option;
                   2640:                 if ($option eq 'norequest') {
                   2641:                     $val = 0;
                   2642:                 }
                   2643:                 if ($option eq 'validate') {
                   2644:                     my $canvalidate = 0;
                   2645:                     if (ref($validations{$item}) eq 'HASH') {
                   2646:                         if ($validations{$item}{'_LC_adv'}) {
                   2647:                             $canvalidate = 1;
                   2648:                         }
                   2649:                     }
                   2650:                     next if (!$canvalidate);
                   2651:                 }
                   2652:                 my $checked = '';
1.104     raeburn  2653:                 if ($val eq $curroption) {
1.101     raeburn  2654:                     $checked = ' checked="checked"';
                   2655:                 } elsif ($option eq 'autolimit') {
                   2656:                     if ($curroption =~ /^autolimit/) {
                   2657:                         $checked = ' checked="checked"';
                   2658:                     }
                   2659:                 }
                   2660:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2661:                                   '<input type="radio" name="crsreq_'.$item.
                   2662:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2663:                                   $titles{$option}.'</label>';
                   2664:                 if ($option eq 'autolimit') {
1.127     raeburn  2665:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2666:                                        $item.'_limit__LC_adv" size="1" '.
                   2667:                                        'value="'.$currlimit.'" />';
                   2668:                 }
1.127     raeburn  2669:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2670:                 if ($option eq 'autolimit') {
1.127     raeburn  2671:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2672:                 }
1.101     raeburn  2673:             }
1.163     raeburn  2674:         } elsif ($context eq 'requestauthor') {
                   2675:             my $curroption;
                   2676:             if (ref($settings) eq 'HASH') {
                   2677:                 $curroption = $settings->{'_LC_adv'};
                   2678:             }
                   2679:             my $checked = '';
                   2680:             if ($curroption eq '') {
                   2681:                 $checked = ' checked="checked"';
                   2682:             }
                   2683:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2684:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2685:                           ' value=""'.$checked.' />'.
                   2686:                           &mt('No override set').'</label></span>&nbsp; ';
                   2687:             foreach my $option (@options) {
                   2688:                 my $val = $option;
                   2689:                 if ($option eq 'norequest') {
                   2690:                     $val = 0;
                   2691:                 }
                   2692:                 my $checked = '';
                   2693:                 if ($val eq $curroption) {
                   2694:                     $checked = ' checked="checked"';
                   2695:                 }
                   2696:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2697:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2698:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2699:                               $titles{$option}.'</label></span>&nbsp; ';
                   2700:             }
1.101     raeburn  2701:         } else {
                   2702:             my $checked = 'checked="checked" ';
                   2703:             if (ref($settings) eq 'HASH') {
                   2704:                 if (ref($settings->{$item}) eq 'HASH') {
                   2705:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2706:                         $checked = '';
                   2707:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2708:                         $checked = 'checked="checked" ';
                   2709:                     }
1.79      raeburn  2710:                 }
1.72      raeburn  2711:             }
1.101     raeburn  2712:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2713:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2714:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2715:                           '</label></span>&nbsp; ';
                   2716:         }
                   2717:     }
                   2718:     if ($context eq 'requestcourses') {
                   2719:         $datatable .= '</tr><tr>';
                   2720:         foreach my $item (@usertools) {
1.106     raeburn  2721:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2722:         }
1.101     raeburn  2723:         $datatable .= '</tr></table>';
1.72      raeburn  2724:     }
1.98      raeburn  2725:     $datatable .= '</td></tr>';
1.30      raeburn  2726:     $$rowtotal += $typecount;
1.3       raeburn  2727:     return $datatable;
                   2728: }
                   2729: 
1.163     raeburn  2730: sub print_requestmail {
1.305     raeburn  2731:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2732:     my ($now,$datatable,%currapp);
1.102     raeburn  2733:     $now = time;
                   2734:     if (ref($settings) eq 'HASH') {
                   2735:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2736:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2737:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2738:             }
                   2739:         }
                   2740:     }
1.191     raeburn  2741:     my $numinrow = 2;
1.224     raeburn  2742:     my $css_class;
1.305     raeburn  2743:     if ($$rowtotal%2) {
                   2744:         $css_class = 'LC_odd_row';
                   2745:     }
                   2746:     if ($customcss) {
                   2747:         $css_class .= " $customcss";
                   2748:     }
                   2749:     $css_class =~ s/^\s+//;
                   2750:     if ($css_class) {
                   2751:         $css_class = ' class="'.$css_class.'"';
                   2752:     }
                   2753:     if ($rowstyle) {
                   2754:         $css_class .= ' style="'.$rowstyle.'"';
                   2755:     }
1.163     raeburn  2756:     my $text;
                   2757:     if ($action eq 'requestcourses') {
                   2758:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2759:     } elsif ($action eq 'requestauthor') {
                   2760:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2761:     } else {
1.224     raeburn  2762:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2763:     }
1.224     raeburn  2764:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2765:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2766:                  ' <td class="LC_left_item">';
1.191     raeburn  2767:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2768:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2769:     if ($numdc > 0) {
                   2770:         $datatable .= $table;
1.102     raeburn  2771:     } else {
                   2772:         $datatable .= &mt('There are no active Domain Coordinators');
                   2773:     }
                   2774:     $datatable .='</td></tr>';
                   2775:     return $datatable;
                   2776: }
                   2777: 
1.216     raeburn  2778: sub print_studentcode {
                   2779:     my ($settings,$rowtotal) = @_;
                   2780:     my $rownum = 0; 
1.218     raeburn  2781:     my ($output,%current);
1.325     raeburn  2782:     my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248     raeburn  2783:     if (ref($settings) eq 'HASH') {
                   2784:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2785:             foreach my $type (@crstypes) {
                   2786:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2787:             }
1.218     raeburn  2788:         }
                   2789:     }
                   2790:     $output .= '<tr>'.
                   2791:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2792:                '<td class="LC_left_item">';
                   2793:     foreach my $type (@crstypes) {
                   2794:         my $check = ' ';
                   2795:         if ($current{$type}) {
                   2796:             $check = ' checked="checked" ';
                   2797:         }
                   2798:         $output .= '<span class="LC_nobreak"><label>'.
                   2799:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2800:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2801:     }
                   2802:     $output .= '</td></tr>';
                   2803:     $$rowtotal ++;
                   2804:     return $output;
1.216     raeburn  2805: }
                   2806: 
                   2807: sub print_textbookcourses {
1.242     raeburn  2808:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2809:     my $rownum = 0;
                   2810:     my $css_class;
                   2811:     my $itemcount = 1;
                   2812:     my $maxnum = 0;
                   2813:     my $bookshash;
                   2814:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2815:         $bookshash = $settings->{$type};
1.216     raeburn  2816:     }
                   2817:     my %ordered;
                   2818:     if (ref($bookshash) eq 'HASH') {
                   2819:         foreach my $item (keys(%{$bookshash})) {
                   2820:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2821:                 my $num = $bookshash->{$item}{'order'};
                   2822:                 $ordered{$num} = $item;
                   2823:             }
                   2824:         }
                   2825:     }
                   2826:     my $confname = $dom.'-domainconfig';
                   2827:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2828:     my $maxnum = scalar(keys(%ordered));
                   2829:     my $datatable;
1.216     raeburn  2830:     if (keys(%ordered)) {
                   2831:         my @items = sort { $a <=> $b } keys(%ordered);
                   2832:         for (my $i=0; $i<@items; $i++) {
                   2833:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2834:             my $key = $ordered{$items[$i]};
                   2835:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2836:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2837:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2838:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2839:                 $subject = $bookshash->{$key}->{'subject'};
                   2840:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2841:                 if ($type eq 'textbooks') {
1.243     raeburn  2842:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2843:                     $author = $bookshash->{$key}->{'author'};
                   2844:                     $image = $bookshash->{$key}->{'image'};
                   2845:                     if ($image ne '') {
                   2846:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2847:                         my $imagethumb = "$path/tn-".$imagefile;
                   2848:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2849:                     }
1.216     raeburn  2850:                 }
                   2851:             }
1.242     raeburn  2852:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2853:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2854:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2855:             for (my $k=0; $k<=$maxnum; $k++) {
                   2856:                 my $vpos = $k+1;
                   2857:                 my $selstr;
                   2858:                 if ($k == $i) {
                   2859:                     $selstr = ' selected="selected" ';
                   2860:                 }
                   2861:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2862:             }
                   2863:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2864:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2865:                 &mt('Delete?').'</label></span></td>'.
                   2866:                 '<td colspan="2">'.
1.242     raeburn  2867:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2868:                 ('&nbsp;'x2).
1.242     raeburn  2869:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2870:             if ($type eq 'textbooks') {
                   2871:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2872:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2873:                               ('&nbsp;'x2).
1.242     raeburn  2874:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2875:                               ('&nbsp;'x2).
                   2876:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2877:                 if ($image) {
1.267     raeburn  2878:                     $datatable .= $imgsrc.
1.242     raeburn  2879:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2880:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2881:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2882:                 }
                   2883:                 if ($switchserver) {
                   2884:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2885:                 } else {
                   2886:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2887:                 }
1.216     raeburn  2888:             }
1.242     raeburn  2889:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2890:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2891:                           $coursetitle.'</span></td></tr>'."\n";
                   2892:             $itemcount ++;
                   2893:         }
                   2894:     }
                   2895:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2896:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2897:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2898:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2899:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2900:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2901:         my $vpos = $k+1;
                   2902:         my $selstr;
                   2903:         if ($k == $maxnum) {
                   2904:             $selstr = ' selected="selected" ';
                   2905:         }
                   2906:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2907:     }
                   2908:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  2909:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216     raeburn  2910:                   '<td colspan="2">'.
1.242     raeburn  2911:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2912:                   ('&nbsp;'x2).
1.242     raeburn  2913:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2914:                   ('&nbsp;'x2);
                   2915:     if ($type eq 'textbooks') {
1.243     raeburn  2916:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2917:                       ('&nbsp;'x2).
                   2918:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2919:                       ('&nbsp;'x2).
                   2920:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2921:         if ($switchserver) {
                   2922:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2923:         } else {
                   2924:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2925:         }
1.334     raeburn  2926:         $datatable .= '</span>'."\n";
1.216     raeburn  2927:     }
1.334     raeburn  2928:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2929:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2930:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2931:                   &Apache::loncommon::selectcourse_link
1.334     raeburn  2932:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216     raeburn  2933:                   '</span></td>'."\n".
                   2934:                   '</tr>'."\n";
                   2935:     $itemcount ++;
                   2936:     return $datatable;
                   2937: }
                   2938: 
1.217     raeburn  2939: sub textbookcourses_javascript {
1.242     raeburn  2940:     my ($settings) = @_;
                   2941:     return unless(ref($settings) eq 'HASH');
                   2942:     my (%ordered,%total,%jstext);
                   2943:     foreach my $type ('textbooks','templates') {
                   2944:         $total{$type} = 0;
                   2945:         if (ref($settings->{$type}) eq 'HASH') {
                   2946:             foreach my $item (keys(%{$settings->{$type}})) {
                   2947:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2948:                     my $num = $settings->{$type}->{$item}{'order'};
                   2949:                     $ordered{$type}{$num} = $item;
                   2950:                 }
                   2951:             }
                   2952:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2953:         }
                   2954:         my @jsarray = ();
                   2955:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2956:             push(@jsarray,$ordered{$type}{$item});
                   2957:         }
                   2958:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2959:     }
                   2960:     return <<"ENDSCRIPT";
                   2961: <script type="text/javascript">
                   2962: // <![CDATA[
1.242     raeburn  2963: function reorderBooks(form,item,caller) {
1.217     raeburn  2964:     var changedVal;
1.242     raeburn  2965: $jstext{'textbooks'};
                   2966: $jstext{'templates'};
                   2967:     var newpos;
                   2968:     var maxh;
                   2969:     if (caller == 'textbooks') {  
                   2970:         newpos = 'textbooks_addbook_pos';
                   2971:         maxh = 1 + $total{'textbooks'};
                   2972:     } else {
                   2973:         newpos = 'templates_addbook_pos';
                   2974:         maxh = 1 + $total{'templates'};
                   2975:     }
1.217     raeburn  2976:     var current = new Array;
                   2977:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2978:     if (item == newpos) {
                   2979:         changedVal = newitemVal;
                   2980:     } else {
                   2981:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2982:         current[newitemVal] = newpos;
                   2983:     }
1.242     raeburn  2984:     if (caller == 'textbooks') {
                   2985:         for (var i=0; i<textbooks.length; i++) {
                   2986:             var elementName = 'textbooks_'+textbooks[i];
                   2987:             if (elementName != item) {
                   2988:                 if (form.elements[elementName]) {
                   2989:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2990:                     current[currVal] = elementName;
                   2991:                 }
                   2992:             }
                   2993:         }
                   2994:     }
                   2995:     if (caller == 'templates') {
                   2996:         for (var i=0; i<templates.length; i++) {
                   2997:             var elementName = 'templates_'+templates[i];
                   2998:             if (elementName != item) {
                   2999:                 if (form.elements[elementName]) {
                   3000:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3001:                     current[currVal] = elementName;
                   3002:                 }
1.217     raeburn  3003:             }
                   3004:         }
                   3005:     }
                   3006:     var oldVal;
                   3007:     for (var j=0; j<maxh; j++) {
                   3008:         if (current[j] == undefined) {
                   3009:             oldVal = j;
                   3010:         }
                   3011:     }
                   3012:     if (oldVal < changedVal) {
                   3013:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3014:            var elementName = current[k];
                   3015:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3016:         }
                   3017:     } else {
                   3018:         for (var k=changedVal; k<oldVal; k++) {
                   3019:             var elementName = current[k];
                   3020:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3021:         }
                   3022:     }
                   3023:     return;
                   3024: }
                   3025: 
                   3026: // ]]>
                   3027: </script>
                   3028: 
                   3029: ENDSCRIPT
                   3030: }
                   3031: 
1.267     raeburn  3032: sub ltitools_javascript {
                   3033:     my ($settings) = @_;
1.319     raeburn  3034:     my $togglejs = &ltitools_toggle_js();
                   3035:     unless (ref($settings) eq 'HASH') {
                   3036:         return $togglejs;
                   3037:     }
1.267     raeburn  3038:     my (%ordered,$total,%jstext);
                   3039:     $total = 0;
                   3040:     foreach my $item (keys(%{$settings})) {
                   3041:         if (ref($settings->{$item}) eq 'HASH') {
                   3042:             my $num = $settings->{$item}{'order'};
                   3043:             $ordered{$num} = $item;
                   3044:         }
                   3045:     }
                   3046:     $total = scalar(keys(%{$settings}));
                   3047:     my @jsarray = ();
                   3048:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3049:         push(@jsarray,$ordered{$item});
                   3050:     }
                   3051:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3052:     return <<"ENDSCRIPT";
                   3053: <script type="text/javascript">
                   3054: // <![CDATA[
1.319     raeburn  3055: function reorderLTITools(form,item) {
1.267     raeburn  3056:     var changedVal;
                   3057: $jstext
                   3058:     var newpos = 'ltitools_add_pos';
                   3059:     var maxh = 1 + $total;
                   3060:     var current = new Array;
                   3061:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3062:     if (item == newpos) {
                   3063:         changedVal = newitemVal;
                   3064:     } else {
                   3065:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3066:         current[newitemVal] = newpos;
                   3067:     }
                   3068:     for (var i=0; i<ltitools.length; i++) {
                   3069:         var elementName = 'ltitools_'+ltitools[i];
                   3070:         if (elementName != item) {
                   3071:             if (form.elements[elementName]) {
                   3072:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3073:                 current[currVal] = elementName;
                   3074:             }
                   3075:         }
                   3076:     }
                   3077:     var oldVal;
                   3078:     for (var j=0; j<maxh; j++) {
                   3079:         if (current[j] == undefined) {
                   3080:             oldVal = j;
                   3081:         }
                   3082:     }
                   3083:     if (oldVal < changedVal) {
                   3084:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3085:            var elementName = current[k];
                   3086:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3087:         }
                   3088:     } else {
                   3089:         for (var k=changedVal; k<oldVal; k++) {
                   3090:             var elementName = current[k];
                   3091:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3092:         }
                   3093:     }
                   3094:     return;
                   3095: }
                   3096: 
                   3097: // ]]>
                   3098: </script>
                   3099: 
1.319     raeburn  3100: $togglejs
                   3101: 
                   3102: ENDSCRIPT
                   3103: }
                   3104: 
                   3105: sub ltitools_toggle_js {
                   3106:     return <<"ENDSCRIPT";
                   3107: <script type="text/javascript">
                   3108: // <![CDATA[
                   3109: 
                   3110: function toggleLTITools(form,setting,item) {
                   3111:     var radioname = '';
                   3112:     var divid = '';
                   3113:     if ((setting == 'passback') || (setting == 'roster')) {
                   3114:         radioname = 'ltitools_'+setting+'_'+item;
                   3115:         divid = 'ltitools_'+setting+'time_'+item;
                   3116:         var num = form.elements[radioname].length;
                   3117:         if (num) {
                   3118:             var setvis = '';
                   3119:             for (var i=0; i<num; i++) {
                   3120:                 if (form.elements[radioname][i].checked) {
                   3121:                     if (form.elements[radioname][i].value == '1') {
                   3122:                         if (document.getElementById(divid)) {
                   3123:                             document.getElementById(divid).style.display = 'inline-block';
                   3124:                         }
                   3125:                         setvis = 1;
                   3126:                     }
                   3127:                     break;
                   3128:                 }
                   3129:             }
                   3130:         }
                   3131:         if (!setvis) {
                   3132:             if (document.getElementById(divid)) {
                   3133:                 document.getElementById(divid).style.display = 'none';
                   3134:             }
                   3135:         }
                   3136:     }
1.324     raeburn  3137:     if (setting == 'user') {
                   3138:         divid = 'ltitools_'+setting+'_div_'+item;
                   3139:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   3140:         if (document.getElementById(divid)) {
                   3141:             if (document.getElementById(checkid)) {
                   3142:                 if (document.getElementById(checkid).checked) {
                   3143:                     document.getElementById(divid).style.display = 'inline-block';
                   3144:                 } else {
                   3145:                     document.getElementById(divid).style.display = 'none';
                   3146:                 }
                   3147:             }
                   3148:         }
                   3149:     }
1.319     raeburn  3150:     return;
                   3151: }
                   3152: // ]]>
                   3153: </script>
                   3154: 
1.267     raeburn  3155: ENDSCRIPT
                   3156: }
                   3157: 
1.381     raeburn  3158: sub wafproxy_javascript {
                   3159:     my ($dom) = @_;
                   3160:     return <<"ENDSCRIPT";
                   3161: <script type="text/javascript">
                   3162: // <![CDATA[
                   3163: function updateWAF() {
                   3164:     if (document.getElementById('wafproxy_remoteip')) {
                   3165:         var wafremote = 0;
                   3166:         if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
                   3167:             wafremote = 1;
                   3168:         }
                   3169:         var fields = new Array('header','trust');
                   3170:         for (var i=0; i<fields.length; i++) {
                   3171:             if (document.getElementById('wafproxy_'+fields[i])) {
                   3172:                 if (wafremote == 1) {
                   3173:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
                   3174:                 }
                   3175:                 else {
                   3176:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
                   3177:                 }
                   3178:             }
                   3179:         }
                   3180:         if (document.getElementById('wafproxyranges_$dom')) {
                   3181:             if (wafremote == 1) {
                   3182:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3183:             } else {
                   3184:                 for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3185:                     if (document.display.wafproxy_vpnaccess[i].checked) {
                   3186:                         if (document.display.wafproxy_vpnaccess[i].value == 0) {
                   3187:                             document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3188:                         }
                   3189:                     }
                   3190:                 }
                   3191:             }
                   3192:         }
                   3193:     }
                   3194:     return;
                   3195: }
                   3196: 
                   3197: function checkWAF() {
                   3198:     if (document.getElementById('wafproxy_remoteip')) {
                   3199:         var wafvpn = 0;
                   3200:         for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3201:             if (document.display.wafproxy_vpnaccess[i].checked) {
                   3202:                 if (document.display.wafproxy_vpnaccess[i].value == 1) {
                   3203:                     wafvpn = 1;
                   3204:                 }
                   3205:                 break;
                   3206:             }
                   3207:         }
                   3208:         var vpn = new Array('vpnint','vpnext');
                   3209:         for (var i=0; i<vpn.length; i++) {
                   3210:             if (document.getElementById('wafproxy_show_'+vpn[i])) {
                   3211:                 if (wafvpn == 1) {
                   3212:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
                   3213:                 }
                   3214:                 else {
                   3215:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
                   3216:                 }
                   3217:             }
                   3218:         }
                   3219:         if (document.getElementById('wafproxyranges_$dom')) {
                   3220:             if (wafvpn == 1) {
                   3221:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3222:             }
                   3223:             else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
                   3224:                 document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3225:             }
                   3226:         }
                   3227:     }
                   3228:     return;
                   3229: }
                   3230: 
                   3231: function toggleWAF() {
                   3232:     if (document.getElementById('wafproxy_table')) {
                   3233:         var wafproxy = 0;
                   3234:         for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
                   3235:              if (document.display.wafproxy_${dom}[i].checked) {
                   3236:                  if (document.display.wafproxy_${dom}[i].value == 1) {
                   3237:                      wafproxy = 1;
                   3238:                      break;
                   3239:                 }
                   3240:             }
                   3241:         }
                   3242:         if (wafproxy == 1) {
                   3243:             document.getElementById('wafproxy_table').style.display='inline';
                   3244:         }
                   3245:         else {
                   3246:            document.getElementById('wafproxy_table').style.display='none';
                   3247:         }
                   3248:         if (document.getElementById('wafproxyrow_${dom}')) {
                   3249:             if (wafproxy == 1) {
                   3250:                 document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
                   3251:             }
                   3252:             else {
                   3253:                 document.getElementById('wafproxyrow_${dom}').style.display = 'none';
                   3254:             }
                   3255:         }
                   3256:         if (document.getElementById('nowafproxyrow_$dom')) {
                   3257:             if (wafproxy == 1) {
                   3258:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
                   3259:             }
                   3260:             else {
                   3261:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
                   3262:             }
                   3263:         }
                   3264:     }
                   3265:     return;
                   3266: }
                   3267: // ]]>
                   3268: </script>
                   3269: 
                   3270: ENDSCRIPT
                   3271: }
                   3272: 
1.372     raeburn  3273: sub proctoring_javascript {
                   3274:     my ($settings) = @_;
                   3275:     my (%ordered,$total,%jstext);
                   3276:     $total = 0;
                   3277:     if (ref($settings) eq 'HASH') {
                   3278:         foreach my $item (keys(%{$settings})) {
                   3279:             if (ref($settings->{$item}) eq 'HASH') {
                   3280:                 my $num = $settings->{$item}{'order'};
                   3281:                 $ordered{$num} = $item;
                   3282:             }
                   3283:         }
                   3284:         $total = scalar(keys(%{$settings}));
                   3285:     } else {
                   3286:         %ordered = (
                   3287:                        0 => 'proctorio',
                   3288:                        1 => 'examity',
                   3289:                    );
                   3290:         $total = 2; 
                   3291:     }
                   3292:     my @jsarray = ();
                   3293:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3294:         push(@jsarray,$ordered{$item});
                   3295:     }
                   3296:     my $jstext = '    var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3297:     return <<"ENDSCRIPT";
                   3298: <script type="text/javascript">
                   3299: // <![CDATA[
                   3300: function reorderProctoring(form,item) {
                   3301:     var changedVal;
                   3302: $jstext
                   3303:     var maxh = $total;
                   3304:     var current = new Array;
                   3305:     var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3306:     for (var i=0; i<proctors.length; i++) {
                   3307:         var elementName = 'proctoring_pos_'+proctors[i];
                   3308:         if (elementName != item) {
                   3309:             if (form.elements[elementName]) {
                   3310:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3311:                 current[currVal] = elementName;
                   3312:             }
                   3313:         }
                   3314:     }
                   3315:     var oldVal;
                   3316:     for (var j=0; j<maxh; j++) {
                   3317:         if (current[j] == undefined) {
                   3318:             oldVal = j;
                   3319:         }
                   3320:     }
                   3321:     if (oldVal < changedVal) {
                   3322:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3323:            var elementName = current[k];
                   3324:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3325:         }
                   3326:     } else {
                   3327:         for (var k=changedVal; k<oldVal; k++) {
                   3328:             var elementName = current[k];
                   3329:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3330:         }
                   3331:     }
                   3332:     return;
                   3333: }
                   3334: 
                   3335: function toggleProctoring(form,item) {
                   3336:     var fieldsets = document.getElementsByClassName('proctoring_'+item);
                   3337:     if (fieldsets.length) {
                   3338:         var radioname = 'proctoring_available_'+item;
                   3339:         var num = form.elements[radioname].length;
                   3340:         if (num) {
                   3341:             var setvis = '';
                   3342:             for (var i=0; i<num; i++) {
                   3343:                 if (form.elements[radioname][i].checked) {
                   3344:                     if (form.elements[radioname][i].value == '1') {
                   3345:                        setvis = 1;
                   3346:                        break;
                   3347:                     }
                   3348:                 }
                   3349:             }
                   3350:             for (var j=0; j<fieldsets.length; j++) {
                   3351:                 if (setvis) {
                   3352:                     fieldsets[j].style.display = 'block';
                   3353:                 } else {
                   3354:                     fieldsets[j].style.display = 'none';
                   3355:                 }
                   3356:             }
                   3357:         }
                   3358:     }
                   3359:     return;
                   3360: }
                   3361: 
                   3362: // ]]>
                   3363: </script>
                   3364: 
                   3365: ENDSCRIPT
                   3366: }
                   3367: 
                   3368: 
1.320     raeburn  3369: sub lti_javascript {
                   3370:     my ($settings) = @_;
                   3371:     my $togglejs = &lti_toggle_js();
                   3372:     unless (ref($settings) eq 'HASH') {
                   3373:         return $togglejs;
                   3374:     }
                   3375:     my (%ordered,$total,%jstext);
1.390     raeburn  3376:     $total = scalar(keys(%{$settings}));
1.320     raeburn  3377:     foreach my $item (keys(%{$settings})) {
                   3378:         if (ref($settings->{$item}) eq 'HASH') {
                   3379:             my $num = $settings->{$item}{'order'};
1.390     raeburn  3380:             if ($num eq '') {
                   3381:                 $num = $total - 1;
                   3382:             }
1.320     raeburn  3383:             $ordered{$num} = $item;
                   3384:         }
                   3385:     }
                   3386:     my @jsarray = ();
                   3387:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3388:         push(@jsarray,$ordered{$item});
                   3389:     }
                   3390:     my $jstext = '    var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3391:     return <<"ENDSCRIPT";
                   3392: <script type="text/javascript">
                   3393: // <![CDATA[
                   3394: function reorderLTI(form,item) {
                   3395:     var changedVal;
                   3396: $jstext
                   3397:     var newpos = 'lti_pos_add';
                   3398:     var maxh = 1 + $total;
                   3399:     var current = new Array;
                   3400:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3401:     if (item == newpos) {
                   3402:         changedVal = newitemVal;
                   3403:     } else {
                   3404:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3405:         current[newitemVal] = newpos;
                   3406:     }
                   3407:     for (var i=0; i<lti.length; i++) {
                   3408:         var elementName = 'lti_pos_'+lti[i];
                   3409:         if (elementName != item) {
                   3410:             if (form.elements[elementName]) {
                   3411:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3412:                 current[currVal] = elementName;
                   3413:             }
                   3414:         }
                   3415:     }
                   3416:     var oldVal;
                   3417:     for (var j=0; j<maxh; j++) {
                   3418:         if (current[j] == undefined) {
                   3419:             oldVal = j;
                   3420:         }
                   3421:     }
                   3422:     if (oldVal < changedVal) {
                   3423:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3424:            var elementName = current[k];
                   3425:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3426:         }
                   3427:     } else {
                   3428:         for (var k=changedVal; k<oldVal; k++) {
                   3429:             var elementName = current[k];
                   3430:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3431:         }
                   3432:     }
                   3433:     return;
                   3434: }
                   3435: // ]]>
                   3436: </script>
                   3437: 
                   3438: $togglejs
                   3439: 
                   3440: ENDSCRIPT
                   3441: }
                   3442: 
                   3443: sub lti_toggle_js {
1.325     raeburn  3444:     my %lcauthparmtext = &Apache::lonlocal::texthash (
                   3445:                             localauth => 'Local auth argument',
                   3446:                             krb       => 'Kerberos domain',
                   3447:                          );
1.391     raeburn  3448:     my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
                   3449:     &js_escape(\$crsincalert);
1.320     raeburn  3450:     return <<"ENDSCRIPT";
                   3451: <script type="text/javascript">
                   3452: // <![CDATA[
                   3453: 
                   3454: function toggleLTI(form,setting,item) {
1.391     raeburn  3455:     if ((setting == 'requser') || (setting == 'crsinc')) {
                   3456:         var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
                   3457:         var setvis = '';
                   3458:         var radioname = 'lti_requser_'+item;
                   3459:         var num = form.elements[radioname].length;
                   3460:         if (num) {
                   3461:             for (var i=0; i<num; i++) {
                   3462:                 if (form.elements[radioname][i].checked) {
                   3463:                     if (form.elements[radioname][i].value == '1') {
                   3464:                         setvis = 1;
                   3465:                         break;
                   3466:                     }
                   3467:                 }
                   3468:             }
                   3469:         }
                   3470:         if (usrfieldsets.length) {
                   3471:             for (var j=0; j<usrfieldsets.length; j++) {
                   3472:                 if (setvis) {
                   3473:                     usrfieldsets[j].style.display = 'block';
                   3474:                 } else {
                   3475:                     usrfieldsets[j].style.display = 'none';
                   3476:                 }
                   3477:             }
                   3478:         }
                   3479:         var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
                   3480:         if (crsfieldsets.length) {
                   3481:             radioname = 'lti_crsinc_'+item;
1.345     raeburn  3482:             var num = form.elements[radioname].length;
                   3483:             if (num) {
1.391     raeburn  3484:                 var crsvis = '';
1.345     raeburn  3485:                 for (var i=0; i<num; i++) {
                   3486:                     if (form.elements[radioname][i].checked) {
                   3487:                         if (form.elements[radioname][i].value == '1') {
1.391     raeburn  3488:                             if (setvis == '') {
                   3489:                                 if (setting == 'crsinc'){
                   3490:                                     alert("$crsincalert");
                   3491:                                     form.elements[radioname][0].checked = true;
                   3492:                                 }
                   3493:                             } else {
                   3494:                                 crsvis = 1;
                   3495:                             }
                   3496:                             break;
1.345     raeburn  3497:                         }
                   3498:                     }
                   3499:                 }
1.391     raeburn  3500:                 setvis = crsvis;
                   3501:             }
                   3502:             for (var j=0; j<crsfieldsets.length; j++) {
                   3503:                 if (setvis) {
                   3504:                     crsfieldsets[j].style.display = 'block';
                   3505:                 } else {
                   3506:                     crsfieldsets[j].style.display = 'none';
1.345     raeburn  3507:                 }
                   3508:             }
                   3509:         }
1.363     raeburn  3510:     } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320     raeburn  3511:         var radioname = '';
                   3512:         var divid = '';
                   3513:         if (setting == 'user') {
                   3514:             radioname = 'lti_mapuser_'+item;
                   3515:             divid = 'lti_userfield_'+item;
1.343     raeburn  3516:         } else if (setting == 'crs') {
1.320     raeburn  3517:             radioname = 'lti_mapcrs_'+item;
                   3518:             divid = 'lti_crsfield_'+item;
1.363     raeburn  3519:         } else if (setting == 'callback') {
                   3520:             radioname = 'lti_callback_'+item;
                   3521:             divid = 'lti_callbackfield_'+item;
1.337     raeburn  3522:         } else {
1.351     raeburn  3523:             radioname = 'lti_passback_'+item;
1.337     raeburn  3524:             divid =  'lti_passback_'+item;
1.320     raeburn  3525:         }
                   3526:         var num = form.elements[radioname].length;
                   3527:         if (num) {
                   3528:             var setvis = '';
                   3529:             for (var i=0; i<num; i++) {
                   3530:                if (form.elements[radioname][i].checked) {
1.363     raeburn  3531:                    if ((setting == 'passback') || (setting == 'callback')) {
1.337     raeburn  3532:                        if (form.elements[radioname][i].value == '1') {
                   3533:                            if (document.getElementById(divid)) {
                   3534:                                document.getElementById(divid).style.display = 'inline-block';
                   3535:                            }
                   3536:                            setvis = 1;
                   3537:                            break;
                   3538:                        }
                   3539:                    } else {
                   3540:                        if (form.elements[radioname][i].value == 'other') {
                   3541:                            if (document.getElementById(divid)) {
                   3542:                                document.getElementById(divid).style.display = 'inline-block';
                   3543:                            }
                   3544:                            setvis = 1;
                   3545:                            break;
1.320     raeburn  3546:                        }
                   3547:                    }
                   3548:                } 
                   3549:             }
                   3550:             if (!setvis) {
                   3551:                 if (document.getElementById(divid)) {
                   3552:                     document.getElementById(divid).style.display = 'none';
                   3553:                 }
                   3554:             }
                   3555:         }
                   3556:     } else if ((setting == 'sec') || (setting == 'secsrc')) {
                   3557:         var numsec = form.elements['lti_crssec_'+item].length;
                   3558:         if (numsec) {
                   3559:             var setvis = '';
                   3560:             for (var i=0; i<numsec; i++) {
                   3561:                 if (form.elements['lti_crssec_'+item][i].checked) {
                   3562:                     if (form.elements['lti_crssec_'+item][i].value == '1') {
                   3563:                         if (document.getElementById('lti_crssecfield_'+item)) {
                   3564:                             document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
                   3565:                             setvis = 1;
                   3566:                             var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
                   3567:                             if (numsrcsec) {
                   3568:                                 var setsrcvis = '';
                   3569:                                 for (var j=0; j<numsrcsec; j++) {
                   3570:                                     if (form.elements['lti_crssecsrc_'+item][j].checked) {
                   3571:                                         if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
                   3572:                                             if (document.getElementById('lti_secsrcfield_'+item)) {
                   3573:                                                 document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
                   3574:                                                 setsrcvis = 1;
                   3575:                                             }
                   3576:                                         }
                   3577:                                     }
                   3578:                                 }
                   3579:                                 if (!setsrcvis) {
                   3580:                                     if (document.getElementById('lti_secsrcfield_'+item)) {
                   3581:                                         document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3582:                                     }
                   3583:                                 }
                   3584:                             }
                   3585:                         }
                   3586:                     }
                   3587:                 }
                   3588:             }
                   3589:             if (!setvis) {
                   3590:                 if (document.getElementById('lti_crssecfield_'+item)) {
                   3591:                     document.getElementById('lti_crssecfield_'+item).style.display = 'none';
                   3592:                 }
                   3593:                 if (document.getElementById('lti_secsrcfield_'+item)) {
                   3594:                     document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3595:                 }
                   3596:             }
                   3597:         }
1.325     raeburn  3598:     } else if (setting == 'lcauth') {
                   3599:         var numauth = form.elements['lti_lcauth_'+item].length;
                   3600:         if (numauth) {
                   3601:             for (var i=0; i<numauth; i++) {
                   3602:                 if (form.elements['lti_lcauth_'+item][i].checked) {
                   3603:                     if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                   3604:                         if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                   3605:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                   3606:                         } else {
                   3607:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                   3608:                             if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                   3609:                                 if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                   3610:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                   3611:                                 } else {
                   3612:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                   3613:                                 }
                   3614:                             }
                   3615:                         }
                   3616:                     }
                   3617:                 }
                   3618:             }
                   3619:         }
1.326     raeburn  3620:     } else if (setting == 'lcmenu') {
                   3621:         var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
                   3622:         var divid = 'lti_menufield_'+item;
                   3623:         var setvis = '';
                   3624:         for (var i=0; i<menus.length; i++) {
                   3625:             var radioname = menus[i];  
                   3626:             var num = form.elements[radioname].length;
                   3627:             if (num) {
                   3628:                 for (var j=0; j<num; j++) {
                   3629:                     if (form.elements[radioname][j].checked) {
                   3630:                         if (form.elements[radioname][j].value == '1') {
                   3631:                             if (document.getElementById(divid)) {
                   3632:                                 document.getElementById(divid).style.display = 'inline-block';
                   3633:                             }
                   3634:                             setvis = 1;
                   3635:                             break;
                   3636:                         }
                   3637:                     }
                   3638:                 }
                   3639:             }
                   3640:             if (setvis == 1) {
                   3641:                 break;
                   3642:             }
                   3643:         }
                   3644:         if (!setvis) {
                   3645:             if (document.getElementById(divid)) {
                   3646:                 document.getElementById(divid).style.display = 'none';
                   3647:             }
                   3648:         }
1.320     raeburn  3649:     }
                   3650:     return;
                   3651: }
                   3652: // ]]>
                   3653: </script>
                   3654: 
                   3655: ENDSCRIPT
                   3656: }
                   3657: 
1.385     raeburn  3658: sub autoupdate_javascript {
                   3659:     return <<"ENDSCRIPT";
                   3660: <script type="text/javascript">
                   3661: // <![CDATA[
                   3662: function toggleLastActiveDays(form) {
                   3663:     var radioname = 'lastactive';
                   3664:     var divid = 'lastactive_div';
                   3665:     var num = form.elements[radioname].length;
                   3666:     if (num) {
                   3667:         var setvis = '';
                   3668:         for (var i=0; i<num; i++) {
                   3669:             if (form.elements[radioname][i].checked) {
                   3670:                 if (form.elements[radioname][i].value == '1') {
                   3671:                     if (document.getElementById(divid)) {
                   3672:                         document.getElementById(divid).style.display = 'inline-block';
                   3673:                     }
                   3674:                     setvis = 1;
                   3675:                 }
                   3676:                 break;
                   3677:             }
                   3678:         }
                   3679:         if (!setvis) {
                   3680:             if (document.getElementById(divid)) {
                   3681:                 document.getElementById(divid).style.display = 'none';
                   3682:             }
                   3683:         }
                   3684:     }
                   3685:     return;
                   3686: }
                   3687: // ]]>
                   3688: </script>
                   3689: 
                   3690: ENDSCRIPT
                   3691: }
                   3692: 
1.399     raeburn  3693: sub autoenroll_javascript {
                   3694:     return <<"ENDSCRIPT";
                   3695: <script type="text/javascript">
                   3696: // <![CDATA[
                   3697: function toggleFailsafe(form) {
                   3698:     var radioname = 'autoenroll_failsafe';
                   3699:     var divid = 'autoenroll_failsafe_div';
                   3700:     var num = form.elements[radioname].length;
                   3701:     if (num) {
                   3702:         var setvis = '';
                   3703:         for (var i=0; i<num; i++) {
                   3704:             if (form.elements[radioname][i].checked) {
                   3705:                 if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
                   3706:                     if (document.getElementById(divid)) {
                   3707:                         document.getElementById(divid).style.display = 'inline-block';
                   3708:                     }
                   3709:                     setvis = 1;
                   3710:                 }
                   3711:                 break;
                   3712:             }
                   3713:         }
                   3714:         if (!setvis) {
                   3715:             if (document.getElementById(divid)) {
                   3716:                 document.getElementById(divid).style.display = 'none';
                   3717:             }
                   3718:         }
                   3719:     }
                   3720:     return;
                   3721: }
                   3722: // ]]>
                   3723: </script>
                   3724: 
                   3725: ENDSCRIPT
                   3726: }
                   3727: 
1.386     raeburn  3728: sub saml_javascript {
                   3729:     return <<"ENDSCRIPT";
                   3730: <script type="text/javascript">
                   3731: // <![CDATA[
                   3732: function toggleSamlOptions(form,hostid) { 
                   3733:     var radioname = 'saml_'+hostid;
                   3734:     var tablecellon = 'samloptionson_'+hostid;
                   3735:     var tablecelloff = 'samloptionsoff_'+hostid;
                   3736:     var num = form.elements[radioname].length;
                   3737:     if (num) {
                   3738:         var setvis = ''; 
                   3739:         for (var i=0; i<num; i++) {
                   3740:             if (form.elements[radioname][i].checked) {
                   3741:                 if (form.elements[radioname][i].value == '1') { 
                   3742:                     if (document.getElementById(tablecellon)) {
                   3743:                         document.getElementById(tablecellon).style.display='';
                   3744:                     }
                   3745:                     if (document.getElementById(tablecelloff)) {
                   3746:                         document.getElementById(tablecelloff).style.display='none';
                   3747:                     }
                   3748:                     setvis = 1;
                   3749:                 }
                   3750:                 break;
                   3751:             }
                   3752:         }
                   3753:         if (!setvis) {
                   3754:             if (document.getElementById(tablecellon)) {
                   3755:                 document.getElementById(tablecellon).style.display='none';
                   3756:             }
                   3757:             if (document.getElementById(tablecelloff)) {
                   3758:                 document.getElementById(tablecelloff).style.display='';
                   3759:             }
                   3760:         }
                   3761:     }
                   3762:     return;
                   3763: }
                   3764: // ]]>
                   3765: </script>
                   3766: 
                   3767: ENDSCRIPT
                   3768: }
                   3769: 
1.394     raeburn  3770: sub ipaccess_javascript {
                   3771:     my ($settings) = @_;
                   3772:     my (%ordered,$total,%jstext);
                   3773:     $total = 0;
                   3774:     if (ref($settings) eq 'HASH') {
                   3775:         foreach my $item (keys(%{$settings})) {
                   3776:             if (ref($settings->{$item}) eq 'HASH') {
                   3777:                 my $num = $settings->{$item}{'order'};
                   3778:                 $ordered{$num} = $item;
                   3779:             }
                   3780:         }
                   3781:         $total = scalar(keys(%{$settings}));
                   3782:     }
                   3783:     my @jsarray = ();
                   3784:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3785:         push(@jsarray,$ordered{$item});
                   3786:     }
                   3787:     my $jstext = '    var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3788:     return <<"ENDSCRIPT";
                   3789: <script type="text/javascript">
                   3790: // <![CDATA[
                   3791: function reorderIPaccess(form,item) {
                   3792:     var changedVal;
                   3793: $jstext
                   3794:     var newpos = 'ipaccess_pos_add';
                   3795:     var maxh = 1 + $total;
                   3796:     var current = new Array;
                   3797:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3798:     if (item == newpos) {
                   3799:         changedVal = newitemVal;
                   3800:     } else {
                   3801:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3802:         current[newitemVal] = newpos;
                   3803:     }
                   3804:     for (var i=0; i<ipaccess.length; i++) {
                   3805:         var elementName = 'ipaccess_pos_'+ipaccess[i];
                   3806:         if (elementName != item) {
                   3807:             if (form.elements[elementName]) {
                   3808:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3809:                 current[currVal] = elementName;
                   3810:             }
                   3811:         }
                   3812:     }
                   3813:     var oldVal;
                   3814:     for (var j=0; j<maxh; j++) {
                   3815:         if (current[j] == undefined) {
                   3816:             oldVal = j;
                   3817:         }
                   3818:     }
                   3819:     if (oldVal < changedVal) {
                   3820:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3821:            var elementName = current[k];
                   3822:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3823:         }
                   3824:     } else {
                   3825:         for (var k=changedVal; k<oldVal; k++) {
                   3826:             var elementName = current[k];
                   3827:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3828:         }
                   3829:     }
                   3830:     return;
                   3831: }
                   3832: // ]]>
                   3833: </script>
                   3834: 
                   3835: ENDSCRIPT
                   3836: }
                   3837: 
1.3       raeburn  3838: sub print_autoenroll {
1.30      raeburn  3839:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  3840:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399     raeburn  3841:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
                   3842:         $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
                   3843:     $failsafesty = 'none';
                   3844:     %failsafechecked = (
                   3845:         off => ' checked="checked"',
                   3846:     );
1.3       raeburn  3847:     if (ref($settings) eq 'HASH') {
                   3848:         if (exists($settings->{'run'})) {
                   3849:             if ($settings->{'run'} eq '0') {
                   3850:                 $runoff = ' checked="checked" ';
                   3851:                 $runon = ' ';
                   3852:             } else {
                   3853:                 $runon = ' checked="checked" ';
                   3854:                 $runoff = ' ';
                   3855:             }
                   3856:         } else {
                   3857:             if ($autorun) {
                   3858:                 $runon = ' checked="checked" ';
                   3859:                 $runoff = ' ';
                   3860:             } else {
                   3861:                 $runoff = ' checked="checked" ';
                   3862:                 $runon = ' ';
                   3863:             }
                   3864:         }
1.129     raeburn  3865:         if (exists($settings->{'co-owners'})) {
                   3866:             if ($settings->{'co-owners'} eq '0') {
                   3867:                 $coownersoff = ' checked="checked" ';
                   3868:                 $coownerson = ' ';
                   3869:             } else {
                   3870:                 $coownerson = ' checked="checked" ';
                   3871:                 $coownersoff = ' ';
                   3872:             }
                   3873:         } else {
                   3874:             $coownersoff = ' checked="checked" ';
                   3875:             $coownerson = ' ';
                   3876:         }
1.3       raeburn  3877:         if (exists($settings->{'sender_domain'})) {
                   3878:             $defdom = $settings->{'sender_domain'};
                   3879:         }
1.399     raeburn  3880:         if (exists($settings->{'failsafe'})) {
                   3881:             $failsafe = $settings->{'failsafe'};
                   3882:             if ($failsafe eq 'zero') {
1.400     raeburn  3883:                 $failsafechecked{'zero'} = ' checked="checked"';
1.399     raeburn  3884:                 $failsafechecked{'off'} = '';
                   3885:                 $failsafesty = 'inline-block';
                   3886:             } elsif ($failsafe eq 'any') {
                   3887:                 $failsafechecked{'any'} = ' checked="checked"';
                   3888:                 $failsafechecked{'off'} = '';
                   3889:             }
                   3890:             $autofailsafe = $settings->{'autofailsafe'};
                   3891:         } elsif (exists($settings->{'autofailsafe'})) {
                   3892:             $autofailsafe = $settings->{'autofailsafe'};
                   3893:             if ($autofailsafe ne '') {
                   3894:                 $failsafechecked{'zero'} = ' checked="checked"';
                   3895:                 $failsafe = 'zero';
1.400     raeburn  3896:                 $failsafechecked{'off'} = '';
1.399     raeburn  3897:             }
1.274     raeburn  3898:         }
1.14      raeburn  3899:     } else {
                   3900:         if ($autorun) {
                   3901:             $runon = ' checked="checked" ';
                   3902:             $runoff = ' ';
                   3903:         } else {
                   3904:             $runoff = ' checked="checked" ';
                   3905:             $runon = ' ';
                   3906:         }
1.3       raeburn  3907:     }
                   3908:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  3909:     my $notif_sender;
                   3910:     if (ref($settings) eq 'HASH') {
                   3911:         $notif_sender = $settings->{'sender_uname'};
                   3912:     }
1.3       raeburn  3913:     my $datatable='<tr class="LC_odd_row">'.
                   3914:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  3915:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3916:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  3917:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3918:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  3919:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3920:                   '</tr><tr>'.
                   3921:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  3922:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  3923:                   &mt('username').':&nbsp;'.
                   3924:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  3925:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  3926:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   3927:                   '<tr class="LC_odd_row">'.
                   3928:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   3929:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3930:                   '<input type="radio" name="autoassign_coowners"'.
                   3931:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3932:                   '<label><input type="radio" name="autoassign_coowners"'.
                   3933:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  3934:                   '</tr><tr>'.
                   3935:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400     raeburn  3936:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3937:                   '<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; '.
                   3938:                   '<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 />'.
                   3939:                   '<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  3940:                   '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
                   3941:                   '<span class="LC_nobreak">'.
                   3942:                   &mt('Threshold for number of students in section to drop: [_1]',
                   3943:                       '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
                   3944:                   '</span></div></td></tr>';
1.274     raeburn  3945:     $$rowtotal += 4;
1.3       raeburn  3946:     return $datatable;
                   3947: }
                   3948: 
                   3949: sub print_autoupdate {
1.30      raeburn  3950:     my ($position,$dom,$settings,$rowtotal) = @_;
1.385     raeburn  3951:     my ($enable,$datatable);
1.3       raeburn  3952:     if ($position eq 'top') {
1.385     raeburn  3953:         my %choices = &Apache::lonlocal::texthash (
                   3954:                           run        => 'Auto-update active?',
                   3955:                           classlists => 'Update information in classlists?',
                   3956:                           unexpired  => 'Skip updates for users without active or future roles?',
                   3957:                           lastactive => 'Skip updates for inactive users?',
                   3958:         );
                   3959:         my $itemcount = 0;
1.3       raeburn  3960:         my $updateon = ' ';
                   3961:         my $updateoff = ' checked="checked" ';
                   3962:         if (ref($settings) eq 'HASH') {
                   3963:             if ($settings->{'run'} eq '1') {
                   3964:                 $updateon = $updateoff;
                   3965:                 $updateoff = ' ';
                   3966:             }
                   3967:         }
1.385     raeburn  3968:         $enable = '<tr class="LC_odd_row">'.
                   3969:                   '<td>'.$choices{'run'}.'</td>'.
                   3970:                   '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3971:                   '<input type="radio" name="autoupdate_run"'.
1.397     raeburn  3972:                   $updateoff.'value="0" />'.&mt('No').'</label>&nbsp;'.
1.8       raeburn  3973:                   '<label><input type="radio" name="autoupdate_run"'.
1.385     raeburn  3974:                   $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3       raeburn  3975:                   '</tr>';
1.385     raeburn  3976:         my @toggles = ('classlists','unexpired');
                   3977:         my %defaultchecked = ('classlists' => 'off',
                   3978:                               'unexpired'  => 'off'
                   3979:                               );
                   3980:         $$rowtotal ++;
                   3981:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3982:                                                      \%choices,$itemcount,'','','left','no');
                   3983:         $datatable = $enable.$datatable;
                   3984:         $$rowtotal += $itemcount;
                   3985:         my $lastactiveon = ' ';
                   3986:         my $lastactiveoff = ' checked="checked" ';
                   3987:         my $lastactivestyle = 'none';
                   3988:         my $lastactivedays;
                   3989:         my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
                   3990:         if (ref($settings) eq 'HASH') {
                   3991:             if ($settings->{'lastactive'} =~ /^\d+$/) {
                   3992:                 $lastactiveon = $lastactiveoff;
                   3993:                 $lastactiveoff = ' ';
                   3994:                 $lastactivestyle = 'inline-block';
                   3995:                 $lastactivedays = $settings->{'lastactive'};
                   3996:             }
                   3997:         }
                   3998:         my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3999:         $datatable .= '<tr'.$css_class.'>'.
                   4000:                       '<td>'.$choices{'lastactive'}.'</td>'.
                   4001:                       '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                   4002:                       '<input type="radio" name="lastactive"'.
                   4003:                       $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   4004:                       '&nbsp;<label>'.
                   4005:                       '<input type="radio" name="lastactive"'.
                   4006:                       $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
                   4007:                       '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
                   4008:                       ':&nbsp;'.&mt('inactive = no activity in last [_1] days',
                   4009:                           '<input type="text" size="5" name="lastactivedays" value="'.
                   4010:                           $lastactivedays.'" />').
                   4011:                       '</span></td>'.
                   4012:                       '</tr>';
                   4013:         $$rowtotal ++;
1.131     raeburn  4014:     } elsif ($position eq 'middle') {
                   4015:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4016:         my $numinrow = 3;
                   4017:         my $locknamesettings;
                   4018:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   4019:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  4020:                                     'lockablenames',$rowtotal);
1.131     raeburn  4021:         $$rowtotal ++;
1.3       raeburn  4022:     } else {
1.44      raeburn  4023:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  4024:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  4025:                       'permanentemail','id');
1.33      raeburn  4026:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  4027:         my $numrows = 0;
1.26      raeburn  4028:         if (ref($types) eq 'ARRAY') {
                   4029:             if (@{$types} > 0) {
                   4030:                 $datatable = 
                   4031:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   4032:                                          \@fields,$types,\$numrows);
1.30      raeburn  4033:                     $$rowtotal += @{$types}; 
1.26      raeburn  4034:             }
1.3       raeburn  4035:         }
                   4036:         $datatable .= 
                   4037:             &usertype_update_row($settings,{'default' => $othertitle},
                   4038:                                  \%fieldtitles,\@fields,['default'],
                   4039:                                  \$numrows);
1.30      raeburn  4040:         $$rowtotal ++;     
1.3       raeburn  4041:     }
                   4042:     return $datatable;
                   4043: }
                   4044: 
1.125     raeburn  4045: sub print_autocreate {
                   4046:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  4047:     my (%createon,%createoff,%currhash);
1.125     raeburn  4048:     my @types = ('xml','req');
                   4049:     if (ref($settings) eq 'HASH') {
                   4050:         foreach my $item (@types) {
                   4051:             $createoff{$item} = ' checked="checked" ';
                   4052:             $createon{$item} = ' ';
                   4053:             if (exists($settings->{$item})) {
                   4054:                 if ($settings->{$item}) {
                   4055:                     $createon{$item} = ' checked="checked" ';
                   4056:                     $createoff{$item} = ' ';
                   4057:                 }
                   4058:             }
                   4059:         }
1.210     raeburn  4060:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  4061:             $currhash{$settings->{'xmldc'}} = 1;
                   4062:         }
1.125     raeburn  4063:     } else {
                   4064:         foreach my $item (@types) {
                   4065:             $createoff{$item} = ' checked="checked" ';
                   4066:             $createon{$item} = ' ';
                   4067:         }
                   4068:     }
                   4069:     $$rowtotal += 2;
1.191     raeburn  4070:     my $numinrow = 2;
1.125     raeburn  4071:     my $datatable='<tr class="LC_odd_row">'.
                   4072:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   4073:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4074:                   '<input type="radio" name="autocreate_xml"'.
                   4075:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4076:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  4077:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   4078:                   '</td></tr><tr>'.
                   4079:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   4080:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4081:                   '<input type="radio" name="autocreate_req"'.
                   4082:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4083:                   '<label><input type="radio" name="autocreate_req"'.
                   4084:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  4085:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4086:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  4087:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  4088:     if ($numdc > 1) {
1.247     raeburn  4089:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   4090:                       '</td><td class="LC_left_item">';
1.125     raeburn  4091:     } else {
1.247     raeburn  4092:         $datatable .= &mt('Course creation processed as:').
                   4093:                       '</td><td class="LC_right_item">';
1.125     raeburn  4094:     }
1.247     raeburn  4095:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  4096:     $$rowtotal += $rows;
1.125     raeburn  4097:     return $datatable;
                   4098: }
                   4099: 
1.23      raeburn  4100: sub print_directorysrch {
1.277     raeburn  4101:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4102:     my $datatable;
                   4103:     if ($position eq 'top') {
                   4104:         my $instsrchon = ' ';
                   4105:         my $instsrchoff = ' checked="checked" ';
                   4106:         my ($exacton,$containson,$beginson);
                   4107:         my $instlocalon = ' ';
                   4108:         my $instlocaloff = ' checked="checked" ';
                   4109:         if (ref($settings) eq 'HASH') {
                   4110:             if ($settings->{'available'} eq '1') {
                   4111:                 $instsrchon = $instsrchoff;
                   4112:                 $instsrchoff = ' ';
                   4113:             }
                   4114:             if ($settings->{'localonly'} eq '1') {
                   4115:                 $instlocalon = $instlocaloff;
                   4116:                 $instlocaloff = ' ';
                   4117:             }
                   4118:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   4119:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   4120:                     if ($type eq 'exact') {
                   4121:                         $exacton = ' checked="checked" ';
                   4122:                     } elsif ($type eq 'contains') {
                   4123:                         $containson = ' checked="checked" ';
                   4124:                     } elsif ($type eq 'begins') {
                   4125:                         $beginson = ' checked="checked" ';
                   4126:                     }
                   4127:                 }
                   4128:             } else {
                   4129:                 if ($settings->{'searchtypes'} eq 'exact') {
                   4130:                     $exacton = ' checked="checked" ';
                   4131:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   4132:                     $containson = ' checked="checked" ';
                   4133:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  4134:                     $exacton = ' checked="checked" ';
                   4135:                     $containson = ' checked="checked" ';
                   4136:                 }
                   4137:             }
1.277     raeburn  4138:         }
                   4139:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   4140:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4141: 
                   4142:         my $numinrow = 4;
                   4143:         my $cansrchrow = 0;
                   4144:         $datatable='<tr class="LC_odd_row">'.
                   4145:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   4146:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4147:                    '<input type="radio" name="dirsrch_available"'.
                   4148:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4149:                    '<label><input type="radio" name="dirsrch_available"'.
                   4150:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4151:                    '</tr><tr>'.
                   4152:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   4153:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4154:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   4155:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4156:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   4157:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4158:                    '</tr>';
                   4159:         $$rowtotal += 2;
                   4160:         if (ref($usertypes) eq 'HASH') {
                   4161:             if (keys(%{$usertypes}) > 0) {
                   4162:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  4163:                                              $numinrow,$othertitle,'cansearch',
                   4164:                                              $rowtotal);
1.277     raeburn  4165:                 $cansrchrow = 1;
1.25      raeburn  4166:             }
1.23      raeburn  4167:         }
1.277     raeburn  4168:         if ($cansrchrow) {
                   4169:             $$rowtotal ++;
                   4170:             $datatable .= '<tr>';
                   4171:         } else {
                   4172:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  4173:         }
1.277     raeburn  4174:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   4175:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   4176:         foreach my $title (@{$titleorder}) {
                   4177:             if (defined($searchtitles->{$title})) {
                   4178:                 my $check = ' ';
                   4179:                 if (ref($settings) eq 'HASH') {
                   4180:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   4181:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   4182:                             $check = ' checked="checked" ';
                   4183:                         }
1.39      raeburn  4184:                     }
1.25      raeburn  4185:                 }
1.277     raeburn  4186:                 $datatable .= '<td class="LC_left_item">'.
                   4187:                               '<span class="LC_nobreak"><label>'.
                   4188:                               '<input type="checkbox" name="searchby" '.
                   4189:                               'value="'.$title.'"'.$check.'/>'.
                   4190:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  4191:             }
                   4192:         }
1.277     raeburn  4193:         $datatable .= '</tr></table></td></tr>';
                   4194:         $$rowtotal ++;
                   4195:         if ($cansrchrow) {
                   4196:             $datatable .= '<tr class="LC_odd_row">';
                   4197:         } else {
                   4198:             $datatable .= '<tr>';
                   4199:         }
                   4200:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   4201:                       '<td class="LC_left_item" colspan="2">'.
                   4202:                       '<span class="LC_nobreak"><label>'.
                   4203:                       '<input type="checkbox" name="searchtypes" '.
                   4204:                       $exacton.' value="exact" />'.&mt('Exact match').
                   4205:                       '</label>&nbsp;'.
                   4206:                       '<label><input type="checkbox" name="searchtypes" '.
                   4207:                       $beginson.' value="begins" />'.&mt('Begins with').
                   4208:                       '</label>&nbsp;'.
                   4209:                       '<label><input type="checkbox" name="searchtypes" '.
                   4210:                       $containson.' value="contains" />'.&mt('Contains').
                   4211:                       '</label></span></td></tr>';
                   4212:         $$rowtotal ++;
1.26      raeburn  4213:     } else {
1.277     raeburn  4214:         my $domsrchon = ' checked="checked" ';
                   4215:         my $domsrchoff = ' ';
                   4216:         my $domlocalon = ' ';
                   4217:         my $domlocaloff = ' checked="checked" ';
                   4218:         if (ref($settings) eq 'HASH') {
                   4219:             if ($settings->{'lclocalonly'} eq '1') {
                   4220:                 $domlocalon = $domlocaloff;
                   4221:                 $domlocaloff = ' ';
                   4222:             }
                   4223:             if ($settings->{'lcavailable'} eq '0') {
                   4224:                 $domsrchoff = $domsrchon;
                   4225:                 $domsrchon = ' ';
                   4226:             }
                   4227:         }
                   4228:         $datatable='<tr class="LC_odd_row">'.
                   4229:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   4230:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4231:                       '<input type="radio" name="dirsrch_domavailable"'.
                   4232:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4233:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   4234:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4235:                       '</tr><tr>'.
                   4236:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   4237:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4238:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   4239:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4240:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   4241:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4242:                       '</tr>';
                   4243:         $$rowtotal += 2;
1.26      raeburn  4244:     }
1.25      raeburn  4245:     return $datatable;
                   4246: }
                   4247: 
1.28      raeburn  4248: sub print_contacts {
1.286     raeburn  4249:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  4250:     my $datatable;
                   4251:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  4252:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340     raeburn  4253:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286     raeburn  4254:     if ($position eq 'top') {
                   4255:         if (ref($settings) eq 'HASH') {
                   4256:             foreach my $item (@contacts) {
                   4257:                 if (exists($settings->{$item})) {
                   4258:                     $to{$item} = $settings->{$item};
                   4259:                 }
                   4260:             }
                   4261:         }
                   4262:     } elsif ($position eq 'middle') {
                   4263:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350     raeburn  4264:                      'updatesmail','idconflictsmail','hostipmail');
1.288     raeburn  4265:         foreach my $type (@mailings) {
                   4266:             $otheremails{$type} = '';
                   4267:         }
1.340     raeburn  4268:     } elsif ($position eq 'lower') {
                   4269:         if (ref($settings) eq 'HASH') {
                   4270:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   4271:                 %lonstatus = %{$settings->{'lonstatus'}};
                   4272:             }
                   4273:         }
1.286     raeburn  4274:     } else {
                   4275:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  4276:         foreach my $type (@mailings) {
                   4277:             $otheremails{$type} = '';
                   4278:         }
1.286     raeburn  4279:         $bccemails{'helpdeskmail'} = '';
                   4280:         $bccemails{'otherdomsmail'} = '';
                   4281:         $includestr{'helpdeskmail'} = '';
                   4282:         $includestr{'otherdomsmail'} = '';
                   4283:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   4284:     }
1.28      raeburn  4285:     if (ref($settings) eq 'HASH') {
1.340     raeburn  4286:         unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4287:             foreach my $type (@mailings) {
                   4288:                 if (exists($settings->{$type})) {
                   4289:                     if (ref($settings->{$type}) eq 'HASH') {
                   4290:                         foreach my $item (@contacts) {
                   4291:                             if ($settings->{$type}{$item}) {
                   4292:                                 $checked{$type}{$item} = ' checked="checked" ';
                   4293:                             }
                   4294:                         }
                   4295:                         $otheremails{$type} = $settings->{$type}{'others'};
                   4296:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4297:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   4298:                             if ($settings->{$type}{'include'} ne '') {
                   4299:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4300:                                 $includestr{$type} = &unescape($includestr{$type});
                   4301:                             }
                   4302:                         }
                   4303:                     }
                   4304:                 } elsif ($type eq 'lonstatusmail') {
                   4305:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   4306:                 }
1.28      raeburn  4307:             }
                   4308:         }
1.286     raeburn  4309:         if ($position eq 'bottom') {
                   4310:             foreach my $type (@mailings) {
                   4311:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   4312:                 if ($settings->{$type}{'include'} ne '') {
                   4313:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4314:                     $includestr{$type} = &unescape($includestr{$type});
                   4315:                 }
                   4316:             }
                   4317:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   4318:                 if (ref($fields) eq 'ARRAY') {
                   4319:                     foreach my $field (@{$fields}) {
                   4320:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  4321:                     }
1.286     raeburn  4322:                 }
                   4323:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   4324:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   4325:                 } else {
1.289     raeburn  4326:                     $maxsize = '1.0';
1.286     raeburn  4327:                 }
                   4328:             } else {
                   4329:                 if (ref($fields) eq 'ARRAY') {
                   4330:                     foreach my $field (@{$fields}) {
                   4331:                         $currfield{$field} = 'yes';
1.134     raeburn  4332:                     }
1.28      raeburn  4333:                 }
1.286     raeburn  4334:                 $maxsize = '1.0';
1.28      raeburn  4335:             }
                   4336:         }
                   4337:     } else {
1.286     raeburn  4338:         if ($position eq 'top') {
                   4339:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   4340:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   4341:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   4342:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  4343:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4344:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   4345:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   4346:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350     raeburn  4347:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4348:         } elsif ($position eq 'bottom') {
                   4349:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   4350:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   4351:             if (ref($fields) eq 'ARRAY') {
                   4352:                 foreach my $field (@{$fields}) {
                   4353:                     $currfield{$field} = 'yes';
                   4354:                 }
                   4355:             }
                   4356:             $maxsize = '1.0';
                   4357:         }
1.28      raeburn  4358:     }
                   4359:     my ($titles,$short_titles) = &contact_titles();
                   4360:     my $rownum = 0;
                   4361:     my $css_class;
1.286     raeburn  4362:     if ($position eq 'top') {
                   4363:         foreach my $item (@contacts) {
                   4364:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4365:             $datatable .= '<tr'.$css_class.'>'. 
                   4366:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   4367:                           '</span></td><td class="LC_right_item">'.
                   4368:                           '<input type="text" name="'.$item.'" value="'.
                   4369:                           $to{$item}.'" /></td></tr>';
                   4370:             $rownum ++;
                   4371:         }
1.315     raeburn  4372:     } elsif ($position eq 'bottom') {
                   4373:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4374:         $datatable .= '<tr'.$css_class.'>'.
                   4375:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   4376:                       &mt('(e-mail, subject, and description always shown)').
                   4377:                       '</td><td class="LC_left_item">';
                   4378:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   4379:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   4380:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   4381:             foreach my $field (@{$fields}) {
                   4382:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   4383:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   4384:                     $datatable .= ' '.&mt('(logged-in users)');
                   4385:                 }
                   4386:                 $datatable .='</td><td>';
                   4387:                 my $clickaction;
                   4388:                 if ($field eq 'screenshot') {
                   4389:                     $clickaction = ' onclick="screenshotSize(this);"';
                   4390:                 }
                   4391:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   4392:                     foreach my $option (@{$possoptions->{$field}}) {
                   4393:                         my $checked;
                   4394:                         if ($currfield{$field} eq $option) {
                   4395:                             $checked = ' checked="checked"';
                   4396:                         }
                   4397:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   4398:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   4399:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   4400:                                       '</label></span>'.('&nbsp;'x2);
                   4401:                     }
                   4402:                 }
                   4403:                 if ($field eq 'screenshot') {
                   4404:                     my $display;
                   4405:                     if ($currfield{$field} eq 'no') {
                   4406:                         $display = ' style="display:none"';
                   4407:                     }
1.334     raeburn  4408:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315     raeburn  4409:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   4410:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   4411:                 }
                   4412:                 $datatable .= '</td></tr>';
                   4413:             }
                   4414:             $datatable .= '</table>';
                   4415:         }
                   4416:         $datatable .= '</td></tr>'."\n";
                   4417:         $rownum ++;
                   4418:     }
1.340     raeburn  4419:     unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4420:         foreach my $type (@mailings) {
                   4421:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4422:             $datatable .= '<tr'.$css_class.'>'.
                   4423:                           '<td><span class="LC_nobreak">'.
                   4424:                           $titles->{$type}.': </span></td>'.
                   4425:                           '<td class="LC_left_item">';
                   4426:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4427:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   4428:             }
                   4429:             $datatable .= '<span class="LC_nobreak">';
                   4430:             foreach my $item (@contacts) {
                   4431:                 $datatable .= '<label>'.
                   4432:                               '<input type="checkbox" name="'.$type.'"'.
                   4433:                               $checked{$type}{$item}.
                   4434:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   4435:                               '</label>&nbsp;';
                   4436:             }
                   4437:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4438:                           '<input type="text" name="'.$type.'_others" '.
                   4439:                           'value="'.$otheremails{$type}.'"  />';
                   4440:             my %locchecked;
                   4441:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4442:                 foreach my $loc ('s','b') {
                   4443:                     if ($includeloc{$type} eq $loc) {
                   4444:                         $locchecked{$loc} = ' checked="checked"';
                   4445:                         last;
                   4446:                     }
                   4447:                 }
                   4448:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4449:                               '<input type="text" name="'.$type.'_bcc" '.
                   4450:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   4451:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4452:                               &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4453:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286     raeburn  4454:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4455:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4456:                               ('&nbsp;'x2).
                   4457:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4458:                               '</span></fieldset>';
                   4459:             }
                   4460:             $datatable .= '</td></tr>'."\n";
                   4461:             $rownum ++;
                   4462:         }
1.28      raeburn  4463:     }
1.286     raeburn  4464:     if ($position eq 'middle') {
                   4465:         my %choices;
1.340     raeburn  4466:         my $corelink = &core_link_msu();
                   4467:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286     raeburn  4468:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340     raeburn  4469:                                         $corelink);
                   4470:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   4471:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286     raeburn  4472:         my %defaultchecked = ('reporterrors'  => 'on',
1.340     raeburn  4473:                               'reportupdates' => 'on',
                   4474:                               'reportstatus'  => 'on');
1.286     raeburn  4475:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4476:                                                    \%choices,$rownum);
                   4477:         $datatable .= $reports;
1.340     raeburn  4478:     } elsif ($position eq 'lower') {
1.378     raeburn  4479:         my (%current,%excluded,%weights);
1.340     raeburn  4480:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   4481:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378     raeburn  4482:             $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340     raeburn  4483:         } else {
1.378     raeburn  4484:             $current{'errorthreshold'} = $defaults->{'threshold'};
1.340     raeburn  4485:         }
                   4486:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378     raeburn  4487:             $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340     raeburn  4488:         } else {
1.378     raeburn  4489:             $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340     raeburn  4490:         }
                   4491:         if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341     raeburn  4492:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4493:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   4494:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   4495:                 } else {
                   4496:                     $weights{$type} = $defaults->{$type};
                   4497:                 }
                   4498:             }
                   4499:         } else {
1.341     raeburn  4500:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4501:                 $weights{$type} = $defaults->{$type};
                   4502:             }
                   4503:         }
                   4504:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   4505:             if (@{$lonstatus{'excluded'}} > 0) {
                   4506:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   4507:             }
                   4508:         }
1.378     raeburn  4509:         foreach my $item ('errorthreshold','errorsysmail') { 
                   4510:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4511:             $datatable .= '<tr'.$css_class.'>'.
                   4512:                           '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4513:                           $titles->{$item}.
                   4514:                           '</span></td><td class="LC_left_item">'.
                   4515:                           '<input type="text" name="'.$item.'" value="'.
                   4516:                           $current{$item}.'" size="5" /></td></tr>';
                   4517:             $rownum ++;
                   4518:         }
1.340     raeburn  4519:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4520:         $datatable .= '<tr'.$css_class.'>'.
                   4521:                       '<td class="LC_left_item">'.
                   4522:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   4523:                       '</span></td><td class="LC_left_item"><table><tr>';
1.341     raeburn  4524:         foreach my $type ('E','W','N','U') {
1.340     raeburn  4525:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   4526:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   4527:                           $weights{$type}.'" size="5" /></td>';
                   4528:         }
                   4529:         $datatable .= '</tr></table></tr>';
                   4530:         $rownum ++;
                   4531:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4532:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   4533:                       $titles->{'errorexcluded'}.'</td>'.
                   4534:                       '<td class="LC_left_item"><table>';
                   4535:         my $numinrow = 4;
                   4536:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   4537:         for (my $i=0; $i<@ids; $i++) {
                   4538:             my $rem = $i%($numinrow);
                   4539:             if ($rem == 0) {
                   4540:                 if ($i > 0) {
                   4541:                     $datatable .= '</tr>';
                   4542:                 }
                   4543:                 $datatable .= '<tr>';
                   4544:             }
                   4545:             my $check;
                   4546:             if ($excluded{$ids[$i]}) {
                   4547:                 $check = ' checked="checked" ';
                   4548:             }
                   4549:             $datatable .= '<td class="LC_left_item">'.
                   4550:                           '<span class="LC_nobreak"><label>'.
                   4551:                           '<input type="checkbox" name="errorexcluded" '.
                   4552:                           'value="'.$ids[$i].'"'.$check.' />'.
                   4553:                           $ids[$i].'</label></span></td>';
                   4554:         }
                   4555:         my $colsleft = $numinrow - @ids%($numinrow);
                   4556:         if ($colsleft > 1 ) {
                   4557:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4558:                           '&nbsp;</td>';
                   4559:         } elsif ($colsleft == 1) {
                   4560:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4561:         }
                   4562:         $datatable .= '</tr></table></td></tr>';
                   4563:         $rownum ++;
1.286     raeburn  4564:     } elsif ($position eq 'bottom') {
1.315     raeburn  4565:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4566:         my (@posstypes,%usertypeshash);
                   4567:         if (ref($types) eq 'ARRAY') {
                   4568:             @posstypes = @{$types};
                   4569:         }
                   4570:         if (@posstypes) {
                   4571:             if (ref($usertypes) eq 'HASH') {
                   4572:                 %usertypeshash = %{$usertypes};
                   4573:             }
                   4574:             my @overridden;
                   4575:             my $numinrow = 4;
                   4576:             if (ref($settings) eq 'HASH') {
                   4577:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   4578:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   4579:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   4580:                             push(@overridden,$key);
                   4581:                             foreach my $item (@contacts) {
                   4582:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   4583:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   4584:                                 }
                   4585:                             }
                   4586:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   4587:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   4588:                             $includeloc{'override_'.$key} = '';
                   4589:                             $includestr{'override_'.$key} = '';
                   4590:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   4591:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
                   4592:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   4593:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   4594:                             }
1.286     raeburn  4595:                         }
                   4596:                     }
                   4597:                 }
1.315     raeburn  4598:             }
                   4599:             my $customclass = 'LC_helpdesk_override';
                   4600:             my $optionsprefix = 'LC_options_helpdesk_';
                   4601: 
                   4602:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   4603:  
                   4604:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   4605:                                          $numinrow,$othertitle,'overrides',
                   4606:                                          \$rownum,$onclicktypes,$customclass);
                   4607:             $rownum ++;
                   4608:             $usertypeshash{'default'} = $othertitle;
                   4609:             foreach my $status (@posstypes) {
                   4610:                 my $css_class;
                   4611:                 if ($rownum%2) {
                   4612:                     $css_class = 'LC_odd_row ';
                   4613:                 }
                   4614:                 $css_class .= $customclass;
                   4615:                 my $rowid = $optionsprefix.$status;
                   4616:                 my $hidden = 1;
                   4617:                 my $currstyle = 'display:none';
                   4618:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   4619:                     $currstyle = 'display:table-row';
                   4620:                     $hidden = 0;
                   4621:                 }
                   4622:                 my $key = 'override_'.$status;
                   4623:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   4624:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   4625:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   4626:                                                   \@contacts,$short_titles);
                   4627:                 unless ($hidden) {
                   4628:                     $rownum ++;
1.286     raeburn  4629:                 }
                   4630:             }
1.134     raeburn  4631:         }
1.28      raeburn  4632:     }
1.30      raeburn  4633:     $$rowtotal += $rownum;
1.28      raeburn  4634:     return $datatable;
                   4635: }
                   4636: 
1.340     raeburn  4637: sub core_link_msu {
                   4638:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   4639:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   4640: }
                   4641: 
1.315     raeburn  4642: sub overridden_helpdesk {
                   4643:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   4644:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   4645:     my $class = 'LC_left_item';
                   4646:     if ($css_class) {
                   4647:         $css_class = ' class="'.$css_class.'"';
                   4648:     }
                   4649:     if ($rowid) {
                   4650:         $rowid = ' id="'.$rowid.'"';
                   4651:     }
                   4652:     if ($rowstyle) {
                   4653:         $rowstyle = ' style="'.$rowstyle.'"';
                   4654:     }
                   4655:     my ($output,$description);
                   4656:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   4657:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   4658:               "<td>$description</td>\n".
                   4659:               '<td class="'.$class.'" colspan="2">'.
                   4660:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   4661:               '<span class="LC_nobreak">';
                   4662:     if (ref($contacts) eq 'ARRAY') {
                   4663:         foreach my $item (@{$contacts}) {
                   4664:             my $check;
                   4665:             if (ref($checked) eq 'HASH') {
                   4666:                $check = $checked->{$item};
                   4667:             }
                   4668:             my $title;
                   4669:             if (ref($short_titles) eq 'HASH') {
                   4670:                 $title = $short_titles->{$item}; 
                   4671:             }
                   4672:             $output .= '<label>'.
                   4673:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   4674:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   4675:         }
                   4676:     }
                   4677:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4678:                '<input type="text" name="override_'.$type.'_others" '.
                   4679:                'value="'.$otheremails.'"  />';
                   4680:     my %locchecked;
                   4681:     foreach my $loc ('s','b') {
                   4682:         if ($includeloc eq $loc) {
                   4683:             $locchecked{$loc} = ' checked="checked"';
                   4684:             last;
                   4685:         }
                   4686:     }
                   4687:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4688:                '<input type="text" name="override_'.$type.'_bcc" '.
                   4689:                'value="'.$bccemails.'"  /></fieldset>'.
                   4690:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4691:                &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4692:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315     raeburn  4693:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4694:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4695:                ('&nbsp;'x2).
                   4696:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4697:                '</span></fieldset>'.
                   4698:                '</td></tr>'."\n";
                   4699:     return $output;
                   4700: }
                   4701: 
1.286     raeburn  4702: sub contacts_javascript {
                   4703:     return <<"ENDSCRIPT";
                   4704: 
                   4705: <script type="text/javascript">
                   4706: // <![CDATA[
                   4707: 
                   4708: function screenshotSize(field) {
                   4709:     if (document.getElementById('help_screenshotsize')) {
                   4710:         if (field.value == 'no') {
1.289     raeburn  4711:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  4712:         } else {
                   4713:             document.getElementById('help_screenshotsize').style.display="";
                   4714:         }
                   4715:     }
                   4716:     return;
                   4717: }
                   4718: 
1.315     raeburn  4719: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   4720:     if (form.elements[checkbox].length != undefined) {
                   4721:         var count = 0;
                   4722:         if (docount) {
                   4723:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   4724:                 if (form.elements[checkbox][i].checked) {
                   4725:                     count ++;
                   4726:                 }
                   4727:             }
                   4728:         }
                   4729:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   4730:             var type = form.elements[checkbox][i].value;
                   4731:             if (document.getElementById(prefix+type)) {
                   4732:                 if (form.elements[checkbox][i].checked) {
                   4733:                     document.getElementById(prefix+type).style.display = 'table-row';
                   4734:                     if (count % 2 == 1) {
                   4735:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   4736:                     } else {
                   4737:                         document.getElementById(prefix+type).className = target;
                   4738:                     }
                   4739:                     count ++;
                   4740:                 } else {
                   4741:                     document.getElementById(prefix+type).style.display = 'none';
                   4742:                 }
                   4743:             }
                   4744:         }
                   4745:     }
                   4746:     return;
                   4747: }
                   4748: 
                   4749: 
1.286     raeburn  4750: // ]]>
                   4751: </script>
                   4752: 
                   4753: ENDSCRIPT
                   4754: }
                   4755: 
1.118     jms      4756: sub print_helpsettings {
1.282     raeburn  4757:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4758:     my $confname = $dom.'-domainconfig';
1.285     raeburn  4759:     my $formname = 'display';
1.168     raeburn  4760:     my ($datatable,$itemcount);
1.282     raeburn  4761:     if ($position eq 'top') {
                   4762:         $itemcount = 1;
                   4763:         my (%choices,%defaultchecked,@toggles);
                   4764:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   4765:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   4766:                                      &mt('LON-CAPA bug tracker'),600,500));
                   4767:         %defaultchecked = ('submitbugs' => 'on');
                   4768:         @toggles = ('submitbugs');
                   4769:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4770:                                                      \%choices,$itemcount);
                   4771:         $$rowtotal ++;
                   4772:     } else {
                   4773:         my $css_class;
                   4774:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  4775:         my (%customroles,%ordered,%current);
1.301     raeburn  4776:         if (ref($settings) eq 'HASH') {
                   4777:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   4778:                 %current = %{$settings->{'adhoc'}};
                   4779:             }
1.285     raeburn  4780:         }
                   4781:         my $count = 0;
                   4782:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  4783:             if ($key=~/^rolesdef\_(\w+)$/) {
                   4784:                 my $rolename = $1;
1.285     raeburn  4785:                 my (%privs,$order);
1.282     raeburn  4786:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   4787:                 $customroles{$rolename} = \%privs;
1.285     raeburn  4788:                 if (ref($current{$rolename}) eq 'HASH') {
                   4789:                     $order = $current{$rolename}{'order'};
                   4790:                 }
                   4791:                 if ($order eq '') {
                   4792:                     $order = $count;
                   4793:                 }
                   4794:                 $ordered{$order} = $rolename;
                   4795:                 $count++;
                   4796:             }
                   4797:         }
                   4798:         my $maxnum = scalar(keys(%ordered));
                   4799:         my @roles_by_num = ();
                   4800:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   4801:             push(@roles_by_num,$item);
                   4802:         }
                   4803:         my $context = 'domprefs';
                   4804:         my $crstype = 'Course';
                   4805:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  4806:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  4807:         my ($numstatustypes,@jsarray);
                   4808:         if (ref($types) eq 'ARRAY') {
                   4809:             if (@{$types} > 0) {
                   4810:                 $numstatustypes = scalar(@{$types});
                   4811:                 push(@accesstypes,'status');
                   4812:                 @jsarray = ('bystatus');
1.282     raeburn  4813:             }
                   4814:         }
1.290     raeburn  4815:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  4816:         if (keys(%domhelpdesk)) {
                   4817:             push(@accesstypes,('inc','exc'));
                   4818:             push(@jsarray,('notinc','notexc'));
                   4819:         }
                   4820:         my $hiddenstr = join("','",@jsarray);
1.282     raeburn  4821:         my $context = 'domprefs';
                   4822:         my $crstype = 'Course';
1.285     raeburn  4823:         my $prefix = 'helproles_';
                   4824:         my $add_class = 'LC_hidden';
                   4825:         foreach my $num (@roles_by_num) {
                   4826:             my $role = $ordered{$num};
                   4827:             my ($desc,$access,@statuses);
                   4828:             if (ref($current{$role}) eq 'HASH') {
                   4829:                 $desc = $current{$role}{'desc'};
                   4830:                 $access = $current{$role}{'access'};
                   4831:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   4832:                     @statuses = @{$current{$role}{'insttypes'}};
                   4833:                 }
                   4834:             }
                   4835:             if ($desc eq '') {
                   4836:                 $desc = $role;
                   4837:             }
                   4838:             my $identifier = 'custhelp'.$num;
1.282     raeburn  4839:             my %full=();
                   4840:             my %levels= (
                   4841:                          course => {},
                   4842:                          domain => {},
                   4843:                          system => {},
                   4844:                         );
                   4845:             my %levelscurrent=(
                   4846:                                course => {},
                   4847:                                domain => {},
                   4848:                                system => {},
                   4849:                               );
                   4850:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   4851:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   4852:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  4853:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  4854:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  4855:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   4856:             for (my $k=0; $k<=$maxnum; $k++) {
                   4857:                 my $vpos = $k+1;
                   4858:                 my $selstr;
                   4859:                 if ($k == $num) {
                   4860:                     $selstr = ' selected="selected" ';
                   4861:                 }
                   4862:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4863:             }
                   4864:             $datatable .= '</select>'.('&nbsp;'x2).
                   4865:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   4866:                           '</td>'.
                   4867:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4868:                           &mt('Name shown to users:').
                   4869:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   4870:                           '</fieldset>'.
                   4871:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   4872:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   4873:                           '<fieldset>'.
                   4874:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  4875:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  4876:                                                                    \%levelscurrent,$identifier,
                   4877:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   4878:                           '</fieldset></td>';
1.282     raeburn  4879:             $itemcount ++;
                   4880:         }
                   4881:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4882:         my $newcust = 'custhelp'.$count;
                   4883:         my (%privs,%levelscurrent);
                   4884:         my %full=();
                   4885:         my %levels= (
                   4886:                      course => {},
                   4887:                      domain => {},
                   4888:                      system => {},
                   4889:                     );
                   4890:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   4891:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  4892:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  4893:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  4894:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   4895:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   4896:         for (my $k=0; $k<$maxnum+1; $k++) {
                   4897:             my $vpos = $k+1;
                   4898:             my $selstr;
                   4899:             if ($k == $maxnum) {
                   4900:                 $selstr = ' selected="selected" ';
                   4901:             }
                   4902:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4903:         }
                   4904:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  4905:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   4906:                       '</label></span></td>'.
1.285     raeburn  4907:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4908:                       '<span class="LC_nobreak">'.
                   4909:                       &mt('Internal name:').
                   4910:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   4911:                       '</span>'.('&nbsp;'x4).
                   4912:                       '<span class="LC_nobreak">'.
                   4913:                       &mt('Name shown to users:').
                   4914:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   4915:                       '</span></fieldset>'.
                   4916:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   4917:                                              $usertypes,$types,\%domhelpdesk).
                   4918:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  4919:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   4920:                                                                 \@templateroles,$newcust).
                   4921:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   4922:                                                                \%levelscurrent,$newcust).
1.334     raeburn  4923:                       '</fieldset>'.
                   4924:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   4925:                       '</td></tr>';
1.282     raeburn  4926:         $count ++;
                   4927:         $$rowtotal += $count;
                   4928:     }
1.166     raeburn  4929:     return $datatable;
1.121     raeburn  4930: }
                   4931: 
1.285     raeburn  4932: sub adhocbutton {
                   4933:     my ($prefix,$num,$field,$visibility) = @_;
                   4934:     my %lt = &Apache::lonlocal::texthash(
                   4935:                                           show => 'Show details',
                   4936:                                           hide => 'Hide details',
                   4937:                                         );
                   4938:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   4939:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   4940:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   4941:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   4942: }
                   4943: 
                   4944: sub helpsettings_javascript {
                   4945:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   4946:     return unless(ref($roles_by_num) eq 'ARRAY');
                   4947:     my %html_js_lt = &Apache::lonlocal::texthash(
                   4948:                                           show => 'Show details',
                   4949:                                           hide => 'Hide details',
                   4950:                                         );
                   4951:     &html_escape(\%html_js_lt);
                   4952:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   4953:     return <<"ENDSCRIPT";
                   4954: <script type="text/javascript">
                   4955: // <![CDATA[
                   4956: 
                   4957: function reorderHelpRoles(form,item) {
                   4958:     var changedVal;
                   4959: $jstext
                   4960:     var newpos = 'helproles_${total}_pos';
                   4961:     var maxh = 1 + $total;
                   4962:     var current = new Array();
                   4963:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4964:     if (item == newpos) {
                   4965:         changedVal = newitemVal;
                   4966:     } else {
                   4967:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4968:         current[newitemVal] = newpos;
                   4969:     }
                   4970:     for (var i=0; i<helproles.length; i++) {
                   4971:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   4972:         if (elementName != item) {
                   4973:             if (form.elements[elementName]) {
                   4974:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4975:                 current[currVal] = elementName;
                   4976:             }
                   4977:         }
                   4978:     }
                   4979:     var oldVal;
                   4980:     for (var j=0; j<maxh; j++) {
                   4981:         if (current[j] == undefined) {
                   4982:             oldVal = j;
                   4983:         }
                   4984:     }
                   4985:     if (oldVal < changedVal) {
                   4986:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4987:            var elementName = current[k];
                   4988:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4989:         }
                   4990:     } else {
                   4991:         for (var k=changedVal; k<oldVal; k++) {
                   4992:             var elementName = current[k];
                   4993:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4994:         }
                   4995:     }
                   4996:     return;
                   4997: }
                   4998: 
                   4999: function helpdeskAccess(num) {
                   5000:     var curraccess = null;
                   5001:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   5002:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   5003:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   5004:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   5005:             }
                   5006:         }
                   5007:     }
                   5008:     var shown = Array();
                   5009:     var hidden = Array();
                   5010:     if (curraccess == 'none') {
                   5011:         hidden = Array('$hiddenstr');
                   5012:     } else {
                   5013:         if (curraccess == 'status') {
                   5014:             shown = Array('bystatus');
                   5015:             hidden = Array('notinc','notexc');
                   5016:         } else {
                   5017:             if (curraccess == 'exc') {
                   5018:                 shown = Array('notexc');
                   5019:                 hidden = Array('notinc','bystatus');
                   5020:             }
                   5021:             if (curraccess == 'inc') {
                   5022:                 shown = Array('notinc');
                   5023:                 hidden = Array('notexc','bystatus');
                   5024:             }
1.293     raeburn  5025:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  5026:                 hidden = Array('notinc','notexc','bystatus');
                   5027:             }
                   5028:         }
                   5029:     }
                   5030:     if (hidden.length > 0) {
                   5031:         for (var i=0; i<hidden.length; i++) {
                   5032:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   5033:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   5034:             }
                   5035:         }
                   5036:     }
                   5037:     if (shown.length > 0) {
                   5038:         for (var i=0; i<shown.length; i++) {
                   5039:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   5040:                 if (shown[i] == 'privs') {
                   5041:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   5042:                 } else {
                   5043:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   5044:                 }
                   5045:             }
                   5046:         }
                   5047:     }
                   5048:     return;
                   5049: }
                   5050: 
                   5051: function toggleHelpdeskItem(num,field) {
                   5052:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   5053:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  5054:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  5055:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   5056:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5057:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   5058:             }
                   5059:         } else {
                   5060:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   5061:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5062:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   5063:             }
                   5064:         }
                   5065:     }
                   5066:     return;
                   5067: }
                   5068: 
                   5069: // ]]>
                   5070: </script>
                   5071: 
                   5072: ENDSCRIPT
                   5073: }
                   5074: 
                   5075: sub helpdeskroles_access {
                   5076:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   5077:         $usertypes,$types,$domhelpdesk) = @_;
                   5078:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   5079:     my %lt = &Apache::lonlocal::texthash(
                   5080:                     'rou'    => 'Role usage',
                   5081:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  5082:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   5083:                     'dh'     => 'All with domain helpdesk role',
                   5084:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  5085:                     'none'   => 'None',
                   5086:                     'status' => 'Determined based on institutional status',
                   5087:                     'inc'    => 'Include all, but exclude specific personnel',
                   5088:                     'exc'    => 'Exclude all, but include specific personnel',
                   5089:                   );
                   5090:     my %usecheck = (
                   5091:                      all => ' checked="checked"',
                   5092:                    );
                   5093:     my %displaydiv = (
                   5094:                       status => 'none',
                   5095:                       inc    => 'none',
                   5096:                       exc    => 'none',
                   5097:                       priv   => 'block',
                   5098:                      );
                   5099:     my $output;
                   5100:     if (ref($current) eq 'HASH') {
                   5101:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   5102:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   5103:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   5104:                 delete($usecheck{'all'});
                   5105:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   5106:                     my $access = $1;
                   5107:                     $displaydiv{$access} = 'inline';
                   5108:                 } elsif ($current->{access} eq 'none') {
                   5109:                     $displaydiv{'priv'} = 'none';
                   5110:                 }
                   5111:             }
                   5112:         }
                   5113:     }
                   5114:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   5115:               '<p>'.$lt{'whi'}.'</p>';
                   5116:     foreach my $access (@{$accesstypes}) {
                   5117:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   5118:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   5119:                    $lt{$access}.'</label>';
                   5120:         if ($access eq 'status') {
                   5121:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   5122:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   5123:                                                                  $othertitle,$usertypes,$types).
                   5124:                        '</div>';
                   5125:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   5126:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   5127:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5128:                        '</div>';
                   5129:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   5130:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   5131:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5132:                        '</div>';
                   5133:         }
                   5134:         $output .= '</p>';
                   5135:     }
                   5136:     $output .= '</fieldset>';
                   5137:     return $output;
                   5138: }
                   5139: 
1.121     raeburn  5140: sub radiobutton_prefs {
1.192     raeburn  5141:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385     raeburn  5142:         $additional,$align,$firstval) = @_;
1.121     raeburn  5143:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   5144:                    (ref($choices) eq 'HASH'));
                   5145: 
1.170     raeburn  5146:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  5147: 
                   5148:     foreach my $item (@{$toggles}) {
                   5149:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      5150:             $checkedon{$item} = ' checked="checked" ';
                   5151:             $checkedoff{$item} = ' ';
1.121     raeburn  5152:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      5153:             $checkedoff{$item} = ' checked="checked" ';
                   5154:             $checkedon{$item} = ' ';
                   5155:         }
                   5156:     }
                   5157:     if (ref($settings) eq 'HASH') {
1.121     raeburn  5158:         foreach my $item (@{$toggles}) {
1.118     jms      5159:             if ($settings->{$item} eq '1') {
                   5160:                 $checkedon{$item} =  ' checked="checked" ';
                   5161:                 $checkedoff{$item} = ' ';
                   5162:             } elsif ($settings->{$item} eq '0') {
                   5163:                 $checkedoff{$item} =  ' checked="checked" ';
                   5164:                 $checkedon{$item} = ' ';
                   5165:             }
                   5166:         }
1.121     raeburn  5167:     }
1.192     raeburn  5168:     if ($onclick) {
                   5169:         $onclick = ' onclick="'.$onclick.'"';
                   5170:     }
1.121     raeburn  5171:     foreach my $item (@{$toggles}) {
1.118     jms      5172:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  5173:         $datatable .=
1.306     raeburn  5174:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  5175:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  5176:             '</span></td>';
                   5177:         if ($align eq 'left') {
                   5178:             $datatable .= '<td class="LC_left_item">';
                   5179:         } else {
                   5180:             $datatable .= '<td class="LC_right_item">';
                   5181:         }
1.385     raeburn  5182:         $datatable .= '<span class="LC_nobreak">';
                   5183:         if ($firstval eq 'no') {
                   5184:             $datatable .=
                   5185:                 '<label><input type="radio" name="'.
                   5186:                 $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
                   5187:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5188:                 $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
                   5189:         } else {
                   5190:             $datatable .=
                   5191:                 '<label><input type="radio" name="'.
                   5192:                 $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
                   5193:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5194:                 $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
                   5195:         }
                   5196:         $datatable .= '</span>'.$additional.'</td></tr>';
1.118     jms      5197:         $itemcount ++;
1.121     raeburn  5198:     }
                   5199:     return ($datatable,$itemcount);
                   5200: }
                   5201: 
1.267     raeburn  5202: sub print_ltitools {
                   5203:     my ($dom,$settings,$rowtotal) = @_;
                   5204:     my $rownum = 0;
                   5205:     my $css_class;
                   5206:     my $itemcount = 1;
                   5207:     my $maxnum = 0;
                   5208:     my %ordered;
                   5209:     if (ref($settings) eq 'HASH') {
                   5210:         foreach my $item (keys(%{$settings})) {
                   5211:             if (ref($settings->{$item}) eq 'HASH') {
                   5212:                 my $num = $settings->{$item}{'order'};
                   5213:                 $ordered{$num} = $item;
                   5214:             }
                   5215:         }
                   5216:     }
                   5217:     my $confname = $dom.'-domainconfig';
                   5218:     my $switchserver = &check_switchserver($dom,$confname);
                   5219:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  5220:     my $datatable;
1.267     raeburn  5221:     my %lt = &ltitools_names();
                   5222:     my @courseroles = ('cc','in','ta','ep','st');
                   5223:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324     raeburn  5224:     my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267     raeburn  5225:     if (keys(%ordered)) {
                   5226:         my @items = sort { $a <=> $b } keys(%ordered);
                   5227:         for (my $i=0; $i<@items; $i++) {
                   5228:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5229:             my $item = $ordered{$items[$i]};
1.323     raeburn  5230:             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267     raeburn  5231:             if (ref($settings->{$item}) eq 'HASH') {
                   5232:                 $title = $settings->{$item}->{'title'};
                   5233:                 $url = $settings->{$item}->{'url'};
                   5234:                 $key = $settings->{$item}->{'key'};
                   5235:                 $secret = $settings->{$item}->{'secret'};
1.322     raeburn  5236:                 $lifetime = $settings->{$item}->{'lifetime'};
1.267     raeburn  5237:                 my $image = $settings->{$item}->{'image'};
                   5238:                 if ($image ne '') {
                   5239:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   5240:                 }
1.323     raeburn  5241:                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   5242:                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   5243:                 } else {
                   5244:                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   5245:                 }
1.267     raeburn  5246:             }
1.319     raeburn  5247:             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267     raeburn  5248:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5249:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   5250:             for (my $k=0; $k<=$maxnum; $k++) {
                   5251:                 my $vpos = $k+1;
                   5252:                 my $selstr;
                   5253:                 if ($k == $i) {
                   5254:                     $selstr = ' selected="selected" ';
                   5255:                 }
                   5256:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5257:             }
                   5258:             $datatable .= '</select>'.('&nbsp;'x2).
                   5259:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   5260:                 &mt('Delete?').'</label></span></td>'.
                   5261:                 '<td colspan="2">'.
                   5262:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5263:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267     raeburn  5264:                 ('&nbsp;'x2).
                   5265:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   5266:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   5267:                 ('&nbsp;'x2).
                   5268:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   5269:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5270:                 ('&nbsp;'x2).
                   5271:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   5272:                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   5273:                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267     raeburn  5274:                 '<br /><br />'.
1.323     raeburn  5275:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267     raeburn  5276:                 ' value="'.$url.'" /></span>'.
                   5277:                 ('&nbsp;'x2).
1.319     raeburn  5278:                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267     raeburn  5279:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   5280:                 ('&nbsp;'x2).
1.322     raeburn  5281:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   5282:                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   5283:                 ('&nbsp;'x2).
1.267     raeburn  5284:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   5285:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   5286:                 '<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>'.
                   5287:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   5288:                 '</fieldset>'.
                   5289:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5290:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   5291:             my %currdisp;
                   5292:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   5293:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   5294:                     $currdisp{'window'} = ' checked="checked"';
1.298     raeburn  5295:                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   5296:                     $currdisp{'tab'} = ' checked="checked"';
1.267     raeburn  5297:                 } else {
                   5298:                     $currdisp{'iframe'} = ' checked="checked"';
                   5299:                 }
                   5300:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   5301:                     $currdisp{'width'} = $1;
                   5302:                 }
                   5303:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   5304:                      $currdisp{'height'} = $1;
                   5305:                 }
1.296     raeburn  5306:                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   5307:                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267     raeburn  5308:             } else {
                   5309:                 $currdisp{'iframe'} = ' checked="checked"';
                   5310:             }
1.298     raeburn  5311:             foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5312:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   5313:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5314:             }
                   5315:             $datatable .= ('&nbsp;'x4);
                   5316:             foreach my $dimen ('width','height') {
                   5317:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5318:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   5319:                               ('&nbsp;'x2);
                   5320:             }
1.334     raeburn  5321:             $datatable .= '</span><br />'.
1.296     raeburn  5322:                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5323:                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296     raeburn  5324:                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   5325:                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   5326:                           '</textarea></div><div style=""></div><br />';
1.319     raeburn  5327:             my %units = (
                   5328:                           'passback' => 'days',
                   5329:                           'roster'   => 'seconds',
                   5330:                         );
1.267     raeburn  5331:             foreach my $extra ('passback','roster') {
1.319     raeburn  5332:                 my $validsty = 'none';
                   5333:                 my $currvalid;
1.267     raeburn  5334:                 my $checkedon = '';
                   5335:                 my $checkedoff = ' checked="checked"';
                   5336:                 if ($settings->{$item}->{$extra}) {
                   5337:                     $checkedon = $checkedoff;
                   5338:                     $checkedoff = '';
1.319     raeburn  5339:                     $validsty = 'inline-block';
                   5340:                     if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
                   5341:                         $currvalid = $settings->{$item}->{$extra.'valid'};
                   5342:                     }
                   5343:                 }
                   5344:                 my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
                   5345:                 $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5346:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
                   5347:                               &mt('No').'</label>'.('&nbsp;'x2).
                   5348:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
                   5349:                               &mt('Yes').'</label></span></div>'.
                   5350:                               '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
                   5351:                               '<span class="LC_nobreak">'.
                   5352:                               &mt("at least [_1] $units{$extra} after launch",
                   5353:                                   '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
                   5354:                               '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5355:             }
1.319     raeburn  5356:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
1.267     raeburn  5357:             if ($imgsrc) {
                   5358:                 $datatable .= $imgsrc.
                   5359:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   5360:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   5361:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   5362:             } else {
                   5363:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5364:             }
                   5365:             if ($switchserver) {
                   5366:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5367:             } else {
                   5368:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   5369:             }
                   5370:             $datatable .= '</span></fieldset>';
1.324     raeburn  5371:             my (%checkedfields,%rolemaps,$userincdom);
1.267     raeburn  5372:             if (ref($settings->{$item}) eq 'HASH') {
                   5373:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   5374:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   5375:                 }
1.324     raeburn  5376:                 $userincdom = $settings->{$item}->{'incdom'};
1.267     raeburn  5377:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   5378:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   5379:                     $checkedfields{'roles'} = 1;
                   5380:                 }
                   5381:             }
                   5382:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5383:                           '<span class="LC_nobreak">';
1.324     raeburn  5384:             my $userfieldstyle = 'display:none;';
                   5385:             my $seluserdom = '';
                   5386:             my $unseluserdom = ' selected="selected"';
1.267     raeburn  5387:             foreach my $field (@fields) {
1.324     raeburn  5388:                 my ($checked,$onclick,$id,$spacer);
1.267     raeburn  5389:                 if ($checkedfields{$field}) {
                   5390:                     $checked = ' checked="checked"';
                   5391:                 }
1.324     raeburn  5392:                 if ($field eq 'user') {
                   5393:                     $id = ' id="ltitools_user_field_'.$i.'"';
                   5394:                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   5395:                     if ($checked) {
                   5396:                         $userfieldstyle = 'display:inline-block';
                   5397:                         if ($userincdom) {
                   5398:                             $seluserdom = $unseluserdom;
                   5399:                             $unseluserdom = '';
                   5400:                         }
                   5401:                     }
                   5402:                 } else {
                   5403:                     $spacer = ('&nbsp;' x2);
                   5404:                 }
1.267     raeburn  5405:                 $datatable .= '<label>'.
1.324     raeburn  5406:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   5407:                               $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5408:             }
1.324     raeburn  5409:             $datatable .= '</span>';
                   5410:             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   5411:                           '<span class="LC_nobreak"> : '.
                   5412:                           '<select name="ltitools_userincdom_'.$i.'">'.
                   5413:                           '<option value="">'.&mt('Select').'</option>'.
                   5414:                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   5415:                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   5416:                           '</select></span></div>';
                   5417:             $datatable .= '</fieldset>'.
1.267     raeburn  5418:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   5419:             foreach my $role (@courseroles) {
                   5420:                 my ($selected,$selectnone);
                   5421:                 if (!$rolemaps{$role}) {
                   5422:                     $selectnone = ' selected="selected"';
                   5423:                 }
1.306     raeburn  5424:                 $datatable .= '<td style="text-align: center">'. 
1.267     raeburn  5425:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5426:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   5427:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5428:                 foreach my $ltirole (@ltiroles) {
                   5429:                     unless ($selectnone) {
                   5430:                         if ($rolemaps{$role} eq $ltirole) {
                   5431:                             $selected = ' selected="selected"';
                   5432:                         } else {
                   5433:                             $selected = '';
                   5434:                         }
                   5435:                     }
                   5436:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   5437:                 }
                   5438:                 $datatable .= '</select></td>';
                   5439:             }
1.273     raeburn  5440:             $datatable .= '</tr></table></fieldset>';
                   5441:             my %courseconfig;
                   5442:             if (ref($settings->{$item}) eq 'HASH') {
                   5443:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   5444:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   5445:                 }
                   5446:             }
                   5447:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5448:             foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  5449:                 my $checked;
                   5450:                 if ($courseconfig{$item}) {
                   5451:                     $checked = ' checked="checked"';
                   5452:                 }
                   5453:                 $datatable .= '<label>'.
                   5454:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372     raeburn  5455:                        $lt{'crs'.$item}.'</label>&nbsp; '."\n";
1.273     raeburn  5456:             }
                   5457:             $datatable .= '</span></fieldset>'.
1.267     raeburn  5458:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5459:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   5460:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   5461:                 my %custom = %{$settings->{$item}->{'custom'}};
                   5462:                 if (keys(%custom) > 0) {
                   5463:                     foreach my $key (sort(keys(%custom))) {
                   5464:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5465:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   5466:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   5467:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   5468:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   5469:                     }
                   5470:                 }
                   5471:             }
                   5472:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5473:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   5474:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   5475:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   5476:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   5477:             $itemcount ++;
                   5478:         }
                   5479:     }
                   5480:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319     raeburn  5481:     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267     raeburn  5482:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   5483:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   5484:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   5485:     for (my $k=0; $k<$maxnum+1; $k++) {
                   5486:         my $vpos = $k+1;
                   5487:         my $selstr;
                   5488:         if ($k == $maxnum) {
                   5489:             $selstr = ' selected="selected" ';
                   5490:         }
                   5491:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5492:     }
                   5493:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  5494:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267     raeburn  5495:                   '<td colspan="2">'.
                   5496:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5497:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267     raeburn  5498:                   ('&nbsp;'x2).
                   5499:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   5500:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   5501:                   ('&nbsp;'x2).
                   5502:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   5503:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5504:                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   5505:                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5506:                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267     raeburn  5507:                   '<br />'.
1.323     raeburn  5508:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267     raeburn  5509:                   ('&nbsp;'x2).
                   5510:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   5511:                   ('&nbsp;'x2).
1.322     raeburn  5512:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   5513:                   ('&nbsp;'x2).
1.267     raeburn  5514:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   5515:                   '<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".
                   5516:                   '</fieldset>'.
                   5517:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5518:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   5519:     my %defaultdisp;
                   5520:     $defaultdisp{'iframe'} = ' checked="checked"';
1.298     raeburn  5521:     foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5522:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   5523:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5524:     }
                   5525:     $datatable .= ('&nbsp;'x4);
                   5526:     foreach my $dimen ('width','height') {
                   5527:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5528:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   5529:                       ('&nbsp;'x2);
                   5530:     }
1.334     raeburn  5531:     $datatable .= '</span><br />'.
1.296     raeburn  5532:                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5533:                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296     raeburn  5534:                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334     raeburn  5535:                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296     raeburn  5536:                   '</div><div style=""></div><br />';
1.319     raeburn  5537:     my %units = (
                   5538:                   'passback' => 'days',
                   5539:                   'roster'   => 'seconds',
                   5540:                 );
                   5541:     my %defaulttimes = (
                   5542:                      'passback' => '7',
1.322     raeburn  5543:                      'roster'   => '300',
1.319     raeburn  5544:                    );
1.267     raeburn  5545:     foreach my $extra ('passback','roster') {
1.319     raeburn  5546:         my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
                   5547:         $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5548:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
                   5549:                       &mt('No').'</label></span>'.('&nbsp;'x2).'<span class="LC_nobreak">'.
                   5550:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
                   5551:                       &mt('Yes').'</label></span></div>'.
                   5552:                       '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
                   5553:                       '<span class="LC_nobreak">'.
                   5554:                       &mt("at least [_1] $units{$extra} after launch",
                   5555:                           '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
                   5556:                       '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5557:     }
1.319     raeburn  5558:     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
1.267     raeburn  5559:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5560:     if ($switchserver) {
                   5561:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5562:     } else {
                   5563:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   5564:     }
                   5565:     $datatable .= '</span></fieldset>'.
                   5566:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5567:                   '<span class="LC_nobreak">';
                   5568:     foreach my $field (@fields) {
1.324     raeburn  5569:         my ($id,$onclick,$spacer);
                   5570:         if ($field eq 'user') {
                   5571:             $id = ' id="ltitools_user_field_add"';
                   5572:             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   5573:         } else {
                   5574:             $spacer = ('&nbsp;' x2);
                   5575:         }
1.267     raeburn  5576:         $datatable .= '<label>'.
1.324     raeburn  5577:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   5578:                       $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5579:     }
1.324     raeburn  5580:     $datatable .= '</span>'.
                   5581:                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   5582:                   '<span class="LC_nobreak"> : '.
                   5583:                   '<select name="ltitools_userincdom_add">'.
                   5584:                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   5585:                   '<option value="0">'.&mt('username').'</option>'.
                   5586:                   '<option value="1">'.&mt('username:domain').'</option>'.
                   5587:                   '</select></span></div></fieldset>';
                   5588:     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267     raeburn  5589:     foreach my $role (@courseroles) {
                   5590:         my ($checked,$checkednone);
1.306     raeburn  5591:         $datatable .= '<td style="text-align: center">'.
1.267     raeburn  5592:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5593:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   5594:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   5595:         foreach my $ltirole (@ltiroles) {
                   5596:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   5597:         }
                   5598:         $datatable .= '</select></td>';
                   5599:     }
                   5600:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  5601:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5602:     foreach my $item ('label','title','target','linktext','explanation','append') {
1.296     raeburn  5603:         $datatable .= '<label>'.
                   5604:                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   5605:                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
1.273     raeburn  5606:     }
                   5607:     $datatable .= '</span></fieldset>'.
1.267     raeburn  5608:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5609:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   5610:                   '<tr><td><span class="LC_nobreak">'.
                   5611:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   5612:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   5613:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334     raeburn  5614:                   '</table></fieldset>'."\n".
1.267     raeburn  5615:                   '</td>'."\n".
                   5616:                   '</tr>'."\n";
                   5617:     $itemcount ++;
                   5618:     return $datatable;
                   5619: }
                   5620: 
                   5621: sub ltitools_names {
                   5622:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  5623:                                           'title'          => 'Title',
                   5624:                                           'version'        => 'Version',
                   5625:                                           'msgtype'        => 'Message Type',
1.323     raeburn  5626:                                           'sigmethod'      => 'Signature Method',
1.296     raeburn  5627:                                           'url'            => 'URL',
                   5628:                                           'key'            => 'Key',
1.322     raeburn  5629:                                           'lifetime'       => 'Nonce lifetime (s)',
1.296     raeburn  5630:                                           'secret'         => 'Secret',
                   5631:                                           'icon'           => 'Icon',   
1.324     raeburn  5632:                                           'user'           => 'User',
1.296     raeburn  5633:                                           'fullname'       => 'Full Name',
                   5634:                                           'firstname'      => 'First Name',
                   5635:                                           'lastname'       => 'Last Name',
                   5636:                                           'email'          => 'E-mail',
                   5637:                                           'roles'          => 'Role',
1.298     raeburn  5638:                                           'window'         => 'Window',
                   5639:                                           'tab'            => 'Tab',
1.296     raeburn  5640:                                           'iframe'         => 'iFrame',
                   5641:                                           'height'         => 'Height',
                   5642:                                           'width'          => 'Width',
                   5643:                                           'linktext'       => 'Default Link Text',
                   5644:                                           'explanation'    => 'Default Explanation',
                   5645:                                           'passback'       => 'Tool can return grades:',
                   5646:                                           'roster'         => 'Tool can retrieve roster:',
                   5647:                                           'crstarget'      => 'Display target',
                   5648:                                           'crslabel'       => 'Course label',
                   5649:                                           'crstitle'       => 'Course title', 
                   5650:                                           'crslinktext'    => 'Link Text',
                   5651:                                           'crsexplanation' => 'Explanation',
1.318     raeburn  5652:                                           'crsappend'      => 'Provider URL',
1.267     raeburn  5653:                                         );
                   5654:     return %lt;
                   5655: }
                   5656: 
1.372     raeburn  5657: sub print_proctoring {
                   5658:     my ($dom,$settings,$rowtotal) = @_;
                   5659:     my $itemcount = 1;
                   5660:     my (%ordered,%providernames,%current,%currentdef);
                   5661:     my $confname = $dom.'-domainconfig';
                   5662:     my $switchserver = &check_switchserver($dom,$confname);
                   5663:     if (ref($settings) eq 'HASH') {
                   5664:         foreach my $item (keys(%{$settings})) {
                   5665:             if (ref($settings->{$item}) eq 'HASH') {
                   5666:                 my $num = $settings->{$item}{'order'};
                   5667:                 $ordered{$num} = $item;
                   5668:             }
                   5669:         }
                   5670:     } else {
                   5671:         %ordered = (
                   5672:                      1 => 'proctorio',
                   5673:                      2 => 'examity',
                   5674:                    );
                   5675:     }
                   5676:     %providernames = &proctoring_providernames();
                   5677:     my $maxnum = scalar(keys(%ordered));
                   5678:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   5679:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   5680:     if (ref($requref) eq 'HASH') {
                   5681:         %requserfields = %{$requref};
                   5682:     }
                   5683:     if (ref($opturef) eq 'HASH') {
                   5684:         %optuserfields = %{$opturef};
                   5685:     }
                   5686:     if (ref($defref) eq 'HASH') {
                   5687:         %defaults = %{$defref};
                   5688:     }
                   5689:     if (ref($extref) eq 'HASH') {
                   5690:         %extended = %{$extref};
                   5691:     }
                   5692:     if (ref($crsref) eq 'HASH') {
                   5693:         %crsconf = %{$crsref};
                   5694:     }
                   5695:     if (ref($rolesref) eq 'ARRAY') {
                   5696:         @courseroles = @{$rolesref};
                   5697:     }
                   5698:     if (ref($ltiref) eq 'ARRAY') {
                   5699:         @ltiroles = @{$ltiref};
                   5700:     }
                   5701:     my $datatable;
                   5702:     my $css_class;
                   5703:     if (keys(%ordered)) {
                   5704:         my @items = sort { $a <=> $b } keys(%ordered);
                   5705:         for (my $i=0; $i<@items; $i++) {
                   5706:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5707:             my $provider = $ordered{$items[$i]};
                   5708:             my $optionsty = 'none';
                   5709:             my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
                   5710:                 %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
                   5711:             if (ref($settings) eq 'HASH') {
                   5712:                 if (ref($settings->{$provider}) eq 'HASH') {
                   5713:                     %current = %{$settings->{$provider}};
                   5714:                     if ($current{'available'}) {
                   5715:                         $optionsty = 'block';
                   5716:                         $available = 1;
                   5717:                     }
                   5718:                     if ($current{'lifetime'} =~ /^\d+$/) {
                   5719:                         $lifetime = $current{'lifetime'};
                   5720:                     }
                   5721:                     if ($current{'version'} =~ /^\d+\.\d+$/) {
                   5722:                         $version = $current{'version'};
                   5723:                     }
                   5724:                     if ($current{'image'} ne '') {
                   5725:                         $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
                   5726:                     }
                   5727:                     if (ref($current{'fields'}) eq 'ARRAY') {
                   5728:                         map { $checkedfields{$_} = 1; } @{$current{'fields'}};
                   5729:                     }
                   5730:                     $userincdom = $current{'incdom'};
                   5731:                     if (ref($current{'roles'}) eq 'HASH') {
                   5732:                         %rolemaps = %{$current{'roles'}};
                   5733:                         $checkedfields{'roles'} = 1;
                   5734:                     }
                   5735:                     if (ref($current{'defaults'}) eq 'ARRAY') {
                   5736:                         foreach my $val (@{$current{'defaults'}}) {
                   5737:                             if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
                   5738:                                 $inuse{$val} = 1;
                   5739:                             } else {
                   5740:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5741:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5742:                                         if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
                   5743:                                             $inuse{$poss} = $val;
                   5744:                                             last;
                   5745:                                         }
                   5746:                                     }
                   5747:                                 }
                   5748:                             }
                   5749:                         }
                   5750:                     } elsif (ref($current{'defaults'}) eq 'HASH') {
                   5751:                         foreach my $key (keys(%{$current{'defaults'}})) {
                   5752:                             my $currval = $current{'defaults'}{$key}; 
                   5753:                             if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
                   5754:                                 $inuse{$key} = 1;
                   5755:                             } else {
                   5756:                                 my $match;
                   5757:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5758:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5759:                                         if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
                   5760:                                             $inuse{$poss} = $key;
                   5761:                                             last;
                   5762:                                         }
                   5763:                                     } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
                   5764:                                         foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
                   5765:                                             if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
                   5766:                                                 if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
                   5767:                                                     $currentdef{$inner} = $currval;
                   5768:                                                     $match = 1;
                   5769:                                                     last;
                   5770:                                                 }
                   5771:                                             } elsif ($inner eq $key) {
                   5772:                                                 $currentdef{$key} = $currval;
                   5773:                                                 $match = 1;
                   5774:                                                 last;
                   5775:                                             }
                   5776:                                         }
                   5777:                                     }
                   5778:                                     last if ($match);
                   5779:                                 }
                   5780:                             }
                   5781:                         }
                   5782:                     }
                   5783:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   5784:                         map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
                   5785:                     }
                   5786:                 }
                   5787:             }
                   5788:             my %lt = &proctoring_titles($provider);
                   5789:             my %fieldtitles = &proctoring_fieldtitles($provider);
                   5790:             my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
                   5791:             my %checkedavailable = (
                   5792:                                    yes => '',
                   5793:                                    no  => ' checked="checked"',
                   5794:                                  );
                   5795:             if ($available) {
                   5796:                 $checkedavailable{'yes'} = $checkedavailable{'no'};
                   5797:                 $checkedavailable{'no'} = '';
                   5798:             }
                   5799:             my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
                   5800:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5801:                          .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
                   5802:             for (my $k=0; $k<$maxnum; $k++) {
                   5803:                 my $vpos = $k+1;
                   5804:                 my $selstr;
                   5805:                 if ($k == $i) {
                   5806:                     $selstr = ' selected="selected" ';
                   5807:                 }
                   5808:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5809:             }
                   5810:             if ($version eq '') {
                   5811:                 if ($provider eq 'proctorio') {
                   5812:                     $version = '1.0';
                   5813:                 } elsif ($provider eq 'examity') {
                   5814:                     $version = '1.1';
                   5815:                 }
                   5816:             }
                   5817:             if ($lifetime eq '') {
                   5818:                 $lifetime = '300';
                   5819:             }
                   5820:             $datatable .=
                   5821:                 '</select>'.('&nbsp;'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
                   5822:                 '<span class="LC_nobreak">'.$lt{'avai'}.'&nbsp;'.
                   5823:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   5824:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
                   5825:                 '</td>'.
                   5826:                 '<td colspan="2">'.
                   5827:                 '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
                   5828:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
                   5829:                 '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
                   5830:                 ('&nbsp;'x2).
                   5831:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
                   5832:                 '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5833:                 '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
                   5834:                 ('&nbsp;'x2).
                   5835:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
                   5836:                 '<br />'.
                   5837:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
                   5838:                 '<br />'.
                   5839:                 '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
                   5840:                 ('&nbsp;'x2).
                   5841:                 '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
                   5842:                 '<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";
                   5843:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   5844:             if ($imgsrc) {
                   5845:                 $datatable .= $imgsrc.
                   5846:                               '<label><input type="checkbox" name="proctoring_image_del"'.
                   5847:                               ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
                   5848:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:');
                   5849:             }
                   5850:             $datatable .= '&nbsp;';
                   5851:             if ($switchserver) {
                   5852:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5853:             } else {
                   5854:                 $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
                   5855:             }
                   5856:             unless ($imgsrc) {
                   5857:                 $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
                   5858:             }
                   5859:             $datatable .= '</fieldset>'."\n";
                   5860:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   5861:                 if (@{$requserfields{$provider}} > 0) {
                   5862:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
                   5863:                     foreach my $field (@{$requserfields{$provider}}) {
                   5864:                         $datatable .= '<span class="LC_nobreak">'.
                   5865:                                       '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
                   5866:                                       $lt{$field}.'</label>';
                   5867:                         if ($field eq 'user') {
                   5868:                             my $seluserdom = '';
                   5869:                             my $unseluserdom = ' selected="selected"';
                   5870:                             if ($userincdom) {
                   5871:                                 $seluserdom = $unseluserdom;
                   5872:                                 $unseluserdom = '';
                   5873:                             }
                   5874:                             $datatable .= ':&nbsp;'.
                   5875:                                 '<select name="proctoring_userincdom_'.$provider.'">'.
                   5876:                                 '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
                   5877:                                 '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
                   5878:                                 '</select>&nbsp;';
                   5879:                         } else {
                   5880:                             $datatable .= '&nbsp;';
                   5881:                             if ($field eq 'roles') {
                   5882:                                 $showroles = 1; 
                   5883:                             } 
                   5884:                         }
                   5885:                         $datatable .= '</span> ';
                   5886:                     }
                   5887:                 }
                   5888:                 $datatable .= '</fieldset>'."\n";
                   5889:             }
                   5890:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   5891:                 if (@{$optuserfields{$provider}} > 0) {
                   5892:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>'; 
                   5893:                     foreach my $field (@{$optuserfields{$provider}}) {
                   5894:                         my $checked;
                   5895:                         if ($checkedfields{$field}) {
                   5896:                             $checked = ' checked="checked"';
                   5897:                         }
                   5898:                         $datatable .= '<span class="LC_nobreak">'.
                   5899:                                       '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span>&nbsp; ';
                   5900:                     }
                   5901:                     $datatable .= '</fieldset>'."\n";
                   5902:                 }
                   5903:             }
                   5904:             if (ref($defaults{$provider}) eq 'ARRAY') {
                   5905:                 if (@{$defaults{$provider}}) {
                   5906:                     my (%options,@selectboxes);
                   5907:                     if (ref($extended{$provider}) eq 'HASH') {
                   5908:                         %options = %{$extended{$provider}};
                   5909:                     }
                   5910:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
                   5911:                     my ($rem,$numinrow,$dropdowns);
                   5912:                     if ($provider eq 'proctorio') { 
                   5913:                         $datatable .= '<table>';
                   5914:                         $numinrow = 4;
                   5915:                     }
                   5916:                     my $i = 0;
                   5917:                     foreach my $field (@{$defaults{$provider}}) {
                   5918:                         my $checked;
                   5919:                         if ($inuse{$field}) {
                   5920:                             $checked = ' checked="checked"';
                   5921:                         }
                   5922:                         if ($provider eq 'examity') {
                   5923:                             if ($field eq 'display') {
                   5924:                                 $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
                   5925:                                 foreach my $option ('iframe','tab','window') {
                   5926:                                     my $checkdisp;
                   5927:                                     if ($currentdef{'target'} eq $option) {
                   5928:                                         $checkdisp = ' checked="checked"';
                   5929:                                     }
                   5930:                                     $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
                   5931:                                     $fieldtitles{$option}.'</label>'.('&nbsp;'x2);
                   5932:                                 }
                   5933:                                 $datatable .= ('&nbsp;'x4);
                   5934:                                 foreach my $dimen ('width','height') {
                   5935:                                     $datatable .= '<label>'.$fieldtitles{$dimen}.'&nbsp;'.
                   5936:                                                   '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
                   5937:                                                   'value="'.$currentdef{$dimen}.'" /></label>'.
                   5938:                                                   ('&nbsp;'x2);
                   5939:                                 }
                   5940:                                 $datatable .= '</span><br />'.
                   5941:                                               '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
                   5942:                                               '<input type="text" name="proctoring_linktext_'.$provider.'" '.
                   5943:                                               'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
                   5944:                                               '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
                   5945:                                               '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
                   5946:                                               $currentdef{'explanation'}.
                   5947:                                               '</textarea></div><div style=""></div><br />';
                   5948:                             }
                   5949:                         } else {
                   5950:                             if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   5951:                                 my ($output,$selnone);
                   5952:                                 unless ($checked) {
                   5953:                                     $selnone = ' selected="selected"';
                   5954:                                 }
                   5955:                                 $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
                   5956:                                            '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
                   5957:                                            '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>'; 
                   5958:                                 foreach my $option (@{$options{$field}}) {
                   5959:                                     my $sel; 
                   5960:                                     if ($inuse{$field} eq $option) {
                   5961:                                         $sel = ' selected="selected"';
                   5962:                                     }
                   5963:                                     $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
                   5964:                                 }
                   5965:                                 $output .= '</select></span>';
                   5966:                                 push(@selectboxes,$output);
                   5967:                             } else {
                   5968:                                 $rem = $i%($numinrow);
                   5969:                                 if ($rem == 0) {
                   5970:                                     if ($i > 0) {
                   5971:                                         $datatable .= '</tr>';
                   5972:                                     }
                   5973:                                     $datatable .= '<tr>';
                   5974:                                 }
                   5975:                                 $datatable .= '<td class="LC_left_item">'.
                   5976:                                               '<span class="LC_nobreak">'.
                   5977:                                               '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
                   5978:                                               $fieldtitles{$field}.'</label></span></td>';
                   5979:                                 $i++;
                   5980:                             }
                   5981:                         }
                   5982:                     }
                   5983:                     if ($provider eq 'proctorio') {
                   5984:                         if ($numinrow) {
                   5985:                             $rem = $i%$numinrow;
                   5986:                         }
                   5987:                         my $colsleft = $numinrow - $rem;
                   5988:                         if ($colsleft > 1) {
                   5989:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   5990:                         } else {
                   5991:                             $datatable .= '<td class="LC_left_item">';
                   5992:                         }
                   5993:                         $datatable .= '&nbsp;'.
                   5994:                                       '</td></tr></table>';
                   5995:                         if (@selectboxes) {
                   5996:                             $datatable .= '<hr /><table>';
                   5997:                             $numinrow = 2;
                   5998:                             for (my $i=0; $i<@selectboxes; $i++) {
                   5999:                                 $rem = $i%($numinrow);
                   6000:                                 if ($rem == 0) {
                   6001:                                     if ($i > 0) {
                   6002:                                         $datatable .= '</tr>';
                   6003:                                     }
                   6004:                                     $datatable .= '<tr>';
                   6005:                                 }
                   6006:                                 $datatable .= '<td class="LC_left_item">'.
                   6007:                                               $selectboxes[$i].'</td>';
                   6008:                             }
                   6009:                             if ($numinrow) {
                   6010:                                 $rem = $i%$numinrow;
                   6011:                             }
                   6012:                             $colsleft = $numinrow - $rem;
                   6013:                             if ($colsleft > 1) {
                   6014:                                 $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6015:                             } else {
                   6016:                                 $datatable .= '<td class="LC_left_item">';
                   6017:                             }
                   6018:                             $datatable .= '&nbsp;'.
                   6019:                                           '</td></tr></table>';
                   6020:                         }
                   6021:                     }
                   6022:                     $datatable .= '</fieldset>';
                   6023:                 }
                   6024:                 if (ref($crsconf{$provider}) eq 'ARRAY') {
                   6025:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6026:                                   '<legend>'.&mt('Configurable in course').'</legend>';
                   6027:                     my ($rem,$numinrow);
                   6028:                     if ($provider eq 'proctorio') {
                   6029:                         $datatable .= '<table>';
                   6030:                         $numinrow = 4;
                   6031:                     }
                   6032:                     my $i = 0;
                   6033:                     foreach my $item (@{$crsconf{$provider}}) {
                   6034:                         my $name;
                   6035:                         if ($provider eq 'examity') {
                   6036:                             $name = $lt{'crs'.$item};
                   6037:                         } elsif ($provider eq 'proctorio') {
                   6038:                             $name = $fieldtitles{$item};
                   6039:                             $rem = $i%($numinrow);
                   6040:                             if ($rem == 0) {
                   6041:                                 if ($i > 0) {
                   6042:                                     $datatable .= '</tr>';
                   6043:                                 }
                   6044:                                 $datatable .= '<tr>';
                   6045:                             }
                   6046:                             $datatable .= '<td class="LC_left_item>';
                   6047:                         }
                   6048:                         my $checked;
                   6049:                         if ($crsconfig{$item}) {
                   6050:                             $checked = ' checked="checked"';
                   6051:                         }
                   6052:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   6053:                                       '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
                   6054:                                       $name.'</label></span>';
                   6055:                         if ($provider eq 'examity') {
                   6056:                             $datatable .= '&nbsp; ';
                   6057:                         }
                   6058:                         $datatable .= "\n";
                   6059:                         $i++;
                   6060:                     }
                   6061:                     if ($provider eq 'proctorio') {
                   6062:                         if ($numinrow) {
                   6063:                             $rem = $i%$numinrow;
                   6064:                         }
                   6065:                         my $colsleft = $numinrow - $rem;
                   6066:                         if ($colsleft > 1) {
                   6067:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6068:                         } else {
                   6069:                             $datatable .= '<td class="LC_left_item">';
                   6070:                         }
                   6071:                         $datatable .= '&nbsp;'.
                   6072:                                       '</td></tr></table>';
                   6073:                     }
                   6074:                     $datatable .= '</fieldset>';
                   6075:                 }
                   6076:                 if ($showroles) {
                   6077:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6078:                                   '<legend>'.&mt('Role mapping').'</legend><table><tr>';
                   6079:                     foreach my $role (@courseroles) {
                   6080:                         my ($selected,$selectnone);
                   6081:                         if (!$rolemaps{$role}) {
                   6082:                             $selectnone = ' selected="selected"';
                   6083:                         }
                   6084:                         $datatable .= '<td style="text-align: center">'.
                   6085:                                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   6086:                                       '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
                   6087:                                       '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6088:                         foreach my $ltirole (@ltiroles) {
                   6089:                             unless ($selectnone) {
                   6090:                                 if ($rolemaps{$role} eq $ltirole) {
                   6091:                                     $selected = ' selected="selected"';
                   6092:                                 } else {
                   6093:                                     $selected = '';
                   6094:                                 }
                   6095:                             }
                   6096:                             $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   6097:                         }
                   6098:                         $datatable .= '</select></td>';
                   6099:                     }
                   6100:                     $datatable .= '</tr></table></fieldset>'.
                   6101:                                   '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6102:                                   '<legend>'.&mt('Custom items sent on launch').'</legend>'.
                   6103:                                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   6104:                                   '<tr><td></td><td>lms</td>'.
                   6105:                                   '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
                   6106:                                   ' value="Loncapa" disabled="disabled"/></td></tr>';
                   6107:                     if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
                   6108:                         (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
                   6109:                         my %custom = %{$settings->{$provider}->{'custom'}};
                   6110:                         if (keys(%custom) > 0) {
                   6111:                             foreach my $key (sort(keys(%custom))) {
                   6112:                                 next if ($key eq 'lms');
                   6113:                                 $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6114:                                               '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
                   6115:                                               $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   6116:                                               '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
                   6117:                                               ' value="'.$custom{$key}.'" /></td></tr>';
                   6118:                             }
                   6119:                         }
                   6120:                     }
                   6121:                     $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6122:                                   '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
                   6123:                                   &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
                   6124:                                   '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
                   6125:                                   '</table></fieldset></td></tr>'."\n";
                   6126:                 }
                   6127:                 $datatable .= '</td></tr>';
                   6128:             }
                   6129:             $itemcount ++;
                   6130:         }
                   6131:     }
                   6132:     return $datatable;
                   6133: }
                   6134: 
                   6135: sub proctoring_data {
                   6136:     my $requserfields = {
                   6137:                       proctorio => ['user'],
                   6138:                       examity   => ['roles','user'],
                   6139:                      };
                   6140:     my $optuserfields = {
                   6141:                         proctorio => ['fullname'],
                   6142:                         examity   => ['fullname','firstname','lastname','email'],
                   6143:                      };
                   6144:     my $defaults = {
                   6145:                   proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6146:                                 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6147:                                 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6148:                                 'closetabs','onescreen','print','downloads','cache','rightclick',
                   6149:                                 'reentry','calculator','whiteboard'],
                   6150:                   examity   => ['display'],
                   6151:                 };
                   6152:     my $extended = { 
                   6153:                   proctorio => {
                   6154:                                  verifyid => ['verifyidauto','verifyidlive'],
                   6155:                                  fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
                   6156:                                  tabslinks => ['notabs','linksonly'],
                   6157:                                  reentry => ['noreentry','agentreentry'],
                   6158:                                  calculator => ['calculatorbasic','calculatorsci'],
                   6159:                                },
                   6160:                   examity => {
                   6161:                                display => {
                   6162:                                            target      => ['iframe','tab','window'],
                   6163:                                            width       => '',
                   6164:                                            height      => '',
                   6165:                                            linktext    => '',
                   6166:                                            explanation => '',
                   6167:                                           },
                   6168:                              },
                   6169:                 };
                   6170:     my $crsconf = {
                   6171:                  proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6172:                                'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6173:                                'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6174:                                'closetabs','onescreen','print','downloads','cache','rightclick',
                   6175:                                'reentry','calculator','whiteboard'],
                   6176:                  examity => ['label','title','target','linktext','explanation','append'],
                   6177:                };
                   6178:     my $courseroles = ['cc','in','ta','ep','st'];
                   6179:     my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
                   6180:     return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
                   6181: }
                   6182: 
                   6183: sub proctoring_titles {
                   6184:     my ($item) = @_;
                   6185:     my (%common_lt,%custom_lt);
                   6186:     %common_lt = &Apache::lonlocal::texthash (
                   6187:                      'avai'      => 'Available?',
                   6188:                      'base'      => 'Basic Settings',
                   6189:                      'requ'      => 'User data required to be sent on launch',
                   6190:                      'optu'      => 'User data optionally sent on launch',
                   6191:                      'udsl'      => 'User data sent on launch',
                   6192:                      'defa'      => 'Defaults for items configurable in course',
                   6193:                      'sigmethod' => 'Signature Method',
                   6194:                      'key'       => 'Key',
                   6195:                      'lifetime'  => 'Nonce lifetime (s)',
                   6196:                      'secret'    => 'Secret',
                   6197:                      'icon'      => 'Icon',
                   6198:                      'fullname'  => 'Full Name',
                   6199:                      'visible'   => 'Visible input',
                   6200:                      'username'  => 'username',
                   6201:                      'user'      => 'User',
                   6202:                  );
                   6203:     if ($item eq 'proctorio') {
                   6204:         %custom_lt = &Apache::lonlocal::texthash (
                   6205:                          'version'        => 'OAuth version',
                   6206:                          'url'            => 'API URL',
                   6207:                          'uname:dom'      => 'username-domain',
                   6208:         );
                   6209:     } elsif ($item eq 'examity') {
                   6210:         %custom_lt = &Apache::lonlocal::texthash (
                   6211:                          'version'        => 'LTI Version',
                   6212:                          'url'            => 'URL',
                   6213:                          'uname:dom'      => 'username:domain',
                   6214:                          'msgtype'        => 'Message Type',
                   6215:                          'firstname'      => 'First Name',
                   6216:                          'lastname'       => 'Last Name',
                   6217:                          'email'          => 'E-mail',
                   6218:                          'roles'          => 'Role',
                   6219:                          'crstarget'      => 'Display target',
                   6220:                          'crslabel'       => 'Course label',
                   6221:                          'crstitle'       => 'Course title', 
                   6222:                          'crslinktext'    => 'Link Text',
                   6223:                          'crsexplanation' => 'Explanation',
                   6224:                          'crsappend'      => 'Provider URL',
                   6225:         );
                   6226:     }
                   6227:     my %lt = (%common_lt,%custom_lt);
                   6228:     return %lt;
                   6229: }
                   6230: 
                   6231: sub proctoring_fieldtitles {
                   6232:     my ($item) = @_;
                   6233:     if ($item eq 'proctorio') {
                   6234:         return &Apache::lonlocal::texthash (
                   6235:                   'recordvideo' => 'Record video',
                   6236:                   'recordaudio' => 'Record audio',
                   6237:                   'recordscreen' => 'Record screen',
                   6238:                   'recordwebtraffic' => 'Record web traffic',
                   6239:                   'recordroomstart' => 'Record room scan',
                   6240:                   'verifyvideo' => 'Verify webcam',
                   6241:                   'verifyaudio' => 'Verify microphone',
                   6242:                   'verifydesktop' => 'Verify desktop recording',
                   6243:                   'verifyid' => 'Photo ID verification',
                   6244:                   'verifysignature' => 'Require signature',
                   6245:                   'fullscreen' => 'Fullscreen',
                   6246:                   'clipboard' => 'Disable copy/paste',
                   6247:                   'tabslinks' => 'New tabs/windows',
                   6248:                   'closetabs' => 'Close other tabs',
                   6249:                   'onescreen' => 'Limit to single screen',
                   6250:                   'print' => 'Disable Printing',
                   6251:                   'downloads' => 'Disable Downloads',
                   6252:                   'cache' => 'Empty cache after exam',
                   6253:                   'rightclick' => 'Disable right click',
                   6254:                   'reentry' => 'Re-entry to exam',
                   6255:                   'calculator' => 'Onscreen calculator',
                   6256:                   'whiteboard' => 'Onscreen whiteboard',
                   6257:                   'verifyidauto' => 'Automated verification',
                   6258:                   'verifyidlive' => 'Live agent verification',
                   6259:                   'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
                   6260:                   'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
                   6261:                   'fullscreensever' => 'Forced, navigation away ends exam',
                   6262:                   'notabs' => 'Disaallowed',
                   6263:                   'linksonly' => 'Allowed from links in exam',
                   6264:                   'noreentry' => 'Disallowed',
                   6265:                   'agentreentry' => 'Agent required for re-entry',
                   6266:                   'calculatorbasic' => 'Basic',
                   6267:                   'calculatorsci' => 'Scientific',
                   6268:         );
                   6269:     } elsif ($item eq 'examity') {
                   6270:         return &Apache::lonlocal::texthash (
                   6271:                 'target'         => 'Display target',   
                   6272:                 'window'         => 'Window',
                   6273:                 'tab'            => 'Tab',
                   6274:                 'iframe'         => 'iFrame',
                   6275:                 'height'         => 'Height (pixels)',
                   6276:                 'width'          => 'Width (pixels)',
                   6277:                 'linktext'       => 'Default Link Text',
                   6278:                 'explanation'    => 'Default Explanation',
                   6279:                 'append'         => 'Provider URL',
                   6280:         );
                   6281:     }
                   6282: }
                   6283: 
                   6284: sub proctoring_providernames {
                   6285:     return (
                   6286:              proctorio => 'Proctorio',
                   6287:              examity   => 'Examity',
                   6288:            );
                   6289: }
                   6290: 
1.320     raeburn  6291: sub print_lti {
                   6292:     my ($dom,$settings,$rowtotal) = @_;
                   6293:     my $itemcount = 1;
                   6294:     my $maxnum = 0;
                   6295:     my $css_class;
                   6296:     my %ordered;
                   6297:     if (ref($settings) eq 'HASH') {
                   6298:         foreach my $item (keys(%{$settings})) {
                   6299:             if (ref($settings->{$item}) eq 'HASH') {
                   6300:                 my $num = $settings->{$item}{'order'};
1.390     raeburn  6301:                 if ($num eq '') {
                   6302:                     $num = scalar(keys(%{$settings}));
                   6303:                 }
1.320     raeburn  6304:                 $ordered{$num} = $item;
                   6305:             }
                   6306:         }
                   6307:     }
                   6308:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  6309:     my $datatable;
1.320     raeburn  6310:     my %lt = &lti_names();
                   6311:     if (keys(%ordered)) {
                   6312:         my @items = sort { $a <=> $b } keys(%ordered);
                   6313:         for (my $i=0; $i<@items; $i++) {
                   6314:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6315:             my $item = $ordered{$items[$i]};
1.391     raeburn  6316:             my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
1.320     raeburn  6317:             if (ref($settings->{$item}) eq 'HASH') {
                   6318:                 $key = $settings->{$item}->{'key'};
                   6319:                 $secret = $settings->{$item}->{'secret'};
                   6320:                 $lifetime = $settings->{$item}->{'lifetime'};
                   6321:                 $consumer = $settings->{$item}->{'consumer'};
1.345     raeburn  6322:                 $requser = $settings->{$item}->{'requser'};
1.391     raeburn  6323:                 $crsinc = $settings->{$item}->{'crsinc'};
1.320     raeburn  6324:                 $current = $settings->{$item};
                   6325:             }
1.345     raeburn  6326:             my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
                   6327:             my %checkedrequser = (
                   6328:                                    yes => ' checked="checked"',
                   6329:                                    no  => '',
                   6330:                                  );
                   6331:             if (!$requser) {
                   6332:                 $checkedrequser{'no'} = $checkedrequser{'yes'};
                   6333:                 $checkedrequser{'yes'} = '';
1.352     raeburn  6334:             }
1.391     raeburn  6335:             my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
                   6336:             my %checkedcrsinc = (
                   6337:                                       yes => ' checked="checked"',
                   6338:                                       no  => '',
                   6339:                                    );
                   6340:             if (!$crsinc) {
                   6341:                 $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
                   6342:                 $checkedcrsinc{'yes'} = '';
                   6343:             }
1.320     raeburn  6344:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
                   6345:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6346:                          .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
                   6347:             for (my $k=0; $k<=$maxnum; $k++) {
                   6348:                 my $vpos = $k+1;
                   6349:                 my $selstr;
                   6350:                 if ($k == $i) {
                   6351:                     $selstr = ' selected="selected" ';
                   6352:                 }
                   6353:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6354:             }
                   6355:             $datatable .= '</select>'.('&nbsp;'x2).
                   6356:                 '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
                   6357:                 &mt('Delete?').'</label></span></td>'.
                   6358:                 '<td colspan="2">'.
                   6359:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6360:                 '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  6361:                 ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320     raeburn  6362:                 ('&nbsp;'x2).
                   6363:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                   6364:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   6365:                 ('&nbsp;'x2).
                   6366:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345     raeburn  6367:                 'value="'.$lifetime.'" size="3" /></span>'.
                   6368:                 ('&nbsp;'x2).
                   6369:                  '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6370:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6371:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  6372:                 '<br /><br />'.
1.391     raeburn  6373:                 '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6374:                 '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6375:                 '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
                   6376:                 ('&nbsp;'x4).
1.320     raeburn  6377:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   6378:                 ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
                   6379:                 ('&nbsp;'x2).
                   6380:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   6381:                 '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
                   6382:                 '<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>'.
                   6383:                 '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325     raeburn  6384:                 '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320     raeburn  6385:             $itemcount ++;
                   6386:         }
                   6387:     }
                   6388:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6389:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
                   6390:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   6391:                   '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
                   6392:                   '<select name="lti_pos_add"'.$chgstr.'>';
                   6393:     for (my $k=0; $k<$maxnum+1; $k++) {
                   6394:         my $vpos = $k+1;
                   6395:         my $selstr;
                   6396:         if ($k == $maxnum) {
                   6397:             $selstr = ' selected="selected" ';
                   6398:         }
                   6399:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6400:     }
                   6401:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  6402:                   '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320     raeburn  6403:                   '<td colspan="2">'.
                   6404:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6405:                   '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  6406:                   ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320     raeburn  6407:                   ('&nbsp;'x2).
                   6408:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   6409:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   6410:                   ('&nbsp;'x2).
1.345     raeburn  6411:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
                   6412:                   ('&nbsp;'x2).
                   6413:                   '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6414:                   '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6415:                   '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  6416:                   '<br /><br />'.
1.391     raeburn  6417:                   '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6418:                   '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6419:                   '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
                   6420:                   ('&nbsp;'x4).
1.320     raeburn  6421:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
                   6422:                   ('&nbsp;'x2).
                   6423:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
                   6424:                   '<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".
1.325     raeburn  6425:                   '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
1.320     raeburn  6426:                   '</td>'."\n".
                   6427:                   '</tr>'."\n";
                   6428:     $$rowtotal ++;
                   6429:     return $datatable;;
                   6430: }
                   6431: 
                   6432: sub lti_names {
                   6433:     my %lt = &Apache::lonlocal::texthash(
                   6434:                                           'version'   => 'LTI Version',
                   6435:                                           'url'       => 'URL',
                   6436:                                           'key'       => 'Key',
1.322     raeburn  6437:                                           'lifetime'  => 'Nonce lifetime (s)',
1.345     raeburn  6438:                                           'consumer'  => 'Consumer',
1.320     raeburn  6439:                                           'secret'    => 'Secret',
1.345     raeburn  6440:                                           'requser'   => "User's identity sent",
1.391     raeburn  6441:                                           'crsinc'    => "Course's identity sent",
1.320     raeburn  6442:                                           'email'     => 'Email address',
                   6443:                                           'sourcedid' => 'User ID',
                   6444:                                           'other'     => 'Other',
                   6445:                                           'passback'  => 'Can return grades to Consumer:',
                   6446:                                           'roster'    => 'Can retrieve roster from Consumer:',
1.326     raeburn  6447:                                           'topmenu'   => 'Display LON-CAPA page header',
1.345     raeburn  6448:                                           'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320     raeburn  6449:                                         );
                   6450:     return %lt;
                   6451: }
                   6452: 
                   6453: sub lti_options {
1.325     raeburn  6454:     my ($num,$current,$itemcount,%lt) = @_;
1.363     raeburn  6455:     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320     raeburn  6456:     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
                   6457:     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392     raeburn  6458:     $checked{'storecrs'}{'Y'} = ' checked="checked"';
                   6459:     $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320     raeburn  6460:     $checked{'mapcrstype'} = {};
                   6461:     $checked{'makeuser'} = {};
                   6462:     $checked{'selfenroll'} = {};
                   6463:     $checked{'crssec'} = {};
                   6464:     $checked{'crssecsrc'} = {};
1.325     raeburn  6465:     $checked{'lcauth'} = {};
1.326     raeburn  6466:     $checked{'menuitem'} = {};
1.325     raeburn  6467:     if ($num eq 'add') {
                   6468:         $checked{'lcauth'}{'lti'} = ' checked="checked"';
                   6469:     }
1.320     raeburn  6470:     my $userfieldsty = 'none';
                   6471:     my $crsfieldsty = 'none';
                   6472:     my $crssecfieldsty = 'none';
                   6473:     my $secsrcfieldsty = 'none';
1.363     raeburn  6474:     my $callbacksty = 'none';
1.337     raeburn  6475:     my $passbacksty = 'none';
1.345     raeburn  6476:     my $optionsty = 'block';
1.391     raeburn  6477:     my $crssty = 'block';
1.325     raeburn  6478:     my $lcauthparm;
                   6479:     my $lcauthparmstyle = 'display:none';
                   6480:     my $lcauthparmtext;
1.326     raeburn  6481:     my $menusty;
1.325     raeburn  6482:     my $numinrow = 4;
1.326     raeburn  6483:     my %menutitles = &ltimenu_titles();
1.320     raeburn  6484: 
                   6485:     if (ref($current) eq 'HASH') {
1.345     raeburn  6486:         if (!$current->{'requser'}) {
                   6487:             $optionsty = 'none';
1.391     raeburn  6488:             $crssty = 'none';
                   6489:         } elsif (!$current->{'crsinc'}) {
                   6490:             $crssty = 'none';
1.345     raeburn  6491:         }
1.320     raeburn  6492:         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
                   6493:             $checked{'mapuser'}{'sourcedid'} = '';
                   6494:             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
                   6495:                 $checked{'mapuser'}{'email'} = ' checked="checked"'; 
                   6496:             } else {
                   6497:                 $checked{'mapuser'}{'other'} = ' checked="checked"';
                   6498:                 $userfield = $current->{'mapuser'};
                   6499:                 $userfieldsty = 'inline-block';
                   6500:             }
                   6501:         }
                   6502:         if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
                   6503:             $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
                   6504:             if ($current->{'mapcrs'} eq 'context_id') {
                   6505:                 $checked{'mapcrs'}{'context_id'} = ' checked="checked"'; 
                   6506:             } else {
                   6507:                 $checked{'mapcrs'}{'other'} = ' checked="checked"';
                   6508:                 $cidfield = $current->{'mapcrs'};
                   6509:                 $crsfieldsty = 'inline-block';
                   6510:             }
                   6511:         }
                   6512:         if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
                   6513:             foreach my $type (@{$current->{'mapcrstype'}}) {
                   6514:                 $checked{'mapcrstype'}{$type} = ' checked="checked"';
                   6515:             }
                   6516:         }
1.392     raeburn  6517:         if (!$current->{'storecrs'}) {
                   6518:             $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
                   6519:             $checked{'storecrs'}{'Y'} = '';
                   6520:         }
1.345     raeburn  6521:         if ($current->{'makecrs'}) {
1.320     raeburn  6522:             $checked{'makecrs'}{'Y'} = '  checked="checked"';
1.326     raeburn  6523:         }
1.320     raeburn  6524:         if (ref($current->{'makeuser'}) eq 'ARRAY') {
                   6525:             foreach my $role (@{$current->{'makeuser'}}) {
                   6526:                 $checked{'makeuser'}{$role} = ' checked="checked"';
                   6527:             }
                   6528:         }
1.325     raeburn  6529:         if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
                   6530:             $checked{'lcauth'}{$1} = ' checked="checked"';
                   6531:             unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   6532:                 $lcauthparm = $current->{'lcauthparm'};
                   6533:                 $lcauthparmstyle = 'display:table-row'; 
                   6534:                 if ($current->{'lcauth'} eq 'localauth') {
                   6535:                     $lcauthparmtext = &mt('Local auth argument');
                   6536:                 } else {
                   6537:                     $lcauthparmtext = &mt('Kerberos domain');
                   6538:                 }
                   6539:             }
                   6540:         }
1.320     raeburn  6541:         if (ref($current->{'selfenroll'}) eq 'ARRAY') {
                   6542:             foreach my $role (@{$current->{'selfenroll'}}) {
                   6543:                 $checked{'selfenroll'}{$role} = ' checked="checked"';
                   6544:             }
                   6545:         }
                   6546:         if (ref($current->{'maproles'}) eq 'HASH') {
                   6547:             %rolemaps = %{$current->{'maproles'}};
                   6548:         }
                   6549:         if ($current->{'section'} ne '') {
                   6550:             $checked{'crssec'}{'Y'} = '  checked="checked"'; 
                   6551:             $crssecfieldsty = 'inline-block';
                   6552:             if ($current->{'section'} eq 'course_section_sourcedid') {
                   6553:                 $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
                   6554:             } else {
                   6555:                 $checked{'crssecsrc'}{'other'} = ' checked="checked"';
                   6556:                 $crssecsrc = $current->{'section'};
                   6557:                 $secsrcfieldsty = 'inline-block';
                   6558:             }
                   6559:         } else {
                   6560:             $checked{'crssec'}{'N'} = ' checked="checked"';
                   6561:         }
1.363     raeburn  6562:         if ($current->{'callback'} ne '') {
                   6563:             $callback = $current->{'callback'};
                   6564:             $checked{'callback'}{'Y'} = ' checked="checked"';
                   6565:             $callbacksty = 'inline-block';
                   6566:         } else {
                   6567:             $checked{'callback'}{'N'} = ' checked="checked"';
                   6568:         }
1.326     raeburn  6569:         if ($current->{'topmenu'}) {
                   6570:             $checked{'topmenu'}{'Y'} = ' checked="checked"';
                   6571:         } else {
                   6572:             $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6573:         }
                   6574:         if ($current->{'inlinemenu'}) {
                   6575:             $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
                   6576:         } else {
                   6577:             $checked{'inlinemenu'}{'N'} = ' checked="checked"';
                   6578:         }
                   6579:         if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
                   6580:             $menusty = 'inline-block';
                   6581:             if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   6582:                 foreach my $item (@{$current->{'lcmenu'}}) {
                   6583:                     if (exists($menutitles{$item})) {
                   6584:                         $checked{'menuitem'}{$item} = ' checked="checked"';
                   6585:                     }
                   6586:                 }
                   6587:             }
                   6588:         } else {
                   6589:             $menusty = 'none';
                   6590:         }
1.320     raeburn  6591:     } else {
                   6592:         $checked{'makecrs'}{'N'} = ' checked="checked"';
                   6593:         $checked{'crssec'}{'N'} = ' checked="checked"';
1.363     raeburn  6594:         $checked{'callback'}{'N'} = ' checked="checked"';
1.326     raeburn  6595:         $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6596:         $checked{'inlinemenu'}{'Y'} = ' checked="checked"'; 
                   6597:         $checked{'menuitem'}{'grades'} = ' checked="checked"';
                   6598:         $menusty = 'inline-block'; 
1.320     raeburn  6599:     }
1.325     raeburn  6600:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  6601:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   6602:                                official   => 'Official',
                   6603:                                unofficial => 'Unofficial',
                   6604:                                community  => 'Community',
                   6605:                                textbook   => 'Textbook',
                   6606:                                placement  => 'Placement Test',
1.325     raeburn  6607:                                lti        => 'LTI Provider',
1.320     raeburn  6608:     );
1.325     raeburn  6609:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6610:     my %shortauth = (
                   6611:                      internal => 'int',
                   6612:                      krb4 => 'krb4',
                   6613:                      krb5 => 'krb5',
                   6614:                      localauth  => 'loc'
                   6615:                     );
                   6616:     my %authnames = &authtype_names();
1.320     raeburn  6617:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   6618:     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
                   6619:     my @courseroles = ('cc','in','ta','ep','st');
                   6620:     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
                   6621:     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
                   6622:     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363     raeburn  6623:     my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320     raeburn  6624:     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325     raeburn  6625:     my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326     raeburn  6626:     my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391     raeburn  6627:     my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392     raeburn  6628:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').':&nbsp;'.
1.391     raeburn  6629:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
                   6630:                  $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6631:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
                   6632:                  $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
                   6633:                  '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
                   6634:                  '<span class="LC_nobreak">'.&mt('Parameter').': '.
                   6635:                  '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
                   6636:                  '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
                   6637:                  '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320     raeburn  6638:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
                   6639:     foreach my $option ('sourcedid','email','other') {
                   6640:         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
                   6641:                    $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
                   6642:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6643:     }
                   6644:     $output .= '</span></div>'.
                   6645:                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                   6646:                '<input type="text" name="lti_customuser_'.$num.'" '.
1.372     raeburn  6647:                'value="'.$userfield.'" /></div></fieldset>'.
1.391     raeburn  6648:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320     raeburn  6649:     foreach my $ltirole (@ltiroles) {
                   6650:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
                   6651:                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';     
                   6652:     }
                   6653:     $output .= '</fieldset>'.
1.391     raeburn  6654:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325     raeburn  6655:                '<table>'.
                   6656:                &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                   6657:                '</table>'.
                   6658:                '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                   6659:                '<td class="LC_left_item">';
                   6660:     foreach my $auth ('lti',@authtypes) {
                   6661:         my $authtext;
                   6662:         if ($auth eq 'lti') {
                   6663:             $authtext = &mt('None');
                   6664:         } else {
                   6665:             $authtext = $authnames{$shortauth{$auth}};
                   6666:         }
                   6667:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                   6668:                    '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                   6669:                    $authtext.'</label></span> &nbsp;';
                   6670:     }
                   6671:     $output .= '</td></tr>'.
                   6672:                '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                   6673:                '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                   6674:                '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                   6675:                '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                   6676:                '</table></fieldset>'.
1.391     raeburn  6677:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
                   6678:                &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
                   6679:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                   6680:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                   6681:                $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6682:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
                   6683:                $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
                   6684:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6685:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                   6686:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                   6687:                $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6688:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
                   6689:                $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
                   6690:      $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6691:                '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                   6692:                '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
                   6693:     foreach my $type ('fullname','coursetitle','role','logout','grades') {
                   6694:         $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                   6695:                    $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                   6696:                    ('&nbsp;'x2);
                   6697:     }
                   6698:     $output .= '</span></div></fieldset>'.
                   6699:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320     raeburn  6700:                '<div class="LC_floatleft"><span class="LC_nobreak">'.
                   6701:                &mt('Unique course identifier').':&nbsp;';
                   6702:     foreach my $option ('course_offering_sourcedid','context_id','other') {
                   6703:         $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
                   6704:                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                   6705:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6706:     }
1.334     raeburn  6707:     $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320     raeburn  6708:                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                   6709:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6710:                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
                   6711:     foreach my $type (@coursetypes) {
                   6712:         $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
                   6713:                    $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
                   6714:                    ('&nbsp;'x2);
                   6715:     }
1.392     raeburn  6716:     $output .= '</span><br /><br />'.
                   6717:                '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').':&nbsp;'.
                   6718:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
                   6719:                $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6720:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
                   6721:                $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6722:                '</fieldset>'.
1.391     raeburn  6723:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
                   6724:     foreach my $ltirole (@lticourseroles) {
                   6725:         my ($selected,$selectnone);
                   6726:         if ($rolemaps{$ltirole} eq '') {
                   6727:             $selectnone = ' selected="selected"';
                   6728:         }
                   6729:         $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
                   6730:                    '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
                   6731:                    '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6732:         foreach my $role (@courseroles) {
                   6733:             unless ($selectnone) {
                   6734:                 if ($rolemaps{$ltirole} eq $role) {
                   6735:                     $selected = ' selected="selected"';
                   6736:                 } else {
                   6737:                     $selected = '';
                   6738:                 }
                   6739:             }
                   6740:             $output .= '<option value="'.$role.'"'.$selected.'>'.
                   6741:                        &Apache::lonnet::plaintext($role,'Course').
                   6742:                        '</option>';
                   6743:         }
                   6744:         $output .= '</select></td>';
                   6745:     }
                   6746:     $output .= '</tr></table></fieldset>'.
                   6747:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320     raeburn  6748:                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                   6749:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                   6750:                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6751:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                   6752:                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6753:                '</fieldset>'.
1.391     raeburn  6754:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320     raeburn  6755:     foreach my $lticrsrole (@lticourseroles) {
                   6756:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                   6757:                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
                   6758:     }
                   6759:     $output .= '</fieldset>'.
1.391     raeburn  6760:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320     raeburn  6761:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                   6762:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                   6763:                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6764:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334     raeburn  6765:                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320     raeburn  6766:                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                   6767:                '<span class="LC_nobreak">'.&mt('From').':<label>'.
                   6768:                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
                   6769:                $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
                   6770:                &mt('Standard field').'</label>'.('&nbsp;'x2).
                   6771:                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                   6772:                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334     raeburn  6773:                '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320     raeburn  6774:                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337     raeburn  6775:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
                   6776:     my ($pb1p1chk,$pb1p0chk,$onclickpb);
                   6777:     foreach my $extra ('roster','passback') {
1.320     raeburn  6778:         my $checkedon = '';
                   6779:         my $checkedoff = ' checked="checked"';
1.337     raeburn  6780:         if ($extra eq 'passback') {
                   6781:             $pb1p1chk = ' checked="checked"';
                   6782:             $pb1p0chk = '';
                   6783:             $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"'; 
                   6784:         } else {
                   6785:             $onclickpb = ''; 
                   6786:         }
1.320     raeburn  6787:         if (ref($current) eq 'HASH') {
                   6788:             if (($current->{$extra})) {
                   6789:                 $checkedon = $checkedoff;
                   6790:                 $checkedoff = '';
1.337     raeburn  6791:                 if ($extra eq 'passback') {
                   6792:                     $passbacksty = 'inline-block';
                   6793:                 }
                   6794:                 if ($current->{'passbackformat'} eq '1.0') {
                   6795:                     $pb1p0chk =  ' checked="checked"';
                   6796:                     $pb1p1chk = '';
                   6797:                 }
1.320     raeburn  6798:             }
                   6799:         }
                   6800:         $output .= $lt{$extra}.'&nbsp;'.
1.337     raeburn  6801:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320     raeburn  6802:                    &mt('No').'</label>'.('&nbsp;'x2).
1.339     raeburn  6803:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320     raeburn  6804:                    &mt('Yes').'</label><br />';
                   6805:     }
1.337     raeburn  6806:     $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                   6807:                '<span class="LC_nobreak">'.&mt('Grade format').
                   6808:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                   6809:                &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                   6810:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363     raeburn  6811:                &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391     raeburn  6812:                '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334     raeburn  6813:     $output .= '</span></div></fieldset>';
1.320     raeburn  6814: #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
                   6815: #
                   6816: #    $output .= '</fieldset>'.
                   6817: #        '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
                   6818:     return $output;
                   6819: }
                   6820: 
1.326     raeburn  6821: sub ltimenu_titles {
                   6822:     return &Apache::lonlocal::texthash(
                   6823:                                         fullname    => 'Full name',
                   6824:                                         coursetitle => 'Course title',
                   6825:                                         role        => 'Role',
                   6826:                                         logout      => 'Logout',
                   6827:                                         grades      => 'Grades',
                   6828:     );
                   6829: }
                   6830: 
1.121     raeburn  6831: sub print_coursedefaults {
1.139     raeburn  6832:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  6833:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  6834:     my $itemcount = 1;
1.192     raeburn  6835:     my %choices =  &Apache::lonlocal::texthash (
                   6836:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  6837:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  6838:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   6839:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  6840:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   6841:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398     raeburn  6842:         inline_chem          => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314     raeburn  6843:         texengine            => 'Default method to display mathematics',
1.257     raeburn  6844:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  6845:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   6846:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192     raeburn  6847:     );
1.198     raeburn  6848:     my %staticdefaults = (
                   6849:                            anonsurvey_threshold => 10,
                   6850:                            uploadquota          => 500,
1.257     raeburn  6851:                            postsubmit           => 60,
1.276     raeburn  6852:                            mysqltables          => 172800,
1.198     raeburn  6853:                          );
1.139     raeburn  6854:     if ($position eq 'top') {
1.257     raeburn  6855:         %defaultchecked = (
                   6856:                             'canuse_pdfforms' => 'off',
                   6857:                             'uselcmath'       => 'on',
                   6858:                             'usejsme'         => 'on',
1.398     raeburn  6859:                             'inline_chem'     => 'on',
1.289     raeburn  6860:                             'canclone'        => 'none',
1.257     raeburn  6861:                           );
1.398     raeburn  6862:         @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349     raeburn  6863:         my $deftex = $Apache::lonnet::deftex;
1.314     raeburn  6864:         if (ref($settings) eq 'HASH') {
                   6865:             if ($settings->{'texengine'}) {
                   6866:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   6867:                     $deftex = $settings->{'texengine'};
                   6868:                 }
                   6869:             }
                   6870:         }
                   6871:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6872:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   6873:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   6874:                        '</span></td><td class="LC_right_item">'.
                   6875:                        '<select name="texengine">'."\n";
                   6876:         my %texoptions = (
                   6877:                             MathJax  => 'MathJax',
                   6878:                             mimetex  => &mt('Convert to Images'),
                   6879:                             tth      => &mt('TeX to HTML'),
                   6880:                          );
                   6881:         foreach my $renderer ('MathJax','mimetex','tth') {
                   6882:             my $selected = '';
                   6883:             if ($renderer eq $deftex) {
                   6884:                 $selected = ' selected="selected"';
                   6885:             }
                   6886:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   6887:         }
                   6888:         $mathdisp .= '</select></td></tr>'."\n";
                   6889:         $itemcount ++;
1.139     raeburn  6890:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  6891:                                                      \%choices,$itemcount);
1.314     raeburn  6892:         $datatable = $mathdisp.$datatable;
1.264     raeburn  6893:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6894:         $datatable .=
1.306     raeburn  6895:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  6896:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   6897:             '</span></td><td class="LC_left_item">';
                   6898:         my $currcanclone = 'none';
                   6899:         my $onclick;
                   6900:         my @cloneoptions = ('none','domain');
1.380     raeburn  6901:         my %clonetitles = &Apache::lonlocal::texthash (
1.264     raeburn  6902:                              none     => 'No additional course requesters',
                   6903:                              domain   => "Any course requester in course's domain",
                   6904:                              instcode => 'Course requests for official courses ...',
                   6905:                           );
                   6906:         my (%codedefaults,@code_order,@posscodes);
                   6907:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   6908:                                                     \@code_order) eq 'ok') {
                   6909:             if (@code_order > 0) {
                   6910:                 push(@cloneoptions,'instcode');
                   6911:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   6912:             }
                   6913:         }
                   6914:         if (ref($settings) eq 'HASH') {
                   6915:             if ($settings->{'canclone'}) {
                   6916:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   6917:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   6918:                         if (@code_order > 0) {
                   6919:                             $currcanclone = 'instcode';
                   6920:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   6921:                         }
                   6922:                     }
                   6923:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   6924:                     $currcanclone = $settings->{'canclone'};
                   6925:                 }
                   6926:             }
1.289     raeburn  6927:         }
1.264     raeburn  6928:         foreach my $option (@cloneoptions) {
                   6929:             my ($checked,$additional);
                   6930:             if ($currcanclone eq $option) {
                   6931:                 $checked = ' checked="checked"';
                   6932:             }
                   6933:             if ($option eq 'instcode') {
                   6934:                 if (@code_order) {
                   6935:                     my $show = 'none';
                   6936:                     if ($checked) {
                   6937:                         $show = 'block';
                   6938:                     }
1.317     raeburn  6939:                     $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264     raeburn  6940:                                   &mt('Institutional codes for new and cloned course have identical:').
                   6941:                                   '<br />';
                   6942:                     foreach my $item (@code_order) {
                   6943:                         my $codechk;
                   6944:                         if ($checked) {
                   6945:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   6946:                                 $codechk = ' checked="checked"';
                   6947:                             }
                   6948:                         }
                   6949:                         $additional .= '<label>'.
                   6950:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   6951:                                        $item.'</label>';
                   6952:                     }
                   6953:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   6954:                 }
                   6955:             }
                   6956:             $datatable .=
                   6957:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   6958:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   6959:                 '</label>&nbsp;'.$additional.'</span><br />';
                   6960:         }
                   6961:         $datatable .= '</td>'.
                   6962:                       '</tr>';
                   6963:         $itemcount ++;
1.139     raeburn  6964:     } else {
                   6965:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  6966:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  6967:         my $currusecredits = 0;
1.257     raeburn  6968:         my $postsubmitclient = 1;
1.271     raeburn  6969:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  6970:         if (ref($settings) eq 'HASH') {
                   6971:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  6972:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   6973:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   6974:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   6975:                 }
                   6976:             }
1.192     raeburn  6977:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  6978:                 foreach my $type (@types) {
                   6979:                     next if ($type eq 'community');
                   6980:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   6981:                     if ($defcredits{$type} ne '') {
                   6982:                         $currusecredits = 1;
                   6983:                     }
                   6984:                 }
                   6985:             }
                   6986:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   6987:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   6988:                     $postsubmitclient = 0;
                   6989:                     foreach my $type (@types) {
                   6990:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   6991:                     }
                   6992:                 } else {
                   6993:                     foreach my $type (@types) {
                   6994:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   6995:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  6996:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  6997:                             } else {
                   6998:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   6999:                             }
                   7000:                         } else {
                   7001:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7002:                         }
                   7003:                     }
                   7004:                 }
                   7005:             } else {
                   7006:                 foreach my $type (@types) {
                   7007:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  7008:                 }
                   7009:             }
1.276     raeburn  7010:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   7011:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   7012:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   7013:                 }
                   7014:             } else {
                   7015:                 foreach my $type (@types) {
                   7016:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   7017:                 }
                   7018:             }
1.258     raeburn  7019:         } else {
                   7020:             foreach my $type (@types) {
                   7021:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7022:             }
1.139     raeburn  7023:         }
                   7024:         if (!$currdefresponder) {
1.198     raeburn  7025:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  7026:         } elsif ($currdefresponder < 1) {
                   7027:             $currdefresponder = 1;
                   7028:         }
1.198     raeburn  7029:         foreach my $type (@types) {
                   7030:             if ($curruploadquota{$type} eq '') {
                   7031:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   7032:             }
                   7033:         }
1.139     raeburn  7034:         $datatable .=
1.192     raeburn  7035:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7036:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  7037:                 '</span></td>'.
                   7038:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7039:                 '<input type="text" name="anonsurvey_threshold"'.
                   7040:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  7041:                 '</td></tr>'."\n";
                   7042:         $itemcount ++;
                   7043:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7044:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7045:                       $choices{'uploadquota'}.
                   7046:                       '</span></td>'.
1.306     raeburn  7047:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  7048:                       '<table><tr>';
1.198     raeburn  7049:         foreach my $type (@types) {
1.306     raeburn  7050:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  7051:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   7052:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   7053:         }
                   7054:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  7055:         $itemcount ++;
1.236     raeburn  7056:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  7057:         my $display = 'none';
1.192     raeburn  7058:         if ($currusecredits) {
                   7059:             $display = 'block';
                   7060:         }
                   7061:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  7062:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   7063:         foreach my $type (@types) {
                   7064:             next if ($type eq 'community');
1.306     raeburn  7065:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7066:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  7067:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  7068:         }
                   7069:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  7070:         %defaultchecked = ('coursecredits' => 'off');
                   7071:         @toggles = ('coursecredits');
                   7072:         my $current = {
                   7073:                         'coursecredits' => $currusecredits,
                   7074:                       };
                   7075:         (my $table,$itemcount) =
                   7076:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  7077:                                \%choices,$itemcount,$onclick,$additional,'left');
                   7078:         $datatable .= $table;
                   7079:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   7080:         my $display = 'none';
                   7081:         if ($postsubmitclient) {
                   7082:             $display = 'block';
                   7083:         }
                   7084:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  7085:                       &mt('Number of seconds submit is disabled').'<br />'.
                   7086:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   7087:                       '<table><tr>';
1.257     raeburn  7088:         foreach my $type (@types) {
1.306     raeburn  7089:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7090:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   7091:                            $deftimeout{$type}.'" size="5" /></td>';
                   7092:         }
                   7093:         $additional .= '</tr></table></div>'."\n";
                   7094:         %defaultchecked = ('postsubmit' => 'on');
                   7095:         @toggles = ('postsubmit');
1.280     raeburn  7096:         $current = {
                   7097:                        'postsubmit' => $postsubmitclient,
                   7098:                    };
1.257     raeburn  7099:         ($table,$itemcount) =
                   7100:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   7101:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  7102:         $datatable .= $table;
1.276     raeburn  7103:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7104:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7105:                       $choices{'mysqltables'}.
                   7106:                       '</span></td>'.
1.306     raeburn  7107:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  7108:                       '<table><tr>';
                   7109:         foreach my $type (@types) {
1.306     raeburn  7110:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  7111:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  7112:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  7113:         }
                   7114:         $datatable .= '</tr></table></td></tr>'."\n";
                   7115:         $itemcount ++;
                   7116: 
1.139     raeburn  7117:     }
1.192     raeburn  7118:     $$rowtotal += $itemcount;
1.121     raeburn  7119:     return $datatable;
1.118     jms      7120: }
                   7121: 
1.231     raeburn  7122: sub print_selfenrollment {
                   7123:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7124:     my ($css_class,$datatable);
                   7125:     my $itemcount = 1;
1.271     raeburn  7126:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  7127:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  7128:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   7129:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  7130:         my @rows;
                   7131:         my $key;
                   7132:         if ($position eq 'top') {
                   7133:             $key = 'admin'; 
                   7134:             if (ref($rowsref) eq 'ARRAY') {
                   7135:                 @rows = @{$rowsref};
                   7136:             }
                   7137:         } elsif ($position eq 'middle') {
                   7138:             $key = 'default';
                   7139:             @rows = ('types','registered','approval','limit');
                   7140:         }
                   7141:         foreach my $row (@rows) {
                   7142:             if (defined($titlesref->{$row})) {
                   7143:                 $itemcount ++;
                   7144:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7145:                 $datatable .= '<tr'.$css_class.'>'.
                   7146:                               '<td>'.$titlesref->{$row}.'</td>'.
                   7147:                               '<td class="LC_left_item">'.
                   7148:                               '<table><tr>';
                   7149:                 my (%current,%currentcap);
                   7150:                 if (ref($settings) eq 'HASH') {
                   7151:                     if (ref($settings->{$key}) eq 'HASH') {
                   7152:                         foreach my $type (@types) {
                   7153:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7154:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   7155:                             }
                   7156:                             if (($row eq 'limit') && ($key eq 'default')) {
                   7157:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7158:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   7159:                                 }
                   7160:                             }
                   7161:                         }
                   7162:                     }
                   7163:                 }
                   7164:                 my %roles = (
                   7165:                              '0' => &Apache::lonnet::plaintext('dc'),
                   7166:                             ); 
                   7167:             
                   7168:                 foreach my $type (@types) {
                   7169:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   7170:                         $datatable .= '<th>'.&mt($type).'</th>';
                   7171:                     }
                   7172:                 }
                   7173:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   7174:                     $datatable .= '</tr><tr>';
                   7175:                 }
                   7176:                 foreach my $type (@types) {
                   7177:                     if ($type eq 'community') {
                   7178:                         $roles{'1'} = &mt('Community personnel');
                   7179:                     } else {
                   7180:                         $roles{'1'} = &mt('Course personnel');
                   7181:                     }
                   7182:                     $datatable .= '<td style="vertical-align: top">';
                   7183:                     if ($position eq 'top') {
                   7184:                         my %checked;
                   7185:                         if ($current{$type} eq '0') {
                   7186:                             $checked{'0'} = ' checked="checked"';
                   7187:                         } else {
                   7188:                             $checked{'1'} = ' checked="checked"';
                   7189:                         }
                   7190:                         foreach my $role ('1','0') {
                   7191:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7192:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   7193:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   7194:                                           $roles{$role}.'</label></span> ';
                   7195:                         }
                   7196:                     } else {
                   7197:                         if ($row eq 'types') {
                   7198:                             my %checked;
                   7199:                             if ($current{$type} =~ /^(all|dom)$/) {
                   7200:                                 $checked{$1} = ' checked="checked"';
                   7201:                             } else {
                   7202:                                 $checked{''} = ' checked="checked"';
                   7203:                             }
                   7204:                             foreach my $val ('','dom','all') {
                   7205:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7206:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7207:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7208:                             }
                   7209:                         } elsif ($row eq 'registered') {
                   7210:                             my %checked;
                   7211:                             if ($current{$type} eq '1') {
                   7212:                                 $checked{'1'} = ' checked="checked"';
                   7213:                             } else {
                   7214:                                 $checked{'0'} = ' checked="checked"';
                   7215:                             }
                   7216:                             foreach my $val ('0','1') {
                   7217:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7218:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7219:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7220:                             }
                   7221:                         } elsif ($row eq 'approval') {
                   7222:                             my %checked;
                   7223:                             if ($current{$type} =~ /^([12])$/) {
                   7224:                                 $checked{$1} = ' checked="checked"';
                   7225:                             } else {
                   7226:                                 $checked{'0'} = ' checked="checked"';
                   7227:                             }
                   7228:                             for my $val (0..2) {
                   7229:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7230:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7231:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7232:                             }
                   7233:                         } elsif ($row eq 'limit') {
                   7234:                             my %checked;
                   7235:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   7236:                                 $checked{$1} = ' checked="checked"';
                   7237:                             } else {
                   7238:                                 $checked{'none'} = ' checked="checked"';
                   7239:                             }
                   7240:                             my $cap;
                   7241:                             if ($currentcap{$type} =~ /^\d+$/) {
                   7242:                                 $cap = $currentcap{$type};
                   7243:                             }
                   7244:                             foreach my $val ('none','allstudents','selfenrolled') {
                   7245:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7246:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7247:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7248:                             }
                   7249:                             $datatable .= '<br />'.
                   7250:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   7251:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   7252:                                           '</span>'; 
                   7253:                         }
                   7254:                     }
                   7255:                     $datatable .= '</td>';
                   7256:                 }
                   7257:                 $datatable .= '</tr>';
                   7258:             }
                   7259:             $datatable .= '</table></td></tr>';
                   7260:         }
                   7261:     } elsif ($position eq 'bottom') {
1.235     raeburn  7262:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   7263:     }
                   7264:     $$rowtotal += $itemcount;
                   7265:     return $datatable;
                   7266: }
                   7267: 
                   7268: sub print_validation_rows {
                   7269:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   7270:     my ($itemsref,$namesref,$fieldsref);
                   7271:     if ($caller eq 'selfenroll') { 
                   7272:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   7273:     } elsif ($caller eq 'requestcourses') {
                   7274:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   7275:     }
                   7276:     my %currvalidation;
                   7277:     if (ref($settings) eq 'HASH') {
                   7278:         if (ref($settings->{'validation'}) eq 'HASH') {
                   7279:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  7280:         }
1.235     raeburn  7281:     }
                   7282:     my $datatable;
                   7283:     my $itemcount = 0;
                   7284:     foreach my $item (@{$itemsref}) {
                   7285:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7286:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7287:                       $namesref->{$item}.
                   7288:                       '</span></td>'.
                   7289:                       '<td class="LC_left_item">';
                   7290:         if (($item eq 'url') || ($item eq 'button')) {
                   7291:             $datatable .= '<span class="LC_nobreak">'.
                   7292:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   7293:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   7294:         } elsif ($item eq 'fields') {
                   7295:             my @currfields;
                   7296:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   7297:                 @currfields = @{$currvalidation{$item}};
                   7298:             }
                   7299:             foreach my $field (@{$fieldsref}) {
                   7300:                 my $check = '';
                   7301:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   7302:                     $check = ' checked="checked"';
                   7303:                 }
                   7304:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7305:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   7306:                               ' value="'.$field.'"'.$check.' />'.$field.
                   7307:                               '</label></span> ';
                   7308:             }
                   7309:         } elsif ($item eq 'markup') {
1.334     raeburn  7310:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235     raeburn  7311:                            $currvalidation{$item}.
1.231     raeburn  7312:                               '</textarea>';
1.235     raeburn  7313:         }
                   7314:         $datatable .= '</td></tr>'."\n";
                   7315:         if (ref($rowtotal)) {
1.231     raeburn  7316:             $itemcount ++;
                   7317:         }
                   7318:     }
1.235     raeburn  7319:     if ($caller eq 'requestcourses') {
                   7320:         my %currhash;
1.248     raeburn  7321:         if (ref($settings) eq 'HASH') {
                   7322:             if (ref($settings->{'validation'}) eq 'HASH') {
                   7323:                 if ($settings->{'validation'}{'dc'} ne '') {
                   7324:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   7325:                 }
1.235     raeburn  7326:             }
                   7327:         }
                   7328:         my $numinrow = 2;
                   7329:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   7330:                                                        'validationdc',%currhash);
1.247     raeburn  7331:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334     raeburn  7332:         $datatable .= '<tr'.$css_class.'><td>';
1.235     raeburn  7333:         if ($numdc > 1) {
1.247     raeburn  7334:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  7335:         } else {
1.247     raeburn  7336:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  7337:         }
1.247     raeburn  7338:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  7339:         $itemcount ++;
                   7340:     }
                   7341:     if (ref($rowtotal)) {
                   7342:         $$rowtotal += $itemcount;
                   7343:     }
1.231     raeburn  7344:     return $datatable;
                   7345: }
                   7346: 
1.357     raeburn  7347: sub print_privacy {
                   7348:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7349:     my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
                   7350:     my $itemcount = 0;
                   7351:     unless ($position eq 'top') {
                   7352:         @items = ('domain','author','course','community');
                   7353:         %names = &Apache::lonlocal::texthash (
                   7354:                      domain => 'Assigned domain role(s)',
                   7355:                      author => 'Assigned co-author role(s)',
                   7356:                      course => 'Assigned course role(s)',
                   7357:                      community => 'Assigned community role',
                   7358:                  );
                   7359:         $numinrow = 4;
                   7360:         ($othertitle,$usertypes,$types) =
                   7361:             &Apache::loncommon::sorted_inst_types($dom);
                   7362:     }
                   7363:     if (($position eq 'top') || ($position eq 'middle')) {
                   7364:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   7365:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   7366:         if ($position eq 'top') {
                   7367:             my %curr;
                   7368:             my @options = ('none','user','domain','auto');
                   7369:             my %titles = &Apache::lonlocal::texthash (
                   7370:                 none   => 'Not allowed',
                   7371:                 user   => 'User authorizes',
                   7372:                 domain => 'DC authorizes',
                   7373:                 auto   => 'Unrestricted',
                   7374:                 instdom => 'Other domain shares institution/provider',
                   7375:                 extdom => 'Other domain has different institution/provider',
                   7376:             );
                   7377:             my %names = &Apache::lonlocal::texthash (
                   7378:                 domain => 'Domain role',
                   7379:                 author => 'Co-author role',
                   7380:                 course => 'Course role',
                   7381:                 community => 'Community role',
                   7382:             );
                   7383:             my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7384:             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7385:             foreach my $domtype ('instdom','extdom') {
                   7386:                 my (%checked,$skip);
                   7387:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7388:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                   7389:                               '<td class="LC_left_item">';
                   7390:                 if ($domtype eq 'instdom') {
                   7391:                     unless (@instdoms > 1) {
                   7392:                         $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                   7393:                         $skip = 1;
                   7394:                     }
                   7395:                 } elsif ($domtype eq 'extdom') {
                   7396:                     if (keys(%by_location) == 0) {
                   7397:                         $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                   7398:                         $skip = 1;
                   7399:                     }
                   7400:                 }
                   7401:                 unless ($skip) {
                   7402:                     foreach my $roletype ('domain','author','course','community') {
                   7403:                         $checked{'auto'} = ' checked="checked"';
                   7404:                         if (ref($settings) eq 'HASH') {
                   7405:                             if (ref($settings->{approval}) eq 'HASH') {
                   7406:                                 if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                   7407:                                     if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                   7408:                                         $checked{$1} = ' checked="checked"';
                   7409:                                         $checked{'auto'} = '';
                   7410:                                     }
                   7411:                                 }
                   7412:                             }
                   7413:                         }
                   7414:                         $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                   7415:                         foreach my $option (@options) {
                   7416:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7417:                                           '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                   7418:                                           'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   7419:                                           '</label></span>&nbsp; ';
                   7420:                         }
                   7421:                         $datatable .= '</fieldset>';
                   7422:                     }
                   7423:                 }
                   7424:                 $datatable .= '</td></tr>';
                   7425:                 $itemcount ++;
                   7426:             }
                   7427:         } elsif ($position eq 'middle') {
                   7428:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   7429:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7430:                     foreach my $item (@{$types}) {
                   7431:                         $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                   7432:                                                                $numinrow,$itemcount,'','','','','',
                   7433:                                                                '',$usertypes->{$item});
                   7434:                         $itemcount ++;
                   7435:                     }
                   7436:                 }
                   7437:                 $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                   7438:                                                        $numinrow,$itemcount,'','','','','',
                   7439:                                                        '',$othertitle);
                   7440:                 $itemcount ++;
                   7441:             } else {
1.360     raeburn  7442:                 my (@insttypes,%insttitles);
                   7443:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7444:                     @insttypes = @{$types};
                   7445:                     %insttitles = %{$usertypes};
                   7446:                 }
                   7447:                 foreach my $item (@insttypes,'default') {
                   7448:                     my $title;
                   7449:                     if ($item eq 'default') {
                   7450:                         $title = $othertitle;
                   7451:                     } else {
                   7452:                         $title = $insttitles{$item};
                   7453:                     }
                   7454:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7455:                     $datatable .= '<tr'.$css_class.'>'.
                   7456:                                   '<td class="LC_left_item">'.$title.'</td>'.
                   7457:                                   '<td class="LC_left_item">'.
                   7458:                                   &mt('Nothing to set here, as there are no other domains').
                   7459:                                   '</td></tr>';
                   7460:                     $itemcount ++;
                   7461:                 }
1.357     raeburn  7462:             }
                   7463:         }
                   7464:     } else {
                   7465:         my $prefix;
                   7466:         if ($position eq 'lower') {
                   7467:             $prefix = 'priv';
                   7468:         } else {
                   7469:             $prefix = 'unpriv';
                   7470:         }
                   7471:         foreach my $item (@items) {
                   7472:             $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                   7473:                                                    $numinrow,$itemcount,'','','','','',
                   7474:                                                    '',$names{$item});
                   7475:             $itemcount ++;
                   7476:         }
                   7477:     }
                   7478:     if (ref($rowtotal)) {
                   7479:         $$rowtotal += $itemcount;
                   7480:     }
                   7481:     return $datatable;
                   7482: }
                   7483: 
1.354     raeburn  7484: sub print_passwords {
                   7485:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   7486:     my ($datatable,$css_class);
                   7487:     my $itemcount = 0;
                   7488:     my %titles = &Apache::lonlocal::texthash (
                   7489:         captcha        => '"Forgot Password" CAPTCHA validation',
                   7490:         link           => 'Reset link expiration (hours)',
                   7491:         case           => 'Case-sensitive usernames/e-mail',
                   7492:         prelink        => 'Information required (form 1)',
                   7493:         postlink       => 'Information required (form 2)',
                   7494:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   7495:         customtext     => 'Domain specific text (HTML)',
                   7496:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   7497:         intauth_check  => 'Check bcrypt cost if authenticated',
                   7498:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   7499:         permanent      => 'Permanent e-mail address',
                   7500:         critical       => 'Critical notification address',
                   7501:         notify         => 'Notification address',
                   7502:         min            => 'Minimum password length',
                   7503:         max            => 'Maximum password length',
                   7504:         chars          => 'Required characters',
                   7505:         expire         => 'Password expiration (days)',
1.356     raeburn  7506:         numsaved       => 'Number of previous passwords to save and disallow reuse',
1.354     raeburn  7507:     );
                   7508:     if ($position eq 'top') {
                   7509:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7510:         my $shownlinklife = 2;
                   7511:         my $prelink = 'both';
                   7512:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   7513:         if (ref($settings) eq 'HASH') {
                   7514:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   7515:                 $shownlinklife = $settings->{resetlink};
                   7516:             }
                   7517:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   7518:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   7519:             }
                   7520:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   7521:                 $prelink = $settings->{resetprelink};
                   7522:             }
                   7523:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   7524:                 %postlink = %{$settings->{resetpostlink}};
                   7525:             }
                   7526:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   7527:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   7528:             }
                   7529:             if ($settings->{resetremove}) {
                   7530:                 $nostdtext = 1;
                   7531:             }
                   7532:             if ($settings->{resetcustom}) {
                   7533:                 $customurl = $settings->{resetcustom};
                   7534:             }
                   7535:         } else {
                   7536:             if (ref($types) eq 'ARRAY') {
                   7537:                 foreach my $item (@{$types}) {
                   7538:                     $casesens{$item} = 1;
                   7539:                     $postlink{$item} = ['username','email'];
                   7540:                 }
                   7541:             }
                   7542:             $casesens{'default'} = 1;
                   7543:             $postlink{'default'} = ['username','email'];
                   7544:             $prelink = 'both';
                   7545:             %emailsrc = (
                   7546:                           permanent => 1,
                   7547:                           critical  => 1,
                   7548:                           notify    => 1,
                   7549:             );
                   7550:         }
                   7551:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   7552:         $itemcount ++;
                   7553:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7554:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   7555:                       '<td class="LC_left_item">'.
                   7556:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   7557:                       'name="passwords_link" size="3" /></td></tr>';
                   7558:         $itemcount ++;
                   7559:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7560:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   7561:                       '<td class="LC_left_item">';
                   7562:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7563:             foreach my $item (@{$types}) {
                   7564:                 my $checkedcase;
                   7565:                 if ($casesens{$item}) {
                   7566:                     $checkedcase = ' checked="checked"';
                   7567:                 }
                   7568:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7569:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   7570:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369     raeburn  7571:                               '</span>&nbsp;&nbsp; ';
1.354     raeburn  7572:             }
                   7573:         }
                   7574:         my $checkedcase;
                   7575:         if ($casesens{'default'}) {
                   7576:             $checkedcase = ' checked="checked"';
                   7577:         }
                   7578:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   7579:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   7580:                       $othertitle.'</label></span></td>';
                   7581:         $itemcount ++;
                   7582:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7583:         my %checkedpre = (
                   7584:                              both => ' checked="checked"',
                   7585:                              either => '',
                   7586:                          );
                   7587:         if ($prelink eq 'either') {
                   7588:             $checkedpre{either} = ' checked="checked"';
                   7589:             $checkedpre{both} = '';
                   7590:         }
                   7591:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   7592:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   7593:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   7594:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   7595:                       '<span class="LC_nobreak"><label>'.
                   7596:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   7597:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   7598:         $itemcount ++;
                   7599:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7600:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   7601:                       '<td class="LC_left_item">';
                   7602:         my %postlinked;
                   7603:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7604:             foreach my $item (@{$types}) {
                   7605:                 undef(%postlinked);
                   7606:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   7607:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   7608:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   7609:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   7610:                 }
                   7611:                 foreach my $field ('email','username') {
                   7612:                     my $checked;
                   7613:                     if ($postlinked{$field}) {
                   7614:                         $checked = ' checked="checked"';
                   7615:                     }
                   7616:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   7617:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   7618:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   7619:                                   '<span>&nbsp;&nbsp; ';
                   7620:                 }
                   7621:                 $datatable .= '</fieldset>';
                   7622:             }
                   7623:         }
                   7624:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   7625:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   7626:         }
                   7627:         $datatable .= '<fieldset style="display: inline-block;">'.
                   7628:                       '<legend>'.$othertitle.'</legend>';
                   7629:         foreach my $field ('email','username') {
                   7630:             my $checked;
                   7631:             if ($postlinked{$field}) {
                   7632:                 $checked = ' checked="checked"';
                   7633:             }
                   7634:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7635:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   7636:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   7637:                           '<span>&nbsp;&nbsp; ';
                   7638:         }
                   7639:         $datatable .= '</fieldset></td></tr>';
                   7640:         $itemcount ++;
                   7641:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7642:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   7643:                       '<td class="LC_left_item">';
                   7644:         foreach my $type ('permanent','critical','notify') {
                   7645:             my $checkedemail;
                   7646:             if ($emailsrc{$type}) {
                   7647:                 $checkedemail = ' checked="checked"';
                   7648:             }
                   7649:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7650:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   7651:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   7652:                           '<span>&nbsp;&nbsp; ';
                   7653:         }
                   7654:         $datatable .= '</td></tr>';
                   7655:         $itemcount ++;
                   7656:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7657:         my $switchserver = &check_switchserver($dom,$confname);
                   7658:         my ($showstd,$noshowstd);
                   7659:         if ($nostdtext) {
                   7660:             $noshowstd = ' checked="checked"';
                   7661:         } else {
                   7662:             $showstd = ' checked="checked"';
                   7663:         }
                   7664:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   7665:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   7666:                       &mt('Retain standard text:').
                   7667:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   7668:                       &mt('Yes').'</label>'.'&nbsp;'.
                   7669:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   7670:                       &mt('No').'</label></span><br />'.
                   7671:                       '<span class="LC_fontsize_small">'.
                   7672:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   7673:                       &mt('Include custom text:');
                   7674:         if ($customurl) {
1.369     raeburn  7675:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354     raeburn  7676:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   7677:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   7678:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   7679:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   7680:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   7681:         }
                   7682:         if ($switchserver) {
                   7683:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   7684:         } else {
                   7685:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   7686:                          '<input type="file" name="passwords_customfile" /></span>';
                   7687:         }
                   7688:         $datatable .= '</td></tr>';
                   7689:     } elsif ($position eq 'middle') {
                   7690:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   7691:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   7692:         my %defaults;
                   7693:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   7694:             %defaults = %{$domconf{'defaults'}};
                   7695:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   7696:                 $defaults{'intauth_cost'} = 10;
                   7697:             }
                   7698:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   7699:                 $defaults{'intauth_check'} = 0;
                   7700:             }
                   7701:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   7702:                 $defaults{'intauth_switch'} = 0;
                   7703:             }
                   7704:         } else {
                   7705:             %defaults = (
                   7706:                           'intauth_cost'   => 10,
                   7707:                           'intauth_check'  => 0,
                   7708:                           'intauth_switch' => 0,
                   7709:                         );
                   7710:         }
                   7711:         foreach my $item (@items) {
                   7712:             if ($itemcount%2) {
                   7713:                 $css_class = '';
                   7714:             } else {
                   7715:                 $css_class = ' class="LC_odd_row" ';
                   7716:             }
                   7717:             $datatable .= '<tr'.$css_class.'>'.
                   7718:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   7719:                           '</span></td><td class="LC_left_item" colspan="3">';
                   7720:             if ($item eq 'intauth_switch') {
                   7721:                 my @options = (0,1,2);
                   7722:                 my %optiondesc = &Apache::lonlocal::texthash (
                   7723:                                    0 => 'No',
                   7724:                                    1 => 'Yes',
                   7725:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   7726:                                  );
                   7727:                 $datatable .= '<table width="100%">';
                   7728:                 foreach my $option (@options) {
                   7729:                     my $checked = ' ';
                   7730:                     if ($defaults{$item} eq $option) {
                   7731:                         $checked = ' checked="checked"';
                   7732:                     }
                   7733:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   7734:                                   '<label><input type="radio" name="'.$item.
                   7735:                                   '" value="'.$option.'"'.$checked.' />'.
                   7736:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   7737:                 }
                   7738:                 $datatable .= '</table>';
                   7739:             } elsif ($item eq 'intauth_check') {
                   7740:                 my @options = (0,1,2);
                   7741:                 my %optiondesc = &Apache::lonlocal::texthash (
                   7742:                                    0 => 'No',
                   7743:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   7744:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   7745:                                  );
                   7746:                 $datatable .= '<table width="100%">';
                   7747:                 foreach my $option (@options) {
                   7748:                     my $checked = ' ';
                   7749:                     my $onclick;
                   7750:                     if ($defaults{$item} eq $option) {
                   7751:                         $checked = ' checked="checked"';
                   7752:                     }
                   7753:                     if ($option == 2) {
                   7754:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   7755:                     }
                   7756:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   7757:                                   '<label><input type="radio" name="'.$item.
                   7758:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   7759:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   7760:                 }
                   7761:                 $datatable .= '</table>';
                   7762:             } else {
                   7763:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   7764:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   7765:             }
                   7766:             $datatable .= '</td></tr>';
                   7767:             $itemcount ++;
                   7768:         }
                   7769:     } elsif ($position eq 'lower') {
1.356     raeburn  7770:         my ($min,$max,%chars,$expire,$numsaved);
1.365     raeburn  7771:         $min = $Apache::lonnet::passwdmin;
1.354     raeburn  7772:         if (ref($settings) eq 'HASH') {
                   7773:             if ($settings->{min}) {
                   7774:                 $min = $settings->{min};
                   7775:             }
                   7776:             if ($settings->{max}) {
                   7777:                 $max = $settings->{max};
                   7778:             }
                   7779:             if (ref($settings->{chars}) eq 'ARRAY') {
                   7780:                 map { $chars{$_} = 1; } (@{$settings->{chars}});
                   7781:             }
                   7782:             if ($settings->{expire}) {
                   7783:                 $expire = $settings->{expire};
                   7784:             }
1.358     raeburn  7785:             if ($settings->{numsaved}) {
                   7786:                 $numsaved = $settings->{numsaved};
1.356     raeburn  7787:             }
1.354     raeburn  7788:         }
                   7789:         my %rulenames = &Apache::lonlocal::texthash(
                   7790:                                                      uc => 'At least one upper case letter',
                   7791:                                                      lc => 'At least one lower case letter',
                   7792:                                                      num => 'At least one number',
                   7793:                                                      spec => 'At least one non-alphanumeric',
                   7794:                                                    );
                   7795:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7796:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   7797:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7798:                       '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
                   7799:                       'onblur="javascript:warnIntPass(this);" />'.
                   7800:                       '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354     raeburn  7801:                       '</span></td></tr>';
                   7802:         $itemcount ++;
                   7803:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7804:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   7805:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7806:                       '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
                   7807:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  7808:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   7809:                       '</span></td></tr>';
                   7810:         $itemcount ++;
                   7811:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7812:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   7813:                       '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   7814:                       '</span></td>';
                   7815:         my $numinrow = 2;
                   7816:         my @possrules = ('uc','lc','num','spec');
                   7817:         $datatable .= '<td class="LC_left_item"><table>';
                   7818:         for (my $i=0; $i<@possrules; $i++) {
                   7819:             my ($rem,$checked);
                   7820:             if ($chars{$possrules[$i]}) {
                   7821:                 $checked = ' checked="checked"';
                   7822:             }
                   7823:             $rem = $i%($numinrow);
                   7824:             if ($rem == 0) {
                   7825:                 if ($i > 0) {
                   7826:                     $datatable .= '</tr>';
                   7827:                 }
                   7828:                 $datatable .= '<tr>';
                   7829:             }
                   7830:             $datatable .= '<td><span class="LC_nobreak"><label>'.
                   7831:                           '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   7832:                           $rulenames{$possrules[$i]}.'</label></span></td>';
                   7833:         }
                   7834:         my $rem = @possrules%($numinrow);
                   7835:         my $colsleft = $numinrow - $rem;
                   7836:         if ($colsleft > 1 ) {
                   7837:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7838:                           '&nbsp;</td>';
                   7839:         } elsif ($colsleft == 1) {
                   7840:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   7841:         }
                   7842:         $datatable .='</table></td></tr>';
                   7843:         $itemcount ++;
                   7844:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7845:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                   7846:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7847:                       '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
                   7848:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  7849:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                   7850:                       '</span></td></tr>';
1.356     raeburn  7851:         $itemcount ++;
                   7852:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7853:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   7854:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367     raeburn  7855:                       '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
                   7856:                       'onblur="javascript:warnIntPass(this);" />'. 
1.356     raeburn  7857:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   7858:                       '</span></td></tr>';
1.354     raeburn  7859:     } else {
1.359     raeburn  7860:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7861:         my %ownerchg = (
                   7862:                           by  => {},
                   7863:                           for => {},
                   7864:                        );
                   7865:         my %ownertitles = &Apache::lonlocal::texthash (
                   7866:                             by  => 'Course owner status(es) allowed',
                   7867:                             for => 'Student status(es) allowed',
                   7868:                           );
1.354     raeburn  7869:         if (ref($settings) eq 'HASH') {
1.359     raeburn  7870:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   7871:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   7872:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   7873:                 }
                   7874:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   7875:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   7876:                 }
1.354     raeburn  7877:             }
                   7878:         }
                   7879:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7880:         $datatable .= '<tr '.$css_class.'>'.
                   7881:                       '<td>'.
                   7882:                       &mt('Requirements').'<ul>'.
1.359     raeburn  7883:                       '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354     raeburn  7884:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   7885:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359     raeburn  7886:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354     raeburn  7887:                       '</ul>'.
                   7888:                       '</td>'.
1.359     raeburn  7889:                       '<td class="LC_left_item">';
                   7890:         foreach my $item ('by','for') {
                   7891:             $datatable .= '<fieldset style="display: inline-block;">'.
                   7892:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   7893:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7894:                 foreach my $type (@{$types}) {
                   7895:                     my $checked;
                   7896:                     if ($ownerchg{$item}{$type}) {
                   7897:                         $checked = ' checked="checked"';
                   7898:                     }
                   7899:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   7900:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   7901:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369     raeburn  7902:                                   '</span>&nbsp;&nbsp; ';
1.359     raeburn  7903:                 }
                   7904:             }
                   7905:             my $checked;
                   7906:             if ($ownerchg{$item}{'default'}) {
                   7907:                 $checked = ' checked="checked"';
                   7908:             }
                   7909:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   7910:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   7911:                           $othertitle.'</label></span></fieldset>';
                   7912:         }
                   7913:         $datatable .= '</td></tr>';
1.354     raeburn  7914:     }
                   7915:     return $datatable;
                   7916: }
                   7917: 
1.373     raeburn  7918: sub print_wafproxy {
                   7919:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7920:     my $css_class;
                   7921:     my $itemcount = 0;
                   7922:     my $datatable;
                   7923:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  7924:     my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374     raeburn  7925:     my %lt = &wafproxy_titles();
1.373     raeburn  7926:     foreach my $server (sort(keys(%servers))) {
                   7927:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381     raeburn  7928:         next if ($serverhome eq '');
1.373     raeburn  7929:         my $serverdom;
                   7930:         if ($serverhome ne $server) {
                   7931:             $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381     raeburn  7932:             if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
                   7933:                 $othercontrol{$server} = $serverdom;
                   7934:             }
1.373     raeburn  7935:         } else {
                   7936:             $serverdom = &Apache::lonnet::host_domain($server);
1.381     raeburn  7937:             next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373     raeburn  7938:             if ($serverdom ne $dom) {
                   7939:                 $othercontrol{$server} = $serverdom;
                   7940:             } else {
                   7941:                 $setdom = 1;
                   7942:                 if (ref($settings) eq 'HASH') {
                   7943:                     if (ref($settings->{'alias'}) eq 'HASH') {
                   7944:                         $aliases{$dom} = $settings->{'alias'};
1.381     raeburn  7945:                         if ($aliases{$dom} ne '') {
                   7946:                             $showdom = 1;
                   7947:                         }
1.373     raeburn  7948:                     }
1.388     raeburn  7949:                     if (ref($settings->{'saml'}) eq 'HASH') {
                   7950:                         $saml{$dom} = $settings->{'saml'};
                   7951:                     }
1.373     raeburn  7952:                 }
                   7953:             }
                   7954:         }
                   7955:     }
1.381     raeburn  7956:     if ($setdom) {
                   7957:         %{$values{$dom}} = ();
                   7958:         if (ref($settings) eq 'HASH') {
                   7959:             foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   7960:                 $values{$dom}{$item} = $settings->{$item};
                   7961:             }
                   7962:         }
                   7963:     }
1.373     raeburn  7964:     if (keys(%othercontrol)) {
                   7965:         %otherdoms = reverse(%othercontrol);
                   7966:         foreach my $domain (keys(%otherdoms)) {
                   7967:             %{$values{$domain}} = ();
                   7968:             my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383     raeburn  7969:             if (ref($config{'wafproxy'}) eq 'HASH') {
                   7970:                 $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388     raeburn  7971:                 if (exists($config{'wafproxy'}{'saml'})) { 
                   7972:                     $saml{$domain} = $config{'wafproxy'}{'saml'};
                   7973:                 }
1.383     raeburn  7974:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   7975:                     $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373     raeburn  7976:                 }
                   7977:             }
                   7978:         }
                   7979:     }
                   7980:     if ($position eq 'top') {
                   7981:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381     raeburn  7982:         my %aliasinfo;
1.373     raeburn  7983:         foreach my $server (sort(keys(%servers))) {
1.381     raeburn  7984:             $itemcount ++;
                   7985:             my $dom_in_effect;
                   7986:             my $aliasrows = '<tr>'.
1.383     raeburn  7987:                             '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   7988:                             &mt('Hostname').':&nbsp;'.
                   7989:                             '<i>'.&Apache::lonnet::hostname($server).'</i></td><td>&nbsp;</td>';
1.373     raeburn  7990:             if ($othercontrol{$server}) {
1.381     raeburn  7991:                 $dom_in_effect = $othercontrol{$server};
1.388     raeburn  7992:                 my ($current,$forsaml);
1.383     raeburn  7993:                 if (ref($aliases{$dom_in_effect}) eq 'HASH') {
                   7994:                     $current = $aliases{$dom_in_effect}{$server};
1.373     raeburn  7995:                 }
1.388     raeburn  7996:                 if (ref($saml{$dom_in_effect}) eq 'HASH') {
                   7997:                     if ($saml{$dom_in_effect}{$server}) {
                   7998:                         $forsaml = 1;
                   7999:                     }
                   8000:                 }
1.383     raeburn  8001:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8002:                               &mt('Alias').':&nbsp';
1.373     raeburn  8003:                 if ($current) {
1.381     raeburn  8004:                     $aliasrows .= $current;
1.388     raeburn  8005:                     if ($forsaml) {
1.396     raeburn  8006:                          $aliasrows .= '&nbsp;('.&mt('also for SSO Auth').')';
1.388     raeburn  8007:                     }
1.373     raeburn  8008:                 } else {
1.383     raeburn  8009:                     $aliasrows .= &mt('None');
1.373     raeburn  8010:                 }
1.383     raeburn  8011:                 $aliasrows .= '&nbsp;<span class="LC_small">('.
                   8012:                               &mt('controlled by domain: [_1]',
                   8013:                                   '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373     raeburn  8014:             } else {
1.381     raeburn  8015:                 $dom_in_effect = $dom;
1.388     raeburn  8016:                 my ($current,$samlon,$samloff);
                   8017:                 $samloff = ' checked="checked"';
1.373     raeburn  8018:                 if (ref($aliases{$dom}) eq 'HASH') {
                   8019:                     if ($aliases{$dom}{$server}) {
                   8020:                         $current = $aliases{$dom}{$server};
                   8021:                     }
                   8022:                 }
1.388     raeburn  8023:                 if (ref($saml{$dom}) eq 'HASH') {
                   8024:                     if ($saml{$dom}{$server}) {
                   8025:                         $samlon = $samloff;
                   8026:                         undef($samloff);
                   8027:                     }
                   8028:                 }
1.383     raeburn  8029:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8030:                               &mt('Alias').':&nbsp;'.
1.381     raeburn  8031:                               '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388     raeburn  8032:                               'value="'.$current.'" size="30" />'.
                   8033:                               ('&nbsp;'x2).'<span class="LC_nobreak">'.
1.396     raeburn  8034:                               &mt('Alias used for SSO Auth').':&nbsp;<label>'.
1.388     raeburn  8035:                               '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
                   8036:                               &mt('No').'</label>&nbsp;<label>'. 
                   8037:                               '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
                   8038:                               &mt('Yes').'</label></span>'.
                   8039:                               '</td>'; 
1.381     raeburn  8040:             }
                   8041:             $aliasrows .= '</tr>';
                   8042:             $aliasinfo{$dom_in_effect} .= $aliasrows;
                   8043:         }
                   8044:         if ($aliasinfo{$dom}) {
                   8045:             my ($onclick,$wafon,$wafoff,$showtable);
                   8046:             $onclick = ' onclick="javascript:toggleWAF();"';
                   8047:             $wafoff = ' checked="checked"';
                   8048:             $showtable = ' style="display:none";';
                   8049:             if ($showdom) {
                   8050:                 $wafon = $wafoff;
                   8051:                 $wafoff = '';
                   8052:                 $showtable = ' style="display:inline;"';
                   8053:             }
                   8054:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8055:             $datatable = '<tr'.$css_class.'>'.
                   8056:                          '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
                   8057:                          '<span class="LC_nobreak">'.&mt('WAF in use?').'&nbsp;<label>'.
                   8058:                          '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
                   8059:                          &mt('Yes').'</label>'.('&nbsp;'x2).'<label>'.
                   8060:                          '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
                   8061:                          &mt('No').'</label></span></td>'.
                   8062:                          '<td class="LC_left_item">'.
                   8063:                          '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
                   8064:                          '</table></td></tr>';
                   8065:             $itemcount++;
                   8066:         }
1.383     raeburn  8067:         if (keys(%otherdoms)) {
                   8068:             foreach my $key (sort(keys(%otherdoms))) {
1.381     raeburn  8069:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383     raeburn  8070:                 $datatable .= '<tr'.$css_class.'>'.
                   8071:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
                   8072:                               '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
                   8073:                               '</table></td></tr>';
1.381     raeburn  8074:                 $itemcount++;
1.373     raeburn  8075:             }
                   8076:         }
                   8077:     } else {
1.383     raeburn  8078:         my %ip_methods = &remoteip_methods();
1.373     raeburn  8079:         if ($setdom) {
                   8080:             $itemcount ++;
                   8081:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381     raeburn  8082:             my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382     raeburn  8083:                 $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381     raeburn  8084:             $wafstyle = ' style="display:none;"';
                   8085:             $nowafstyle = ' style="display:table-row;"';
                   8086:             $currwafdisplay = ' style="display: none"';
                   8087:             $wafrangestyle = ' style="display: none"';
                   8088:             $curr_remotip = 'n';
1.382     raeburn  8089:             $ssltossl = ' checked="checked"';
1.381     raeburn  8090:             if ($showdom) {
                   8091:                 $wafstyle = ' style="display:table-row;"';
                   8092:                 $nowafstyle =  ' style="display:none;"';
                   8093:                 if (keys(%{$values{$dom}})) {
                   8094:                     if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
                   8095:                         $curr_remotip = $values{$dom}{remoteip};
                   8096:                     }
                   8097:                     if ($curr_remotip eq 'h') {
                   8098:                         $currwafdisplay = ' style="display:table-row"';
                   8099:                         $wafrangestyle = ' style="display:inline-block;"';
                   8100:                     }
1.382     raeburn  8101:                     if ($values{$dom}{'sslopt'}) {
                   8102:                         $alltossl = ' checked="checked"';
                   8103:                         $ssltossl = '';
                   8104:                     }
1.381     raeburn  8105:                 }
                   8106:                 if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
                   8107:                     $vpndircheck = ' checked="checked"';
                   8108:                     $currwafvpn = ' style="display:table-row;"';
                   8109:                     $wafrangestyle = ' style="display:inline-block;"';
                   8110:                 } else {
                   8111:                     $vpnaliascheck = ' checked="checked"';
                   8112:                     $currwafvpn = ' style="display:none;"';
                   8113:                 }
                   8114:             }
                   8115:             $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                   8116:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
                   8117:                           '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
                   8118:                           '</tr>'.
                   8119:                           '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374     raeburn  8120:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381     raeburn  8121:                           '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393     raeburn  8122:                           &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   8123:                           &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381     raeburn  8124:                           '<td class="LC_left_item"><table>'.
                   8125:                           '<tr>'.
                   8126:                           '<td valign="top">'.$lt{'remoteip'}.':&nbsp;'.
                   8127:                           '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
                   8128:             foreach my $option ('m','h','n') {
                   8129:                 my $sel;
                   8130:                 if ($option eq $curr_remotip) {
                   8131:                    $sel = ' selected="selected"';
                   8132:                 }
                   8133:                 $datatable .= '<option value="'.$option.'"'.$sel.'>'.
                   8134:                               $ip_methods{$option}.'</option>';
                   8135:             }
                   8136:             $datatable .= '</select></td></tr>'."\n".
                   8137:                           '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
                   8138:                           $lt{'ipheader'}.':&nbsp;'.
                   8139:                           '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
                   8140:                           'name="wafproxy_ipheader" />'.
                   8141:                           '</td></tr>'."\n".
                   8142:                           '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382     raeburn  8143:                           $lt{'trusted'}.':<br />'.
1.381     raeburn  8144:                           '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
                   8145:                           $values{$dom}{'trusted'}.'</textarea>'.
                   8146:                           '</td></tr>'."\n".
                   8147:                           '<tr><td><hr /></td></tr>'."\n".
                   8148:                           '<tr>'.
                   8149:                           '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
                   8150:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
                   8151:                           $lt{'vpndirect'}.'</label>'.('&nbsp;'x2).
                   8152:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
                   8153:                           $lt{'vpnaliased'}.'</label></span></td></tr>';
                   8154:             foreach my $item ('vpnint','vpnext') {
                   8155:                 $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382     raeburn  8156:                               '<td valign="top">'.$lt{$item}.':<br />'.
1.381     raeburn  8157:                               '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
                   8158:                               $values{$dom}{$item}.'</textarea>'.
                   8159:                               '</td></tr>'."\n";
1.373     raeburn  8160:             }
1.382     raeburn  8161:             $datatable .= '<tr><td><hr /></td></tr>'."\n".
                   8162:                           '<tr>'.
                   8163:                           '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
                   8164:                           '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
                   8165:                           $lt{'alltossl'}.'</label>'.('&nbsp;'x2).
                   8166:                           '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
                   8167:                           $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
                   8168:                           '</table></td></tr>';
1.373     raeburn  8169:         }
                   8170:         if (keys(%otherdoms)) {
                   8171:             foreach my $domain (sort(keys(%otherdoms))) {
                   8172:                 $itemcount ++;
                   8173:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8174:                 $datatable .= '<tr'.$css_class.'>'.
1.383     raeburn  8175:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374     raeburn  8176:                               '<td class="LC_left_item"><table>';
1.382     raeburn  8177:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  8178:                     my $showval = &mt('None');
1.382     raeburn  8179:                     if ($item eq 'ssl') {
                   8180:                         $showval = $lt{'ssltossl'};
                   8181:                     }
1.373     raeburn  8182:                     if ($values{$domain}{$item}) {
1.381     raeburn  8183:                         $showval = $values{$domain}{$item};
1.382     raeburn  8184:                         if ($item eq 'ssl') {
                   8185:                             $showval = $lt{'alltossl'};
1.383     raeburn  8186:                         } elsif ($item eq 'remoteip') {
                   8187:                             $showval = $ip_methods{$values{$domain}{$item}};
1.382     raeburn  8188:                         }
1.373     raeburn  8189:                     }
                   8190:                     $datatable .= '<tr>'.
                   8191:                                   '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';
                   8192:                 }
1.381     raeburn  8193:                 $datatable .= '</table></td></tr>';
1.373     raeburn  8194:             }
                   8195:         }
                   8196:     }
                   8197:     $$rowtotal += $itemcount;
                   8198:     return $datatable;
                   8199: }
                   8200: 
                   8201: sub wafproxy_titles {
                   8202:     return &Apache::lonlocal::texthash(
1.381     raeburn  8203:                remoteip   => "Method for determining user's IP",
                   8204:                ipheader   => 'Request header containing remote IP',
                   8205:                trusted    => 'Trusted IP range(s)',
                   8206:                vpnaccess  => 'Access from institutional VPN',
                   8207:                vpndirect  => 'via regular hostname (no WAF)',
                   8208:                vpnaliased => 'via aliased hostname (WAF)',
                   8209:                vpnint     => 'Internal IP Range(s) for VPN sessions',
                   8210:                vpnext     => 'IP Range(s) for backend WAF connections',
1.382     raeburn  8211:                sslopt     => 'Forwarding http/https',
1.381     raeburn  8212:                alltossl   => 'WAF forwards both http and https requests to https',
                   8213:                ssltossl   => 'WAF forwards http requests to http and https to https',
                   8214:            );
                   8215: }
                   8216: 
                   8217: sub remoteip_methods {
                   8218:     return &Apache::lonlocal::texthash(
                   8219:               m => 'Use Apache mod_remoteip',
                   8220:               h => 'Use headers parsed by LON-CAPA',
                   8221:               n => 'Not in use',
1.373     raeburn  8222:            );
                   8223: }
                   8224: 
1.137     raeburn  8225: sub print_usersessions {
                   8226:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  8227:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  8228:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8229:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  8230: 
                   8231:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  8232:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  8233:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  8234:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  8235:     if ($position eq 'top') {
1.152     raeburn  8236:         if (keys(%serverhomes) > 1) {
1.145     raeburn  8237:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.371     raeburn  8238:             my ($curroffloadnow,$curroffloadoth);
1.261     raeburn  8239:             if (ref($settings) eq 'HASH') {
                   8240:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   8241:                     $curroffloadnow = $settings->{'offloadnow'};
                   8242:                 }
1.371     raeburn  8243:                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   8244:                     $curroffloadoth = $settings->{'offloadoth'};
                   8245:                 }
1.261     raeburn  8246:             }
1.371     raeburn  8247:             my $other_insts = scalar(keys(%by_location));
                   8248:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   8249:                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  8250:         } else {
1.140     raeburn  8251:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  8252:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   8253:                           '</td></tr>';
1.140     raeburn  8254:         }
1.137     raeburn  8255:     } else {
1.279     raeburn  8256:         my %titles = &usersession_titles();
                   8257:         my ($prefix,@types);
                   8258:         if ($position eq 'bottom') {
                   8259:             $prefix = 'remote';
                   8260:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  8261:         } else {
1.279     raeburn  8262:             $prefix = 'hosted';
                   8263:             @types = ('excludedomain','includedomain');
                   8264:         }
                   8265:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8266:     }
                   8267:     $$rowtotal += $itemcount;
                   8268:     return $datatable;
                   8269: }
                   8270: 
                   8271: sub rules_by_location {
                   8272:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   8273:     my ($datatable,$itemcount,$css_class);
                   8274:     if (keys(%{$by_location}) == 0) {
                   8275:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8276:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   8277:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   8278:                      '</td></tr>';
                   8279:         $itemcount = 1;
                   8280:     } else {
                   8281:         $itemcount = 0;
                   8282:         my $numinrow = 5;
                   8283:         my (%current,%checkedon,%checkedoff);
                   8284:         my @locations = sort(keys(%{$by_location}));
                   8285:         foreach my $type (@{$types}) {
                   8286:             $checkedon{$type} = '';
                   8287:             $checkedoff{$type} = ' checked="checked"';
                   8288:         }
                   8289:         if (ref($settings) eq 'HASH') {
                   8290:             if (ref($settings->{$prefix}) eq 'HASH') {
                   8291:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   8292:                     $current{$key} = $settings->{$prefix}{$key};
                   8293:                     if ($key eq 'version') {
                   8294:                         if ($current{$key} ne '') {
1.145     raeburn  8295:                             $checkedon{$key} = ' checked="checked"';
                   8296:                             $checkedoff{$key} = '';
                   8297:                         }
1.279     raeburn  8298:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   8299:                         $checkedon{$key} = ' checked="checked"';
                   8300:                         $checkedoff{$key} = '';
1.137     raeburn  8301:                     }
                   8302:                 }
                   8303:             }
1.279     raeburn  8304:         }
                   8305:         foreach my $type (@{$types}) {
                   8306:             next if ($type ne 'version' && !@locations);
                   8307:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8308:             $datatable .= '<tr'.$css_class.'>
                   8309:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   8310:                            <span class="LC_nobreak">&nbsp;
                   8311:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   8312:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   8313:             if ($type eq 'version') {
                   8314:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   8315:                 my $selector = '<select name="'.$prefix.'_version">';
                   8316:                 foreach my $version (@lcversions) {
                   8317:                     my $selected = '';
                   8318:                     if ($current{'version'} eq $version) {
                   8319:                         $selected = ' selected="selected"';
1.145     raeburn  8320:                     }
1.279     raeburn  8321:                     $selector .= ' <option value="'.$version.'"'.
                   8322:                                  $selected.'>'.$version.'</option>';
                   8323:                 }
                   8324:                 $selector .= '</select> ';
                   8325:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   8326:             } else {
                   8327:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   8328:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   8329:                              ' />'.('&nbsp;'x2).
                   8330:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   8331:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   8332:                              "\n".
                   8333:                              '</div><div><table>';
                   8334:                 my $rem;
                   8335:                 for (my $i=0; $i<@locations; $i++) {
                   8336:                     my ($showloc,$value,$checkedtype);
                   8337:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   8338:                         my $ip = $by_location->{$locations[$i]}->[0];
                   8339:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8340:                             $value = join(':',@{$by_ip->{$ip}});
                   8341:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   8342:                             if (ref($current{$type}) eq 'ARRAY') {
                   8343:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   8344:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   8345:                                         $checkedtype = ' checked="checked"';
                   8346:                                         last;
1.145     raeburn  8347:                                     }
1.138     raeburn  8348:                                 }
                   8349:                             }
                   8350:                         }
1.137     raeburn  8351:                     }
1.279     raeburn  8352:                     $rem = $i%($numinrow);
                   8353:                     if ($rem == 0) {
                   8354:                         if ($i > 0) {
                   8355:                             $datatable .= '</tr>';
                   8356:                         }
                   8357:                         $datatable .= '<tr>';
                   8358:                     }
                   8359:                     $datatable .= '<td class="LC_left_item">'.
                   8360:                                   '<span class="LC_nobreak"><label>'.
                   8361:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   8362:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   8363:                                   '</label></span></td>';
                   8364:                 }
                   8365:                 $rem = @locations%($numinrow);
                   8366:                 my $colsleft = $numinrow - $rem;
                   8367:                 if ($colsleft > 1 ) {
                   8368:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8369:                                   '&nbsp;</td>';
                   8370:                 } elsif ($colsleft == 1) {
                   8371:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  8372:                 }
1.279     raeburn  8373:                 $datatable .= '</tr></table>';
1.137     raeburn  8374:             }
1.279     raeburn  8375:             $datatable .= '</td></tr>';
                   8376:             $itemcount ++;
1.137     raeburn  8377:         }
                   8378:     }
1.279     raeburn  8379:     return ($datatable,$itemcount);
1.137     raeburn  8380: }
                   8381: 
1.275     raeburn  8382: sub print_ssl {
                   8383:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8384:     my ($css_class,$datatable);
                   8385:     my $itemcount = 1;
                   8386:     if ($position eq 'top') {
1.281     raeburn  8387:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8388:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8389:         my $same_institution;
                   8390:         if ($intdom ne '') {
                   8391:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   8392:             if (ref($internet_names) eq 'ARRAY') {
                   8393:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   8394:                     $same_institution = 1;
                   8395:                 }
                   8396:             }
                   8397:         }
1.275     raeburn  8398:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  8399:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   8400:         if ($same_institution) {
                   8401:             my %domservers = &Apache::lonnet::get_servers($dom);
                   8402:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   8403:         } else {
                   8404:             $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.");
                   8405:         }
                   8406:         $datatable .= '</td></tr>';
1.275     raeburn  8407:         $itemcount ++;
                   8408:     } else {
                   8409:         my %titles = &ssl_titles();
                   8410:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   8411:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8412:         my @alldoms = &Apache::lonnet::all_domains();
                   8413:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   8414:         my @domservers = &Apache::lonnet::get_servers($dom);
                   8415:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8416:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  8417:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   8418:             my $legacy;
                   8419:             unless (ref($settings) eq 'HASH') {
                   8420:                 my $name;
                   8421:                 if ($position eq 'connto') {
                   8422:                     $name = 'loncAllowInsecure';
                   8423:                 } else {
                   8424:                     $name = 'londAllowInsecure';
                   8425:                 }
                   8426:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   8427:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8428:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   8429:                     my %what = (
                   8430:                                    $name => 1,
                   8431:                                );
                   8432:                     my ($result,$returnhash) =
                   8433:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   8434:                     if ($result eq 'ok') {
                   8435:                         if (ref($returnhash) eq 'HASH') {
                   8436:                             $legacy = $returnhash->{$name};
                   8437:                         }
                   8438:                     }
                   8439:                 } else {
                   8440:                     $legacy = $Apache::lonnet::perlvar{$name};
                   8441:                 }
                   8442:             }
1.275     raeburn  8443:             foreach my $type ('dom','intdom','other') {
                   8444:                 my %checked;
                   8445:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8446:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   8447:                               '<td class="LC_right_item">';
                   8448:                 my $skip; 
                   8449:                 if ($type eq 'dom') {
                   8450:                     unless (keys(%servers) > 1) {
                   8451:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   8452:                         $skip = 1;
                   8453:                     }
                   8454:                 }
                   8455:                 if ($type eq 'intdom') {
                   8456:                     unless (@instdoms > 1) {
                   8457:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   8458:                         $skip = 1;
                   8459:                     } 
                   8460:                 } elsif ($type eq 'other') {
                   8461:                     if (keys(%by_location) == 0) {
                   8462:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   8463:                         $skip = 1;
                   8464:                     }
                   8465:                 }
                   8466:                 unless ($skip) {
                   8467:                     $checked{'yes'} = ' checked="checked"'; 
                   8468:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  8469:                         if (ref($settings->{$position}) eq 'HASH') {
                   8470:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  8471:                                 $checked{$1} = $checked{'yes'};
                   8472:                                 delete($checked{'yes'}); 
                   8473:                             }
                   8474:                         }
1.293     raeburn  8475:                     } else {
                   8476:                         if ($legacy == 0) {
                   8477:                             $checked{'req'} = $checked{'yes'};
                   8478:                             delete($checked{'yes'});    
                   8479:                         }
1.275     raeburn  8480:                     }
                   8481:                     foreach my $option ('no','yes','req') {
                   8482:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  8483:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  8484:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   8485:                                       '</label></span>'.('&nbsp;'x2);
                   8486:                     }
                   8487:                 }
                   8488:                 $datatable .= '</td></tr>';
                   8489:                 $itemcount ++; 
                   8490:             }
                   8491:         } else {
                   8492:             my $prefix = 'replication';
                   8493:             my @types = ('certreq','nocertreq');
1.279     raeburn  8494:             if (keys(%by_location) == 0) {
                   8495:                 $datatable .= '<tr'.$css_class.'><td>'.
                   8496:                               &mt('Nothing to set here, as there are no other institutions').
                   8497:                               '</td></tr>';
                   8498:                 $itemcount ++;
1.275     raeburn  8499:             } else {
1.279     raeburn  8500:                 ($datatable,$itemcount) = 
                   8501:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  8502:             }
                   8503:         }
                   8504:     }
                   8505:     $$rowtotal += $itemcount;
                   8506:     return $datatable;
                   8507: }
                   8508: 
                   8509: sub ssl_titles {
                   8510:     return &Apache::lonlocal::texthash (
                   8511:                dom           => 'LON-CAPA servers/VMs from same domain',
                   8512:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   8513:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  8514:                connto        => 'Connections to other servers',
                   8515:                connfrom      => 'Connections from other servers',
1.275     raeburn  8516:                replication   => 'Replicating content to other institutions',
                   8517:                certreq       => 'Client certificate required, but specific domains exempt',
                   8518:                nocertreq     => 'No client certificate required, except for specific domains',
                   8519:                no            => 'SSL not used',
                   8520:                yes           => 'SSL Optional (used if available)',
                   8521:                req           => 'SSL Required',
                   8522:     );
1.279     raeburn  8523: }
                   8524: 
                   8525: sub print_trust {
                   8526:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   8527:     my ($css_class,$datatable,%checked,%choices);
                   8528:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8529:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8530:     my $itemcount = 1;
                   8531:     my %titles = &trust_titles();
                   8532:     my @types = ('exc','inc');
                   8533:     if ($prefix eq 'top') {
                   8534:         $prefix = 'content';
                   8535:     } elsif ($prefix eq 'bottom') {
                   8536:         $prefix = 'msg';
                   8537:     }
                   8538:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8539:     $$rowtotal += $itemcount;
                   8540:     return $datatable;
                   8541: }
                   8542: 
                   8543: sub trust_titles {
                   8544:     return &Apache::lonlocal::texthash(
                   8545:                content  => "Access to this domain's content by others",
                   8546:                shared   => "Access to other domain's content by this domain",
                   8547:                enroll   => "Enrollment in this domain's courses by others", 
                   8548:                othcoau  => "Co-author roles in this domain for others",
                   8549:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   8550:                domroles => "Domain roles in this domain assignable to others",
                   8551:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   8552:                reqcrs   => "Requests for creation of courses in this domain by others",
                   8553:                msg      => "Users in other domains can send messages to this domain",
                   8554:                exc      => "Allow all, but exclude specific domains",
                   8555:                inc      => "Deny all, but include specific domains",
                   8556:            );
1.275     raeburn  8557: } 
                   8558: 
1.138     raeburn  8559: sub build_location_hashes {
1.275     raeburn  8560:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  8561:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  8562:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  8563:     my %iphost = &Apache::lonnet::get_iphost();
                   8564:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   8565:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   8566:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   8567:         foreach my $id (@{$iphost{$primary_ip}}) {
                   8568:             my $intdom = &Apache::lonnet::internet_dom($id);
                   8569:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   8570:                 push(@{$intdoms},$intdom);
                   8571:             }
                   8572:         }
                   8573:     }
                   8574:     foreach my $ip (keys(%iphost)) {
                   8575:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   8576:             foreach my $id (@{$iphost{$ip}}) {
                   8577:                 my $location = &Apache::lonnet::internet_dom($id);
                   8578:                 if ($location) {
1.275     raeburn  8579:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   8580:                         my $dom = &Apache::lonnet::host_domain($id);
                   8581:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   8582:                             push(@{$instdoms},$dom);
                   8583:                         }
                   8584:                         next;
                   8585:                     }
1.138     raeburn  8586:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8587:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   8588:                             push(@{$by_ip->{$ip}},$location);
                   8589:                         }
                   8590:                     } else {
                   8591:                         $by_ip->{$ip} = [$location];
                   8592:                     }
                   8593:                 }
                   8594:             }
                   8595:         }
                   8596:     }
                   8597:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   8598:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8599:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   8600:             my $first = $by_ip->{$ip}->[0];
                   8601:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   8602:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   8603:                     push(@{$by_location->{$first}},$ip);
                   8604:                 }
                   8605:             } else {
                   8606:                 $by_location->{$first} = [$ip];
                   8607:             }
                   8608:         }
                   8609:     }
                   8610:     return;
                   8611: }
                   8612: 
1.145     raeburn  8613: sub current_offloads_to {
                   8614:     my ($dom,$settings,$servers) = @_;
                   8615:     my (%spareid,%otherdomconfigs);
1.152     raeburn  8616:     if (ref($servers) eq 'HASH') {
1.145     raeburn  8617:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   8618:             my $gotspares;
1.152     raeburn  8619:             if (ref($settings) eq 'HASH') {
                   8620:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   8621:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   8622:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   8623:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   8624:                         $gotspares = 1;
                   8625:                     }
1.145     raeburn  8626:                 }
                   8627:             }
                   8628:             unless ($gotspares) {
                   8629:                 my $gotspares;
                   8630:                 my $serverhomeID =
                   8631:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   8632:                 my $serverhomedom =
                   8633:                     &Apache::lonnet::host_domain($serverhomeID);
                   8634:                 if ($serverhomedom ne $dom) {
                   8635:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   8636:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   8637:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   8638:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   8639:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   8640:                                 $gotspares = 1;
                   8641:                             }
                   8642:                         }
                   8643:                     } else {
                   8644:                         $otherdomconfigs{$serverhomedom} =
                   8645:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   8646:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   8647:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   8648:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   8649:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   8650:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   8651:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   8652:                                         $gotspares = 1;
                   8653:                                     }
                   8654:                                 }
                   8655:                             }
                   8656:                         }
                   8657:                     }
                   8658:                 }
                   8659:             }
                   8660:             unless ($gotspares) {
                   8661:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   8662:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   8663:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   8664:                } else {
                   8665:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   8666:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   8667:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   8668:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   8669:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   8670:                     } else {
1.150     raeburn  8671:                         my %what = (
                   8672:                              spareid => 1,
                   8673:                         );
                   8674:                         my ($result,$returnhash) = 
                   8675:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   8676:                         if ($result eq 'ok') { 
                   8677:                             if (ref($returnhash) eq 'HASH') {
                   8678:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   8679:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   8680:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   8681:                                 }
                   8682:                             }
1.145     raeburn  8683:                         }
                   8684:                     }
                   8685:                 }
                   8686:             }
                   8687:         }
                   8688:     }
                   8689:     return %spareid;
                   8690: }
                   8691: 
                   8692: sub spares_row {
1.371     raeburn  8693:     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   8694:         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  8695:     my $css_class;
                   8696:     my $numinrow = 4;
                   8697:     my $itemcount = 1;
                   8698:     my $datatable;
1.152     raeburn  8699:     my %typetitles = &sparestype_titles();
                   8700:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  8701:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  8702:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   8703:             my ($othercontrol,$serverdom);
                   8704:             if ($serverhome ne $server) {
                   8705:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   8706:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   8707:             } else {
                   8708:                 $serverdom = &Apache::lonnet::host_domain($server);
                   8709:                 if ($serverdom ne $dom) {
                   8710:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   8711:                 }
                   8712:             }
                   8713:             next unless (ref($spareid->{$server}) eq 'HASH');
1.371     raeburn  8714:             my ($checkednow,$checkedoth);
1.261     raeburn  8715:             if (ref($curroffloadnow) eq 'HASH') {
                   8716:                 if ($curroffloadnow->{$server}) {
                   8717:                     $checkednow = ' checked="checked"';
                   8718:                 }
                   8719:             }
1.371     raeburn  8720:             if (ref($curroffloadoth) eq 'HASH') {
                   8721:                 if ($curroffloadoth->{$server}) {
                   8722:                     $checkedoth = ' checked="checked"';
                   8723:                 }
                   8724:             }
1.145     raeburn  8725:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8726:             $datatable .= '<tr'.$css_class.'>
                   8727:                            <td rowspan="2">
1.183     bisitz   8728:                             <span class="LC_nobreak">'.
                   8729:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  8730:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  8731:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  8732:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371     raeburn  8733:                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.183     bisitz   8734:                           "\n";
1.371     raeburn  8735:             if ($other_insts) {
                   8736:                 $datatable .= '<br />'.
                   8737:                               '<span class="LC_nobreak">'."\n".
                   8738:                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   8739:                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   8740:                           "\n";
                   8741:             }
1.145     raeburn  8742:             my (%current,%canselect);
1.152     raeburn  8743:             my @choices = 
                   8744:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   8745:             foreach my $type ('primary','default') {
                   8746:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  8747:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   8748:                         my @spares = @{$spareid->{$server}{$type}};
                   8749:                         if (@spares > 0) {
1.152     raeburn  8750:                             if ($othercontrol) {
                   8751:                                 $current{$type} = join(', ',@spares);
                   8752:                             } else {
                   8753:                                 $current{$type} .= '<table>';
                   8754:                                 my $numspares = scalar(@spares);
                   8755:                                 for (my $i=0;  $i<@spares; $i++) {
                   8756:                                     my $rem = $i%($numinrow);
                   8757:                                     if ($rem == 0) {
                   8758:                                         if ($i > 0) {
                   8759:                                             $current{$type} .= '</tr>';
                   8760:                                         }
                   8761:                                         $current{$type} .= '<tr>';
1.145     raeburn  8762:                                     }
1.152     raeburn  8763:                                     $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;'.
                   8764:                                                        $spareid->{$server}{$type}[$i].
                   8765:                                                        '</label></td>'."\n";
                   8766:                                 }
                   8767:                                 my $rem = @spares%($numinrow);
                   8768:                                 my $colsleft = $numinrow - $rem;
                   8769:                                 if ($colsleft > 1 ) {
                   8770:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   8771:                                                        '" class="LC_left_item">'.
                   8772:                                                        '&nbsp;</td>';
                   8773:                                 } elsif ($colsleft == 1) {
                   8774:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  8775:                                 }
1.152     raeburn  8776:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  8777:                             }
1.145     raeburn  8778:                         }
                   8779:                     }
                   8780:                     if ($current{$type} eq '') {
                   8781:                         $current{$type} = &mt('None specified');
                   8782:                     }
1.152     raeburn  8783:                     if ($othercontrol) {
                   8784:                         if ($type eq 'primary') {
                   8785:                             $canselect{$type} = $othercontrol;
                   8786:                         }
                   8787:                     } else {
                   8788:                         $canselect{$type} = 
                   8789:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   8790:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   8791:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   8792:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   8793:                         if (@choices > 0) {
                   8794:                             foreach my $lonhost (@choices) {
                   8795:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   8796:                             }
                   8797:                         }
                   8798:                         $canselect{$type} .= '</select>'."\n";
                   8799:                     }
                   8800:                 } else {
                   8801:                     $current{$type} = &mt('Could not be determined');
                   8802:                     if ($type eq 'primary') {
                   8803:                         $canselect{$type} =  $othercontrol;
                   8804:                     }
1.145     raeburn  8805:                 }
1.152     raeburn  8806:                 if ($type eq 'default') {
                   8807:                     $datatable .= '<tr'.$css_class.'>';
                   8808:                 }
                   8809:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   8810:                               '<td>'.$current{$type}.'</td>'."\n".
                   8811:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  8812:             }
                   8813:             $itemcount ++;
                   8814:         }
                   8815:     }
                   8816:     $$rowtotal += $itemcount;
                   8817:     return $datatable;
                   8818: }
                   8819: 
1.152     raeburn  8820: sub possible_newspares {
                   8821:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   8822:     my $serverhostname = &Apache::lonnet::hostname($server);
                   8823:     my %excluded;
                   8824:     if ($serverhostname ne '') {
                   8825:         %excluded = (
                   8826:                        $serverhostname => 1,
                   8827:                     );
                   8828:     }
                   8829:     if (ref($currspares) eq 'HASH') {
                   8830:         foreach my $type (keys(%{$currspares})) {
                   8831:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   8832:                 if (@{$currspares->{$type}} > 0) {
                   8833:                     foreach my $curr (@{$currspares->{$type}}) {
                   8834:                         my $hostname = &Apache::lonnet::hostname($curr);
                   8835:                         $excluded{$hostname} = 1;
                   8836:                     }
                   8837:                 }
                   8838:             }
                   8839:         }
                   8840:     }
                   8841:     my @choices;
                   8842:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   8843:         if (keys(%{$serverhomes}) > 1) {
                   8844:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   8845:                 unless ($excluded{$name}) {
                   8846:                     if (exists($altids->{$serverhomes->{$name}})) {
                   8847:                         push(@choices,$altids->{$serverhomes->{$name}});
                   8848:                     } else {
                   8849:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  8850:                     }
                   8851:                 }
                   8852:             }
                   8853:         }
                   8854:     }
1.152     raeburn  8855:     return sort(@choices);
1.145     raeburn  8856: }
                   8857: 
1.150     raeburn  8858: sub print_loadbalancing {
                   8859:     my ($dom,$settings,$rowtotal) = @_;
                   8860:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8861:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8862:     my $numinrow = 1;
                   8863:     my $datatable;
                   8864:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342     raeburn  8865:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  8866:     if (ref($settings) eq 'HASH') {
                   8867:         %existing = %{$settings};
                   8868:     }
                   8869:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   8870:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  8871:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  8872:     } else {
                   8873:         return;
                   8874:     }
                   8875:     my ($othertitle,$usertypes,$types) =
                   8876:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  8877:     my $rownum = 8;
1.150     raeburn  8878:     if (ref($types) eq 'ARRAY') {
                   8879:         $rownum += scalar(@{$types});
                   8880:     }
1.171     raeburn  8881:     my @css_class = ('LC_odd_row','LC_even_row');
                   8882:     my $balnum = 0;
                   8883:     my $islast;
                   8884:     my (@toshow,$disabledtext);
                   8885:     if (keys(%currbalancer) > 0) {
                   8886:         @toshow = sort(keys(%currbalancer));
                   8887:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   8888:             push(@toshow,'');
                   8889:         }
                   8890:     } else {
                   8891:         @toshow = ('');
                   8892:         $disabledtext = &mt('No existing load balancer');
                   8893:     }
                   8894:     foreach my $lonhost (@toshow) {
                   8895:         if ($balnum == scalar(@toshow)-1) {
                   8896:             $islast = 1;
                   8897:         } else {
                   8898:             $islast = 0;
                   8899:         }
                   8900:         my $cssidx = $balnum%2;
                   8901:         my $targets_div_style = 'display: none';
                   8902:         my $disabled_div_style = 'display: block';
                   8903:         my $homedom_div_style = 'display: none';
                   8904:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  8905:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  8906:                       '<p>';
                   8907:         if ($lonhost eq '') {
1.210     raeburn  8908:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  8909:             if (keys(%currbalancer) > 0) {
                   8910:                 $datatable .= &mt('Add balancer:');
                   8911:             } else {
                   8912:                 $datatable .= &mt('Enable balancer:');
                   8913:             }
                   8914:             $datatable .= '&nbsp;'.
                   8915:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   8916:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   8917:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   8918:                           '<option value="" selected="selected">'.&mt('None').
                   8919:                           '</option>'."\n";
                   8920:             foreach my $server (sort(keys(%servers))) {
                   8921:                 next if ($currbalancer{$server});
                   8922:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   8923:             }
1.210     raeburn  8924:             $datatable .=
1.171     raeburn  8925:                 '</select>'."\n".
                   8926:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   8927:         } else {
                   8928:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   8929:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   8930:                            &mt('Stop balancing').'</label>'.
                   8931:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   8932:             $targets_div_style = 'display: block';
                   8933:             $disabled_div_style = 'display: none';
                   8934:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   8935:                 $homedom_div_style = 'display: block';
                   8936:             }
                   8937:         }
1.306     raeburn  8938:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  8939:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   8940:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   8941:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   8942:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   8943:         my @sparestypes = ('primary','default');
                   8944:         my %typetitles = &sparestype_titles();
1.284     raeburn  8945:         my %hostherechecked = (
                   8946:                                   no => ' checked="checked"',
                   8947:                               );
1.342     raeburn  8948:         my %balcookiechecked = (
                   8949:                                   no => ' checked="checked"', 
                   8950:                                );
1.171     raeburn  8951:         foreach my $sparetype (@sparestypes) {
                   8952:             my $targettable;
                   8953:             for (my $i=0; $i<$numspares; $i++) {
                   8954:                 my $checked;
                   8955:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   8956:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   8957:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   8958:                             $checked = ' checked="checked"';
                   8959:                         }
                   8960:                     }
                   8961:                 }
                   8962:                 my ($chkboxval,$disabled);
                   8963:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   8964:                     $chkboxval = $spares[$i];
                   8965:                 }
                   8966:                 if (exists($currbalancer{$spares[$i]})) {
                   8967:                     $disabled = ' disabled="disabled"';
                   8968:                 }
1.210     raeburn  8969:                 $targettable .=
1.253     raeburn  8970:                     '<td><span class="LC_nobreak"><label>'.
                   8971:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  8972:                     $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  8973:                     '</span></label></span></td>';
1.171     raeburn  8974:                 my $rem = $i%($numinrow);
                   8975:                 if ($rem == 0) {
                   8976:                     if (($i > 0) && ($i < $numspares-1)) {
                   8977:                         $targettable .= '</tr>';
                   8978:                     }
                   8979:                     if ($i < $numspares-1) {
                   8980:                         $targettable .= '<tr>';
1.150     raeburn  8981:                     }
                   8982:                 }
                   8983:             }
1.171     raeburn  8984:             if ($targettable ne '') {
                   8985:                 my $rem = $numspares%($numinrow);
                   8986:                 my $colsleft = $numinrow - $rem;
                   8987:                 if ($colsleft > 1 ) {
                   8988:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8989:                                     '&nbsp;</td>';
                   8990:                 } elsif ($colsleft == 1) {
                   8991:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   8992:                 }
                   8993:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   8994:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   8995:             }
1.284     raeburn  8996:             $hostherechecked{$sparetype} = '';
                   8997:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   8998:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   8999:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   9000:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   9001:                         $hostherechecked{'no'} = '';
                   9002:                     }
                   9003:                 }
                   9004:             }
                   9005:         }
1.342     raeburn  9006:         if ($currcookies{$lonhost}) {
                   9007:             %balcookiechecked = (
                   9008:                                     yes => ' checked="checked"',
                   9009:                                 );
                   9010:         }
1.284     raeburn  9011:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   9012:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   9013:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   9014:         foreach my $sparetype (@sparestypes) {
                   9015:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   9016:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   9017:                           '</i></label><br />';
1.171     raeburn  9018:         }
1.342     raeburn  9019:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   9020:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   9021:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   9022:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   9023:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   9024:                       '</div></td></tr>'.
1.171     raeburn  9025:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   9026:                                            $othertitle,$usertypes,$types,\%servers,
                   9027:                                            \%currbalancer,$lonhost,
                   9028:                                            $targets_div_style,$homedom_div_style,
                   9029:                                            $css_class[$cssidx],$balnum,$islast);
                   9030:         $$rowtotal += $rownum;
                   9031:         $balnum ++;
                   9032:     }
                   9033:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   9034:     return $datatable;
                   9035: }
                   9036: 
                   9037: sub get_loadbalancers_config {
1.342     raeburn  9038:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171     raeburn  9039:     return unless ((ref($servers) eq 'HASH') &&
                   9040:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342     raeburn  9041:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   9042:                    (ref($currcookies) eq 'HASH'));
1.171     raeburn  9043:     if (keys(%{$existing}) > 0) {
                   9044:         my $oldlonhost;
                   9045:         foreach my $key (sort(keys(%{$existing}))) {
                   9046:             if ($key eq 'lonhost') {
                   9047:                 $oldlonhost = $existing->{'lonhost'};
                   9048:                 $currbalancer->{$oldlonhost} = 1;
                   9049:             } elsif ($key eq 'targets') {
                   9050:                 if ($oldlonhost) {
                   9051:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   9052:                 }
                   9053:             } elsif ($key eq 'rules') {
                   9054:                 if ($oldlonhost) {
                   9055:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   9056:                 }
                   9057:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   9058:                 $currbalancer->{$key} = 1;
                   9059:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   9060:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.342     raeburn  9061:                 if ($existing->{$key}{'cookie'}) {
                   9062:                     $currcookies->{$key} = 1;
                   9063:                 }
1.150     raeburn  9064:             }
                   9065:         }
1.171     raeburn  9066:     } else {
                   9067:         my ($balancerref,$targetsref) =
                   9068:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   9069:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   9070:             foreach my $server (sort(keys(%{$balancerref}))) {
                   9071:                 $currbalancer->{$server} = 1;
                   9072:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  9073:             }
                   9074:         }
                   9075:     }
1.171     raeburn  9076:     return;
1.150     raeburn  9077: }
                   9078: 
                   9079: sub loadbalancing_rules {
                   9080:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  9081:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   9082:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  9083:     my $output;
1.171     raeburn  9084:     my $num = 0;
1.210     raeburn  9085:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  9086:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   9087:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   9088:         foreach my $type (@{$alltypes}) {
1.171     raeburn  9089:             $num ++;
1.150     raeburn  9090:             my $current;
                   9091:             if (ref($currrules) eq 'HASH') {
                   9092:                 $current = $currrules->{$type};
                   9093:             }
1.253     raeburn  9094:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  9095:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  9096:                     $current = '';
                   9097:                 }
                   9098:             }
                   9099:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  9100:                                              $servers,$currbalancer,$lonhost,$dom,
                   9101:                                              $targets_div_style,$homedom_div_style,
                   9102:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  9103:         }
                   9104:     }
                   9105:     return $output;
                   9106: }
                   9107: 
                   9108: sub loadbalancing_titles {
                   9109:     my ($dom,$intdom,$usertypes,$types) = @_;
                   9110:     my %othertypes = (
                   9111:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   9112:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   9113:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   9114:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  9115:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   9116:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  9117:                      );
1.209     raeburn  9118:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  9119:     my @available;
1.150     raeburn  9120:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  9121:         @available = @{$types};
1.150     raeburn  9122:     }
1.302     raeburn  9123:     unless (grep(/^default$/,@available)) {
                   9124:         push(@available,'default');
                   9125:     }
                   9126:     unshift(@alltypes,@available);
1.150     raeburn  9127:     my %titles;
                   9128:     foreach my $type (@alltypes) {
                   9129:         if ($type =~ /^_LC_/) {
                   9130:             $titles{$type} = $othertypes{$type};
                   9131:         } elsif ($type eq 'default') {
                   9132:             $titles{$type} = &mt('All users from [_1]',$dom);
                   9133:             if (ref($types) eq 'ARRAY') {
                   9134:                 if (@{$types} > 0) {
                   9135:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   9136:                 }
                   9137:             }
                   9138:         } elsif (ref($usertypes) eq 'HASH') {
                   9139:             $titles{$type} = $usertypes->{$type};
                   9140:         }
                   9141:     }
                   9142:     return (\@alltypes,\%othertypes,\%titles);
                   9143: }
                   9144: 
                   9145: sub loadbalance_rule_row {
1.171     raeburn  9146:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   9147:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  9148:     my @rulenames;
1.150     raeburn  9149:     my %ruletitles = &offloadtype_text();
1.209     raeburn  9150:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  9151:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  9152:     } else {
1.209     raeburn  9153:         @rulenames = ('default','homeserver');
                   9154:         if ($type eq '_LC_external') {
                   9155:             push(@rulenames,'externalbalancer');
                   9156:         } else {
                   9157:             push(@rulenames,'specific');
                   9158:         }
                   9159:         push(@rulenames,'none');
1.150     raeburn  9160:     }
                   9161:     my $style = $targets_div_style;
1.253     raeburn  9162:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  9163:         $style = $homedom_div_style;
                   9164:     }
1.171     raeburn  9165:     my $space;
                   9166:     if ($islast && $num == 1) {
1.317     raeburn  9167:         $space = '<div style="display:inline-block;">&nbsp;</div>';
1.171     raeburn  9168:     }
1.210     raeburn  9169:     my $output =
1.306     raeburn  9170:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  9171:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   9172:         '<td valaign="top">'.$space.
                   9173:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  9174:     for (my $i=0; $i<@rulenames; $i++) {
                   9175:         my $rule = $rulenames[$i];
                   9176:         my ($checked,$extra);
                   9177:         if ($rulenames[$i] eq 'default') {
                   9178:             $rule = '';
                   9179:         }
                   9180:         if ($rulenames[$i] eq 'specific') {
                   9181:             if (ref($servers) eq 'HASH') {
                   9182:                 my $default;
                   9183:                 if (($current ne '') && (exists($servers->{$current}))) {
                   9184:                     $checked = ' checked="checked"';
                   9185:                 }
                   9186:                 unless ($checked) {
                   9187:                     $default = ' selected="selected"';
                   9188:                 }
1.210     raeburn  9189:                 $extra =
1.171     raeburn  9190:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9191:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9192:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   9193:                     '<option value=""'.$default.'></option>'."\n";
                   9194:                 foreach my $server (sort(keys(%{$servers}))) {
                   9195:                     if (ref($currbalancer) eq 'HASH') {
                   9196:                         next if (exists($currbalancer->{$server}));
                   9197:                     }
1.150     raeburn  9198:                     my $selected;
1.171     raeburn  9199:                     if ($server eq $current) {
1.150     raeburn  9200:                         $selected = ' selected="selected"';
                   9201:                     }
1.171     raeburn  9202:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  9203:                 }
                   9204:                 $extra .= '</select>';
                   9205:             }
                   9206:         } elsif ($rule eq $current) {
                   9207:             $checked = ' checked="checked"';
                   9208:         }
                   9209:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  9210:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   9211:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   9212:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  9213:                    ')"'.$checked.' />&nbsp;';
                   9214:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   9215:             $output .= $ruletitles{'particular'};
                   9216:         } else {
                   9217:             $output .= $ruletitles{$rulenames[$i]};
                   9218:         }
                   9219:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  9220:     }
                   9221:     $output .= '</div></td></tr>'."\n";
                   9222:     return $output;
                   9223: }
                   9224: 
                   9225: sub offloadtype_text {
                   9226:     my %ruletitles = &Apache::lonlocal::texthash (
                   9227:            'default'          => 'Offloads to default destinations',
                   9228:            'homeserver'       => "Offloads to user's home server",
                   9229:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   9230:            'specific'         => 'Offloads to specific server',
1.161     raeburn  9231:            'none'             => 'No offload',
1.209     raeburn  9232:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   9233:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  9234:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  9235:     );
                   9236:     return %ruletitles;
                   9237: }
                   9238: 
                   9239: sub sparestype_titles {
                   9240:     my %typestitles = &Apache::lonlocal::texthash (
                   9241:                           'primary' => 'primary',
                   9242:                           'default' => 'default',
                   9243:                       );
                   9244:     return %typestitles;
                   9245: }
                   9246: 
1.28      raeburn  9247: sub contact_titles {
                   9248:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  9249:                    'supportemail'    => 'Support E-mail address',
                   9250:                    'adminemail'      => 'Default Server Admin E-mail address',
                   9251:                    'errormail'       => 'Error reports to be e-mailed to',
                   9252:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  9253:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   9254:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  9255:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   9256:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   9257:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  9258:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350     raeburn  9259:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.378     raeburn  9260:                    'errorthreshold'  => 'Error count threshold for status e-mail to admin(s)',
                   9261:                    'errorsysmail'    => 'Error count threshold for e-mail to developer group',
1.340     raeburn  9262:                    'errorweights'    => 'Weights used to compute error count',
                   9263:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  9264:                  );
                   9265:     my %short_titles = &Apache::lonlocal::texthash (
                   9266:                            adminemail   => 'Admin E-mail address',
                   9267:                            supportemail => 'Support E-mail',
                   9268:                        );   
                   9269:     return (\%titles,\%short_titles);
                   9270: }
                   9271: 
1.286     raeburn  9272: sub helpform_fields {
                   9273:     my %titles =  &Apache::lonlocal::texthash (
                   9274:                        'username'   => 'Name',
                   9275:                        'user'       => 'Username/domain',
                   9276:                        'phone'      => 'Phone',
                   9277:                        'cc'         => 'Cc e-mail',
                   9278:                        'course'     => 'Course Details',
                   9279:                        'section'    => 'Sections',
1.289     raeburn  9280:                        'screenshot' => 'File upload',
1.286     raeburn  9281:     );
                   9282:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   9283:     my %possoptions = (
                   9284:                         username     => ['yes','no','req'],
1.289     raeburn  9285:                         phone        => ['yes','no','req'],
1.286     raeburn  9286:                         user         => ['yes','no'],
1.289     raeburn  9287:                         cc           => ['yes','no'],
1.286     raeburn  9288:                         course       => ['yes','no'],
                   9289:                         section      => ['yes','no'],
                   9290:                         screenshot   => ['yes','no'],
                   9291:                       );
                   9292:     my %fieldoptions = &Apache::lonlocal::texthash (
                   9293:                          'yes'  => 'Optional',
                   9294:                          'req'  => 'Required',
                   9295:                          'no'   => "Not shown",
                   9296:     );
                   9297:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   9298: }
                   9299: 
1.72      raeburn  9300: sub tool_titles {
                   9301:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  9302:                      aboutme    => 'Personal web page',
1.86      raeburn  9303:                      blog       => 'Blog',
1.162     raeburn  9304:                      webdav     => 'WebDAV',
1.86      raeburn  9305:                      portfolio  => 'Portfolio',
1.88      bisitz   9306:                      official   => 'Official courses (with institutional codes)',
                   9307:                      unofficial => 'Unofficial courses',
1.98      raeburn  9308:                      community  => 'Communities',
1.216     raeburn  9309:                      textbook   => 'Textbook courses',
1.271     raeburn  9310:                      placement  => 'Placement tests',
1.86      raeburn  9311:                  );
1.72      raeburn  9312:     return %titles;
                   9313: }
                   9314: 
1.101     raeburn  9315: sub courserequest_titles {
                   9316:     my %titles = &Apache::lonlocal::texthash (
                   9317:                                    official   => 'Official',
                   9318:                                    unofficial => 'Unofficial',
                   9319:                                    community  => 'Communities',
1.216     raeburn  9320:                                    textbook   => 'Textbook',
1.271     raeburn  9321:                                    placement  => 'Placement tests',
1.325     raeburn  9322:                                    lti        => 'LTI Provider',
1.101     raeburn  9323:                                    norequest  => 'Not allowed',
1.325     raeburn  9324:                                    approval   => 'Approval by DC',
1.101     raeburn  9325:                                    validate   => 'With validation',
                   9326:                                    autolimit  => 'Numerical limit',
1.103     raeburn  9327:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  9328:                  );
                   9329:     return %titles;
                   9330: }
                   9331: 
1.163     raeburn  9332: sub authorrequest_titles {
                   9333:     my %titles = &Apache::lonlocal::texthash (
                   9334:                                    norequest  => 'Not allowed',
                   9335:                                    approval   => 'Approval by Dom. Coord.',
                   9336:                                    automatic  => 'Automatic approval',
                   9337:                  );
                   9338:     return %titles;
1.210     raeburn  9339: }
1.163     raeburn  9340: 
1.101     raeburn  9341: sub courserequest_conditions {
                   9342:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  9343:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   9344:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  9345:                  );
                   9346:     return %conditions;
                   9347: }
                   9348: 
                   9349: 
1.27      raeburn  9350: sub print_usercreation {
1.30      raeburn  9351:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  9352:     my $numinrow = 4;
1.28      raeburn  9353:     my $datatable;
                   9354:     if ($position eq 'top') {
1.30      raeburn  9355:         $$rowtotal ++;
1.34      raeburn  9356:         my $rowcount = 0;
1.32      raeburn  9357:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  9358:         if (ref($rules) eq 'HASH') {
                   9359:             if (keys(%{$rules}) > 0) {
1.32      raeburn  9360:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   9361:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  9362:                 $$rowtotal ++;
1.32      raeburn  9363:                 $rowcount ++;
                   9364:             }
                   9365:         }
                   9366:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   9367:         if (ref($idrules) eq 'HASH') {
                   9368:             if (keys(%{$idrules}) > 0) {
                   9369:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   9370:                                                 $idruleorder,$numinrow,$rowcount);
                   9371:                 $$rowtotal ++;
                   9372:                 $rowcount ++;
1.28      raeburn  9373:             }
                   9374:         }
1.39      raeburn  9375:         if ($rowcount == 0) {
                   9376:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   9377:             $$rowtotal ++;
                   9378:             $rowcount ++;
                   9379:         }
1.34      raeburn  9380:     } elsif ($position eq 'middle') {
1.224     raeburn  9381:         my @creators = ('author','course','requestcrs');
1.37      raeburn  9382:         my ($rules,$ruleorder) =
                   9383:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  9384:         my %lt = &usercreation_types();
                   9385:         my %checked;
                   9386:         if (ref($settings) eq 'HASH') {
                   9387:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9388:                 foreach my $item (@creators) {
                   9389:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   9390:                 }
                   9391:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   9392:                 foreach my $item (@creators) {
                   9393:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   9394:                         $checked{$item} = 'none';
                   9395:                     }
                   9396:                 }
                   9397:             }
                   9398:         }
                   9399:         my $rownum = 0;
                   9400:         foreach my $item (@creators) {
                   9401:             $rownum ++;
1.224     raeburn  9402:             if ($checked{$item} eq '') {
                   9403:                 $checked{$item} = 'any';
1.34      raeburn  9404:             }
                   9405:             my $css_class;
                   9406:             if ($rownum%2) {
                   9407:                 $css_class = '';
                   9408:             } else {
                   9409:                 $css_class = ' class="LC_odd_row" ';
                   9410:             }
                   9411:             $datatable .= '<tr'.$css_class.'>'.
                   9412:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  9413:                          '</span></td><td style="text-align: right">';
1.224     raeburn  9414:             my @options = ('any');
                   9415:             if (ref($rules) eq 'HASH') {
                   9416:                 if (keys(%{$rules}) > 0) {
                   9417:                     push(@options,('official','unofficial'));
1.37      raeburn  9418:                 }
                   9419:             }
1.224     raeburn  9420:             push(@options,'none');
1.37      raeburn  9421:             foreach my $option (@options) {
1.50      raeburn  9422:                 my $type = 'radio';
1.34      raeburn  9423:                 my $check = ' ';
1.224     raeburn  9424:                 if ($checked{$item} eq $option) {
                   9425:                     $check = ' checked="checked" ';
1.34      raeburn  9426:                 } 
                   9427:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  9428:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  9429:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   9430:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   9431:             }
                   9432:             $datatable .= '</td></tr>';
                   9433:         }
1.28      raeburn  9434:     } else {
                   9435:         my @contexts = ('author','course','domain');
1.325     raeburn  9436:         my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  9437:         my %checked;
                   9438:         if (ref($settings) eq 'HASH') {
                   9439:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   9440:                 foreach my $item (@contexts) {
                   9441:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   9442:                         foreach my $auth (@authtypes) {
                   9443:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   9444:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   9445:                             }
                   9446:                         }
                   9447:                     }
                   9448:                 }
1.27      raeburn  9449:             }
1.35      raeburn  9450:         } else {
                   9451:             foreach my $item (@contexts) {
1.36      raeburn  9452:                 foreach my $auth (@authtypes) {
1.35      raeburn  9453:                     $checked{$item}{$auth} = ' checked="checked" ';
                   9454:                 }
                   9455:             }
1.27      raeburn  9456:         }
1.28      raeburn  9457:         my %title = &context_names();
                   9458:         my %authname = &authtype_names();
                   9459:         my $rownum = 0;
                   9460:         my $css_class; 
                   9461:         foreach my $item (@contexts) {
                   9462:             if ($rownum%2) {
                   9463:                 $css_class = '';
                   9464:             } else {
                   9465:                 $css_class = ' class="LC_odd_row" ';
                   9466:             }
1.30      raeburn  9467:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  9468:                             '<td>'.$title{$item}.
                   9469:                             '</td><td class="LC_left_item">'.
                   9470:                             '<span class="LC_nobreak">';
                   9471:             foreach my $auth (@authtypes) {
                   9472:                 $datatable .= '<label>'. 
                   9473:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   9474:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   9475:                               $authname{$auth}.'</label>&nbsp;';
                   9476:             }
                   9477:             $datatable .= '</span></td></tr>';
                   9478:             $rownum ++;
1.27      raeburn  9479:         }
1.30      raeburn  9480:         $$rowtotal += $rownum;
1.27      raeburn  9481:     }
                   9482:     return $datatable;
                   9483: }
                   9484: 
1.224     raeburn  9485: sub print_selfcreation {
                   9486:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  9487:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   9488:         $emaildomain,$datatable);
1.224     raeburn  9489:     if (ref($settings) eq 'HASH') {
                   9490:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9491:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  9492:             if (ref($createsettings) eq 'HASH') {
                   9493:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   9494:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   9495:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   9496:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   9497:                         @selfcreate = ('email','login','sso');
                   9498:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   9499:                         @selfcreate = ($createsettings->{'selfcreate'});
                   9500:                     }
                   9501:                 }
                   9502:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   9503:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  9504:                 }
1.305     raeburn  9505:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   9506:                     $emailoptions = $createsettings->{'emailoptions'};
                   9507:                 }
1.303     raeburn  9508:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   9509:                     $emailverified = $createsettings->{'emailverified'};
                   9510:                 }
                   9511:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   9512:                     $emaildomain = $createsettings->{'emaildomain'};
                   9513:                 }
1.224     raeburn  9514:             }
                   9515:         }
                   9516:     }
                   9517:     my %radiohash;
                   9518:     my $numinrow = 4;
                   9519:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  9520:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  9521:     if ($position eq 'top') {
                   9522:         my %choices = &Apache::lonlocal::texthash (
                   9523:                                                       cancreate_login      => 'Institutional Login',
                   9524:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   9525:                                                   );
                   9526:         my @toggles = sort(keys(%choices));
                   9527:         my %defaultchecked = (
                   9528:                                'cancreate_login' => 'off',
                   9529:                                'cancreate_sso'   => 'off',
                   9530:                              );
1.228     raeburn  9531:         my ($onclick,$itemcount);
1.224     raeburn  9532:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   9533:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  9534:         $$rowtotal += $itemcount;
                   9535:         
1.224     raeburn  9536:         if (ref($usertypes) eq 'HASH') {
                   9537:             if (keys(%{$usertypes}) > 0) {
                   9538:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   9539:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  9540:                                              'statustocreate',$rowtotal);
1.224     raeburn  9541:                 $$rowtotal ++;
                   9542:             }
                   9543:         }
1.240     raeburn  9544:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   9545:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9546:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   9547:         my $rem;
                   9548:         my $numperrow = 2;
                   9549:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   9550:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  9551:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  9552:                      '<td class="LC_left_item">'."\n".
1.334     raeburn  9553:                      '<table>'."\n";
1.240     raeburn  9554:         for (my $i=0; $i<@fields; $i++) {
                   9555:             $rem = $i%($numperrow);
                   9556:             if ($rem == 0) {
                   9557:                 if ($i > 0) {
                   9558:                     $datatable .= '</tr>';
                   9559:                 }
                   9560:                 $datatable .= '<tr>';
                   9561:             }
                   9562:             my $currval;
1.248     raeburn  9563:             if (ref($createsettings) eq 'HASH') {
                   9564:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   9565:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   9566:                 }
1.240     raeburn  9567:             }
                   9568:             $datatable .= '<td class="LC_left_item">'.
                   9569:                           '<span class="LC_nobreak">'.
                   9570:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   9571:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   9572:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   9573:         }
                   9574:         my $colsleft = $numperrow - $rem;
                   9575:         if ($colsleft > 1 ) {
                   9576:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9577:                          '&nbsp;</td>';
                   9578:         } elsif ($colsleft == 1) {
                   9579:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   9580:         }
                   9581:         $datatable .= '</tr></table></td></tr>';
                   9582:         $$rowtotal ++;
1.224     raeburn  9583:     } elsif ($position eq 'middle') {
                   9584:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  9585:         my @posstypes;
1.224     raeburn  9586:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  9587:             @posstypes = @{$types};
                   9588:         }
                   9589:         unless (grep(/^default$/,@posstypes)) {
                   9590:             push(@posstypes,'default');
                   9591:         }
                   9592:         my %usertypeshash;
                   9593:         if (ref($usertypes) eq 'HASH') {
                   9594:             %usertypeshash = %{$usertypes};
                   9595:         }
                   9596:         $usertypeshash{'default'} = $othertitle;
                   9597:         foreach my $status (@posstypes) {
                   9598:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   9599:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   9600:             $$rowtotal ++;
1.224     raeburn  9601:         }
                   9602:     } else {
1.236     raeburn  9603:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  9604:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  9605:                                                   );
                   9606:         my @toggles = sort(keys(%choices));
                   9607:         my %defaultchecked = (
                   9608:                                'cancreate_email' => 'off',
                   9609:                              );
1.305     raeburn  9610:         my $customclass = 'LC_selfcreate_email';
                   9611:         my $classprefix = 'LC_canmodify_emailusername_';
                   9612:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  9613:         my $display = 'none';
1.305     raeburn  9614:         my $rowstyle = 'display:none';
1.236     raeburn  9615:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   9616:             $display = 'block';
1.305     raeburn  9617:             $rowstyle = 'display:table-row';
1.236     raeburn  9618:         }
1.305     raeburn  9619:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   9620:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   9621:                                                      \%choices,$$rowtotal,$onclick);
                   9622:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   9623:                                          $rowstyle);
                   9624:         $$rowtotal ++;
                   9625:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   9626:                                       $rowstyle);
                   9627:         $$rowtotal ++;
                   9628:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  9629:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  9630:         my ($emailrules,$emailruleorder) =
                   9631:             &Apache::lonnet::inst_userrules($dom,'email');
                   9632:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9633:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9634:         if (ref($types) eq 'ARRAY') {
                   9635:             @posstypes = @{$types};
                   9636:         }
                   9637:         if (@posstypes) {
                   9638:             unless (grep(/^default$/,@posstypes)) {
                   9639:                 push(@posstypes,'default');
1.302     raeburn  9640:             }
                   9641:             if (ref($usertypes) eq 'HASH') {
                   9642:                 %usertypeshash = %{$usertypes};
                   9643:             }
1.305     raeburn  9644:             my $currassign;
                   9645:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   9646:                 $currassign = {
                   9647:                                   selfassign => $domdefaults{'inststatusguest'},
                   9648:                               };
                   9649:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   9650:             } else {
                   9651:                 $currassign = { selfassign => [] };
                   9652:             }
                   9653:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   9654:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   9655:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   9656:                                          $numinrow,$othertitle,'selfassign',
                   9657:                                          $rowtotal,$onclicktypes,$customclass,
                   9658:                                          $rowstyle);
                   9659:             $$rowtotal ++;
1.302     raeburn  9660:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  9661:             foreach my $status (@posstypes) {
                   9662:                 my $css_class;
                   9663:                 if ($$rowtotal%2) {
                   9664:                     $css_class = 'LC_odd_row ';
                   9665:                 }
                   9666:                 $css_class .= $customclass;
                   9667:                 my $rowid = $optionsprefix.$status;
                   9668:                 my $hidden = 1;
                   9669:                 my $currstyle = 'display:none';
                   9670:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   9671:                     $currstyle = $rowstyle;
                   9672:                     $hidden = 0; 
                   9673:                 }
                   9674:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   9675:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   9676:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   9677:                 unless ($hidden) {
                   9678:                     $$rowtotal ++;
                   9679:                 }
1.224     raeburn  9680:             }
1.302     raeburn  9681:         } else {
1.305     raeburn  9682:             my $css_class;
                   9683:             if ($$rowtotal%2) {
                   9684:                 $css_class = 'LC_odd_row ';
                   9685:             }
                   9686:             $css_class .= $customclass;
1.302     raeburn  9687:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  9688:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   9689:                                          $emailrules,$emailruleorder,$settings,'default','',
                   9690:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   9691:             $$rowtotal ++;
1.224     raeburn  9692:         }
                   9693:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  9694:         $numinrow = 1;
1.305     raeburn  9695:         if (@posstypes) {
                   9696:             foreach my $status (@posstypes) {
                   9697:                 my $rowid = $classprefix.$status;
                   9698:                 my $datarowstyle = 'display:none';
                   9699:                 if (grep(/^\Q$status\E$/,@ordered)) { 
                   9700:                     $datarowstyle = $rowstyle; 
                   9701:                 }
                   9702:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   9703:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   9704:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   9705:                 unless ($datarowstyle eq 'display:none') {
                   9706:                     $$rowtotal ++;
                   9707:                 }
1.224     raeburn  9708:             }
1.305     raeburn  9709:         } else {
                   9710:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   9711:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   9712:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  9713:         }
                   9714:     }
                   9715:     return $datatable;
                   9716: }
                   9717: 
1.305     raeburn  9718: sub selfcreate_javascript {
                   9719:     return <<"ENDSCRIPT";
                   9720: 
                   9721: <script type="text/javascript">
                   9722: // <![CDATA[
                   9723: 
                   9724: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   9725:     var x = document.getElementsByClassName(target);
                   9726:     var insttypes = 0;
                   9727:     var insttypeRegExp = new RegExp(prefix);
                   9728:     if ((x.length != undefined) && (x.length > 0)) {
                   9729:         if (form.elements[radio].length != undefined) {
                   9730:             for (var i=0; i<form.elements[radio].length; i++) {
                   9731:                 if (form.elements[radio][i].checked) {
                   9732:                     if (form.elements[radio][i].value == 1) {
                   9733:                         for (var j=0; j<x.length; j++) {
                   9734:                             if (x[j].id == 'undefined') {
                   9735:                                 x[j].style.display = 'table-row';
                   9736:                             } else if (insttypeRegExp.test(x[j].id)) {
                   9737:                                 insttypes ++;
                   9738:                             } else {
                   9739:                                 x[j].style.display = 'table-row';
                   9740:                             }
                   9741:                         }
                   9742:                     } else {
                   9743:                         for (var j=0; j<x.length; j++) {
                   9744:                             x[j].style.display = 'none';
                   9745:                         }
1.236     raeburn  9746:                     }
1.305     raeburn  9747:                     break;
                   9748:                 }
                   9749:             }
                   9750:             if (insttypes > 0) {
                   9751:                 toggleDataRow(form,checkbox,target,altprefix);
                   9752:                 toggleDataRow(form,checkbox,target,prefix,1);
                   9753:             }
                   9754:         }
                   9755:     }
                   9756:     return;
                   9757: }
                   9758: 
                   9759: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   9760:     if (form.elements[checkbox].length != undefined) {
                   9761:         var count = 0;
                   9762:         if (docount) {
                   9763:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   9764:                 if (form.elements[checkbox][i].checked) {
                   9765:                     count ++;
1.236     raeburn  9766:                 }
1.305     raeburn  9767:             }
                   9768:         }
                   9769:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   9770:             var type = form.elements[checkbox][i].value;
                   9771:             if (document.getElementById(prefix+type)) {
                   9772:                 if (form.elements[checkbox][i].checked) {
                   9773:                     document.getElementById(prefix+type).style.display = 'table-row';
                   9774:                     if (count % 2 == 1) {
                   9775:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   9776:                     } else {
                   9777:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  9778:                     }
1.305     raeburn  9779:                     count ++;
1.236     raeburn  9780:                 } else {
1.305     raeburn  9781:                     document.getElementById(prefix+type).style.display = 'none';
                   9782:                 }
                   9783:             }
                   9784:         }
                   9785:     }
                   9786:     return;
                   9787: }
                   9788: 
                   9789: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   9790:     var caller = radio+'_'+status;
                   9791:     if (form.elements[caller].length != undefined) {
                   9792:         for (var i=0; i<form.elements[caller].length; i++) {
                   9793:             if (form.elements[caller][i].checked) {
                   9794:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   9795:                     var curr = form.elements[caller][i].value;
                   9796:                     if (prefix) {
                   9797:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   9798:                     }
                   9799:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   9800:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   9801:                     if (curr == 'custom') {
                   9802:                         if (prefix) { 
                   9803:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   9804:                         }
                   9805:                     } else if (curr == 'inst') {
                   9806:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   9807:                     } else if (curr == 'noninst') {
                   9808:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  9809:                     }
1.305     raeburn  9810:                     break;
1.236     raeburn  9811:                 }
                   9812:             }
                   9813:         }
                   9814:     }
                   9815: }
                   9816: 
1.305     raeburn  9817: // ]]>
                   9818: </script>
                   9819: 
                   9820: ENDSCRIPT
                   9821: }
                   9822: 
                   9823: sub noninst_users {
                   9824:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   9825:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                   9826:     my $class = 'LC_left_item';
                   9827:     if ($css_class) {
                   9828:         $css_class = ' class="'.$css_class.'"'; 
                   9829:     }
                   9830:     if ($rowid) {
                   9831:         $rowid = ' id="'.$rowid.'"';
                   9832:     }
                   9833:     if ($rowstyle) {
                   9834:         $rowstyle = ' style="'.$rowstyle.'"';
                   9835:     }
                   9836:     my ($output,$description);
                   9837:     if ($type eq 'default') {
                   9838:         $description = &mt('Requests for: [_1]',$typetitle);
                   9839:     } else {
                   9840:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   9841:     }
                   9842:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   9843:               "<td>$description</td>\n".           
                   9844:               '<td class="'.$class.'" colspan="2">'.
                   9845:               '<table><tr>';
                   9846:     my %headers = &Apache::lonlocal::texthash( 
                   9847:               approve  => 'Processing',
                   9848:               email    => 'E-mail',
                   9849:               username => 'Username',
                   9850:     );
                   9851:     foreach my $item ('approve','email','username') {
                   9852:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  9853:     }
1.305     raeburn  9854:     $output .= '</tr><tr>';
                   9855:     foreach my $item ('approve','email','username') {
1.306     raeburn  9856:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  9857:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   9858:         if ($item eq 'approve') {
                   9859:             %choices = &Apache::lonlocal::texthash (
                   9860:                                                      automatic => 'Automatically approved',
                   9861:                                                      approval  => 'Queued for approval',
                   9862:                                                    );
                   9863:             @options = ('automatic','approval');
                   9864:             $hashref = $processing;
                   9865:             $defoption = 'automatic';
                   9866:             $name = 'cancreate_emailprocess_'.$type;
                   9867:         } elsif ($item eq 'email') {
                   9868:             %choices = &Apache::lonlocal::texthash (
                   9869:                                                      any     => 'Any e-mail',
                   9870:                                                      inst    => 'Institutional only',
                   9871:                                                      noninst => 'Non-institutional only',
                   9872:                                                      custom  => 'Custom restrictions',
                   9873:                                                    );
                   9874:             @options = ('any','inst','noninst');
                   9875:             my $showcustom;
                   9876:             if (ref($emailrules) eq 'HASH') {
                   9877:                 if (keys(%{$emailrules}) > 0) {
                   9878:                     push(@options,'custom');
                   9879:                     $showcustom = 'cancreate_emailrule';
                   9880:                     if (ref($settings) eq 'HASH') {
                   9881:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   9882:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   9883:                                 if (exists($emailrules->{$rule})) {
                   9884:                                     $hascustom ++;
                   9885:                                 }
                   9886:                             }
                   9887:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   9888:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   9889:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   9890:                                     if (exists($emailrules->{$rule})) {
                   9891:                                         $hascustom ++;
                   9892:                                     }
                   9893:                                 }
                   9894:                             }
                   9895:                         }
                   9896:                     }
                   9897:                 }
                   9898:             }
                   9899:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   9900:                                                      "'cancreate_emaildomain','$type'".');"';
                   9901:             $hashref = $emailoptions;
                   9902:             $defoption = 'any';
                   9903:             $name = 'cancreate_emailoptions_'.$type;
                   9904:         } elsif ($item eq 'username') {
                   9905:             %choices = &Apache::lonlocal::texthash (
                   9906:                                                      all    => 'Same as e-mail',
                   9907:                                                      first  => 'Omit @domain',
                   9908:                                                      free   => 'Free to choose',
                   9909:                                                    );
                   9910:             @options = ('all','first','free');
                   9911:             $hashref = $emailverified;
                   9912:             $defoption = 'all';
                   9913:             $name = 'cancreate_usernameoptions_'.$type;
                   9914:         }
                   9915:         foreach my $option (@options) {
                   9916:             my $checked;
                   9917:             if (ref($hashref) eq 'HASH') {
                   9918:                 if ($type eq '') {
                   9919:                     if (!exists($hashref->{'default'})) {
                   9920:                         if ($option eq $defoption) {
                   9921:                             $checked = ' checked="checked"';
                   9922:                         }
                   9923:                     } else {
                   9924:                         if ($hashref->{'default'} eq $option) {
                   9925:                             $checked = ' checked="checked"';
                   9926:                         }
1.303     raeburn  9927:                     }
                   9928:                 } else {
1.305     raeburn  9929:                     if (!exists($hashref->{$type})) {
                   9930:                         if ($option eq $defoption) {
                   9931:                             $checked = ' checked="checked"';
                   9932:                         }
                   9933:                     } else {
                   9934:                         if ($hashref->{$type} eq $option) {
                   9935:                             $checked = ' checked="checked"';
                   9936:                         }
1.303     raeburn  9937:                     }
                   9938:                 }
1.305     raeburn  9939:             } elsif (($item eq 'email') && ($hascustom)) {
                   9940:                 if ($option eq 'custom') {
                   9941:                     $checked = ' checked="checked"';
                   9942:                 }
                   9943:             } elsif ($option eq $defoption) {
                   9944:                 $checked = ' checked="checked"';
                   9945:             }
                   9946:             $output .= '<span class="LC_nobreak"><label>'.
                   9947:                        '<input type="radio" name="'.$name.'"'.
                   9948:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   9949:                        $choices{$option}.'</label></span><br />';
                   9950:             if ($item eq 'email') {
                   9951:                 if ($option eq 'custom') {
                   9952:                     my $id = 'cancreate_emailrule_'.$type;
                   9953:                     my $display = 'none';
                   9954:                     if ($checked) {
                   9955:                         $display = 'inline';
1.303     raeburn  9956:                     }
1.305     raeburn  9957:                     my $numinrow = 2;
                   9958:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   9959:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   9960:                                &user_formats_row('email',$settings,$emailrules,
                   9961:                                                  $emailruleorder,$numinrow,'',$type);
                   9962:                               '</table></fieldset>';
                   9963:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   9964:                     my %text = &Apache::lonlocal::texthash (
                   9965:                                                              inst    => 'must end:',
                   9966:                                                              noninst => 'cannot end:',
                   9967:                                                            );
                   9968:                     my $value;
                   9969:                     if (ref($emaildomain) eq 'HASH') {
                   9970:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   9971:                             $value = $emaildomain->{$type}->{$option}; 
1.303     raeburn  9972:                         }
                   9973:                     }
1.305     raeburn  9974:                     if ($value eq '') {
                   9975:                         $value = '@'.$intdom;
                   9976:                     }
                   9977:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   9978:                     my $display = 'none';
                   9979:                     if ($checked) {
                   9980:                         $display = 'inline';
                   9981:                     }
                   9982:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   9983:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   9984:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   9985:                                '</div>';
1.303     raeburn  9986:                 }
                   9987:             }
                   9988:         }
1.305     raeburn  9989:         $output .= '</td>'."\n";
1.303     raeburn  9990:     }
1.305     raeburn  9991:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  9992:     return $output;
                   9993: }
                   9994: 
1.165     raeburn  9995: sub captcha_choice {
1.305     raeburn  9996:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  9997:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   9998:         $vertext,$currver);
1.165     raeburn  9999:     my %lt = &captcha_phrases();
                   10000:     $keyentry = 'hidden';
1.354     raeburn  10001:     my $colspan=2;
1.165     raeburn  10002:     if ($context eq 'cancreate') {
1.224     raeburn  10003:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  10004:     } elsif ($context eq 'login') {
                   10005:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.354     raeburn  10006:     } elsif ($context eq 'passwords') {
                   10007:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   10008:         $colspan=1;
1.165     raeburn  10009:     }
                   10010:     if (ref($settings) eq 'HASH') {
                   10011:         if ($settings->{'captcha'}) {
                   10012:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   10013:         } else {
                   10014:             $checked{'original'} = ' checked="checked"';
                   10015:         }
                   10016:         if ($settings->{'captcha'} eq 'recaptcha') {
                   10017:             $pubtext = $lt{'pub'};
                   10018:             $privtext = $lt{'priv'};
                   10019:             $keyentry = 'text';
1.269     raeburn  10020:             $vertext = $lt{'ver'};
                   10021:             $currver = $settings->{'recaptchaversion'};
                   10022:             if ($currver ne '2') {
                   10023:                 $currver = 1;
                   10024:             }
1.165     raeburn  10025:         }
                   10026:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   10027:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   10028:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   10029:         }
                   10030:     } else {
                   10031:         $checked{'original'} = ' checked="checked"';
                   10032:     }
1.305     raeburn  10033:     my $css_class;
                   10034:     if ($itemcount%2) {
                   10035:         $css_class = 'LC_odd_row';
                   10036:     }
                   10037:     if ($customcss) {
                   10038:         $css_class .= " $customcss";
                   10039:     }
                   10040:     $css_class =~ s/^\s+//;
                   10041:     if ($css_class) {
                   10042:         $css_class = ' class="'.$css_class.'"';
                   10043:     }
                   10044:     if ($rowstyle) {
                   10045:         $css_class .= ' style="'.$rowstyle.'"';
                   10046:     }
1.169     raeburn  10047:     my $output = '<tr'.$css_class.'>'.
1.354     raeburn  10048:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165     raeburn  10049:                  '<table><tr><td>'."\n";
                   10050:     foreach my $option ('original','recaptcha','notused') {
                   10051:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   10052:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   10053:                    $lt{$option}.'</label></span>';
                   10054:         unless ($option eq 'notused') {
                   10055:             $output .= ('&nbsp;'x2)."\n";
                   10056:         }
                   10057:     }
                   10058: #
                   10059: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   10060: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  10061: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  10062: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  10063: #
1.165     raeburn  10064:     $output .= '</td></tr>'."\n".
1.305     raeburn  10065:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  10066:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   10067:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   10068:                $currpub.'" size="40" /></span><br />'."\n".
                   10069:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   10070:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  10071:                $currpriv.'" size="40" /></span><br />'.
                   10072:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   10073:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   10074:                $currver.'" size="3" /></span><br />'.
                   10075:                '</td></tr></table>'."\n".
1.165     raeburn  10076:                '</td></tr>';
                   10077:     return $output;
                   10078: }
                   10079: 
1.32      raeburn  10080: sub user_formats_row {
1.305     raeburn  10081:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  10082:     my $output;
                   10083:     my %text = (
                   10084:                    'username' => 'new usernames',
                   10085:                    'id'       => 'IDs',
                   10086:                );
1.305     raeburn  10087:     unless ($type eq 'email') {
                   10088:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   10089:         $output = '<tr '.$css_class.'>'.
                   10090:                   '<td><span class="LC_nobreak">'.
                   10091:                   &mt("Format rules to check for $text{$type}: ").
                   10092:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  10093:     }
1.27      raeburn  10094:     my $rem;
                   10095:     if (ref($ruleorder) eq 'ARRAY') {
                   10096:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   10097:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   10098:                 my $rem = $i%($numinrow);
                   10099:                 if ($rem == 0) {
                   10100:                     if ($i > 0) {
                   10101:                         $output .= '</tr>';
                   10102:                     }
                   10103:                     $output .= '<tr>';
                   10104:                 }
                   10105:                 my $check = ' ';
1.39      raeburn  10106:                 if (ref($settings) eq 'HASH') {
                   10107:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   10108:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   10109:                             $check = ' checked="checked" ';
                   10110:                         }
1.305     raeburn  10111:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   10112:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   10113:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   10114:                                 $check = ' checked="checked" ';
                   10115:                             }
                   10116:                         }
1.27      raeburn  10117:                     }
                   10118:                 }
1.305     raeburn  10119:                 my $name = $type.'_rule';
                   10120:                 if ($type eq 'email') {
                   10121:                     $name .= '_'.$status;
                   10122:                 }
1.27      raeburn  10123:                 $output .= '<td class="LC_left_item">'.
                   10124:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  10125:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  10126:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   10127:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   10128:             }
                   10129:         }
                   10130:         $rem = @{$ruleorder}%($numinrow);
                   10131:     }
1.305     raeburn  10132:     my $colsleft;
                   10133:     if ($rem) {
                   10134:         $colsleft = $numinrow - $rem;
                   10135:     }
1.27      raeburn  10136:     if ($colsleft > 1 ) {
                   10137:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   10138:                    '&nbsp;</td>';
                   10139:     } elsif ($colsleft == 1) {
                   10140:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   10141:     }
1.305     raeburn  10142:     $output .= '</tr></table>';
                   10143:     unless ($type eq 'email') {
                   10144:         $output .= '</td></tr>';
                   10145:     }
1.27      raeburn  10146:     return $output;
                   10147: }
                   10148: 
1.34      raeburn  10149: sub usercreation_types {
                   10150:     my %lt = &Apache::lonlocal::texthash (
                   10151:                     author     => 'When adding a co-author',
                   10152:                     course     => 'When adding a user to a course',
1.100     raeburn  10153:                     requestcrs => 'When requesting a course',
1.34      raeburn  10154:                     any        => 'Any',
                   10155:                     official   => 'Institutional only ',
                   10156:                     unofficial => 'Non-institutional only',
                   10157:                     none       => 'None',
                   10158:     );
                   10159:     return %lt;
1.48      raeburn  10160: }
1.34      raeburn  10161: 
1.224     raeburn  10162: sub selfcreation_types {
                   10163:     my %lt = &Apache::lonlocal::texthash (
                   10164:                     selfcreate => 'User creates own account',
                   10165:                     any        => 'Any',
                   10166:                     official   => 'Institutional only ',
                   10167:                     unofficial => 'Non-institutional only',
                   10168:                     email      => 'E-mail address',
                   10169:                     login      => 'Institutional Login',
                   10170:                     sso        => 'SSO',
                   10171:              );
                   10172: }
                   10173: 
1.28      raeburn  10174: sub authtype_names {
                   10175:     my %lt = &Apache::lonlocal::texthash(
                   10176:                       int    => 'Internal',
                   10177:                       krb4   => 'Kerberos 4',
                   10178:                       krb5   => 'Kerberos 5',
                   10179:                       loc    => 'Local',
1.325     raeburn  10180:                       lti    => 'LTI',
1.28      raeburn  10181:                   );
                   10182:     return %lt;
                   10183: }
                   10184: 
                   10185: sub context_names {
                   10186:     my %context_title = &Apache::lonlocal::texthash(
                   10187:        author => 'Creating users when an Author',
                   10188:        course => 'Creating users when in a course',
                   10189:        domain => 'Creating users when a Domain Coordinator',
                   10190:     );
                   10191:     return %context_title;
                   10192: }
                   10193: 
1.33      raeburn  10194: sub print_usermodification {
                   10195:     my ($position,$dom,$settings,$rowtotal) = @_;
                   10196:     my $numinrow = 4;
                   10197:     my ($context,$datatable,$rowcount);
                   10198:     if ($position eq 'top') {
                   10199:         $rowcount = 0;
                   10200:         $context = 'author'; 
                   10201:         foreach my $role ('ca','aa') {
                   10202:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10203:                                                    $numinrow,$rowcount);
                   10204:             $$rowtotal ++;
                   10205:             $rowcount ++;
                   10206:         }
1.230     raeburn  10207:     } elsif ($position eq 'bottom') {
1.33      raeburn  10208:         $context = 'course';
                   10209:         $rowcount = 0;
                   10210:         foreach my $role ('st','ep','ta','in','cr') {
                   10211:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10212:                                                    $numinrow,$rowcount);
                   10213:             $$rowtotal ++;
                   10214:             $rowcount ++;
                   10215:         }
                   10216:     }
                   10217:     return $datatable;
                   10218: }
                   10219: 
1.43      raeburn  10220: sub print_defaults {
1.236     raeburn  10221:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  10222:     my $rownum = 0;
1.294     raeburn  10223:     my ($datatable,$css_class,$titles);
                   10224:     unless ($position eq 'bottom') {
                   10225:         $titles = &defaults_titles($dom);
                   10226:     }
1.236     raeburn  10227:     if ($position eq 'top') {
                   10228:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   10229:                      'datelocale_def','portal_def');
                   10230:         my %defaults;
                   10231:         if (ref($settings) eq 'HASH') {
                   10232:             %defaults = %{$settings};
1.43      raeburn  10233:         } else {
1.236     raeburn  10234:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10235:             foreach my $item (@items) {
                   10236:                 $defaults{$item} = $domdefaults{$item};
                   10237:             }
1.43      raeburn  10238:         }
1.236     raeburn  10239:         foreach my $item (@items) {
                   10240:             if ($rownum%2) {
                   10241:                 $css_class = '';
                   10242:             } else {
                   10243:                 $css_class = ' class="LC_odd_row" ';
                   10244:             }
                   10245:             $datatable .= '<tr'.$css_class.'>'.
                   10246:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   10247:                           '</span></td><td class="LC_right_item" colspan="3">';
                   10248:             if ($item eq 'auth_def') {
1.325     raeburn  10249:                 my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236     raeburn  10250:                 my %shortauth = (
                   10251:                                  internal => 'int',
                   10252:                                  krb4 => 'krb4',
                   10253:                                  krb5 => 'krb5',
1.325     raeburn  10254:                                  localauth  => 'loc',
                   10255:                                  lti => 'lti',
1.236     raeburn  10256:                                 );
                   10257:                 my %authnames = &authtype_names();
                   10258:                 foreach my $auth (@authtypes) {
                   10259:                     my $checked = ' ';
                   10260:                     if ($defaults{$item} eq $auth) {
                   10261:                         $checked = ' checked="checked" ';
                   10262:                     }
                   10263:                     $datatable .= '<label><input type="radio" name="'.$item.
                   10264:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   10265:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   10266:                 }
                   10267:             } elsif ($item eq 'timezone_def') {
                   10268:                 my $includeempty = 1;
                   10269:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   10270:             } elsif ($item eq 'datelocale_def') {
                   10271:                 my $includeempty = 1;
                   10272:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   10273:             } elsif ($item eq 'lang_def') {
1.263     raeburn  10274:                 my $includeempty = 1;
                   10275:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  10276:             } else {
                   10277:                 my $size;
                   10278:                 if ($item eq 'portal_def') {
                   10279:                     $size = ' size="25"';
                   10280:                 }
                   10281:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   10282:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  10283:             }
1.236     raeburn  10284:             $datatable .= '</td></tr>';
                   10285:             $rownum ++;
                   10286:         }
1.354     raeburn  10287:     } else {
1.294     raeburn  10288:         my %defaults;
                   10289:         if (ref($settings) eq 'HASH') {
1.354     raeburn  10290:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   10291:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   10292:                 for (my $i=0; $i<$maxnum; $i++) {
                   10293:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10294:                     my $item = $settings->{'inststatusorder'}->[$i];
                   10295:                     my $title = $settings->{'inststatustypes'}->{$item};
                   10296:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   10297:                     $datatable .= '<tr'.$css_class.'>'.
                   10298:                                   '<td><span class="LC_nobreak">'.
                   10299:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   10300:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10301:                         my $vpos = $k+1;
                   10302:                         my $selstr;
                   10303:                         if ($k == $i) {
                   10304:                             $selstr = ' selected="selected" ';
                   10305:                         }
                   10306:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10307:                     }
                   10308:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   10309:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   10310:                                   &mt('delete').'</span></td>'.
1.380     raeburn  10311:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354     raeburn  10312:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   10313:                                   '</span></td></tr>';
                   10314:                 }
                   10315:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10316:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   10317:                 $datatable .= '<tr '.$css_class.'>'.
                   10318:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   10319:                 for (my $k=0; $k<=$maxnum; $k++) {
                   10320:                     my $vpos = $k+1;
                   10321:                     my $selstr;
                   10322:                     if ($k == $maxnum) {
                   10323:                         $selstr = ' selected="selected" ';
                   10324:                     }
                   10325:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10326:                 }
                   10327:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                   10328:                               '<input type="text" size="10" name="addinststatus" value="" />'.
                   10329:                               '&nbsp;'.&mt('(new)').
                   10330:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380     raeburn  10331:                               &mt('Name displayed').':'.
1.354     raeburn  10332:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   10333:                               '</tr>'."\n";
                   10334:                 $rownum ++;
1.294     raeburn  10335:             }
1.354     raeburn  10336:         }
                   10337:     }
                   10338:     $$rowtotal += $rownum;
1.43      raeburn  10339:     return $datatable;
                   10340: }
                   10341: 
1.168     raeburn  10342: sub get_languages_hash {
                   10343:     my %langchoices;
                   10344:     foreach my $id (&Apache::loncommon::languageids()) {
                   10345:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   10346:         if ($code ne '') {
                   10347:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   10348:         }
                   10349:     }
                   10350:     return %langchoices;
                   10351: }
                   10352: 
1.43      raeburn  10353: sub defaults_titles {
1.141     raeburn  10354:     my ($dom) = @_;
1.43      raeburn  10355:     my %titles = &Apache::lonlocal::texthash (
                   10356:                    'auth_def'      => 'Default authentication type',
                   10357:                    'auth_arg_def'  => 'Default authentication argument',
                   10358:                    'lang_def'      => 'Default language',
1.54      raeburn  10359:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  10360:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  10361:                    'portal_def'     => 'Portal/Default URL',
1.294     raeburn  10362:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   10363:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   10364:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  10365:                  );
1.141     raeburn  10366:     if ($dom) {
                   10367:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   10368:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   10369:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   10370:         $protocol = 'http' if ($protocol ne 'https');
                   10371:         if ($uint_dom) {
                   10372:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   10373:                                          $uint_dom);
                   10374:         }
                   10375:     }
1.43      raeburn  10376:     return (\%titles);
                   10377: }
                   10378: 
1.346     raeburn  10379: sub print_scantron {
                   10380:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   10381:     if ($position eq 'top') {
                   10382:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   10383:     } else {
                   10384:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   10385:     }
                   10386: }
                   10387: 
                   10388: sub scantron_javascript {
                   10389:     return <<"ENDSCRIPT";
                   10390: 
                   10391: <script type="text/javascript">
                   10392: // <![CDATA[
                   10393: 
                   10394: function toggleScantron(form) {
1.347     raeburn  10395:     var csvfieldset = new Array();
1.346     raeburn  10396:     if (document.getElementById('scantroncsv_cols')) {
1.347     raeburn  10397:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   10398:     }
                   10399:     if (document.getElementById('scantroncsv_options')) {
                   10400:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   10401:     }
                   10402:     if (csvfieldset.length) {
1.346     raeburn  10403:         if (document.getElementById('scantronconfcsv')) {
1.347     raeburn  10404:             var scantroncsv = document.getElementById('scantronconfcsv');
1.346     raeburn  10405:             if (scantroncsv.checked) {
1.347     raeburn  10406:                 for (var i=0; i<csvfieldset.length; i++) {
                   10407:                     csvfieldset[i].style.display = 'block';
                   10408:                 }
1.346     raeburn  10409:             } else {
1.347     raeburn  10410:                 for (var i=0; i<csvfieldset.length; i++) {
                   10411:                     csvfieldset[i].style.display = 'none';
                   10412:                 }
1.346     raeburn  10413:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   10414:                 if (csvselects.length) {
                   10415:                     for (var j=0; j<csvselects.length; j++) {
                   10416:                         csvselects[j].selectedIndex = 0;
                   10417:                     }
                   10418:                 }
                   10419:             }
                   10420:         }
                   10421:     }
                   10422:     return;
                   10423: }
                   10424: // ]]>
                   10425: </script>
                   10426: 
                   10427: ENDSCRIPT
                   10428: 
                   10429: }
                   10430: 
1.46      raeburn  10431: sub print_scantronformat {
                   10432:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   10433:     my $itemcount = 1;
1.60      raeburn  10434:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   10435:         %confhash);
1.46      raeburn  10436:     my $switchserver = &check_switchserver($dom,$confname);
                   10437:     my %lt = &Apache::lonlocal::texthash (
1.95      www      10438:                 default => 'Default bubblesheet format file error',
                   10439:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  10440:              );
                   10441:     my %scantronfiles = (
                   10442:         default => 'default.tab',
                   10443:         custom => 'custom.tab',
                   10444:     );
                   10445:     foreach my $key (keys(%scantronfiles)) {
                   10446:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   10447:                               .$scantronfiles{$key};
                   10448:     }
                   10449:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   10450:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   10451:         if (!$switchserver) {
                   10452:             my $servadm = $r->dir_config('lonAdmEMail');
                   10453:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   10454:             if ($configuserok eq 'ok') {
                   10455:                 if ($author_ok eq 'ok') {
                   10456:                     my %legacyfile = (
1.346     raeburn  10457:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   10458:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  10459:                     );
                   10460:                     my %md5chk;
                   10461:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  10462:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   10463:                         chomp($md5chk{$type});
1.46      raeburn  10464:                     }
                   10465:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   10466:                         foreach my $type (keys(%legacyfile)) {
1.346     raeburn  10467:                             ($scantronurls{$type},my $error) =
1.46      raeburn  10468:                                 &legacy_scantronformat($r,$dom,$confname,
                   10469:                                                  $type,$legacyfile{$type},
                   10470:                                                  $scantronurls{$type},
                   10471:                                                  $scantronfiles{$type});
1.60      raeburn  10472:                             if ($error ne '') {
                   10473:                                 $error{$type} = $error;
                   10474:                             }
                   10475:                         }
                   10476:                         if (keys(%error) == 0) {
                   10477:                             $is_custom = 1;
1.346     raeburn  10478:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  10479:                                 $scantronurls{'custom'};
1.346     raeburn  10480:                             my $putresult =
1.60      raeburn  10481:                                 &Apache::lonnet::put_dom('configuration',
                   10482:                                                          \%confhash,$dom);
                   10483:                             if ($putresult ne 'ok') {
1.346     raeburn  10484:                                 $error{'custom'} =
1.60      raeburn  10485:                                     '<span class="LC_error">'.
                   10486:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10487:                             }
1.46      raeburn  10488:                         }
                   10489:                     } else {
1.60      raeburn  10490:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  10491:                             &legacy_scantronformat($r,$dom,$confname,
                   10492:                                           'default',$legacyfile{'default'},
                   10493:                                           $scantronurls{'default'},
                   10494:                                           $scantronfiles{'default'});
1.60      raeburn  10495:                         if ($error eq '') {
                   10496:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   10497:                             my $putresult =
                   10498:                                 &Apache::lonnet::put_dom('configuration',
                   10499:                                                          \%confhash,$dom);
                   10500:                             if ($putresult ne 'ok') {
                   10501:                                 $error{'default'} =
                   10502:                                     '<span class="LC_error">'.
                   10503:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10504:                             }
                   10505:                         } else {
                   10506:                             $error{'default'} = $error;
                   10507:                         }
1.46      raeburn  10508:                     }
                   10509:                 }
                   10510:             }
                   10511:         } else {
1.95      www      10512:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  10513:         }
                   10514:     }
                   10515:     if (ref($settings) eq 'HASH') {
                   10516:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   10517:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   10518:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   10519:                 $scantronurl = '';
                   10520:             } else {
                   10521:                 $scantronurl = $settings->{'scantronformat'};
                   10522:             }
                   10523:             $is_custom = 1;
                   10524:         } else {
                   10525:             $scantronurl = $scantronurls{'default'};
                   10526:         }
                   10527:     } else {
1.60      raeburn  10528:         if ($is_custom) {
                   10529:             $scantronurl = $scantronurls{'custom'};
                   10530:         } else {
                   10531:             $scantronurl = $scantronurls{'default'};
                   10532:         }
1.46      raeburn  10533:     }
                   10534:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10535:     $datatable .= '<tr'.$css_class.'>';
                   10536:     if (!$is_custom) {
1.65      raeburn  10537:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   10538:                       '<span class="LC_nobreak">';
1.46      raeburn  10539:         if ($scantronurl) {
1.199     raeburn  10540:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   10541:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  10542:         } else {
                   10543:             $datatable = &mt('File unavailable for display');
                   10544:         }
1.65      raeburn  10545:         $datatable .= '</span></td>';
1.60      raeburn  10546:         if (keys(%error) == 0) { 
1.306     raeburn  10547:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  10548:             if (!$switchserver) {
                   10549:                 $datatable .= &mt('Upload:').'<br />';
                   10550:             }
                   10551:         } else {
                   10552:             my $errorstr;
                   10553:             foreach my $key (sort(keys(%error))) {
                   10554:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   10555:             }
                   10556:             $datatable .= '<td>'.$errorstr;
                   10557:         }
1.46      raeburn  10558:     } else {
                   10559:         if (keys(%error) > 0) {
                   10560:             my $errorstr;
                   10561:             foreach my $key (sort(keys(%error))) {
                   10562:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   10563:             } 
1.60      raeburn  10564:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  10565:         } elsif ($scantronurl) {
1.199     raeburn  10566:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   10567:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  10568:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  10569:                           $link.
                   10570:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   10571:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  10572:                           '<td><span class="LC_nobreak">&nbsp;'.
                   10573:                           &mt('Replace:').'</span><br />';
1.46      raeburn  10574:         }
                   10575:     }
                   10576:     if (keys(%error) == 0) {
                   10577:         if ($switchserver) {
                   10578:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   10579:         } else {
1.65      raeburn  10580:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   10581:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  10582:         }
                   10583:     }
                   10584:     $datatable .= '</td></tr>';
                   10585:     $$rowtotal ++;
                   10586:     return $datatable;
                   10587: }
                   10588: 
                   10589: sub legacy_scantronformat {
                   10590:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   10591:     my ($url,$error);
                   10592:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   10593:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   10594:         (my $result,$url) =
                   10595:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   10596:                          '','',$newfile);
                   10597:         if ($result ne 'ok') {
1.130     raeburn  10598:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  10599:         }
                   10600:     }
                   10601:     return ($url,$error);
                   10602: }
1.43      raeburn  10603: 
1.346     raeburn  10604: sub print_scantronconfig {
                   10605:     my ($dom,$settings,$rowtotal) = @_;
                   10606:     my $itemcount = 2;
                   10607:     my $is_checked = ' checked="checked"';
1.347     raeburn  10608:     my %optionson = (
                   10609:                      hdr => ' checked="checked"',
                   10610:                      pad => ' checked="checked"',
                   10611:                      rem => ' checked="checked"',
                   10612:                     );
                   10613:     my %optionsoff = (
                   10614:                       hdr => '',
                   10615:                       pad => '',
                   10616:                       rem => '',
                   10617:                      );
1.346     raeburn  10618:     my $currcsvsty = 'none';
1.347     raeburn  10619:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346     raeburn  10620:     my @fields = &scantroncsv_fields();
                   10621:     my %titles = &scantronconfig_titles();
                   10622:     if (ref($settings) eq 'HASH') {
                   10623:         if (ref($settings->{config}) eq 'HASH') {
                   10624:             if ($settings->{config}->{dat}) {
                   10625:                 $checked{'dat'} = $is_checked;
                   10626:             }
                   10627:             if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347     raeburn  10628:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   10629:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   10630:                     if (keys(%csvfields) > 0) {
                   10631:                         $checked{'csv'} = $is_checked;
                   10632:                         $currcsvsty = 'block';
                   10633:                     }
                   10634:                 }
                   10635:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   10636:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   10637:                     foreach my $option (keys(%optionson)) {
                   10638:                         unless ($csvoptions{$option}) {
                   10639:                             $optionsoff{$option} = $optionson{$option};
                   10640:                             $optionson{$option} = '';
                   10641:                         }
                   10642:                     }
1.346     raeburn  10643:                 }
                   10644:             }
                   10645:         } else {
                   10646:             $checked{'dat'} = $is_checked;
                   10647:         }
                   10648:     } else {
                   10649:         $checked{'dat'} = $is_checked;
                   10650:     }
                   10651:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   10652:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   10653:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   10654:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   10655:     foreach my $item ('dat','csv') {
                   10656:         my $id;
                   10657:         if ($item eq 'csv') {
                   10658:             $id = 'id="scantronconfcsv" ';
1.347     raeburn  10659:         }
1.346     raeburn  10660:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   10661:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   10662:         if ($item eq 'csv') {
                   10663:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   10664:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   10665:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   10666:             foreach my $col (@fields) {
                   10667:                 my $selnone;
                   10668:                 if ($csvfields{$col} eq '') {
                   10669:                     $selnone = ' selected="selected"';
                   10670:                 }
                   10671:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   10672:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   10673:                               '<option value=""'.$selnone.'></option>';
                   10674:                 for (my $i=0; $i<20; $i++) {
                   10675:                     my $shown = $i+1;
                   10676:                     my $sel;
                   10677:                     unless ($selnone) {
                   10678:                         if (exists($csvfields{$col})) {
                   10679:                             if ($csvfields{$col} == $i) {
                   10680:                                 $sel = ' selected="selected"';
                   10681:                             }
                   10682:                         }
                   10683:                     }
                   10684:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   10685:                 }
                   10686:                 $datatable .= '</select></td></tr>';
                   10687:            }
1.347     raeburn  10688:            $datatable .= '</table></fieldset>'.
                   10689:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   10690:                          '<legend>'.&mt('CSV Options').'</legend>';
                   10691:            foreach my $option ('hdr','pad','rem') {
                   10692:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   10693:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   10694:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   10695:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   10696:            }
                   10697:            $datatable .= '</fieldset>';
1.346     raeburn  10698:            $itemcount ++;
                   10699:         }
                   10700:     }
                   10701:     $datatable .= '</td></tr>';
                   10702:     $$rowtotal ++;
                   10703:     return $datatable;
                   10704: }
                   10705: 
                   10706: sub scantronconfig_titles {
                   10707:     return &Apache::lonlocal::texthash(
                   10708:                                           dat => 'Standard format (.dat)',
                   10709:                                           csv => 'Comma separated values (.csv)',
1.347     raeburn  10710:                                           hdr => 'Remove first line in file (contains column titles)',
                   10711:                                           pad => 'Prepend 0s to PaperID',
1.348     raeburn  10712:                                           rem => 'Remove leading spaces (except Question Response columns)',
1.346     raeburn  10713:                                           CODE => 'CODE',
                   10714:                                           ID   => 'Student ID',
                   10715:                                           PaperID => 'Paper ID',
                   10716:                                           FirstName => 'First Name',
                   10717:                                           LastName => 'Last Name',
                   10718:                                           FirstQuestion => 'First Question Response',
                   10719:                                           Section => 'Section',
                   10720:     );
                   10721: }
                   10722: 
                   10723: sub scantroncsv_fields {
                   10724:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   10725: }
                   10726: 
1.49      raeburn  10727: sub print_coursecategories {
1.57      raeburn  10728:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   10729:     my $datatable;
                   10730:     if ($position eq 'top') {
1.238     raeburn  10731:         my (%checked);
                   10732:         my @catitems = ('unauth','auth');
                   10733:         my @cattypes = ('std','domonly','codesrch','none');
                   10734:         $checked{'unauth'} = 'std';
                   10735:         $checked{'auth'} = 'std';
                   10736:         if (ref($settings) eq 'HASH') {
                   10737:             foreach my $type (@cattypes) {
                   10738:                 if ($type eq $settings->{'unauth'}) {
                   10739:                     $checked{'unauth'} = $type;
                   10740:                 }
                   10741:                 if ($type eq $settings->{'auth'}) {
                   10742:                     $checked{'auth'} = $type;
                   10743:                 }
                   10744:             }
                   10745:         }
                   10746:         my %lt = &Apache::lonlocal::texthash (
                   10747:                                                unauth   => 'Catalog type for unauthenticated users',
                   10748:                                                auth     => 'Catalog type for authenticated users',
                   10749:                                                none     => 'No catalog',
                   10750:                                                std      => 'Standard catalog',
                   10751:                                                domonly  => 'Domain-only catalog',
                   10752:                                                codesrch => "Code search form",
                   10753:                                              );
                   10754:        my $itemcount = 0;
                   10755:        foreach my $item (@catitems) {
                   10756:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   10757:            $datatable .= '<tr '.$css_class.'>'.
                   10758:                          '<td>'.$lt{$item}.'</td>'.
                   10759:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   10760:            foreach my $type (@cattypes) {
                   10761:                my $ischecked;
                   10762:                if ($checked{$item} eq $type) {
                   10763:                    $ischecked=' checked="checked"';
                   10764:                }
                   10765:                $datatable .= '<label>'.
                   10766:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   10767:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   10768:            }
1.327     raeburn  10769:            $datatable .= '</span></td></tr>';
1.238     raeburn  10770:            $itemcount ++;
                   10771:         }
                   10772:         $$rowtotal += $itemcount;
                   10773:     } elsif ($position eq 'middle') {
1.57      raeburn  10774:         my $toggle_cats_crs = ' ';
                   10775:         my $toggle_cats_dom = ' checked="checked" ';
                   10776:         my $can_cat_crs = ' ';
                   10777:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  10778:         my $toggle_catscomm_comm = ' ';
                   10779:         my $toggle_catscomm_dom = ' checked="checked" ';
                   10780:         my $can_catcomm_comm = ' ';
                   10781:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  10782:         my $toggle_catsplace_place = ' ';
                   10783:         my $toggle_catsplace_dom = ' checked="checked" ';
                   10784:         my $can_catplace_place = ' ';
                   10785:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  10786: 
1.57      raeburn  10787:         if (ref($settings) eq 'HASH') {
                   10788:             if ($settings->{'togglecats'} eq 'crs') {
                   10789:                 $toggle_cats_crs = $toggle_cats_dom;
                   10790:                 $toggle_cats_dom = ' ';
                   10791:             }
                   10792:             if ($settings->{'categorize'} eq 'crs') {
                   10793:                 $can_cat_crs = $can_cat_dom;
                   10794:                 $can_cat_dom = ' ';
                   10795:             }
1.120     raeburn  10796:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   10797:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   10798:                 $toggle_catscomm_dom = ' ';
                   10799:             }
                   10800:             if ($settings->{'categorizecomm'} eq 'comm') {
                   10801:                 $can_catcomm_comm = $can_catcomm_dom;
                   10802:                 $can_catcomm_dom = ' ';
                   10803:             }
1.272     raeburn  10804:             if ($settings->{'togglecatsplace'} eq 'place') {
                   10805:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   10806:                 $toggle_catsplace_dom = ' ';
                   10807:             }
                   10808:             if ($settings->{'categorizeplace'} eq 'place') {
                   10809:                 $can_catplace_place = $can_catplace_dom;
                   10810:                 $can_catplace_dom = ' ';
                   10811:             }
1.57      raeburn  10812:         }
                   10813:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  10814:                      togglecats      => 'Show/Hide a course in catalog',
                   10815:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   10816:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   10817:                      categorize      => 'Assign a category to a course',
                   10818:                      categorizecomm  => 'Assign a category to a community',
                   10819:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  10820:                     );
                   10821:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  10822:                      dom   => 'Set in Domain',
                   10823:                      crs   => 'Set in Course',
                   10824:                      comm  => 'Set in Community',
                   10825:                      place => 'Set in Placement Test',
1.57      raeburn  10826:                     );
                   10827:         $datatable = '<tr class="LC_odd_row">'.
                   10828:                   '<td>'.$title{'togglecats'}.'</td>'.
                   10829:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10830:                   '<input type="radio" name="togglecats"'.
                   10831:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10832:                   '<label><input type="radio" name="togglecats"'.
                   10833:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   10834:                   '</tr><tr>'.
                   10835:                   '<td>'.$title{'categorize'}.'</td>'.
                   10836:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10837:                   '<label><input type="radio" name="categorize"'.
                   10838:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10839:                   '<label><input type="radio" name="categorize"'.
                   10840:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  10841:                   '</tr><tr class="LC_odd_row">'.
                   10842:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   10843:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10844:                   '<input type="radio" name="togglecatscomm"'.
                   10845:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10846:                   '<label><input type="radio" name="togglecatscomm"'.
                   10847:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   10848:                   '</tr><tr>'.
                   10849:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   10850:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10851:                   '<label><input type="radio" name="categorizecomm"'.
                   10852:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10853:                   '<label><input type="radio" name="categorizecomm"'.
                   10854:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327     raeburn  10855:                   '</tr><tr class="LC_odd_row">'.
1.272     raeburn  10856:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   10857:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10858:                   '<input type="radio" name="togglecatsplace"'.
                   10859:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10860:                   '<label><input type="radio" name="togglecatscomm"'.
                   10861:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   10862:                   '</tr><tr>'.
                   10863:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   10864:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10865:                   '<label><input type="radio" name="categorizeplace"'.
                   10866:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10867:                   '<label><input type="radio" name="categorizeplace"'.
                   10868:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  10869:                   '</tr>';
1.272     raeburn  10870:         $$rowtotal += 6;
1.57      raeburn  10871:     } else {
                   10872:         my $css_class;
                   10873:         my $itemcount = 1;
                   10874:         my $cathash; 
                   10875:         if (ref($settings) eq 'HASH') {
                   10876:             $cathash = $settings->{'cats'};
                   10877:         }
                   10878:         if (ref($cathash) eq 'HASH') {
                   10879:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   10880:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   10881:                                                    \%allitems,\%idx,\@jsarray);
                   10882:             my $maxdepth = scalar(@cats);
                   10883:             my $colattrib = '';
                   10884:             if ($maxdepth > 2) {
                   10885:                 $colattrib = ' colspan="2" ';
                   10886:             }
                   10887:             my @path;
                   10888:             if (@cats > 0) {
                   10889:                 if (ref($cats[0]) eq 'ARRAY') {
                   10890:                     my $numtop = @{$cats[0]};
                   10891:                     my $maxnum = $numtop;
1.120     raeburn  10892:                     my %default_names = (
                   10893:                           instcode    => &mt('Official courses'),
                   10894:                           communities => &mt('Communities'),
1.272     raeburn  10895:                           placement   => &mt('Placement Tests'),
1.120     raeburn  10896:                     );
                   10897: 
                   10898:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   10899:                         ($cathash->{'instcode::0'} eq '') ||
                   10900:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  10901:                         ($cathash->{'communities::0'} eq '') ||
                   10902:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   10903:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  10904:                         $maxnum ++;
                   10905:                     }
                   10906:                     my $lastidx;
                   10907:                     for (my $i=0; $i<$numtop; $i++) {
                   10908:                         my $parent = $cats[0][$i];
                   10909:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10910:                         my $item = &escape($parent).'::0';
                   10911:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   10912:                         $lastidx = $idx{$item};
                   10913:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   10914:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   10915:                         for (my $k=0; $k<=$maxnum; $k++) {
                   10916:                             my $vpos = $k+1;
                   10917:                             my $selstr;
                   10918:                             if ($k == $i) {
                   10919:                                 $selstr = ' selected="selected" ';
                   10920:                             }
                   10921:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10922:                         }
1.214     raeburn  10923:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  10924:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  10925:                             $datatable .=  '<span class="LC_nobreak">'
                   10926:                                            .$default_names{$parent}.'</span>';
                   10927:                             if ($parent eq 'instcode') {
                   10928:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   10929:                                               .&mt('with institutional codes')
                   10930:                                               .')</span></td><td'.$colattrib.'>';
                   10931:                             } else {
                   10932:                                 $datatable .= '<table><tr><td>';
                   10933:                             }
                   10934:                             $datatable .= '<span class="LC_nobreak">'
                   10935:                                           .'<label><input type="radio" name="'
                   10936:                                           .$parent.'" value="1" checked="checked" />'
                   10937:                                           .&mt('Display').'</label>';
                   10938:                             if ($parent eq 'instcode') {
                   10939:                                 $datatable .= '&nbsp;';
                   10940:                             } else {
                   10941:                                 $datatable .= '</span></td></tr><tr><td>'
                   10942:                                               .'<span class="LC_nobreak">';
                   10943:                             }
                   10944:                             $datatable .= '<label><input type="radio" name="'
                   10945:                                           .$parent.'" value="0" />'
                   10946:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  10947:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  10948:                                 $datatable .= '</td></tr></table>';
                   10949:                             }
                   10950:                             $datatable .= '</td>';
1.57      raeburn  10951:                         } else {
                   10952:                             $datatable .= $parent
1.214     raeburn  10953:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   10954:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  10955:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   10956:                         }
                   10957:                         my $depth = 1;
                   10958:                         push(@path,$parent);
                   10959:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   10960:                         pop(@path);
                   10961:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   10962:                         $itemcount ++;
                   10963:                     }
1.48      raeburn  10964:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  10965:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   10966:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  10967:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10968:                         my $vpos = $k+1;
                   10969:                         my $selstr;
1.57      raeburn  10970:                         if ($k == $numtop) {
1.48      raeburn  10971:                             $selstr = ' selected="selected" ';
                   10972:                         }
                   10973:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10974:                     }
1.59      bisitz   10975:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  10976:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   10977:                                   .'</tr>'."\n";
1.48      raeburn  10978:                     $itemcount ++;
1.272     raeburn  10979:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  10980:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   10981:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10982:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   10983:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   10984:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   10985:                             for (my $k=0; $k<=$maxnum; $k++) {
                   10986:                                 my $vpos = $k+1;
                   10987:                                 my $selstr;
                   10988:                                 if ($k == $maxnum) {
                   10989:                                     $selstr = ' selected="selected" ';
                   10990:                                 }
                   10991:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  10992:                             }
1.120     raeburn  10993:                             $datatable .= '</select></span></td>'.
                   10994:                                           '<td><span class="LC_nobreak">'.
                   10995:                                           $default_names{$default}.'</span>';
                   10996:                             if ($default eq 'instcode') {
                   10997:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   10998:                                               .&mt('with institutional codes').')</span>';
                   10999:                             }
                   11000:                             $datatable .= '</td>'
                   11001:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   11002:                                           .&mt('Display').'</label>&nbsp;'
                   11003:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   11004:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  11005:                         }
                   11006:                     }
                   11007:                 }
1.57      raeburn  11008:             } else {
                   11009:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  11010:             }
                   11011:         } else {
1.327     raeburn  11012:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  11013:                           .&initialize_categories($itemcount);
1.48      raeburn  11014:         }
1.57      raeburn  11015:         $$rowtotal += $itemcount;
1.48      raeburn  11016:     }
                   11017:     return $datatable;
                   11018: }
                   11019: 
1.69      raeburn  11020: sub print_serverstatuses {
                   11021:     my ($dom,$settings,$rowtotal) = @_;
                   11022:     my $datatable;
                   11023:     my @pages = &serverstatus_pages();
                   11024:     my (%namedaccess,%machineaccess);
                   11025:     foreach my $type (@pages) {
                   11026:         $namedaccess{$type} = '';
                   11027:         $machineaccess{$type}= '';
                   11028:     }
                   11029:     if (ref($settings) eq 'HASH') {
                   11030:         foreach my $type (@pages) {
                   11031:             if (exists($settings->{$type})) {
                   11032:                 if (ref($settings->{$type}) eq 'HASH') {
                   11033:                     foreach my $key (keys(%{$settings->{$type}})) {
                   11034:                         if ($key eq 'namedusers') {
                   11035:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   11036:                         } elsif ($key eq 'machines') {
                   11037:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   11038:                         }
                   11039:                     }
                   11040:                 }
                   11041:             }
                   11042:         }
                   11043:     }
1.81      raeburn  11044:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  11045:     my $rownum = 0;
                   11046:     my $css_class;
                   11047:     foreach my $type (@pages) {
                   11048:         $rownum ++;
                   11049:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   11050:         $datatable .= '<tr'.$css_class.'>'.
                   11051:                       '<td><span class="LC_nobreak">'.
                   11052:                       $titles->{$type}.'</span></td>'.
                   11053:                       '<td class="LC_left_item">'.
                   11054:                       '<input type="text" name="'.$type.'_namedusers" '.
                   11055:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   11056:                       '<td class="LC_right_item">'.
                   11057:                       '<span class="LC_nobreak">'.
                   11058:                       '<input type="text" name="'.$type.'_machines" '.
                   11059:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.334     raeburn  11060:                       '</span></td></tr>'."\n";
1.69      raeburn  11061:     }
                   11062:     $$rowtotal += $rownum;
                   11063:     return $datatable;
                   11064: }
                   11065: 
                   11066: sub serverstatus_pages {
                   11067:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  11068:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   11069:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   11070:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  11071: }
                   11072: 
1.236     raeburn  11073: sub defaults_javascript {
                   11074:     my ($settings) = @_;
1.354     raeburn  11075:     return unless (ref($settings) eq 'HASH');
1.236     raeburn  11076:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   11077:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   11078:         if ($maxnum eq '') {
                   11079:             $maxnum = 0;
                   11080:         }
                   11081:         $maxnum ++;
1.249     raeburn  11082:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  11083:         return <<"ENDSCRIPT";
                   11084: <script type="text/javascript">
                   11085: // <![CDATA[
                   11086: function reorderTypes(form,caller) {
                   11087:     var changedVal;
                   11088: $jstext 
                   11089:     var newpos = 'addinststatus_pos';
                   11090:     var current = new Array;
                   11091:     var maxh = $maxnum;
                   11092:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11093:     var oldVal;
                   11094:     if (caller == newpos) {
                   11095:         changedVal = newitemVal;
                   11096:     } else {
                   11097:         var curritem = 'inststatus_pos_'+caller;
                   11098:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   11099:         current[newitemVal] = newpos;
                   11100:     }
                   11101:     for (var i=0; i<inststatuses.length; i++) {
                   11102:         if (inststatuses[i] != caller) {
                   11103:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   11104:             if (form.elements[elementName]) {
                   11105:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11106:                 current[currVal] = elementName;
                   11107:             }
                   11108:         }
                   11109:     }
                   11110:     for (var j=0; j<maxh; j++) {
                   11111:         if (current[j] == undefined) {
                   11112:             oldVal = j;
                   11113:         }
                   11114:     }
                   11115:     if (oldVal < changedVal) {
                   11116:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11117:            var elementName = current[k];
                   11118:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11119:         }
                   11120:     } else {
                   11121:         for (var k=changedVal; k<oldVal; k++) {
                   11122:             var elementName = current[k];
                   11123:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11124:         }
                   11125:     }
                   11126:     return;
                   11127: }
                   11128: 
                   11129: // ]]>
                   11130: </script>
                   11131: 
                   11132: ENDSCRIPT
                   11133:     }
1.354     raeburn  11134:     return;
                   11135: }
                   11136: 
                   11137: sub passwords_javascript {
1.365     raeburn  11138:     my %intalert = &Apache::lonlocal::texthash (
                   11139:         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.',
                   11140:         authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   11141:         passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   11142:         passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   11143:         passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   11144:         passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   11145:     );
                   11146:     &js_escape(\%intalert);
                   11147:     my $defmin = $Apache::lonnet::passwdmin;
1.354     raeburn  11148:     my $intauthjs = <<"ENDSCRIPT";
                   11149: 
                   11150: function warnIntAuth(field) {
                   11151:     if (field.name == 'intauth_check') {
                   11152:         if (field.value == '2') {
1.365     raeburn  11153:             alert('$intalert{authcheck}');
1.354     raeburn  11154:         }
                   11155:     }
                   11156:     if (field.name == 'intauth_cost') {
                   11157:         field.value.replace(/\s/g,'');
                   11158:         if (field.value != '') {
                   11159:             var regexdigit=/^\\d+\$/;
                   11160:             if (!regexdigit.test(field.value)) {
1.365     raeburn  11161:                 alert('$intalert{authcost}');
                   11162:             }
                   11163:         }
                   11164:     }
                   11165:     return;
                   11166: }
                   11167: 
                   11168: function warnIntPass(field) {
                   11169:     field.value.replace(/^\s+/,'');
                   11170:     field.value.replace(/\s+\$/,'');
                   11171:     var regexdigit=/^\\d+\$/;
                   11172:     if (field.name == 'passwords_min') {
                   11173:         if (field.value == '') {
                   11174:             alert('$intalert{passmin}');
                   11175:             field.value = '$defmin';
                   11176:         } else {
                   11177:             if (!regexdigit.test(field.value)) {
                   11178:                 alert('$intalert{passmin}');
                   11179:                 field.value = '$defmin';
                   11180:             }
1.366     raeburn  11181:             var minval = parseInt(field.value,10);
1.365     raeburn  11182:             if (minval < $defmin) {
                   11183:                 alert('$intalert{passmin}');
                   11184:                 field.value = '$defmin';
                   11185:             }
                   11186:         }
                   11187:     } else {
                   11188:         if (field.value == '0') {
                   11189:             field.value = '';
                   11190:         }
                   11191:         if (field.value != '') {
                   11192:             if (field.name == 'passwords_expire') {
                   11193:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/; 
                   11194:                 if (!regexpposnum.test(field.value)) {
                   11195:                     alert('$intalert{passexp}');
                   11196:                     field.value = '';
                   11197:                 } else {
                   11198:                     var expval = parseFloat(field.value);
                   11199:                     if (expval == 0) {
                   11200:                         alert('$intalert{passexp}');
                   11201:                         field.value = '';
                   11202:                     }
                   11203:                 }
                   11204:             } else {
                   11205:                 if (!regexdigit.test(field.value)) {
                   11206:                     if (field.name == 'passwords_max') {
                   11207:                         alert('$intalert{passmax}');
                   11208:                     } else {
                   11209:                         if (field.name == 'passwords_numsaved') {
                   11210:                             alert('$intalert{passnum}');
                   11211:                         }
                   11212:                     }
1.370     raeburn  11213:                     field.value = '';
1.365     raeburn  11214:                 }
1.354     raeburn  11215:             }
                   11216:         }
                   11217:     }
                   11218:     return;
                   11219: }
                   11220: 
                   11221: ENDSCRIPT
                   11222:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  11223: }
                   11224: 
1.49      raeburn  11225: sub coursecategories_javascript {
                   11226:     my ($settings) = @_;
1.57      raeburn  11227:     my ($output,$jstext,$cathash);
1.49      raeburn  11228:     if (ref($settings) eq 'HASH') {
1.57      raeburn  11229:         $cathash = $settings->{'cats'};
                   11230:     }
                   11231:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  11232:         my (@cats,@jsarray,%idx);
1.57      raeburn  11233:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  11234:         if (@jsarray > 0) {
                   11235:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   11236:             for (my $i=0; $i<@jsarray; $i++) {
                   11237:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   11238:                     my $catstr = join('","',@{$jsarray[$i]});
                   11239:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   11240:                 }
                   11241:             }
                   11242:         }
                   11243:     } else {
                   11244:         $jstext  = '    var categories = Array(1);'."\n".
                   11245:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   11246:     }
1.237     bisitz   11247:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   11248:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  11249:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  11250:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   11251:     &js_escape(\$instcode_reserved);
                   11252:     &js_escape(\$communities_reserved);
1.272     raeburn  11253:     &js_escape(\$placement_reserved);
1.265     damieng  11254:     &js_escape(\$choose_again);
1.49      raeburn  11255:     $output = <<"ENDSCRIPT";
                   11256: <script type="text/javascript">
1.109     raeburn  11257: // <![CDATA[
1.49      raeburn  11258: function reorderCats(form,parent,item,idx) {
                   11259:     var changedVal;
                   11260: $jstext
                   11261:     var newpos = 'addcategory_pos';
                   11262:     if (parent == '') {
                   11263:         var has_instcode = 0;
                   11264:         var maxtop = categories[idx].length;
                   11265:         for (var j=0; j<maxtop; j++) {
                   11266:             if (categories[idx][j] == 'instcode::0') {
                   11267:                 has_instcode == 1;
                   11268:             }
                   11269:         }
                   11270:         if (has_instcode == 0) {
                   11271:             categories[idx][maxtop] = 'instcode_pos';
                   11272:         }
                   11273:     } else {
                   11274:         newpos += '_'+parent;
                   11275:     }
                   11276:     var maxh = 1 + categories[idx].length;
                   11277:     var current = new Array;
                   11278:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11279:     if (item == newpos) {
                   11280:         changedVal = newitemVal;
                   11281:     } else {
                   11282:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   11283:         current[newitemVal] = newpos;
                   11284:     }
                   11285:     for (var i=0; i<categories[idx].length; i++) {
                   11286:         var elementName = categories[idx][i];
                   11287:         if (elementName != item) {
                   11288:             if (form.elements[elementName]) {
                   11289:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11290:                 current[currVal] = elementName;
                   11291:             }
                   11292:         }
                   11293:     }
                   11294:     var oldVal;
                   11295:     for (var j=0; j<maxh; j++) {
                   11296:         if (current[j] == undefined) {
                   11297:             oldVal = j;
                   11298:         }
                   11299:     }
                   11300:     if (oldVal < changedVal) {
                   11301:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11302:            var elementName = current[k];
                   11303:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11304:         }
                   11305:     } else {
                   11306:         for (var k=changedVal; k<oldVal; k++) {
                   11307:             var elementName = current[k];
                   11308:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11309:         }
                   11310:     }
                   11311:     return;
                   11312: }
1.120     raeburn  11313: 
                   11314: function categoryCheck(form) {
                   11315:     if (form.elements['addcategory_name'].value == 'instcode') {
                   11316:         alert('$instcode_reserved\\n$choose_again');
                   11317:         return false;
                   11318:     }
                   11319:     if (form.elements['addcategory_name'].value == 'communities') {
                   11320:         alert('$communities_reserved\\n$choose_again');
                   11321:         return false;
                   11322:     }
1.272     raeburn  11323:     if (form.elements['addcategory_name'].value == 'placement') {
                   11324:         alert('$placement_reserved\\n$choose_again');
                   11325:         return false;
                   11326:     }
1.120     raeburn  11327:     return true;
                   11328: }
                   11329: 
1.109     raeburn  11330: // ]]>
1.49      raeburn  11331: </script>
                   11332: 
                   11333: ENDSCRIPT
                   11334:     return $output;
                   11335: }
                   11336: 
1.48      raeburn  11337: sub initialize_categories {
                   11338:     my ($itemcount) = @_;
1.120     raeburn  11339:     my ($datatable,$css_class,$chgstr);
1.380     raeburn  11340:     my %default_names = &Apache::lonlocal::texthash (
1.120     raeburn  11341:                       instcode    => 'Official courses (with institutional codes)',
                   11342:                       communities => 'Communities',
1.272     raeburn  11343:                       placement   => 'Placement Tests',
1.120     raeburn  11344:                         );
1.328     raeburn  11345:     my %selnum = (
                   11346:                    instcode    => '0',
                   11347:                    communities => '1',
                   11348:                    placement   => '2',
                   11349:                  );
                   11350:     my %selected;
1.272     raeburn  11351:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  11352:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327     raeburn  11353:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328     raeburn  11354:         map { $selected{$selnum{$_}} = '' } keys(%selnum);
                   11355:         $selected{$selnum{$default}} = ' selected="selected"';
1.120     raeburn  11356:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328     raeburn  11357:                      .'<select name="'.$default.'_pos"'.$chgstr.'>'
                   11358:                      .'<option value="0"'.$selected{'0'}.'>1</option>'
                   11359:                      .'<option value="1"'.$selected{'1'}.'>2</option>'
                   11360:                      .'<option value="2"'.$selected{'2'}.'>3</option>'
                   11361:                      .'<option value="3">4</option></select>&nbsp;'
1.120     raeburn  11362:                      .$default_names{$default}
                   11363:                      .'</span></td><td><span class="LC_nobreak">'
                   11364:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   11365:                      .&mt('Display').'</label>&nbsp;<label>'
                   11366:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  11367:                  .'</label></span></td></tr>';
1.120     raeburn  11368:         $itemcount ++;
                   11369:     }
1.48      raeburn  11370:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  11371:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  11372:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  11373:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   11374:                   .'<option value="0">1</option>'
                   11375:                   .'<option value="1">2</option>'
1.328     raeburn  11376:                   .'<option value="2">3</option>'
                   11377:                   .'<option value="3" selected="selected">4</option></select>&nbsp;'
1.327     raeburn  11378:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                   11379:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   11380:                   .'</td></tr>';
1.48      raeburn  11381:     return $datatable;
                   11382: }
                   11383: 
                   11384: sub build_category_rows {
1.49      raeburn  11385:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   11386:     my ($text,$name,$item,$chgstr);
1.48      raeburn  11387:     if (ref($cats) eq 'ARRAY') {
                   11388:         my $maxdepth = scalar(@{$cats});
                   11389:         if (ref($cats->[$depth]) eq 'HASH') {
                   11390:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   11391:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   11392:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  11393:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  11394:                 my ($idxnum,$parent_name,$parent_item);
                   11395:                 my $higher = $depth - 1;
                   11396:                 if ($higher == 0) {
                   11397:                     $parent_name = &escape($parent).'::'.$higher;
                   11398:                 } else {
                   11399:                     if (ref($path) eq 'ARRAY') {
                   11400:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11401:                     }
                   11402:                 }
                   11403:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  11404:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  11405:                     if ($j < $numchildren) {
1.48      raeburn  11406:                         $name = $cats->[$depth]{$parent}[$j];
                   11407:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  11408:                         $idxnum = $idx->{$item};
                   11409:                     } else {
                   11410:                         $name = $parent_name;
                   11411:                         $item = $parent_item;
1.48      raeburn  11412:                     }
1.49      raeburn  11413:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   11414:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  11415:                     for (my $i=0; $i<=$numchildren; $i++) {
                   11416:                         my $vpos = $i+1;
                   11417:                         my $selstr;
                   11418:                         if ($j == $i) {
                   11419:                             $selstr = ' selected="selected" ';
                   11420:                         }
                   11421:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   11422:                     }
                   11423:                     $text .= '</select>&nbsp;';
                   11424:                     if ($j < $numchildren) {
                   11425:                         my $deeper = $depth+1;
                   11426:                         $text .= $name.'&nbsp;'
                   11427:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   11428:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   11429:                         if(ref($path) eq 'ARRAY') {
                   11430:                             push(@{$path},$name);
1.49      raeburn  11431:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  11432:                             pop(@{$path});
                   11433:                         }
                   11434:                     } else {
1.330     raeburn  11435:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  11436:                         if ($j == $numchildren) {
                   11437:                             $text .= $name;
                   11438:                         } else {
                   11439:                             $text .= $item;
                   11440:                         }
                   11441:                         $text .= '" value="" />';
                   11442:                     }
                   11443:                     $text .= '</td></tr>';
                   11444:                 }
                   11445:                 $text .= '</table></td>';
                   11446:             } else {
                   11447:                 my $higher = $depth-1;
                   11448:                 if ($higher == 0) {
                   11449:                     $name = &escape($parent).'::'.$higher;
                   11450:                 } else {
                   11451:                     if (ref($path) eq 'ARRAY') {
                   11452:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11453:                     }
                   11454:                 }
                   11455:                 my $colspan;
                   11456:                 if ($parent ne 'instcode') {
                   11457:                     $colspan = $maxdepth - $depth - 1;
1.330     raeburn  11458:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  11459:                 }
                   11460:             }
                   11461:         }
                   11462:     }
                   11463:     return $text;
                   11464: }
                   11465: 
1.33      raeburn  11466: sub modifiable_userdata_row {
1.305     raeburn  11467:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357     raeburn  11468:         $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228     raeburn  11469:     my ($role,$rolename,$statustype);
                   11470:     $role = $item;
1.224     raeburn  11471:     if ($context eq 'cancreate') {
1.305     raeburn  11472:         if ($item =~ /^(emailusername)_(.+)$/) {
                   11473:             $role = $1;
                   11474:             $statustype = $2;
1.228     raeburn  11475:             if (ref($usertypes) eq 'HASH') {
                   11476:                 if ($usertypes->{$statustype}) {
                   11477:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   11478:                 } else {
                   11479:                     $rolename = &mt('Data provided by user');
                   11480:                 }
                   11481:             }
1.224     raeburn  11482:         }
                   11483:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  11484:         if (ref($usertypes) eq 'HASH') {
                   11485:             $rolename = $usertypes->{$role};
                   11486:         } else {
                   11487:             $rolename = $role;
                   11488:         }
1.325     raeburn  11489:     } elsif ($context eq 'lti') {
                   11490:         $rolename = &mt('Institutional data used (if available)');
1.357     raeburn  11491:     } elsif ($context eq 'privacy') {
                   11492:         $rolename = $itemdesc;
1.33      raeburn  11493:     } else {
1.63      raeburn  11494:         if ($role eq 'cr') {
                   11495:             $rolename = &mt('Custom role');
                   11496:         } else {
                   11497:             $rolename = &Apache::lonnet::plaintext($role);
                   11498:         }
1.33      raeburn  11499:     }
1.224     raeburn  11500:     my (@fields,%fieldtitles);
                   11501:     if (ref($fieldsref) eq 'ARRAY') {
                   11502:         @fields = @{$fieldsref};
                   11503:     } else {
                   11504:         @fields = ('lastname','firstname','middlename','generation',
                   11505:                    'permanentemail','id');
                   11506:     }
                   11507:     if ((ref($titlesref) eq 'HASH')) {
                   11508:         %fieldtitles = %{$titlesref};
                   11509:     } else {
                   11510:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   11511:     }
1.33      raeburn  11512:     my $output;
1.305     raeburn  11513:     my $css_class;
                   11514:     if ($rowcount%2) {
                   11515:         $css_class = 'LC_odd_row';
                   11516:     }
                   11517:     if ($customcss) {
                   11518:         $css_class .= " $customcss";
                   11519:     }
                   11520:     $css_class =~ s/^\s+//;
                   11521:     if ($css_class) {
                   11522:         $css_class = ' class="'.$css_class.'"';
                   11523:     }
                   11524:     if ($rowstyle) {
                   11525:         $css_class .= ' style="'.$rowstyle.'"';
                   11526:     }
                   11527:     if ($rowid) {
                   11528:         $rowid = ' id="'.$rowid.'"';
                   11529:     }
                   11530:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  11531:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   11532:               '<td class="LC_left_item" colspan="2"><table>';
                   11533:     my $rem;
                   11534:     my %checks;
1.325     raeburn  11535:     my %current;
1.33      raeburn  11536:     if (ref($settings) eq 'HASH') {
1.325     raeburn  11537:         my $hashref;
                   11538:         if ($context eq 'lti') {
                   11539:             if (ref($settings) eq 'HASH') {
                   11540:                 $hashref = $settings->{'instdata'};
                   11541:             }
1.357     raeburn  11542:         } elsif ($context eq 'privacy') {
                   11543:             my ($key,$inner) = split(/_/,$role);
                   11544:             if (ref($settings) eq 'HASH') {
                   11545:                 if (ref($settings->{$key}) eq 'HASH') {
                   11546:                     $hashref = $settings->{$key}->{$inner};
                   11547:                 }
                   11548:             }
1.325     raeburn  11549:         } elsif (ref($settings->{$context}) eq 'HASH') {
1.33      raeburn  11550:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325     raeburn  11551:                 $hashref = $settings->{'lti_instdata'};
                   11552:             }
                   11553:             if ($role eq 'emailusername') {
                   11554:                 if ($statustype) {
                   11555:                     if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   11556:                         $hashref = $settings->{$context}->{$role}->{$statustype};
1.228     raeburn  11557:                     }
1.325     raeburn  11558:                 }
                   11559:             }
                   11560:         }
                   11561:         if (ref($hashref) eq 'HASH') { 
                   11562:             foreach my $field (@fields) {
                   11563:                 if ($hashref->{$field}) {
                   11564:                     if ($role eq 'emailusername') {
                   11565:                         $checks{$field} = $hashref->{$field};
                   11566:                     } else {
                   11567:                         $checks{$field} = ' checked="checked" ';
1.33      raeburn  11568:                     }
                   11569:                 }
                   11570:             }
                   11571:         }
                   11572:     }
1.305     raeburn  11573:  
                   11574:     my $total = scalar(@fields);
                   11575:     for (my $i=0; $i<$total; $i++) {
                   11576:         $rem = $i%($numinrow);
1.33      raeburn  11577:         if ($rem == 0) {
                   11578:             if ($i > 0) {
                   11579:                 $output .= '</tr>';
                   11580:             }
                   11581:             $output .= '<tr>';
                   11582:         }
                   11583:         my $check = ' ';
1.228     raeburn  11584:         unless ($role eq 'emailusername') {
                   11585:             if (exists($checks{$fields[$i]})) {
1.354     raeburn  11586:                 $check = $checks{$fields[$i]};
1.357     raeburn  11587:             } elsif ($context eq 'privacy') {
                   11588:                 if ($role =~ /^priv_(domain|course)$/) {
                   11589:                     if (ref($settings) ne 'HASH') {
                   11590:                         $check = ' checked="checked" ';
                   11591:                     }
                   11592:                 } elsif ($role =~ /^priv_(author|community)$/) {
                   11593:                     if (ref($settings) ne 'HASH') {
                   11594:                         unless ($fields[$i] eq 'id') {
                   11595:                             $check = ' checked="checked" ';
                   11596:                         }
                   11597:                     }
                   11598:                 } elsif ($role =~ /^(unpriv|othdom)_/) {
                   11599:                     if (ref($settings) ne 'HASH') {
                   11600:                         if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                   11601:                             $check = ' checked="checked" ';
                   11602:                         }
                   11603:                     }
                   11604:                 }
1.325     raeburn  11605:             } elsif ($context ne 'lti') {
1.228     raeburn  11606:                 if ($role eq 'st') {
                   11607:                     if (ref($settings) ne 'HASH') {
                   11608:                         $check = ' checked="checked" '; 
                   11609:                     }
1.33      raeburn  11610:                 }
                   11611:             }
                   11612:         }
                   11613:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  11614:                    '<span class="LC_nobreak">';
1.325     raeburn  11615:         my $prefix = 'canmodify';
1.228     raeburn  11616:         if ($role eq 'emailusername') {
                   11617:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   11618:                 $checks{$fields[$i]} = 'omit';
                   11619:             }
                   11620:             foreach my $option ('required','optional','omit') {
                   11621:                 my $checked='';
                   11622:                 if ($checks{$fields[$i]} eq $option) {
                   11623:                     $checked='checked="checked" ';
                   11624:                 }
                   11625:                 $output .= '<label>'.
1.325     raeburn  11626:                            '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228     raeburn  11627:                            &mt($option).'</label>'.('&nbsp;' x2);
                   11628:             }
                   11629:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   11630:         } else {
1.325     raeburn  11631:             if ($context eq 'lti') {
                   11632:                 $prefix = 'lti';
1.357     raeburn  11633:             } elsif ($context eq 'privacy') {
                   11634:                 $prefix = 'privacy';
1.325     raeburn  11635:             }
1.228     raeburn  11636:             $output .= '<label>'.
1.325     raeburn  11637:                        '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228     raeburn  11638:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   11639:                        '</label>';
                   11640:         }
                   11641:         $output .= '</span></td>';
1.33      raeburn  11642:     }
1.305     raeburn  11643:     $rem = $total%$numinrow;
                   11644:     my $colsleft;
                   11645:     if ($rem) {
                   11646:         $colsleft = $numinrow - $rem;
                   11647:     }
                   11648:     if ($colsleft > 1) {
1.33      raeburn  11649:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   11650:                    '&nbsp;</td>';
                   11651:     } elsif ($colsleft == 1) {
                   11652:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   11653:     }
                   11654:     $output .= '</tr></table></td></tr>';
                   11655:     return $output;
                   11656: }
1.28      raeburn  11657: 
1.93      raeburn  11658: sub insttypes_row {
1.305     raeburn  11659:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   11660:         $customcss,$rowstyle) = @_;
1.93      raeburn  11661:     my %lt = &Apache::lonlocal::texthash (
                   11662:                       cansearch => 'Users allowed to search',
                   11663:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  11664:                       lockablenames => 'User preference to lock name',
1.305     raeburn  11665:                       selfassign    => 'Self-reportable affiliations',
1.315     raeburn  11666:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  11667:              );
                   11668:     my $showdom;
                   11669:     if ($context eq 'cansearch') {
                   11670:         $showdom = ' ('.$dom.')';
                   11671:     }
1.165     raeburn  11672:     my $class = 'LC_left_item';
                   11673:     if ($context eq 'statustocreate') {
                   11674:         $class = 'LC_right_item';
                   11675:     }
1.305     raeburn  11676:     my $css_class;
                   11677:     if ($$rowtotal%2) {
                   11678:         $css_class = 'LC_odd_row';
                   11679:     }
                   11680:     if ($customcss) {
                   11681:         $css_class .= ' '.$customcss;
                   11682:     }
                   11683:     $css_class =~ s/^\s+//;
                   11684:     if ($css_class) {
                   11685:         $css_class = ' class="'.$css_class.'"';
                   11686:     }
                   11687:     if ($rowstyle) {
                   11688:         $css_class .= ' style="'.$rowstyle.'"';
                   11689:     }
                   11690:     if ($onclick) {
                   11691:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  11692:     }
                   11693:     my $output = '<tr'.$css_class.'>'.
                   11694:                  '<td>'.$lt{$context}.$showdom.
                   11695:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  11696:     my $rem;
                   11697:     if (ref($types) eq 'ARRAY') {
                   11698:         for (my $i=0; $i<@{$types}; $i++) {
                   11699:             if (defined($usertypes->{$types->[$i]})) {
                   11700:                 my $rem = $i%($numinrow);
                   11701:                 if ($rem == 0) {
                   11702:                     if ($i > 0) {
                   11703:                         $output .= '</tr>';
                   11704:                     }
                   11705:                     $output .= '<tr>';
1.23      raeburn  11706:                 }
1.26      raeburn  11707:                 my $check = ' ';
1.99      raeburn  11708:                 if (ref($settings) eq 'HASH') {
                   11709:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   11710:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   11711:                             $check = ' checked="checked" ';
                   11712:                         }
1.315     raeburn  11713:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   11714:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   11715:                             $check = ' checked="checked" ';
                   11716:                         }
1.99      raeburn  11717:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  11718:                         $check = ' checked="checked" ';
                   11719:                     }
1.23      raeburn  11720:                 }
1.26      raeburn  11721:                 $output .= '<td class="LC_left_item">'.
                   11722:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  11723:                            '<input type="checkbox" name="'.$context.'" '.
1.305     raeburn  11724:                            'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26      raeburn  11725:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  11726:             }
                   11727:         }
1.26      raeburn  11728:         $rem = @{$types}%($numinrow);
1.23      raeburn  11729:     }
                   11730:     my $colsleft = $numinrow - $rem;
1.315     raeburn  11731:     if ($context eq 'overrides') {
                   11732:         if ($colsleft > 1) {
                   11733:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   11734:         } else {
                   11735:             $output .= '<td class="LC_left_item">';
                   11736:         }
                   11737:         $output .= '&nbsp;';  
1.23      raeburn  11738:     } else {
1.334     raeburn  11739:         if ($rem == 0) {
1.315     raeburn  11740:             $output .= '<tr>';
                   11741:         }
                   11742:         if ($colsleft > 1) {
                   11743:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   11744:         } else {
                   11745:             $output .= '<td class="LC_left_item">';
                   11746:         }
                   11747:         my $defcheck = ' ';
                   11748:         if (ref($settings) eq 'HASH') {  
                   11749:             if (ref($settings->{$context}) eq 'ARRAY') {
                   11750:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   11751:                     $defcheck = ' checked="checked" ';
                   11752:                 }
                   11753:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  11754:                 $defcheck = ' checked="checked" ';
                   11755:             }
1.26      raeburn  11756:         }
1.315     raeburn  11757:         $output .= '<span class="LC_nobreak"><label>'.
                   11758:                    '<input type="checkbox" name="'.$context.'" '.
                   11759:                    'value="default"'.$defcheck.$onclick.' />'.
                   11760:                    $othertitle.'</label></span>';
1.23      raeburn  11761:     }
1.315     raeburn  11762:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  11763:     return $output;
1.23      raeburn  11764: }
                   11765: 
                   11766: sub sorted_searchtitles {
                   11767:     my %searchtitles = &Apache::lonlocal::texthash(
                   11768:                          'uname' => 'username',
                   11769:                          'lastname' => 'last name',
                   11770:                          'lastfirst' => 'last name, first name',
                   11771:                      );
                   11772:     my @titleorder = ('uname','lastname','lastfirst');
                   11773:     return (\%searchtitles,\@titleorder);
                   11774: }
                   11775: 
1.25      raeburn  11776: sub sorted_searchtypes {
                   11777:     my %srchtypes_desc = (
                   11778:                            exact    => 'is exact match',
                   11779:                            contains => 'contains ..',
                   11780:                            begins   => 'begins with ..',
                   11781:                          );
                   11782:     my @srchtypeorder = ('exact','begins','contains');
                   11783:     return (\%srchtypes_desc,\@srchtypeorder);
                   11784: }
                   11785: 
1.3       raeburn  11786: sub usertype_update_row {
                   11787:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   11788:     my $datatable;
                   11789:     my $numinrow = 4;
                   11790:     foreach my $type (@{$types}) {
                   11791:         if (defined($usertypes->{$type})) {
                   11792:             $$rownums ++;
                   11793:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   11794:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   11795:                           '</td><td class="LC_left_item"><table>';
                   11796:             for (my $i=0; $i<@{$fields}; $i++) {
                   11797:                 my $rem = $i%($numinrow);
                   11798:                 if ($rem == 0) {
                   11799:                     if ($i > 0) {
                   11800:                         $datatable .= '</tr>';
                   11801:                     }
                   11802:                     $datatable .= '<tr>';
                   11803:                 }
                   11804:                 my $check = ' ';
1.39      raeburn  11805:                 if (ref($settings) eq 'HASH') {
                   11806:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   11807:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   11808:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   11809:                                 $check = ' checked="checked" ';
                   11810:                             }
1.3       raeburn  11811:                         }
                   11812:                     }
                   11813:                 }
                   11814: 
                   11815:                 if ($i == @{$fields}-1) {
                   11816:                     my $colsleft = $numinrow - $rem;
                   11817:                     if ($colsleft > 1) {
                   11818:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   11819:                     } else {
                   11820:                         $datatable .= '<td>';
                   11821:                     }
                   11822:                 } else {
                   11823:                     $datatable .= '<td>';
                   11824:                 }
1.8       raeburn  11825:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   11826:                               '<input type="checkbox" name="updateable_'.$type.
                   11827:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   11828:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  11829:             }
                   11830:             $datatable .= '</tr></table></td></tr>';
                   11831:         }
                   11832:     }
                   11833:     return $datatable;
1.1       raeburn  11834: }
                   11835: 
                   11836: sub modify_login {
1.205     raeburn  11837:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  11838:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386     raeburn  11839:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
                   11840:         %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168     raeburn  11841:     %title = ( coursecatalog => 'Display course catalog',
                   11842:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  11843:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  11844:                newuser => 'Link for visitors to create a user account',
1.386     raeburn  11845:                loginheader => 'Log-in box header',
                   11846:                saml => 'Dual SSO and non-SSO login');
1.168     raeburn  11847:     @offon = ('off','on');
1.112     raeburn  11848:     if (ref($domconfig{login}) eq 'HASH') {
                   11849:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   11850:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   11851:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   11852:             }
                   11853:         }
1.386     raeburn  11854:         if (ref($domconfig{login}{'saml'}) eq 'HASH') {
                   11855:             foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
                   11856:                 if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
                   11857:                     $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
                   11858:                     $saml{$lonhost} = 1;
                   11859:                     $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
                   11860:                     $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
                   11861:                     $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                   11862:                     $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                   11863:                     $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
                   11864:                     $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                   11865:                 }
                   11866:             }
                   11867:         }
1.112     raeburn  11868:     }
1.9       raeburn  11869:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   11870:                                            \%domconfig,\%loginhash);
1.188     raeburn  11871:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  11872:     foreach my $item (@toggles) {
                   11873:         $loginhash{login}{$item} = $env{'form.'.$item};
                   11874:     }
1.41      raeburn  11875:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  11876:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   11877:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   11878:                                          \%loginhash);
                   11879:     }
1.110     raeburn  11880: 
1.149     raeburn  11881:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  11882:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  11883:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  11884:     if (keys(%servers) > 1) {
                   11885:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  11886:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   11887:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   11888:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   11889:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   11890:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   11891:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11892:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   11893:                         $changes{'loginvia'}{$lonhost} = 1;
                   11894:                     } else {
                   11895:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   11896:                         $changes{'loginvia'}{$lonhost} = 1;
                   11897:                     }
                   11898:                 } else {
                   11899:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11900:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   11901:                         $changes{'loginvia'}{$lonhost} = 1;
                   11902:                     }
                   11903:                 }
                   11904:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   11905:                     foreach my $item (@loginvia_attribs) {
                   11906:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   11907:                     }
                   11908:                 } else {
                   11909:                     foreach my $item (@loginvia_attribs) {
                   11910:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   11911:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   11912:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   11913:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   11914:                                 $new = '/';
                   11915:                             }
                   11916:                         }
                   11917:                         if (($item eq 'custompath') && 
                   11918:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   11919:                             $new = '';
                   11920:                         }
                   11921:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   11922:                             $changes{'loginvia'}{$lonhost} = 1;
                   11923:                         }
                   11924:                         if ($item eq 'exempt') {
1.256     raeburn  11925:                             $new = &check_exempt_addresses($new);
1.128     raeburn  11926:                         }
                   11927:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   11928:                     }
                   11929:                 }
1.112     raeburn  11930:             } else {
1.128     raeburn  11931:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11932:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  11933:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  11934:                     foreach my $item (@loginvia_attribs) {
                   11935:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   11936:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   11937:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   11938:                                 $new = '/';
                   11939:                             }
                   11940:                         }
                   11941:                         if (($item eq 'custompath') && 
                   11942:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   11943:                             $new = '';
                   11944:                         }
                   11945:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   11946:                     }
1.110     raeburn  11947:                 }
                   11948:             }
                   11949:         }
                   11950:     }
1.119     raeburn  11951: 
1.168     raeburn  11952:     my $servadm = $r->dir_config('lonAdmEMail');
                   11953:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   11954:     if (ref($domconfig{'login'}) eq 'HASH') {
                   11955:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   11956:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   11957:                 if ($lang eq 'nolang') {
                   11958:                     push(@currlangs,$lang);
                   11959:                 } elsif (defined($langchoices{$lang})) {
                   11960:                     push(@currlangs,$lang);
                   11961:                 } else {
                   11962:                     next;
                   11963:                 }
                   11964:             }
                   11965:         }
                   11966:     }
                   11967:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   11968:     if (@currlangs > 0) {
                   11969:         foreach my $lang (@currlangs) {
                   11970:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   11971:                 $changes{'helpurl'}{$lang} = 1;
                   11972:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   11973:                 $changes{'helpurl'}{$lang} = 1;
                   11974:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   11975:                 push(@newlangs,$lang);
                   11976:             } else {
                   11977:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   11978:             }
                   11979:         }
                   11980:     }
                   11981:     unless (grep(/^nolang$/,@currlangs)) {
                   11982:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   11983:             $changes{'helpurl'}{'nolang'} = 1;
                   11984:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   11985:             push(@newlangs,'nolang');
                   11986:         }
                   11987:     }
                   11988:     if ($env{'form.loginhelpurl_add_lang'}) {
                   11989:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   11990:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   11991:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   11992:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   11993:         }
                   11994:     }
                   11995:     if ((@newlangs > 0) || ($addedfile)) {
                   11996:         my $error;
                   11997:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   11998:         if ($configuserok eq 'ok') {
                   11999:             if ($switchserver) {
                   12000:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   12001:             } elsif ($author_ok eq 'ok') {
                   12002:                 my @allnew = @newlangs;
                   12003:                 if ($addedfile ne '') {
                   12004:                     push(@allnew,$addedfile);
                   12005:                 }
                   12006:                 foreach my $lang (@allnew) {
                   12007:                     my $formelem = 'loginhelpurl_'.$lang;
                   12008:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   12009:                         $formelem = 'loginhelpurl_add_file';
                   12010:                     }
                   12011:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12012:                                                                "help/$lang",'','',$newfile{$lang});
                   12013:                     if ($result eq 'ok') {
                   12014:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   12015:                         $changes{'helpurl'}{$lang} = 1;
                   12016:                     } else {
                   12017:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   12018:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  12019:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  12020:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   12021:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   12022:                         }
                   12023:                     }
                   12024:                 }
                   12025:             } else {
                   12026:                 $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);
                   12027:             }
                   12028:         } else {
                   12029:             $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);
                   12030:         }
                   12031:         if ($error) {
                   12032:             &Apache::lonnet::logthis($error);
                   12033:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12034:         }
                   12035:     }
1.256     raeburn  12036: 
                   12037:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   12038:     if (ref($domconfig{'login'}) eq 'HASH') {
                   12039:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   12040:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   12041:                 if ($domservers{$lonhost}) {
                   12042:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12043:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  12044:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  12045:                     }
                   12046:                 }
                   12047:             }
                   12048:         }
                   12049:     }
                   12050:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   12051:     foreach my $lonhost (sort(keys(%domservers))) {
                   12052:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12053:             $changes{'headtag'}{$lonhost} = 1;
                   12054:         } else {
                   12055:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   12056:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   12057:             }
                   12058:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   12059:                 push(@newhosts,$lonhost);
                   12060:             } elsif ($currheadtagurls{$lonhost}) {
                   12061:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   12062:                 if ($currexempt{$lonhost}) {
1.289     raeburn  12063:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  12064:                         $changes{'headtag'}{$lonhost} = 1;
                   12065:                     }
                   12066:                 } elsif ($possexempt{$lonhost}) {
                   12067:                     $changes{'headtag'}{$lonhost} = 1;
                   12068:                 }
                   12069:                 if ($possexempt{$lonhost}) {
                   12070:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12071:                 }
                   12072:             }
                   12073:         }
                   12074:     }
                   12075:     if (@newhosts) {
                   12076:         my $error;
                   12077:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12078:         if ($configuserok eq 'ok') {
                   12079:             if ($switchserver) {
                   12080:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   12081:             } elsif ($author_ok eq 'ok') {
                   12082:                 foreach my $lonhost (@newhosts) {
                   12083:                     my $formelem = 'loginheadtag_'.$lonhost;
                   12084:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12085:                                                                           "login/headtag/$lonhost",'','',
                   12086:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   12087:                     if ($result eq 'ok') {
                   12088:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   12089:                         $changes{'headtag'}{$lonhost} = 1;
                   12090:                         if ($possexempt{$lonhost}) {
                   12091:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12092:                         }
                   12093:                     } else {
                   12094:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   12095:                                            $newheadtagurls{$lonhost},$result);
                   12096:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12097:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   12098:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   12099:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   12100:                         }
                   12101:                     }
                   12102:                 }
                   12103:             } else {
                   12104:                 $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);
                   12105:             }
                   12106:         } else {
                   12107:             $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);
                   12108:         }
                   12109:         if ($error) {
                   12110:             &Apache::lonnet::logthis($error);
                   12111:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12112:         }
                   12113:     }
1.386     raeburn  12114:     my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
                   12115:     my @newsamlimgs;
                   12116:     foreach my $lonhost (keys(%domservers)) {
                   12117:         if ($env{'form.saml_'.$lonhost}) {
                   12118:             if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                   12119:                 push(@newsamlimgs,$lonhost);
                   12120:             }
                   12121:             foreach my $item ('text','alt','url','title','notsso') {
                   12122:                 $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
                   12123:             }
                   12124:             if ($saml{$lonhost}) {
                   12125:                 if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
                   12126: #FIXME Need to obsolete published image
                   12127:                     delete($currsaml{$lonhost}{'img'});
                   12128:                     $changes{'saml'}{$lonhost} = 1;
                   12129:                 }
                   12130:                 if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
                   12131:                     $changes{'saml'}{$lonhost} = 1;
                   12132:                 }
                   12133:                 if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
                   12134:                     $changes{'saml'}{$lonhost} = 1;
                   12135:                 }
                   12136:                 if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
                   12137:                     $changes{'saml'}{$lonhost} = 1;
                   12138:                 }
                   12139:                 if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
                   12140:                     $changes{'saml'}{$lonhost} = 1;
                   12141:                 }
                   12142:                 if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
                   12143:                     $changes{'saml'}{$lonhost} = 1;
                   12144:                 }
                   12145:             } else {
                   12146:                 $changes{'saml'}{$lonhost} = 1;
                   12147:             }
                   12148:             foreach my $item ('text','alt','url','title','notsso') {
                   12149:                 $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
                   12150:             }
                   12151:         } else {
1.389     raeburn  12152:             if ($saml{$lonhost}) {  
                   12153:                 $changes{'saml'}{$lonhost} = 1;
                   12154:                 delete($currsaml{$lonhost});
                   12155:             }
1.386     raeburn  12156:         }
                   12157:     }
                   12158:     foreach my $posshost (keys(%currsaml)) {
                   12159:         unless (exists($domservers{$posshost})) { 
                   12160:             delete($currsaml{$posshost}); 
                   12161:         }
                   12162:     }
                   12163:     %{$loginhash{'login'}{'saml'}} = %currsaml;
                   12164:     if (@newsamlimgs) {
                   12165:         my $error;
                   12166:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12167:         if ($configuserok eq 'ok') {
                   12168:             if ($switchserver) {
                   12169:                 $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
                   12170:             } elsif ($author_ok eq 'ok') {
                   12171:                 foreach my $lonhost (@newsamlimgs) {
                   12172:                     my $formelem = 'saml_img_'.$lonhost;
                   12173:                     my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12174:                                                         "login/saml/$lonhost",'','',
                   12175:                                                         $env{'form.saml_img_'.$lonhost.'.filename'});
                   12176:                     if ($result eq 'ok') {
                   12177:                         $currsaml{$lonhost}{'img'} = $imgurl;
                   12178:                         $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
                   12179:                         $changes{'saml'}{$lonhost} = 1;
                   12180:                     } else {
                   12181:                         my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
                   12182:                                            $lonhost,$result);
                   12183:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12184:                     }
                   12185:                 }
                   12186:             } else {
                   12187:                 $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);
                   12188:             }
                   12189:         } else {
                   12190:             $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);
                   12191:         }
                   12192:         if ($error) {
                   12193:             &Apache::lonnet::logthis($error);
                   12194:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12195:         }
                   12196:     }
1.169     raeburn  12197:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  12198: 
                   12199:     my $defaulthelpfile = '/adm/loginproblems.html';
                   12200:     my $defaulttext = &mt('Default in use');
                   12201: 
1.1       raeburn  12202:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   12203:                                              $dom);
                   12204:     if ($putresult eq 'ok') {
1.188     raeburn  12205:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  12206:         my %defaultchecked = (
                   12207:                     'coursecatalog' => 'on',
1.188     raeburn  12208:                     'helpdesk'      => 'on',
1.42      raeburn  12209:                     'adminmail'     => 'off',
1.43      raeburn  12210:                     'newuser'       => 'off',
1.42      raeburn  12211:         );
1.55      raeburn  12212:         if (ref($domconfig{'login'}) eq 'HASH') {
                   12213:             foreach my $item (@toggles) {
                   12214:                 if ($defaultchecked{$item} eq 'on') { 
                   12215:                     if (($domconfig{'login'}{$item} eq '0') &&
                   12216:                         ($env{'form.'.$item} eq '1')) {
                   12217:                         $changes{$item} = 1;
                   12218:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12219:                               $domconfig{'login'}{$item} eq '1') &&
                   12220:                              ($env{'form.'.$item} eq '0')) {
                   12221:                         $changes{$item} = 1;
                   12222:                     }
                   12223:                 } elsif ($defaultchecked{$item} eq 'off') {
                   12224:                     if (($domconfig{'login'}{$item} eq '1') &&
                   12225:                         ($env{'form.'.$item} eq '0')) {
                   12226:                         $changes{$item} = 1;
                   12227:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12228:                               $domconfig{'login'}{$item} eq '0') &&
                   12229:                              ($env{'form.'.$item} eq '1')) {
                   12230:                         $changes{$item} = 1;
                   12231:                     }
1.42      raeburn  12232:                 }
                   12233:             }
1.41      raeburn  12234:         }
1.6       raeburn  12235:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  12236:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386     raeburn  12237:             if (exists($changes{'saml'})) {
                   12238:                 my $hostid_in_use;
                   12239:                 my @hosts = &Apache::lonnet::current_machine_ids();
                   12240:                 if (@hosts > 1) {
                   12241:                     foreach my $hostid (@hosts) {
                   12242:                         if (&Apache::lonnet::host_domain($hostid) eq $dom) {
                   12243:                             $hostid_in_use = $hostid;
                   12244:                             last;
                   12245:                         }
                   12246:                     }
                   12247:                 } else {
                   12248:                     $hostid_in_use = $r->dir_config('lonHostID');
                   12249:                 }
                   12250:                 if (($hostid_in_use) &&
                   12251:                     (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387     raeburn  12252:                     &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386     raeburn  12253:                 }
                   12254:                 if (ref($lastactref) eq 'HASH') {
                   12255:                     if (ref($changes{'saml'}) eq 'HASH') {
                   12256:                         my %updates;
                   12257:                         map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
                   12258:                         $lastactref->{'samllanding'} = \%updates;
                   12259:                     }
                   12260:                 }
                   12261:             }
1.212     raeburn  12262:             if (ref($lastactref) eq 'HASH') {
                   12263:                 $lastactref->{'domainconfig'} = 1;
                   12264:             }
1.1       raeburn  12265:             $resulttext = &mt('Changes made:').'<ul>';
                   12266:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   12267:                 if ($item eq 'loginvia') {
1.112     raeburn  12268:                     if (ref($changes{$item}) eq 'HASH') {
                   12269:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   12270:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  12271:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   12272:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   12273:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   12274:                                     $protocol = 'http' if ($protocol ne 'https');
                   12275:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   12276: 
                   12277:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   12278:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   12279:                                     } else {
                   12280:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   12281:                                     }
                   12282:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   12283:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   12284:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   12285:                                     }
                   12286:                                     $resulttext .= '</li>';
                   12287:                                 } else {
                   12288:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   12289:                                 }
1.112     raeburn  12290:                             } else {
1.128     raeburn  12291:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  12292:                             }
                   12293:                         }
1.128     raeburn  12294:                         $resulttext .= '</ul></li>';
1.112     raeburn  12295:                     }
1.168     raeburn  12296:                 } elsif ($item eq 'helpurl') {
                   12297:                     if (ref($changes{$item}) eq 'HASH') {
                   12298:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   12299:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   12300:                                 my ($chg,$link);
                   12301:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   12302:                                 if ($lang eq 'nolang') {
                   12303:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   12304:                                 } else {
                   12305:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   12306:                                 }
                   12307:                                 $resulttext .= '<li>'.$chg.'</li>';
                   12308:                             } else {
                   12309:                                 my $chg;
                   12310:                                 if ($lang eq 'nolang') {
                   12311:                                     $chg = &mt('custom log-in help file for no preferred language');
                   12312:                                 } else {
                   12313:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   12314:                                 }
                   12315:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   12316:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   12317:                                                       '?inhibitmenu=yes',$chg,600,500).
                   12318:                                                '</li>';
                   12319:                             }
                   12320:                         }
                   12321:                     }
1.256     raeburn  12322:                 } elsif ($item eq 'headtag') {
                   12323:                     if (ref($changes{$item}) eq 'HASH') {
                   12324:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12325:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12326:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   12327:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12328:                                 $resulttext .= '<li><a href="'.
                   12329:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   12330:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   12331:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   12332:                                 if ($possexempt{$lonhost}) {
                   12333:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   12334:                                 } else {
                   12335:                                     $resulttext .= &mt('included for any client IP');
                   12336:                                 }
                   12337:                                 $resulttext .= '</li>';
                   12338:                             }
                   12339:                         }
                   12340:                     }
1.386     raeburn  12341:                 } elsif ($item eq 'saml') {
                   12342:                     if (ref($changes{$item}) eq 'HASH') {
                   12343:                         my %notlt = (
                   12344:                                        text   => 'Text for log-in by SSO',
                   12345:                                        img    => 'SSO button image',
                   12346:                                        alt    => 'Alt text for button image',
                   12347:                                        url    => 'SSO URL',
                   12348:                                        title  => 'Tooltip for SSO link',
                   12349:                                        notsso => 'Text for non-SSO log-in',
                   12350:                                     );
                   12351:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12352:                             if (ref($currsaml{$lonhost}) eq 'HASH') {
                   12353:                                 $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
                   12354:                                                '<ul>';
                   12355:                                 foreach my $key ('text','img','alt','url','title','notsso') {
                   12356:                                     if ($currsaml{$lonhost}{$key} eq '') {
                   12357:                                         $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
                   12358:                                     } else {
                   12359:                                         my $value = "'$currsaml{$lonhost}{$key}'";
                   12360:                                         if ($key eq 'img') {
                   12361:                                             $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
                   12362:                                         }
                   12363:                                         $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                   12364:                                                                   $value).'</li>';
                   12365:                                     }
                   12366:                                 }
                   12367:                                 $resulttext .= '</ul></li>';
                   12368:                             } else {
                   12369:                                 $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
                   12370:                             }
                   12371:                         }
                   12372:                     }
1.169     raeburn  12373:                 } elsif ($item eq 'captcha') {
                   12374:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  12375:                         my $chgtxt;
1.169     raeburn  12376:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   12377:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   12378:                         } else {
                   12379:                             my %captchas = &captcha_phrases();
                   12380:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   12381:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   12382:                             } else {
                   12383:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   12384:                             }
                   12385:                         }
                   12386:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12387:                     }
                   12388:                 } elsif ($item eq 'recaptchakeys') {
                   12389:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12390:                         my ($privkey,$pubkey);
                   12391:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   12392:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   12393:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   12394:                         }
                   12395:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   12396:                         if (!$pubkey) {
                   12397:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   12398:                         } else {
                   12399:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   12400:                         }
                   12401:                         if (!$privkey) {
                   12402:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   12403:                         } else {
1.251     raeburn  12404:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  12405:                         }
                   12406:                         $chgtxt .= '</ul>';
                   12407:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12408:                     }
1.269     raeburn  12409:                 } elsif ($item eq 'recaptchaversion') {
                   12410:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12411:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  12412:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  12413:                                            '</li>';
                   12414:                         }
                   12415:                     }
1.41      raeburn  12416:                 } else {
                   12417:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   12418:                 }
1.1       raeburn  12419:             }
1.6       raeburn  12420:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  12421:         } else {
                   12422:             $resulttext = &mt('No changes made to log-in page settings');
                   12423:         }
                   12424:     } else {
1.11      albertel 12425:         $resulttext = '<span class="LC_error">'.
                   12426: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  12427:     }
1.6       raeburn  12428:     if ($errors) {
1.9       raeburn  12429:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  12430:                        $errors.'</ul>';
                   12431:     }
                   12432:     return $resulttext;
                   12433: }
                   12434: 
1.256     raeburn  12435: sub check_exempt_addresses {
                   12436:     my ($iplist) = @_;
                   12437:     $iplist =~ s/^\s+//;
                   12438:     $iplist =~ s/\s+$//;
                   12439:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   12440:     my (@okips,$new);
                   12441:     foreach my $ip (@poss_ips) {
                   12442:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   12443:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   12444:                 push(@okips,$ip);
                   12445:             }
                   12446:         }
                   12447:     }
                   12448:     if (@okips > 0) {
                   12449:         $new = join(',',@okips);
                   12450:     } else {
                   12451:         $new = '';
                   12452:     }
                   12453:     return $new;
                   12454: }
                   12455: 
1.6       raeburn  12456: sub color_font_choices {
                   12457:     my %choices =
                   12458:         &Apache::lonlocal::texthash (
                   12459:             img => "Header",
                   12460:             bgs => "Background colors",
                   12461:             links => "Link colors",
1.55      raeburn  12462:             images => "Images",
1.6       raeburn  12463:             font => "Font color",
1.201     raeburn  12464:             fontmenu => "Font menu",
1.76      raeburn  12465:             pgbg => "Page",
1.6       raeburn  12466:             tabbg => "Header",
                   12467:             sidebg => "Border",
                   12468:             link => "Link",
                   12469:             alink => "Active link",
                   12470:             vlink => "Visited link",
                   12471:         );
                   12472:     return %choices;
                   12473: }
                   12474: 
1.394     raeburn  12475: sub modify_ipaccess {
                   12476:     my ($dom,$lastactref,%domconfig) = @_;
                   12477:     my (@allpos,%changes,%confhash,$errors,$resulttext);
                   12478:     my (@items,%deletions,%itemids,@warnings);
                   12479:     my ($typeorder,$types) = &commblocktype_text();
                   12480:     if ($env{'form.ipaccess_add'}) {
                   12481:         my $name = $env{'form.ipaccess_name_add'};
                   12482:         my ($newid,$error) = &get_ipaccess_id($dom,$name);
                   12483:         if ($newid) {
                   12484:             $itemids{'add'} = $newid;
                   12485:             push(@items,'add');
                   12486:             $changes{$newid} = 1;
                   12487:         } else {
                   12488:             $error = &mt('Failed to acquire unique ID for new IP access control item');
                   12489:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12490:         }
                   12491:     }
                   12492:     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   12493:         my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
                   12494:         if (@todelete) {
                   12495:             map { $deletions{$_} = 1; } @todelete;
                   12496:         }
                   12497:         my $maxnum = $env{'form.ipaccess_maxnum'};
                   12498:         for (my $i=0; $i<$maxnum; $i++) {
                   12499:             my $itemid = $env{'form.ipaccess_id_'.$i};
                   12500:             $itemid =~ s/\D+//g;
                   12501:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12502:                 if ($deletions{$itemid}) {
                   12503:                     $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
                   12504:                 } else {
                   12505:                     push(@items,$i);
                   12506:                     $itemids{$i} = $itemid;
                   12507:                 }
                   12508:             }
                   12509:         }
                   12510:     }
                   12511:     foreach my $idx (@items) {
                   12512:         my $itemid = $itemids{$idx};
                   12513:         next unless ($itemid);
                   12514:         my %current;
                   12515:         unless ($idx eq 'add') {
                   12516:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12517:                 %current = %{$domconfig{'ipaccess'}{$itemid}};
                   12518:             }
                   12519:         }
                   12520:         my $position = $env{'form.ipaccess_pos_'.$itemid};
                   12521:         $position =~ s/\D+//g;
                   12522:         if ($position ne '') {
                   12523:             $allpos[$position] = $itemid;
                   12524:         }
                   12525:         my $name = $env{'form.ipaccess_name_'.$idx};
                   12526:         $name =~ s/^\s+|\s+$//g;
                   12527:         $confhash{$itemid}{'name'} = $name;
                   12528:         my $possrange = $env{'form.ipaccess_range_'.$idx};
                   12529:         $possrange =~ s/^\s+|\s+$//g;
                   12530:         unless ($possrange eq '') {
                   12531:             $possrange =~ s/[\r\n]+/\s/g;
                   12532:             $possrange =~ s/\s*-\s*/-/g;
                   12533:             $possrange =~ s/\s+/,/g;
                   12534:             $possrange =~ s/,+/,/g;
                   12535:             if ($possrange ne '') {
                   12536:                 my (@ok,$count);
                   12537:                 $count = 0; 
                   12538:                 foreach my $poss (split(/\,/,$possrange)) {
                   12539:                     $count ++;
                   12540:                     $poss = &validate_ip_pattern($poss);
                   12541:                     if ($poss ne '') {
                   12542:                         push(@ok,$poss);
                   12543:                     }
                   12544:                 }
                   12545:                 my $diff = $count - scalar(@ok);
                   12546:                 if ($diff) {
                   12547:                     $errors .= '<li><span class="LC_error">'.
                   12548:                                &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
                   12549:                                    $diff,$name).
                   12550:                                '</span></li>';
                   12551:                 }
                   12552:                 if (@ok) {
                   12553:                     my @cidr_list;
                   12554:                     foreach my $item (@ok) {
                   12555:                         @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   12556:                     }
                   12557:                     $confhash{$itemid}{'ip'} = join(',',@cidr_list);
                   12558:                 }
                   12559:             }
                   12560:         }
                   12561:         foreach my $field ('name','ip') {
                   12562:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   12563:                 if ($current{$field} ne $confhash{$itemid}{$field}) {
                   12564:                     $changes{$itemid} = 1;
                   12565:                     last;
                   12566:                 }
                   12567:             }
                   12568:         }
                   12569:         $confhash{$itemid}{'commblocks'} = {};
                   12570:          
                   12571:         my %commblocks;
                   12572:         map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);  
                   12573:         foreach my $type (@{$typeorder}) {
                   12574:             if ($commblocks{$type}) {
                   12575:                 $confhash{$itemid}{'commblocks'}{$type} = 'on';
                   12576:             }
                   12577:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   12578:                 if (ref($current{'commblocks'}) eq 'HASH') {
                   12579:                     if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
                   12580:                         $changes{$itemid} = 1;
                   12581:                     }
                   12582:                 } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
                   12583:                     $changes{$itemid} = 1;
                   12584:                 }
                   12585:             }
                   12586:         }
                   12587:         $confhash{$itemid}{'courses'} = {};
                   12588:         my %crsdeletions;
                   12589:         my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
                   12590:         if (@delcrs) {
                   12591:             map { $crsdeletions{$_} = 1; } @delcrs;
                   12592:         }
                   12593:         if (ref($current{'courses'}) eq 'HASH') {
                   12594:             foreach my $cid (sort(keys(%{$current{'courses'}}))) {
                   12595:                 if ($crsdeletions{$cid}) {
                   12596:                     $changes{$itemid} = 1;
                   12597:                 } else {
                   12598:                     $confhash{$itemid}{'courses'}{$cid} = 1;
                   12599:                 }
                   12600:             }
                   12601:         }
                   12602:         $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
                   12603:         $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
                   12604:         if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) && 
                   12605:             ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
                   12606:             if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
                   12607:                                             $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
                   12608:                 $errors .= '<li><span class="LC_error">'.
                   12609:                            &mt('Invalid courseID [_1] omitted from list of allowed courses',
                   12610:                                $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
                   12611:                            '</span></li>';
                   12612:             } else {
                   12613:                 $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
                   12614:                 $changes{$itemid} = 1;
                   12615:             }
                   12616:         }
                   12617:     }
                   12618:     if (@allpos > 0) {
                   12619:         my $idx = 0;
                   12620:         foreach my $itemid (@allpos) {
                   12621:             if ($itemid ne '') {
                   12622:                 $confhash{$itemid}{'order'} = $idx;
                   12623:                 unless ($changes{$itemid}) {
                   12624:                     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   12625:                         if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12626:                             if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
                   12627:                                 $changes{$itemid} = 1;
                   12628:                             }
                   12629:                         }
                   12630:                     }
                   12631:                 }
                   12632:                 $idx ++;
                   12633:             }
                   12634:         }
                   12635:     }
                   12636:     if (keys(%changes)) {
                   12637:         my %defaultshash = (
                   12638:                               ipaccess => \%confhash,
                   12639:                            );
                   12640:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12641:                                                  $dom);
                   12642:         if ($putresult eq 'ok') {
                   12643:             my $cachetime = 1800;
                   12644:             &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
                   12645:             if (ref($lastactref) eq 'HASH') {
                   12646:                 $lastactref->{'ipaccess'} = 1;
                   12647:             }
                   12648:             $resulttext = &mt('Changes made:').'<ul>';
                   12649:             my %bynum;
                   12650:             foreach my $itemid (sort(keys(%changes))) {
                   12651:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   12652:                     my $position = $confhash{$itemid}{'order'};
                   12653:                     if ($position =~ /^\d+$/) {
                   12654:                         $bynum{$position} = $itemid;
                   12655:                     }
                   12656:                 }
                   12657:             }
                   12658:             if (keys(%deletions)) {
                   12659:                 foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
                   12660:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12661:                 }
                   12662:             }
                   12663:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12664:                 my $itemid = $bynum{$pos};
                   12665:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   12666:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
                   12667:                     my $position = $pos + 1;
                   12668:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   12669:                     if ($confhash{$itemid}{'ip'} eq '') {
                   12670:                         $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
                   12671:                     } else {
                   12672:                         $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
                   12673:                     }
                   12674:                     if (keys(%{$confhash{$itemid}{'commblocks'}})) {
                   12675:                         $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
                   12676:                                                   join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
                   12677:                                        '</li>';
                   12678:                     } else {
                   12679:                         $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
                   12680:                     }
                   12681:                     if (keys(%{$confhash{$itemid}{'courses'}})) {
                   12682:                         my @courses;
                   12683:                         foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
                   12684:                             my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1}); 
                   12685:                             push(@courses,$courseinfo{'description'}.' ('.$cid.')');
                   12686:                         }
                   12687:                         $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
                   12688:                                              join('</li><li>',@courses).'</li></ul>';
                   12689:                     } else {
                   12690:                         $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
                   12691:                     }
1.395     raeburn  12692:                     $resulttext .= '</ul></li>';
1.394     raeburn  12693:                 }
                   12694:             }
1.395     raeburn  12695:             $resulttext .= '</ul>';
1.394     raeburn  12696:         } else {
                   12697:             $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   12698:         }
                   12699:     } else {
                   12700:         $resulttext = &mt('No changes made');
                   12701:     }
                   12702:     if ($errors) {
                   12703:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   12704:                        $errors.'</ul></p>';
                   12705:     }
                   12706:     return $resulttext;
                   12707: }
                   12708: 
                   12709: sub get_ipaccess_id {
                   12710:     my ($domain,$location) = @_;
                   12711:     # get lock on ipaccess db
                   12712:     my $lockhash = {
                   12713:                       lock => $env{'user.name'}.
                   12714:                               ':'.$env{'user.domain'},
                   12715:                    };
                   12716:     my $tries = 0;
                   12717:     my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   12718:     my ($id,$error);
                   12719: 
                   12720:     while (($gotlock ne 'ok') && ($tries<10)) {
                   12721:         $tries ++;
                   12722:         sleep (0.1);
                   12723:         $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   12724:     }
                   12725:     if ($gotlock eq 'ok') {
                   12726:         my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
                   12727:         if ($currids{'lock'}) {
                   12728:             delete($currids{'lock'});
                   12729:             if (keys(%currids)) {
                   12730:                 my @curr = sort { $a <=> $b } keys(%currids);
                   12731:                 if ($curr[-1] =~ /^\d+$/) {
                   12732:                     $id = 1 + $curr[-1];
                   12733:                 }
                   12734:             } else {
                   12735:                 $id = 1;
                   12736:             }
                   12737:             if ($id) {
                   12738:                 unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
                   12739:                     $error = 'nostore';
                   12740:                 }
                   12741:             } else {
                   12742:                 $error = 'nonumber';
                   12743:             }
                   12744:         }
                   12745:         my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
                   12746:     } else {
                   12747:         $error = 'nolock';
                   12748:     }
                   12749:     return ($id,$error);
                   12750: }
                   12751: 
1.6       raeburn  12752: sub modify_rolecolors {
1.205     raeburn  12753:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  12754:     my ($resulttext,%rolehash);
                   12755:     $rolehash{'rolecolors'} = {};
1.55      raeburn  12756:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   12757:         if ($domconfig{'rolecolors'} eq '') {
                   12758:             $domconfig{'rolecolors'} = {};
                   12759:         }
                   12760:     }
1.9       raeburn  12761:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  12762:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   12763:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   12764:                                              $dom);
                   12765:     if ($putresult eq 'ok') {
                   12766:         if (keys(%changes) > 0) {
1.41      raeburn  12767:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  12768:             if (ref($lastactref) eq 'HASH') {
                   12769:                 $lastactref->{'domainconfig'} = 1;
                   12770:             }
1.6       raeburn  12771:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   12772:                                              $rolehash{'rolecolors'});
                   12773:         } else {
                   12774:             $resulttext = &mt('No changes made to default color schemes');
                   12775:         }
                   12776:     } else {
1.11      albertel 12777:         $resulttext = '<span class="LC_error">'.
                   12778: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  12779:     }
                   12780:     if ($errors) {
                   12781:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   12782:                        $errors.'</ul>';
                   12783:     }
                   12784:     return $resulttext;
                   12785: }
                   12786: 
                   12787: sub modify_colors {
1.9       raeburn  12788:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  12789:     my (%changes,%choices);
1.51      raeburn  12790:     my @bgs;
1.6       raeburn  12791:     my @links = ('link','alink','vlink');
1.41      raeburn  12792:     my @logintext;
1.6       raeburn  12793:     my @images;
                   12794:     my $servadm = $r->dir_config('lonAdmEMail');
                   12795:     my $errors;
1.200     raeburn  12796:     my %defaults;
1.6       raeburn  12797:     foreach my $role (@{$roles}) {
                   12798:         if ($role eq 'login') {
1.12      raeburn  12799:             %choices = &login_choices();
1.41      raeburn  12800:             @logintext = ('textcol','bgcol');
1.12      raeburn  12801:         } else {
                   12802:             %choices = &color_font_choices();
                   12803:         }
                   12804:         if ($role eq 'login') {
1.41      raeburn  12805:             @images = ('img','logo','domlogo','login');
1.51      raeburn  12806:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  12807:         } else {
                   12808:             @images = ('img');
1.200     raeburn  12809:             @bgs = ('pgbg','tabbg','sidebg');
                   12810:         }
                   12811:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   12812:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   12813:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   12814:         }
                   12815:         if ($role eq 'login') {
                   12816:             foreach my $item (@logintext) {
1.234     raeburn  12817:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12818:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12819:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12820:                 }
                   12821:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  12822:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12823:                 }
                   12824:             }
                   12825:         } else {
1.234     raeburn  12826:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   12827:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   12828:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   12829:             }
                   12830:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  12831:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   12832:             }
1.6       raeburn  12833:         }
1.200     raeburn  12834:         foreach my $item (@bgs) {
1.234     raeburn  12835:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12836:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12837:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12838:             }
                   12839:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  12840:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12841:             }
                   12842:         }
                   12843:         foreach my $item (@links) {
1.234     raeburn  12844:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12845:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12846:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12847:             }
                   12848:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  12849:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12850:             }
1.6       raeburn  12851:         }
1.46      raeburn  12852:         my ($configuserok,$author_ok,$switchserver) = 
                   12853:             &config_check($dom,$confname,$servadm);
1.9       raeburn  12854:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  12855:         if (ref($domconfig->{$role}) ne 'HASH') {
                   12856:             $domconfig->{$role} = {};
                   12857:         }
1.8       raeburn  12858:         foreach my $img (@images) {
1.70      raeburn  12859:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   12860:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   12861:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   12862:                 } else { 
                   12863:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   12864:                 }
                   12865:             } 
1.18      albertel 12866: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   12867: 		 && !defined($domconfig->{$role}{$img})
                   12868: 		 && !$env{'form.'.$role.'_del_'.$img}
                   12869: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   12870: 		# import the old configured image from the .tab setting
                   12871: 		# if they haven't provided a new one 
                   12872: 		$domconfig->{$role}{$img} = 
                   12873: 		    $env{'form.'.$role.'_import_'.$img};
                   12874: 	    }
1.6       raeburn  12875:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  12876:                 my $error;
1.6       raeburn  12877:                 if ($configuserok eq 'ok') {
1.9       raeburn  12878:                     if ($switchserver) {
1.12      raeburn  12879:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  12880:                     } else {
                   12881:                         if ($author_ok eq 'ok') {
                   12882:                             my ($result,$logourl) = 
                   12883:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   12884:                                            $dom,$confname,$img,$width,$height);
                   12885:                             if ($result eq 'ok') {
                   12886:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  12887:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  12888:                             } else {
1.12      raeburn  12889:                                 $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  12890:                             }
                   12891:                         } else {
1.46      raeburn  12892:                             $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  12893:                         }
                   12894:                     }
                   12895:                 } else {
1.46      raeburn  12896:                     $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  12897:                 }
                   12898:                 if ($error) {
1.8       raeburn  12899:                     &Apache::lonnet::logthis($error);
1.11      albertel 12900:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  12901:                 }
                   12902:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  12903:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   12904:                     my $error;
                   12905:                     if ($configuserok eq 'ok') {
                   12906: # is confname an author?
                   12907:                         if ($switchserver eq '') {
                   12908:                             if ($author_ok eq 'ok') {
                   12909:                                 my ($result,$logourl) = 
                   12910:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   12911:                                             $dom,$confname,$img,$width,$height);
                   12912:                                 if ($result eq 'ok') {
                   12913:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 12914: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  12915:                                 }
                   12916:                             }
                   12917:                         }
                   12918:                     }
1.6       raeburn  12919:                 }
                   12920:             }
                   12921:         }
                   12922:         if (ref($domconfig) eq 'HASH') {
                   12923:             if (ref($domconfig->{$role}) eq 'HASH') {
                   12924:                 foreach my $img (@images) {
                   12925:                     if ($domconfig->{$role}{$img} ne '') {
                   12926:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   12927:                             $confhash->{$role}{$img} = '';
1.12      raeburn  12928:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  12929:                         } else {
1.9       raeburn  12930:                             if ($confhash->{$role}{$img} eq '') {
                   12931:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   12932:                             }
1.6       raeburn  12933:                         }
                   12934:                     } else {
                   12935:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   12936:                             $confhash->{$role}{$img} = '';
1.12      raeburn  12937:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  12938:                         } 
                   12939:                     }
1.70      raeburn  12940:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   12941:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   12942:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   12943:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   12944:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   12945:                             }
                   12946:                         } else {
                   12947:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   12948:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   12949:                             }
                   12950:                         }
                   12951:                     }
                   12952:                 }
1.6       raeburn  12953:                 if ($domconfig->{$role}{'font'} ne '') {
                   12954:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   12955:                         $changes{$role}{'font'} = 1;
                   12956:                     }
                   12957:                 } else {
                   12958:                     if ($confhash->{$role}{'font'}) {
                   12959:                         $changes{$role}{'font'} = 1;
                   12960:                     }
                   12961:                 }
1.107     raeburn  12962:                 if ($role ne 'login') {
                   12963:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   12964:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   12965:                             $changes{$role}{'fontmenu'} = 1;
                   12966:                         }
                   12967:                     } else {
                   12968:                         if ($confhash->{$role}{'fontmenu'}) {
                   12969:                             $changes{$role}{'fontmenu'} = 1;
                   12970:                         }
1.97      tempelho 12971:                     }
                   12972:                 }
1.6       raeburn  12973:                 foreach my $item (@bgs) {
                   12974:                     if ($domconfig->{$role}{$item} ne '') {
                   12975:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   12976:                             $changes{$role}{'bgs'}{$item} = 1;
                   12977:                         } 
                   12978:                     } else {
                   12979:                         if ($confhash->{$role}{$item}) {
                   12980:                             $changes{$role}{'bgs'}{$item} = 1;
                   12981:                         }
                   12982:                     }
                   12983:                 }
                   12984:                 foreach my $item (@links) {
                   12985:                     if ($domconfig->{$role}{$item} ne '') {
                   12986:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   12987:                             $changes{$role}{'links'}{$item} = 1;
                   12988:                         }
                   12989:                     } else {
                   12990:                         if ($confhash->{$role}{$item}) {
                   12991:                             $changes{$role}{'links'}{$item} = 1;
                   12992:                         }
                   12993:                     }
                   12994:                 }
1.41      raeburn  12995:                 foreach my $item (@logintext) {
                   12996:                     if ($domconfig->{$role}{$item} ne '') {
                   12997:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   12998:                             $changes{$role}{'logintext'}{$item} = 1;
                   12999:                         }
                   13000:                     } else {
                   13001:                         if ($confhash->{$role}{$item}) {
                   13002:                             $changes{$role}{'logintext'}{$item} = 1;
                   13003:                         }
                   13004:                     }
                   13005:                 }
1.6       raeburn  13006:             } else {
                   13007:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13008:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  13009:             }
                   13010:         } else {
                   13011:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13012:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  13013:         }
                   13014:     }
                   13015:     return ($errors,%changes);
                   13016: }
                   13017: 
1.46      raeburn  13018: sub config_check {
                   13019:     my ($dom,$confname,$servadm) = @_;
                   13020:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   13021:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   13022:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   13023:                                                    $confname,$servadm);
                   13024:     if ($configuserok eq 'ok') {
                   13025:         $switchserver = &check_switchserver($dom,$confname);
                   13026:         if ($switchserver eq '') {
                   13027:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   13028:         }
                   13029:     }
                   13030:     return ($configuserok,$author_ok,$switchserver);
                   13031: }
                   13032: 
1.6       raeburn  13033: sub default_change_checker {
1.41      raeburn  13034:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  13035:     foreach my $item (@{$links}) {
                   13036:         if ($confhash->{$role}{$item}) {
                   13037:             $changes->{$role}{'links'}{$item} = 1;
                   13038:         }
                   13039:     }
                   13040:     foreach my $item (@{$bgs}) {
                   13041:         if ($confhash->{$role}{$item}) {
                   13042:             $changes->{$role}{'bgs'}{$item} = 1;
                   13043:         }
                   13044:     }
1.41      raeburn  13045:     foreach my $item (@{$logintext}) {
                   13046:         if ($confhash->{$role}{$item}) {
                   13047:             $changes->{$role}{'logintext'}{$item} = 1;
                   13048:         }
                   13049:     }
1.6       raeburn  13050:     foreach my $img (@{$images}) {
                   13051:         if ($env{'form.'.$role.'_del_'.$img}) {
                   13052:             $confhash->{$role}{$img} = '';
1.12      raeburn  13053:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  13054:         }
1.70      raeburn  13055:         if ($role eq 'login') {
                   13056:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   13057:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   13058:             }
                   13059:         }
1.6       raeburn  13060:     }
                   13061:     if ($confhash->{$role}{'font'}) {
                   13062:         $changes->{$role}{'font'} = 1;
                   13063:     }
1.48      raeburn  13064: }
1.6       raeburn  13065: 
                   13066: sub display_colorchgs {
                   13067:     my ($dom,$changes,$roles,$confhash) = @_;
                   13068:     my (%choices,$resulttext);
                   13069:     if (!grep(/^login$/,@{$roles})) {
                   13070:         $resulttext = &mt('Changes made:').'<br />';
                   13071:     }
                   13072:     foreach my $role (@{$roles}) {
                   13073:         if ($role eq 'login') {
                   13074:             %choices = &login_choices();
                   13075:         } else {
                   13076:             %choices = &color_font_choices();
                   13077:         }
                   13078:         if (ref($changes->{$role}) eq 'HASH') {
                   13079:             if ($role ne 'login') {
                   13080:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   13081:             }
                   13082:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   13083:                 if ($role ne 'login') {
                   13084:                     $resulttext .= '<ul>';
                   13085:                 }
                   13086:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   13087:                     if ($role ne 'login') {
                   13088:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   13089:                     }
                   13090:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  13091:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   13092:                             if ($confhash->{$role}{$key}{$item}) {
                   13093:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   13094:                             } else {
                   13095:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   13096:                             }
                   13097:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  13098:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   13099:                         } else {
1.12      raeburn  13100:                             my $newitem = $confhash->{$role}{$item};
                   13101:                             if ($key eq 'images') {
1.306     raeburn  13102:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  13103:                             }
                   13104:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  13105:                         }
                   13106:                     }
                   13107:                     if ($role ne 'login') {
                   13108:                         $resulttext .= '</ul></li>';
                   13109:                     }
                   13110:                 } else {
                   13111:                     if ($confhash->{$role}{$key} eq '') {
                   13112:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   13113:                     } else {
                   13114:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   13115:                     }
                   13116:                 }
                   13117:                 if ($role ne 'login') {
                   13118:                     $resulttext .= '</ul>';
                   13119:                 }
                   13120:             }
                   13121:         }
                   13122:     }
1.3       raeburn  13123:     return $resulttext;
1.1       raeburn  13124: }
                   13125: 
1.9       raeburn  13126: sub thumb_dimensions {
                   13127:     return ('200','50');
                   13128: }
                   13129: 
1.16      raeburn  13130: sub check_dimensions {
                   13131:     my ($inputfile) = @_;
                   13132:     my ($fullwidth,$fullheight);
                   13133:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   13134:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   13135:             my $imageinfo = <PIPE>;
                   13136:             if (!close(PIPE)) {
                   13137:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   13138:             }
                   13139:             chomp($imageinfo);
                   13140:             my ($fullsize) = 
1.21      raeburn  13141:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  13142:             if ($fullsize) {
                   13143:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   13144:             }
                   13145:         }
                   13146:     }
                   13147:     return ($fullwidth,$fullheight);
                   13148: }
                   13149: 
1.9       raeburn  13150: sub check_configuser {
                   13151:     my ($uhome,$dom,$confname,$servadm) = @_;
                   13152:     my ($configuserok,%currroles);
                   13153:     if ($uhome eq 'no_host') {
                   13154:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.361     raeburn  13155:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  13156:         $configuserok = 
                   13157:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   13158:                              $configpass,'','','','','',undef,$servadm);
                   13159:     } else {
                   13160:         $configuserok = 'ok';
                   13161:         %currroles = 
                   13162:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   13163:     }
                   13164:     return ($configuserok,%currroles);
                   13165: }
                   13166: 
                   13167: sub check_authorstatus {
                   13168:     my ($dom,$confname,%currroles) = @_;
                   13169:     my $author_ok;
1.40      raeburn  13170:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  13171:         my $start = time;
                   13172:         my $end = 0;
                   13173:         $author_ok = 
                   13174:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  13175:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  13176:     } else {
                   13177:         $author_ok = 'ok';
                   13178:     }
                   13179:     return $author_ok;
                   13180: }
                   13181: 
                   13182: sub publishlogo {
1.46      raeburn  13183:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  13184:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  13185:     if ($action eq 'upload') {
                   13186:         $fname=$env{'form.'.$formname.'.filename'};
                   13187:         chop($env{'form.'.$formname});
                   13188:     } else {
                   13189:         ($fname) = ($formname =~ /([^\/]+)$/);
                   13190:     }
1.46      raeburn  13191:     if ($savefileas ne '') {
                   13192:         $fname = $savefileas;
                   13193:     }
1.9       raeburn  13194:     $fname=&Apache::lonnet::clean_filename($fname);
                   13195: # See if there is anything left
                   13196:     unless ($fname) { return ('error: no uploaded file'); }
                   13197:     $fname="$subdir/$fname";
1.210     raeburn  13198:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  13199:     my $filepath="$docroot/priv";
                   13200:     my $relpath = "$dom/$confname";
1.9       raeburn  13201:     my ($fnamepath,$file,$fetchthumb);
                   13202:     $file=$fname;
                   13203:     if ($fname=~m|/|) {
                   13204:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   13205:     }
1.164     raeburn  13206:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  13207:     my $count;
1.164     raeburn  13208:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  13209:         $filepath.="/$parts[$count]";
                   13210:         if ((-e $filepath)!=1) {
                   13211:             mkdir($filepath,02770);
                   13212:         }
                   13213:     }
                   13214:     # Check for bad extension and disallow upload
                   13215:     if ($file=~/\.(\w+)$/ &&
                   13216:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   13217:         $output = 
1.207     bisitz   13218:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  13219:     } elsif ($file=~/\.(\w+)$/ &&
                   13220:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   13221:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   13222:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   13223:         $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  13224:     } elsif (-d "$filepath/$file") {
1.195     bisitz   13225:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  13226:     } else {
                   13227:         my $source = $filepath.'/'.$file;
                   13228:         my $logfile;
1.316     raeburn  13229:         if (!open($logfile,">>",$source.'.log')) {
1.196     raeburn  13230:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  13231:         }
                   13232:         print $logfile
                   13233: "\n================= Publish ".localtime()." ================\n".
                   13234: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   13235: # Save the file
1.316     raeburn  13236:         if (!open(FH,">",$source)) {
1.9       raeburn  13237:             &Apache::lonnet::logthis('Failed to create '.$source);
                   13238:             return (&mt('Failed to create file'));
                   13239:         }
                   13240:         if ($action eq 'upload') {
                   13241:             if (!print FH ($env{'form.'.$formname})) {
                   13242:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   13243:                 return (&mt('Failed to write file'));
                   13244:             }
                   13245:         } else {
                   13246:             my $original = &Apache::lonnet::filelocation('',$formname);
                   13247:             if(!copy($original,$source)) {
                   13248:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   13249:                 return (&mt('Failed to write file'));
                   13250:             }
                   13251:         }
                   13252:         close(FH);
                   13253:         chmod(0660, $source); # Permissions to rw-rw---.
                   13254: 
                   13255:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   13256:         my $copyfile=$targetdir.'/'.$file;
                   13257: 
                   13258:         my @parts=split(/\//,$targetdir);
                   13259:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   13260:         for (my $count=5;$count<=$#parts;$count++) {
                   13261:             $path.="/$parts[$count]";
                   13262:             if (!-e $path) {
                   13263:                 print $logfile "\nCreating directory ".$path;
                   13264:                 mkdir($path,02770);
                   13265:             }
                   13266:         }
                   13267:         my $versionresult;
                   13268:         if (-e $copyfile) {
                   13269:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   13270:         } else {
                   13271:             $versionresult = 'ok';
                   13272:         }
                   13273:         if ($versionresult eq 'ok') {
                   13274:             if (copy($source,$copyfile)) {
                   13275:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   13276:                 $output = 'ok';
                   13277:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  13278:                 push(@{$modified_urls},[$copyfile,$source]);
                   13279:                 my $metaoutput = 
                   13280:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   13281:                 unless ($registered_cleanup) {
                   13282:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13283:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13284:                     $registered_cleanup=1;
                   13285:                 }
1.9       raeburn  13286:             } else {
                   13287:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   13288:                 $output = &mt('Failed to copy file to RES space').", $!";
                   13289:             }
                   13290:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   13291:                 my $inputfile = $filepath.'/'.$file;
                   13292:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  13293:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   13294:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   13295:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   13296:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316     raeburn  13297:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   13298:                         system({$args[0]} @args);
1.16      raeburn  13299:                         chmod(0660, $filepath.'/tn-'.$file);
                   13300:                         if (-e $outfile) {
                   13301:                             my $copyfile=$targetdir.'/tn-'.$file;
                   13302:                             if (copy($outfile,$copyfile)) {
                   13303:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  13304:                                 my $thumb_metaoutput = 
                   13305:                                     &write_metadata($dom,$confname,$formname,
                   13306:                                                     $targetdir,'tn-'.$file,$logfile);
                   13307:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   13308:                                 unless ($registered_cleanup) {
                   13309:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13310:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13311:                                     $registered_cleanup=1;
                   13312:                                 }
1.267     raeburn  13313:                                 $madethumb = 1;
1.16      raeburn  13314:                             } else {
                   13315:                                 print $logfile "\nUnable to write ".$copyfile.
                   13316:                                                ':'.$!."\n";
                   13317:                             }
                   13318:                         }
1.9       raeburn  13319:                     }
                   13320:                 }
                   13321:             }
                   13322:         } else {
                   13323:             $output = $versionresult;
                   13324:         }
                   13325:     }
1.267     raeburn  13326:     return ($output,$logourl,$madethumb);
1.9       raeburn  13327: }
                   13328: 
                   13329: sub logo_versioning {
                   13330:     my ($targetdir,$file,$logfile) = @_;
                   13331:     my $target = $targetdir.'/'.$file;
                   13332:     my ($maxversion,$fn,$extn,$output);
                   13333:     $maxversion = 0;
                   13334:     if ($file =~ /^(.+)\.(\w+)$/) {
                   13335:         $fn=$1;
                   13336:         $extn=$2;
                   13337:     }
                   13338:     opendir(DIR,$targetdir);
                   13339:     while (my $filename=readdir(DIR)) {
                   13340:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   13341:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   13342:         }
                   13343:     }
                   13344:     $maxversion++;
                   13345:     print $logfile "\nCreating old version ".$maxversion."\n";
                   13346:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   13347:     if (copy($target,$copyfile)) {
                   13348:         print $logfile "Copied old target to ".$copyfile."\n";
                   13349:         $copyfile=$copyfile.'.meta';
                   13350:         if (copy($target.'.meta',$copyfile)) {
                   13351:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   13352:             $output = 'ok';
                   13353:         } else {
                   13354:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   13355:             $output = &mt('Failed to copy old meta').", $!, ";
                   13356:         }
                   13357:     } else {
                   13358:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   13359:         $output = &mt('Failed to copy old target').", $!, ";
                   13360:     }
                   13361:     return $output;
                   13362: }
                   13363: 
                   13364: sub write_metadata {
                   13365:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   13366:     my (%metadatafields,%metadatakeys,$output);
                   13367:     $metadatafields{'title'}=$formname;
                   13368:     $metadatafields{'creationdate'}=time;
                   13369:     $metadatafields{'lastrevisiondate'}=time;
                   13370:     $metadatafields{'copyright'}='public';
                   13371:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   13372:                                          $env{'user.domain'};
                   13373:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   13374:     $metadatafields{'domain'}=$dom;
                   13375:     {
                   13376:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   13377:         my $mfh;
1.316     raeburn  13378:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  13379:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  13380:                 unless ($_=~/\./) {
                   13381:                     my $unikey=$_;
                   13382:                     $unikey=~/^([A-Za-z]+)/;
                   13383:                     my $tag=$1;
                   13384:                     $tag=~tr/A-Z/a-z/;
                   13385:                     print $mfh "\n\<$tag";
                   13386:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   13387:                         my $value=$metadatafields{$unikey.'.'.$_};
                   13388:                         $value=~s/\"/\'\'/g;
                   13389:                         print $mfh ' '.$_.'="'.$value.'"';
                   13390:                     }
                   13391:                     print $mfh '>'.
                   13392:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   13393:                             .'</'.$tag.'>';
                   13394:                 }
                   13395:             }
                   13396:             $output = 'ok';
                   13397:             print $logfile "\nWrote metadata";
                   13398:             close($mfh);
                   13399:         } else {
                   13400:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  13401:             $output = &mt('Could not write metadata');
                   13402:         }
                   13403:     }
1.155     raeburn  13404:     return $output;
                   13405: }
                   13406: 
                   13407: sub notifysubscribed {
                   13408:     foreach my $targetsource (@{$modified_urls}){
                   13409:         next unless (ref($targetsource) eq 'ARRAY');
                   13410:         my ($target,$source)=@{$targetsource};
                   13411:         if ($source ne '') {
1.316     raeburn  13412:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  13413:                 print $logfh "\nCleanup phase: Notifications\n";
                   13414:                 my @subscribed=&subscribed_hosts($target);
                   13415:                 foreach my $subhost (@subscribed) {
                   13416:                     print $logfh "\nNotifying host ".$subhost.':';
                   13417:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   13418:                     print $logfh $reply;
                   13419:                 }
                   13420:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   13421:                 foreach my $subhost (@subscribedmeta) {
                   13422:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   13423:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   13424:                                                         $subhost);
                   13425:                     print $logfh $reply;
                   13426:                 }
                   13427:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  13428:                 close($logfh);
1.155     raeburn  13429:             }
                   13430:         }
                   13431:     }
                   13432:     return OK;
                   13433: }
                   13434: 
                   13435: sub subscribed_hosts {
                   13436:     my ($target) = @_;
                   13437:     my @subscribed;
1.316     raeburn  13438:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  13439:         while (my $subline=<$fh>) {
                   13440:             if ($subline =~ /^($match_lonid):/) {
                   13441:                 my $host = $1;
                   13442:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   13443:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   13444:                         push(@subscribed,$host);
                   13445:                     }
                   13446:                 }
                   13447:             }
                   13448:         }
                   13449:     }
                   13450:     return @subscribed;
1.9       raeburn  13451: }
                   13452: 
                   13453: sub check_switchserver {
                   13454:     my ($dom,$confname) = @_;
                   13455:     my ($allowed,$switchserver);
                   13456:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   13457:     if ($home eq 'no_host') {
                   13458:         $home = &Apache::lonnet::domain($dom,'primary');
                   13459:     }
                   13460:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 13461:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   13462:     if (!$allowed) {
1.180     raeburn  13463: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  13464:     }
                   13465:     return $switchserver;
                   13466: }
                   13467: 
1.1       raeburn  13468: sub modify_quotas {
1.216     raeburn  13469:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  13470:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  13471:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  13472:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   13473:         $validationfieldsref);
1.86      raeburn  13474:     if ($action eq 'quotas') {
                   13475:         $context = 'tools'; 
1.163     raeburn  13476:     } else {
1.86      raeburn  13477:         $context = $action;
                   13478:     }
                   13479:     if ($context eq 'requestcourses') {
1.325     raeburn  13480:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  13481:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  13482:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   13483:         %titles = &courserequest_titles();
                   13484:         $toolregexp = join('|',@usertools);
                   13485:         %conditions = &courserequest_conditions();
1.216     raeburn  13486:         $confname = $dom.'-domainconfig';
                   13487:         my $servadm = $r->dir_config('lonAdmEMail');
                   13488:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  13489:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   13490:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  13491:     } elsif ($context eq 'requestauthor') {
                   13492:         @usertools = ('author');
                   13493:         %titles = &authorrequest_titles();
1.86      raeburn  13494:     } else {
1.162     raeburn  13495:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  13496:         %titles = &tool_titles();
1.86      raeburn  13497:     }
1.212     raeburn  13498:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  13499:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  13500:     foreach my $key (keys(%env)) {
1.101     raeburn  13501:         if ($context eq 'requestcourses') {
                   13502:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   13503:                 my $item = $1;
                   13504:                 my $type = $2;
                   13505:                 if ($type =~ /^limit_(.+)/) {
                   13506:                     $limithash{$item}{$1} = $env{$key};
                   13507:                 } else {
                   13508:                     $confhash{$item}{$type} = $env{$key};
                   13509:                 }
                   13510:             }
1.163     raeburn  13511:         } elsif ($context eq 'requestauthor') {
                   13512:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   13513:                 $confhash{$1} = $env{$key};
                   13514:             }
1.101     raeburn  13515:         } else {
1.86      raeburn  13516:             if ($key =~ /^form\.quota_(.+)$/) {
                   13517:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  13518:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   13519:                 $confhash{'authorquota'}{$1} = $env{$key};
                   13520:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  13521:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   13522:             }
1.72      raeburn  13523:         }
                   13524:     }
1.163     raeburn  13525:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  13526:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  13527:         @approvalnotify = sort(@approvalnotify);
                   13528:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325     raeburn  13529:         my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218     raeburn  13530:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   13531:         foreach my $type (@hasuniquecode) {
                   13532:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   13533:                 $confhash{'uniquecode'}{$type} = 1;
                   13534:             }
1.216     raeburn  13535:         }
1.242     raeburn  13536:         my (%newbook,%allpos);
1.216     raeburn  13537:         if ($context eq 'requestcourses') {
1.242     raeburn  13538:             foreach my $type ('textbooks','templates') {
                   13539:                 @{$allpos{$type}} = (); 
                   13540:                 my $invalid;
                   13541:                 if ($type eq 'textbooks') {
                   13542:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   13543:                 } else {
                   13544:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   13545:                 }
                   13546:                 if ($env{'form.'.$type.'_addbook'}) {
                   13547:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   13548:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   13549:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   13550:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   13551:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   13552:                         } else {
                   13553:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   13554:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   13555:                             $position =~ s/\D+//g;
                   13556:                             if ($position ne '') {
                   13557:                                 $allpos{$type}[$position] = $newbook{$type};
                   13558:                             }
1.216     raeburn  13559:                         }
1.242     raeburn  13560:                     } else {
                   13561:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  13562:                     }
                   13563:                 }
1.242     raeburn  13564:             } 
1.216     raeburn  13565:         }
1.102     raeburn  13566:         if (ref($domconfig{$action}) eq 'HASH') {
                   13567:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   13568:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   13569:                     $changes{'notify'}{'approval'} = 1;
                   13570:                 }
                   13571:             } else {
1.144     raeburn  13572:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  13573:                     $changes{'notify'}{'approval'} = 1;
                   13574:                 }
                   13575:             }
1.218     raeburn  13576:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   13577:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   13578:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   13579:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   13580:                             $changes{'uniquecode'} = 1;
                   13581:                         }
                   13582:                     }
                   13583:                     unless ($changes{'uniquecode'}) {
                   13584:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   13585:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   13586:                                 $changes{'uniquecode'} = 1;
                   13587:                             }
                   13588:                         }
                   13589:                     }
                   13590:                } else {
                   13591:                    $changes{'uniquecode'} = 1;
                   13592:                }
                   13593:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   13594:                 $changes{'uniquecode'} = 1;
1.216     raeburn  13595:             }
                   13596:             if ($context eq 'requestcourses') {
1.242     raeburn  13597:                 foreach my $type ('textbooks','templates') {
                   13598:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   13599:                         my %deletions;
                   13600:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   13601:                         if (@todelete) {
                   13602:                             map { $deletions{$_} = 1; } @todelete;
                   13603:                         }
                   13604:                         my %imgdeletions;
                   13605:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   13606:                         if (@todeleteimages) {
                   13607:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   13608:                         }
                   13609:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   13610:                         for (my $i=0; $i<=$maxnum; $i++) {
                   13611:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   13612:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   13613:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   13614:                                 if ($deletions{$key}) {
                   13615:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   13616:                                         #FIXME need to obsolete item in RES space
                   13617:                                     }
                   13618:                                     next;
                   13619:                                 } else {
                   13620:                                     my $newpos = $env{'form.'.$itemid};
                   13621:                                     $newpos =~ s/\D+//g;
1.243     raeburn  13622:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  13623:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  13624:                                                  ($type eq 'templates'));
1.242     raeburn  13625:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   13626:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   13627:                                             $changes{$type}{$key} = 1;
                   13628:                                         }
                   13629:                                     }
                   13630:                                     $allpos{$type}[$newpos] = $key;
                   13631:                                 }
                   13632:                                 if ($imgdeletions{$key}) {
                   13633:                                     $changes{$type}{$key} = 1;
1.216     raeburn  13634:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  13635:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   13636:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  13637:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   13638:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   13639:                                     } else {
                   13640:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   13641:                                                                                       $cdom,$cnum,$type,$configuserok,
                   13642:                                                                                       $switchserver,$author_ok);
                   13643:                                         if ($imgurl) {
                   13644:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   13645:                                             $changes{$type}{$key} = 1; 
                   13646:                                         }
                   13647:                                         if ($error) {
                   13648:                                             &Apache::lonnet::logthis($error);
                   13649:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13650:                                         }
                   13651:                                     }
1.242     raeburn  13652:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   13653:                                     $confhash{$type}{$key}{'image'} = 
                   13654:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  13655:                                 }
                   13656:                             }
                   13657:                         }
                   13658:                     }
                   13659:                 }
                   13660:             }
1.102     raeburn  13661:         } else {
1.144     raeburn  13662:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  13663:                 $changes{'notify'}{'approval'} = 1;
                   13664:             }
1.218     raeburn  13665:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  13666:                 $changes{'uniquecode'} = 1;
                   13667:             }
                   13668:         }
                   13669:         if ($context eq 'requestcourses') {
1.242     raeburn  13670:             foreach my $type ('textbooks','templates') {
                   13671:                 if ($newbook{$type}) {
                   13672:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  13673:                     foreach my $item ('subject','title','publisher','author') {
                   13674:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   13675:                                  ($type eq 'template'));
1.242     raeburn  13676:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   13677:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   13678:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   13679:                         }
                   13680:                     }
                   13681:                     if ($type eq 'textbooks') {
                   13682:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   13683:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  13684:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   13685:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   13686:                             } else {
                   13687:                                 my ($imageurl,$error) =
                   13688:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   13689:                                                             $configuserok,$switchserver,$author_ok);
                   13690:                                 if ($imageurl) {
                   13691:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   13692:                                 }
                   13693:                                 if ($error) {
                   13694:                                     &Apache::lonnet::logthis($error);
                   13695:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13696:                                 }
1.242     raeburn  13697:                             }
                   13698:                         }
1.216     raeburn  13699:                     }
                   13700:                 }
1.242     raeburn  13701:                 if (@{$allpos{$type}} > 0) {
                   13702:                     my $idx = 0;
                   13703:                     foreach my $item (@{$allpos{$type}}) {
                   13704:                         if ($item ne '') {
                   13705:                             $confhash{$type}{$item}{'order'} = $idx;
                   13706:                             if (ref($domconfig{$action}) eq 'HASH') {
                   13707:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   13708:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   13709:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   13710:                                             $changes{$type}{$item} = 1;
                   13711:                                         }
1.216     raeburn  13712:                                     }
                   13713:                                 }
                   13714:                             }
1.242     raeburn  13715:                             $idx ++;
1.216     raeburn  13716:                         }
                   13717:                     }
                   13718:                 }
                   13719:             }
1.235     raeburn  13720:             if (ref($validationitemsref) eq 'ARRAY') {
                   13721:                 foreach my $item (@{$validationitemsref}) {
                   13722:                     if ($item eq 'fields') {
                   13723:                         my @changed;
                   13724:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   13725:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   13726:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   13727:                         }
1.266     raeburn  13728:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13729:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13730:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   13731:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   13732:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   13733:                                 } else {
                   13734:                                     @changed = @{$confhash{'validation'}{$item}};
                   13735:                                 }
1.235     raeburn  13736:                             } else {
                   13737:                                 @changed = @{$confhash{'validation'}{$item}};
                   13738:                             }
                   13739:                         } else {
                   13740:                             @changed = @{$confhash{'validation'}{$item}};
                   13741:                         }
                   13742:                         if (@changed) {
                   13743:                             if ($confhash{'validation'}{$item}) {
                   13744:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   13745:                             } else {
                   13746:                                 $changes{'validation'}{$item} = &mt('None');
                   13747:                             }
                   13748:                         }
                   13749:                     } else {
                   13750:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   13751:                         if ($item eq 'markup') {
                   13752:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   13753:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   13754:                             }
                   13755:                         }
1.266     raeburn  13756:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13757:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13758:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   13759:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13760:                                 }
                   13761:                             } else {
                   13762:                                 if ($confhash{'validation'}{$item} ne '') {
                   13763:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13764:                                 }
1.235     raeburn  13765:                             }
                   13766:                         } else {
                   13767:                             if ($confhash{'validation'}{$item} ne '') {
                   13768:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13769:                             }
                   13770:                         }
                   13771:                     }
                   13772:                 }
                   13773:             }
                   13774:             if ($env{'form.validationdc'}) {
                   13775:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  13776:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  13777:                 if (exists($domcoords{$newval})) {
                   13778:                     $confhash{'validation'}{'dc'} = $newval;
                   13779:                 }
                   13780:             }
                   13781:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  13782:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13783:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13784:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13785:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13786:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   13787:                                     $changes{'validation'}{'dc'} = &mt('None');
                   13788:                                 } else {
                   13789:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   13790:                                 }
1.235     raeburn  13791:                             }
1.266     raeburn  13792:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13793:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  13794:                         }
                   13795:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13796:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   13797:                     }
                   13798:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13799:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  13800:                 }
1.266     raeburn  13801:             } else {
                   13802:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13803:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13804:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13805:                             $changes{'validation'}{'dc'} = &mt('None');
                   13806:                         }
                   13807:                     }
1.235     raeburn  13808:                 }
                   13809:             }
1.102     raeburn  13810:         }
                   13811:     } else {
1.86      raeburn  13812:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  13813:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  13814:     }
1.72      raeburn  13815:     foreach my $item (@usertools) {
                   13816:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  13817:             my $unset; 
1.101     raeburn  13818:             if ($context eq 'requestcourses') {
1.104     raeburn  13819:                 $unset = '0';
                   13820:                 if ($type eq '_LC_adv') {
                   13821:                     $unset = '';
                   13822:                 }
1.101     raeburn  13823:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   13824:                     $confhash{$item}{$type} .= '=';
                   13825:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   13826:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   13827:                     }
                   13828:                 }
1.163     raeburn  13829:             } elsif ($context eq 'requestauthor') {
                   13830:                 $unset = '0';
                   13831:                 if ($type eq '_LC_adv') {
                   13832:                     $unset = '';
                   13833:                 }
1.72      raeburn  13834:             } else {
1.101     raeburn  13835:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   13836:                     $confhash{$item}{$type} = 1;
                   13837:                 } else {
                   13838:                     $confhash{$item}{$type} = 0;
                   13839:                 }
1.72      raeburn  13840:             }
1.86      raeburn  13841:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  13842:                 if ($action eq 'requestauthor') {
                   13843:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   13844:                         $changes{$type} = 1;
                   13845:                     }
                   13846:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  13847:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   13848:                         $changes{$item}{$type} = 1;
                   13849:                     }
                   13850:                 } else {
                   13851:                     if ($context eq 'requestcourses') {
1.104     raeburn  13852:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  13853:                             $changes{$item}{$type} = 1;
                   13854:                         }
                   13855:                     } else {
                   13856:                         if (!$confhash{$item}{$type}) {
                   13857:                             $changes{$item}{$type} = 1;
                   13858:                         }
                   13859:                     }
                   13860:                 }
                   13861:             } else {
                   13862:                 if ($context eq 'requestcourses') {
1.104     raeburn  13863:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  13864:                         $changes{$item}{$type} = 1;
                   13865:                     }
1.163     raeburn  13866:                 } elsif ($context eq 'requestauthor') {
                   13867:                     if ($confhash{$type} ne $unset) {
                   13868:                         $changes{$type} = 1;
                   13869:                     }
1.72      raeburn  13870:                 } else {
                   13871:                     if (!$confhash{$item}{$type}) {
                   13872:                         $changes{$item}{$type} = 1;
                   13873:                     }
                   13874:                 }
                   13875:             }
1.1       raeburn  13876:         }
                   13877:     }
1.163     raeburn  13878:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  13879:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13880:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   13881:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   13882:                     if (exists($confhash{'defaultquota'}{$key})) {
                   13883:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   13884:                             $changes{'defaultquota'}{$key} = 1;
                   13885:                         }
                   13886:                     } else {
                   13887:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  13888:                     }
                   13889:                 }
1.86      raeburn  13890:             } else {
                   13891:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   13892:                     if (exists($confhash{'defaultquota'}{$key})) {
                   13893:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   13894:                             $changes{'defaultquota'}{$key} = 1;
                   13895:                         }
                   13896:                     } else {
                   13897:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  13898:                     }
1.1       raeburn  13899:                 }
                   13900:             }
1.197     raeburn  13901:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   13902:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   13903:                     if (exists($confhash{'authorquota'}{$key})) {
                   13904:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   13905:                             $changes{'authorquota'}{$key} = 1;
                   13906:                         }
                   13907:                     } else {
                   13908:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   13909:                     }
                   13910:                 }
                   13911:             }
1.1       raeburn  13912:         }
1.86      raeburn  13913:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   13914:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   13915:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13916:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   13917:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   13918:                             $changes{'defaultquota'}{$key} = 1;
                   13919:                         }
                   13920:                     } else {
                   13921:                         if (!exists($domconfig{'quotas'}{$key})) {
                   13922:                             $changes{'defaultquota'}{$key} = 1;
                   13923:                         }
1.72      raeburn  13924:                     }
                   13925:                 } else {
1.86      raeburn  13926:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  13927:                 }
1.1       raeburn  13928:             }
                   13929:         }
1.197     raeburn  13930:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   13931:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   13932:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13933:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   13934:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   13935:                             $changes{'authorquota'}{$key} = 1;
                   13936:                         }
                   13937:                     } else {
                   13938:                         $changes{'authorquota'}{$key} = 1;
                   13939:                     }
                   13940:                 } else {
                   13941:                     $changes{'authorquota'}{$key} = 1;
                   13942:                 }
                   13943:             }
                   13944:         }
1.1       raeburn  13945:     }
1.72      raeburn  13946: 
1.163     raeburn  13947:     if ($context eq 'requestauthor') {
                   13948:         $domdefaults{'requestauthor'} = \%confhash;
                   13949:     } else {
                   13950:         foreach my $key (keys(%confhash)) {
1.242     raeburn  13951:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  13952:                 $domdefaults{$key} = $confhash{$key};
                   13953:             }
1.163     raeburn  13954:         }
1.72      raeburn  13955:     }
1.163     raeburn  13956: 
1.1       raeburn  13957:     my %quotahash = (
1.86      raeburn  13958:                       $action => { %confhash }
1.1       raeburn  13959:                     );
                   13960:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   13961:                                              $dom);
                   13962:     if ($putresult eq 'ok') {
                   13963:         if (keys(%changes) > 0) {
1.72      raeburn  13964:             my $cachetime = 24*60*60;
                   13965:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  13966:             if (ref($lastactref) eq 'HASH') {
                   13967:                 $lastactref->{'domdefaults'} = 1;
                   13968:             }
1.1       raeburn  13969:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  13970:             unless (($context eq 'requestcourses') ||
1.163     raeburn  13971:                     ($context eq 'requestauthor')) {
1.86      raeburn  13972:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   13973:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   13974:                     foreach my $type (@{$types},'default') {
                   13975:                         if (defined($changes{'defaultquota'}{$type})) {
                   13976:                             my $typetitle = $usertypes->{$type};
                   13977:                             if ($type eq 'default') {
                   13978:                                 $typetitle = $othertitle;
                   13979:                             }
1.213     raeburn  13980:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  13981:                         }
                   13982:                     }
1.86      raeburn  13983:                     $resulttext .= '</ul></li>';
1.72      raeburn  13984:                 }
1.197     raeburn  13985:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   13986:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  13987:                     foreach my $type (@{$types},'default') {
                   13988:                         if (defined($changes{'authorquota'}{$type})) {
                   13989:                             my $typetitle = $usertypes->{$type};
                   13990:                             if ($type eq 'default') {
                   13991:                                 $typetitle = $othertitle;
                   13992:                             }
1.213     raeburn  13993:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  13994:                         }
                   13995:                     }
                   13996:                     $resulttext .= '</ul></li>';
                   13997:                 }
1.72      raeburn  13998:             }
1.80      raeburn  13999:             my %newenv;
1.72      raeburn  14000:             foreach my $item (@usertools) {
1.163     raeburn  14001:                 my (%haschgs,%inconf);
                   14002:                 if ($context eq 'requestauthor') {
                   14003:                     %haschgs = %changes;
1.210     raeburn  14004:                     %inconf = %confhash;
1.163     raeburn  14005:                 } else {
                   14006:                     if (ref($changes{$item}) eq 'HASH') {
                   14007:                         %haschgs = %{$changes{$item}};
                   14008:                     }
                   14009:                     if (ref($confhash{$item}) eq 'HASH') {
                   14010:                         %inconf = %{$confhash{$item}};
                   14011:                     }
                   14012:                 }
                   14013:                 if (keys(%haschgs) > 0) {
1.80      raeburn  14014:                     my $newacc = 
                   14015:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   14016:                                                           $env{'user.domain'},
1.86      raeburn  14017:                                                           $item,'reload',$context);
1.210     raeburn  14018:                     if (($context eq 'requestcourses') ||
1.163     raeburn  14019:                         ($context eq 'requestauthor')) {
1.108     raeburn  14020:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   14021:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  14022:                         }
                   14023:                     } else {
                   14024:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   14025:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   14026:                         }
1.80      raeburn  14027:                     }
1.163     raeburn  14028:                     unless ($context eq 'requestauthor') {
                   14029:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   14030:                     }
1.72      raeburn  14031:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  14032:                         if ($haschgs{$type}) {
1.72      raeburn  14033:                             my $typetitle = $usertypes->{$type};
                   14034:                             if ($type eq 'default') {
                   14035:                                 $typetitle = $othertitle;
                   14036:                             } elsif ($type eq '_LC_adv') {
                   14037:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   14038:                             }
1.163     raeburn  14039:                             if ($inconf{$type}) {
1.101     raeburn  14040:                                 if ($context eq 'requestcourses') {
                   14041:                                     my $cond;
1.163     raeburn  14042:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  14043:                                         if ($1 eq '') {
                   14044:                                             $cond = &mt('(Automatic processing of any request).');
                   14045:                                         } else {
                   14046:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   14047:                                         }
                   14048:                                     } else { 
1.163     raeburn  14049:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  14050:                                     }
                   14051:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  14052:                                 } elsif ($context eq 'requestauthor') {
                   14053:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   14054:                                                              $titles{$inconf{$type}},$typetitle);
                   14055: 
1.101     raeburn  14056:                                 } else {
                   14057:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   14058:                                 }
1.72      raeburn  14059:                             } else {
1.104     raeburn  14060:                                 if ($type eq '_LC_adv') {
1.163     raeburn  14061:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  14062:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14063:                                     } else { 
                   14064:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   14065:                                     }
                   14066:                                 } else {
                   14067:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14068:                                 }
1.72      raeburn  14069:                             }
                   14070:                         }
1.26      raeburn  14071:                     }
1.163     raeburn  14072:                     unless ($context eq 'requestauthor') {
                   14073:                         $resulttext .= '</ul></li>';
                   14074:                     }
1.26      raeburn  14075:                 }
1.1       raeburn  14076:             }
1.163     raeburn  14077:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  14078:                 if (ref($changes{'notify'}) eq 'HASH') {
                   14079:                     if ($changes{'notify'}{'approval'}) {
                   14080:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   14081:                             if ($confhash{'notify'}{'approval'}) {
                   14082:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   14083:                             } else {
1.163     raeburn  14084:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  14085:                             }
                   14086:                         }
                   14087:                     }
                   14088:                 }
                   14089:             }
1.216     raeburn  14090:             if ($action eq 'requestcourses') {
                   14091:                 my @offon = ('off','on');
                   14092:                 if ($changes{'uniquecode'}) {
1.218     raeburn  14093:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14094:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   14095:                         $resulttext .= '<li>'.
                   14096:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   14097:                                        '</li>';
                   14098:                     } else {
                   14099:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   14100:                                        '</li>';
                   14101:                     }
1.216     raeburn  14102:                 }
1.242     raeburn  14103:                 foreach my $type ('textbooks','templates') {
                   14104:                     if (ref($changes{$type}) eq 'HASH') {
                   14105:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   14106:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   14107:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   14108:                             my $coursetitle = $coursehash{'description'};
                   14109:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   14110:                             $resulttext .= '<li>';
1.243     raeburn  14111:                             foreach my $item ('subject','title','publisher','author') {
                   14112:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   14113:                                          ($type eq 'templates'));
1.242     raeburn  14114:                                 my $name = $item.':';
                   14115:                                 $name =~ s/^(\w)/\U$1/;
                   14116:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   14117:                             }
                   14118:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   14119:                             if ($type eq 'textbooks') {
                   14120:                                 if ($confhash{$type}{$key}{'image'}) {
                   14121:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   14122:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   14123:                                                    ' alt="Textbook cover" />').'<br />';
                   14124:                                 }
                   14125:                             }
                   14126:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  14127:                         }
1.242     raeburn  14128:                         $resulttext .= '</ul></li>';
1.216     raeburn  14129:                     }
                   14130:                 }
1.235     raeburn  14131:                 if (ref($changes{'validation'}) eq 'HASH') {
                   14132:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   14133:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   14134:                         foreach my $item (@{$validationitemsref}) {
                   14135:                             if (exists($changes{'validation'}{$item})) {
                   14136:                                 if ($item eq 'markup') {
                   14137:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14138:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   14139:                                 } else {
                   14140:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14141:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   14142:                                 }
                   14143:                             }
                   14144:                         }
                   14145:                         if (exists($changes{'validation'}{'dc'})) {
                   14146:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   14147:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   14148:                         }
                   14149:                     }
                   14150:                 }
1.216     raeburn  14151:             }
1.1       raeburn  14152:             $resulttext .= '</ul>';
1.80      raeburn  14153:             if (keys(%newenv)) {
                   14154:                 &Apache::lonnet::appenv(\%newenv);
                   14155:             }
1.1       raeburn  14156:         } else {
1.86      raeburn  14157:             if ($context eq 'requestcourses') {
                   14158:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  14159:             } elsif ($context eq 'requestauthor') {
                   14160:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  14161:             } else {
1.90      weissno  14162:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  14163:             }
1.1       raeburn  14164:         }
                   14165:     } else {
1.11      albertel 14166:         $resulttext = '<span class="LC_error">'.
                   14167: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  14168:     }
1.216     raeburn  14169:     if ($errors) {
                   14170:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   14171:                        '<ul>'.$errors.'</ul></p>';
                   14172:     }
1.3       raeburn  14173:     return $resulttext;
1.1       raeburn  14174: }
                   14175: 
1.216     raeburn  14176: sub process_textbook_image {
1.242     raeburn  14177:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  14178:     my $filename = $env{'form.'.$caller.'.filename'};
                   14179:     my ($error,$url);
                   14180:     my ($width,$height) = (50,50);
                   14181:     if ($configuserok eq 'ok') {
                   14182:         if ($switchserver) {
                   14183:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   14184:                          $switchserver);
                   14185:         } elsif ($author_ok eq 'ok') {
                   14186:             my ($result,$imageurl) =
                   14187:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.312     raeburn  14188:                              "$type/$cdom/$cnum/cover",$width,$height);
1.216     raeburn  14189:             if ($result eq 'ok') {
                   14190:                 $url = $imageurl;
                   14191:             } else {
                   14192:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14193:             }
                   14194:         } else {
                   14195:             $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);
                   14196:         }
                   14197:     } else {
                   14198:         $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);
                   14199:     }
                   14200:     return ($url,$error);
                   14201: }
                   14202: 
1.267     raeburn  14203: sub modify_ltitools {
                   14204:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   14205:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297     raeburn  14206:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267     raeburn  14207:     my $confname = $dom.'-domainconfig';
                   14208:     my $servadm = $r->dir_config('lonAdmEMail');
                   14209:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   14210:     my (%posslti,%possfield);
                   14211:     my @courseroles = ('cc','in','ta','ep','st');
                   14212:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   14213:     map { $posslti{$_} = 1; } @ltiroles;
                   14214:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   14215:     map { $possfield{$_} = 1; } @allfields;
                   14216:     my %lt = &ltitools_names(); 
                   14217:     if ($env{'form.ltitools_add'}) {
                   14218:         my $title = $env{'form.ltitools_add_title'};
                   14219:         $title =~ s/(`)/'/g;
                   14220:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   14221:         if ($newid) {
                   14222:             my $position = $env{'form.ltitools_add_pos'};
                   14223:             $position =~ s/\D+//g;
                   14224:             if ($position ne '') {
                   14225:                 $allpos[$position] = $newid;
                   14226:             }
                   14227:             $changes{$newid} = 1;
1.322     raeburn  14228:             foreach my $item ('title','url','key','secret','lifetime') {
1.267     raeburn  14229:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322     raeburn  14230:                 if ($item eq 'lifetime') {
                   14231:                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   14232:                 }
1.267     raeburn  14233:                 if ($env{'form.ltitools_add_'.$item}) {
1.297     raeburn  14234:                     if (($item eq 'key') || ($item eq 'secret')) {
                   14235:                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14236:                     } else {
                   14237:                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14238:                     }
1.267     raeburn  14239:                 }
                   14240:             }
                   14241:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   14242:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   14243:             }
                   14244:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   14245:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   14246:             }
1.323     raeburn  14247:             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   14248:                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   14249:             } else {
                   14250:                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   14251:             }
1.296     raeburn  14252:             foreach my $item ('width','height','linktext','explanation') {
1.267     raeburn  14253:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   14254:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296     raeburn  14255:                 if (($item eq 'width') || ($item eq 'height')) {
                   14256:                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   14257:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   14258:                     }
                   14259:                 } else {
                   14260:                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   14261:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item}; 
                   14262:                     }
1.267     raeburn  14263:                 }
                   14264:             }
                   14265:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   14266:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298     raeburn  14267:             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   14268:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267     raeburn  14269:             } else {
                   14270:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   14271:             }
                   14272:             foreach my $item ('passback','roster') {
1.319     raeburn  14273:                 if ($env{'form.ltitools_'.$item.'_add'}) {
1.267     raeburn  14274:                     $confhash{$newid}{$item} = 1;
1.319     raeburn  14275:                     if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
                   14276:                         my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
                   14277:                         $lifetime =~ s/^\s+|\s+$//g;
                   14278:                         if ($lifetime =~ /^\d+\.?\d*$/) {
                   14279:                             $confhash{$newid}{$item.'valid'} = $lifetime;
                   14280:                         }
                   14281:                     }
1.267     raeburn  14282:                 }
                   14283:             }
                   14284:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   14285:                 my ($imageurl,$error) =
1.307     raeburn  14286:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267     raeburn  14287:                                             $configuserok,$switchserver,$author_ok);
                   14288:                 if ($imageurl) {
                   14289:                     $confhash{$newid}{'image'} = $imageurl;
                   14290:                 }
                   14291:                 if ($error) {
                   14292:                     &Apache::lonnet::logthis($error);
                   14293:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14294:                 }
                   14295:             }
                   14296:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   14297:             foreach my $field (@fields) {
                   14298:                 if ($possfield{$field}) {
                   14299:                     if ($field eq 'roles') {
                   14300:                         foreach my $role (@courseroles) {
                   14301:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   14302:                             if (($choice ne '') && ($posslti{$choice})) {
                   14303:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   14304:                                 if ($role eq 'cc') {
                   14305:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   14306:                                 }
                   14307:                             }
                   14308:                         }
                   14309:                     } else {
                   14310:                         $confhash{$newid}{'fields'}{$field} = 1;
                   14311:                     }
                   14312:                 }
                   14313:             }
1.324     raeburn  14314:             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   14315:                 if ($confhash{$newid}{'fields'}{'user'}) {
                   14316:                     if ($env{'form.ltitools_userincdom_add'}) {
                   14317:                         $confhash{$newid}{'incdom'} = 1;
                   14318:                     }
                   14319:                 }
                   14320:             }
1.273     raeburn  14321:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   14322:             foreach my $item (@courseconfig) {
                   14323:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   14324:             }
1.267     raeburn  14325:             if ($env{'form.ltitools_add_custom'}) {
                   14326:                 my $name = $env{'form.ltitools_add_custom_name'};
                   14327:                 my $value = $env{'form.ltitools_add_custom_value'};
                   14328:                 $value =~ s/(`)/'/g;
                   14329:                 $name =~ s/(`)/'/g;
                   14330:                 $confhash{$newid}{'custom'}{$name} = $value;
                   14331:             }
                   14332:         } else {
                   14333:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   14334:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14335:         }
                   14336:     }
                   14337:     if (ref($domconfig{$action}) eq 'HASH') {
                   14338:         my %deletions;
                   14339:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   14340:         if (@todelete) {
                   14341:             map { $deletions{$_} = 1; } @todelete;
                   14342:         }
                   14343:         my %customadds;
                   14344:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   14345:         if (@newcustom) {
                   14346:             map { $customadds{$_} = 1; } @newcustom;
                   14347:         } 
                   14348:         my %imgdeletions;
                   14349:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   14350:         if (@todeleteimages) {
                   14351:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14352:         }
                   14353:         my $maxnum = $env{'form.ltitools_maxnum'};
                   14354:         for (my $i=0; $i<=$maxnum; $i++) {
                   14355:             my $itemid = $env{'form.ltitools_id_'.$i};
1.308     raeburn  14356:             $itemid =~ s/\D+//g;
1.267     raeburn  14357:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   14358:                 if ($deletions{$itemid}) {
                   14359:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   14360:                         #FIXME need to obsolete item in RES space
                   14361:                     }
                   14362:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   14363:                     next;
                   14364:                 } else {
                   14365:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   14366:                     $newpos =~ s/\D+//g;
1.322     raeburn  14367:                     foreach my $item ('title','url','lifetime') {
1.267     raeburn  14368:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14369:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   14370:                             $changes{$itemid} = 1;
                   14371:                         }
                   14372:                     }
1.297     raeburn  14373:                     foreach my $item ('key','secret') {
                   14374:                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14375:                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   14376:                             $changes{$itemid} = 1;
                   14377:                         }
                   14378:                     }
1.267     raeburn  14379:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   14380:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   14381:                     }
                   14382:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   14383:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   14384:                     }
1.323     raeburn  14385:                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   14386:                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   14387:                     } else {
                   14388:                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1'; 
                   14389:                     }
                   14390:                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   14391:                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   14392:                             $changes{$itemid} = 1;
                   14393:                         }
                   14394:                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   14395:                         $changes{$itemid} = 1;
                   14396:                     }
1.267     raeburn  14397:                     foreach my $size ('width','height') {
                   14398:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   14399:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   14400:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   14401:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   14402:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14403:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   14404:                                     $changes{$itemid} = 1;
                   14405:                                 }
                   14406:                             } else {
                   14407:                                 $changes{$itemid} = 1;
                   14408:                             }
1.296     raeburn  14409:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14410:                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   14411:                                 $changes{$itemid} = 1;
                   14412:                             }
                   14413:                         }
                   14414:                     }
                   14415:                     foreach my $item ('linktext','explanation') {
                   14416:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   14417:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   14418:                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   14419:                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14420:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14421:                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   14422:                                     $changes{$itemid} = 1;
                   14423:                                 }
                   14424:                             } else {
                   14425:                                 $changes{$itemid} = 1;
                   14426:                             }
                   14427:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14428:                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   14429:                                 $changes{$itemid} = 1;
                   14430:                             }
1.267     raeburn  14431:                         }
                   14432:                     }
                   14433:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   14434:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298     raeburn  14435:                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   14436:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267     raeburn  14437:                     } else {
                   14438:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   14439:                     }
                   14440:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14441:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   14442:                             $changes{$itemid} = 1;
                   14443:                         }
                   14444:                     } else {
                   14445:                         $changes{$itemid} = 1;
                   14446:                     }
                   14447:                     foreach my $extra ('passback','roster') {
                   14448:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   14449:                             $confhash{$itemid}{$extra} = 1;
1.319     raeburn  14450:                             if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338     raeburn  14451:                                 my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319     raeburn  14452:                                 $lifetime =~ s/^\s+|\s+$//g;
                   14453:                                 if ($lifetime =~ /^\d+\.?\d*$/) {
                   14454:                                     $confhash{$itemid}{$extra.'valid'} = $lifetime;
                   14455:                                 }
                   14456:                             }
1.267     raeburn  14457:                         }
                   14458:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   14459:                             $changes{$itemid} = 1;
                   14460:                         }
1.319     raeburn  14461:                         if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
                   14462:                             $changes{$itemid} = 1;
                   14463:                         }
1.267     raeburn  14464:                     }
1.273     raeburn  14465:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318     raeburn  14466:                     foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  14467:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   14468:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   14469:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   14470:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   14471:                                     $changes{$itemid} = 1;
                   14472:                                 }
                   14473:                             } else {
                   14474:                                 $changes{$itemid} = 1;
                   14475:                             }
                   14476:                         }
                   14477:                     }
1.267     raeburn  14478:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   14479:                     foreach my $field (@fields) {
                   14480:                         if ($possfield{$field}) {
                   14481:                             if ($field eq 'roles') {
                   14482:                                 foreach my $role (@courseroles) {
                   14483:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   14484:                                     if (($choice ne '') && ($posslti{$choice})) {
                   14485:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   14486:                                         if ($role eq 'cc') {
                   14487:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   14488:                                         }
                   14489:                                     }
                   14490:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   14491:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   14492:                                             $changes{$itemid} = 1;
                   14493:                                         }
                   14494:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   14495:                                         $changes{$itemid} = 1;
                   14496:                                     }
                   14497:                                 }
                   14498:                             } else {
                   14499:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   14500:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   14501:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   14502:                                         $changes{$itemid} = 1;
                   14503:                                     }
                   14504:                                 } else {
                   14505:                                     $changes{$itemid} = 1;
                   14506:                                 }
                   14507:                             }
                   14508:                         }
                   14509:                     }
1.324     raeburn  14510:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   14511:                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   14512:                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   14513:                                 $confhash{$itemid}{'incdom'} = 1;
                   14514:                             }
                   14515:                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   14516:                                 $changes{$itemid} = 1;
                   14517:                             }
                   14518:                         }
                   14519:                     }
1.267     raeburn  14520:                     $allpos[$newpos] = $itemid;
                   14521:                 }
                   14522:                 if ($imgdeletions{$itemid}) {
                   14523:                     $changes{$itemid} = 1;
                   14524:                     #FIXME need to obsolete item in RES space
                   14525:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   14526:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   14527:                                                                  $itemid,$configuserok,$switchserver,
                   14528:                                                                  $author_ok);
                   14529:                     if ($imgurl) {
                   14530:                         $confhash{$itemid}{'image'} = $imgurl;
                   14531:                         $changes{$itemid} = 1;
                   14532:                     }
                   14533:                     if ($error) {
                   14534:                         &Apache::lonnet::logthis($error);
                   14535:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14536:                     }
                   14537:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   14538:                     $confhash{$itemid}{'image'} =
                   14539:                        $domconfig{$action}{$itemid}{'image'};
                   14540:                 }
                   14541:                 if ($customadds{$i}) {
                   14542:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   14543:                     $name =~ s/(`)/'/g;
                   14544:                     $name =~ s/^\s+//;
                   14545:                     $name =~ s/\s+$//;
                   14546:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   14547:                     $value =~ s/(`)/'/g;
                   14548:                     $value =~ s/^\s+//;
                   14549:                     $value =~ s/\s+$//;
                   14550:                     if ($name ne '') {
                   14551:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   14552:                         $changes{$itemid} = 1;
                   14553:                     }
                   14554:                 }
                   14555:                 my %customdels;
                   14556:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   14557:                 if (@customdeletions) {
                   14558:                     $changes{$itemid} = 1;
                   14559:                 }
                   14560:                 map { $customdels{$_} = 1; } @customdeletions;
                   14561:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   14562:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   14563:                         unless ($customdels{$key}) {
                   14564:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   14565:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   14566:                             }
                   14567:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   14568:                                 $changes{$itemid} = 1;
                   14569:                             }
                   14570:                         }
                   14571:                     }
                   14572:                 }
                   14573:                 unless ($changes{$itemid}) {
                   14574:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   14575:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   14576:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   14577:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   14578:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   14579:                                         $changes{$itemid} = 1;
                   14580:                                         last;
                   14581:                                     }
                   14582:                                 }
                   14583:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   14584:                                 $changes{$itemid} = 1;
                   14585:                             }
                   14586:                         }
                   14587:                         last if ($changes{$itemid});
                   14588:                     }
                   14589:                 }
                   14590:             }
                   14591:         }
                   14592:     }
                   14593:     if (@allpos > 0) {
                   14594:         my $idx = 0;
                   14595:         foreach my $itemid (@allpos) {
                   14596:             if ($itemid ne '') {
                   14597:                 $confhash{$itemid}{'order'} = $idx;
                   14598:                 if (ref($domconfig{$action}) eq 'HASH') {
                   14599:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   14600:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   14601:                             $changes{$itemid} = 1;
                   14602:                         }
                   14603:                     }
                   14604:                 }
                   14605:                 $idx ++;
                   14606:             }
                   14607:         }
                   14608:     }
                   14609:     my %ltitoolshash = (
                   14610:                           $action => { %confhash }
                   14611:                        );
                   14612:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   14613:                                              $dom);
                   14614:     if ($putresult eq 'ok') {
1.297     raeburn  14615:         my %ltienchash = (
                   14616:                              $action => { %encconfig }
                   14617:                          );
1.384     raeburn  14618:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267     raeburn  14619:         if (keys(%changes) > 0) {
                   14620:             my $cachetime = 24*60*60;
1.297     raeburn  14621:             my %ltiall = %confhash;
                   14622:             foreach my $id (keys(%ltiall)) {
                   14623:                 if (ref($encconfig{$id}) eq 'HASH') {
                   14624:                     foreach my $item ('key','secret') {
                   14625:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   14626:                     }
                   14627:                 }
                   14628:             }
                   14629:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267     raeburn  14630:             if (ref($lastactref) eq 'HASH') {
                   14631:                 $lastactref->{'ltitools'} = 1;
                   14632:             }
                   14633:             $resulttext = &mt('Changes made:').'<ul>';
                   14634:             my %bynum;
                   14635:             foreach my $itemid (sort(keys(%changes))) {
                   14636:                 my $position = $confhash{$itemid}{'order'};
                   14637:                 $bynum{$position} = $itemid;
                   14638:             }
                   14639:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   14640:                 my $itemid = $bynum{$pos}; 
                   14641:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   14642:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   14643:                 } else {
                   14644:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   14645:                     if ($confhash{$itemid}{'image'}) {
                   14646:                         $resulttext .= '&nbsp;'.
                   14647:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   14648:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   14649:                     }
                   14650:                     $resulttext .= '</li><ul>';
                   14651:                     my $position = $pos + 1;
                   14652:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323     raeburn  14653:                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267     raeburn  14654:                         if ($confhash{$itemid}{$item} ne '') {
                   14655:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   14656:                         }
                   14657:                     }
1.297     raeburn  14658:                     if ($encconfig{$itemid}{'key'} ne '') {
                   14659:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   14660:                     }
                   14661:                     if ($encconfig{$itemid}{'secret'} ne '') {
1.267     raeburn  14662:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
1.297     raeburn  14663:                         my $num = length($encconfig{$itemid}{'secret'});
1.267     raeburn  14664:                         $resulttext .= ('*'x$num).'</li>';
                   14665:                     }
1.273     raeburn  14666:                     $resulttext .= '<li>'.&mt('Configurable in course:');
1.318     raeburn  14667:                     my @possconfig = ('label','title','target','linktext','explanation','append');
1.273     raeburn  14668:                     my $numconfig = 0; 
                   14669:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   14670:                         foreach my $item (@possconfig) {
                   14671:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   14672:                                 $numconfig ++;
1.296     raeburn  14673:                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273     raeburn  14674:                             }
                   14675:                         }
                   14676:                     }
                   14677:                     if (!$numconfig) {
1.372     raeburn  14678:                         $resulttext .= '&nbsp;'.&mt('None');
1.273     raeburn  14679:                     }
                   14680:                     $resulttext .= '</li>';
1.267     raeburn  14681:                     foreach my $item ('passback','roster') {
                   14682:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   14683:                         if ($confhash{$itemid}{$item}) {
                   14684:                             $resulttext .= &mt('Yes');
1.319     raeburn  14685:                             if ($confhash{$itemid}{$item.'valid'}) {
                   14686:                                 if ($item eq 'passback') {
                   14687:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
                   14688:                                                            $confhash{$itemid}{$item.'valid'});
                   14689:                                 } else {
                   14690:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
                   14691:                                                            $confhash{$itemid}{$item.'valid'});
                   14692:                                 }
                   14693:                             }
1.267     raeburn  14694:                         } else {
                   14695:                             $resulttext .= &mt('No');
                   14696:                         }
                   14697:                         $resulttext .= '</li>';
                   14698:                     }
                   14699:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   14700:                         my $displaylist;
                   14701:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   14702:                             $displaylist = &mt('Display target').':&nbsp;'.
                   14703:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   14704:                         }
                   14705:                         foreach my $size ('width','height') { 
                   14706:                             if ($confhash{$itemid}{'display'}{$size}) {
                   14707:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   14708:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   14709:                             }
                   14710:                         }
                   14711:                         if ($displaylist) {
                   14712:                             $displaylist =~ s/,$//;
                   14713:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   14714:                         }
1.296     raeburn  14715:                         foreach my $item ('linktext','explanation') {
                   14716:                             if ($confhash{$itemid}{'display'}{$item}) {
                   14717:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   14718:                             }
                   14719:                         }
                   14720:                     }
1.267     raeburn  14721:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   14722:                         my $fieldlist;
                   14723:                         foreach my $field (@allfields) {
                   14724:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   14725:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   14726:                             }
                   14727:                         }
                   14728:                         if ($fieldlist) {
                   14729:                             $fieldlist =~ s/,$//;
1.324     raeburn  14730:                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   14731:                                 if ($confhash{$itemid}{'incdom'}) {
                   14732:                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   14733:                                 } else {
                   14734:                                     $fieldlist .= ' ('.&mt('username').')';
                   14735:                                 }
                   14736:                             }
1.267     raeburn  14737:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   14738:                         }
                   14739:                     }
                   14740:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   14741:                         my $rolemaps;
                   14742:                         foreach my $role (@courseroles) {
                   14743:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   14744:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   14745:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   14746:                             }
                   14747:                         }
                   14748:                         if ($rolemaps) {
                   14749:                             $rolemaps =~ s/,$//; 
                   14750:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   14751:                         }
                   14752:                     }
                   14753:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   14754:                         my $customlist;
                   14755:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   14756:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   14757:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   14758:                             } 
                   14759:                         }
                   14760:                         if ($customlist) {
1.317     raeburn  14761:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267     raeburn  14762:                         }
                   14763:                     } 
                   14764:                     $resulttext .= '</ul></li>';
                   14765:                 }
                   14766:             }
                   14767:             $resulttext .= '</ul>';
                   14768:         } else {
                   14769:             $resulttext = &mt('No changes made.');
                   14770:         }
                   14771:     } else {
                   14772:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   14773:     }
                   14774:     if ($errors) {
                   14775:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   14776:                        $errors.'</ul>';
                   14777:     }
                   14778:     return $resulttext;
                   14779: }
                   14780: 
                   14781: sub process_ltitools_image {
                   14782:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   14783:     my $filename = $env{'form.'.$caller.'.filename'};
                   14784:     my ($error,$url);
                   14785:     my ($width,$height) = (21,21);
                   14786:     if ($configuserok eq 'ok') {
                   14787:         if ($switchserver) {
                   14788:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   14789:                          $switchserver);
                   14790:         } elsif ($author_ok eq 'ok') {
                   14791:             my ($result,$imageurl,$madethumb) =
                   14792:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   14793:                              "ltitools/$itemid/icon",$width,$height);
                   14794:             if ($result eq 'ok') {
                   14795:                 if ($madethumb) {
                   14796:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   14797:                     my $imagethumb = "$path/tn-".$imagefile;
                   14798:                     $url = $imagethumb;
                   14799:                 } else {
                   14800:                     $url = $imageurl;
                   14801:                 }
                   14802:             } else {
                   14803:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14804:             }
                   14805:         } else {
                   14806:             $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);
                   14807:         }
                   14808:     } else {
                   14809:         $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);
                   14810:     }
                   14811:     return ($url,$error);
                   14812: }
                   14813: 
                   14814: sub get_ltitools_id {
                   14815:     my ($cdom,$title) = @_;
                   14816:     # get lock on ltitools db
                   14817:     my $lockhash = {
                   14818:                       lock => $env{'user.name'}.
                   14819:                               ':'.$env{'user.domain'},
                   14820:                    };
                   14821:     my $tries = 0;
                   14822:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   14823:     my ($id,$error);
                   14824:  
                   14825:     while (($gotlock ne 'ok') && ($tries<10)) {
                   14826:         $tries ++;
                   14827:         sleep (0.1);
                   14828:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   14829:     }
                   14830:     if ($gotlock eq 'ok') {
                   14831:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   14832:         if ($currids{'lock'}) {
                   14833:             delete($currids{'lock'});
                   14834:             if (keys(%currids)) {
                   14835:                 my @curr = sort { $a <=> $b } keys(%currids);
                   14836:                 if ($curr[-1] =~ /^\d+$/) {
                   14837:                     $id = 1 + $curr[-1];
                   14838:                 }
                   14839:             } else {
                   14840:                 $id = 1;
                   14841:             }
                   14842:             if ($id) {
                   14843:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   14844:                     $error = 'nostore';
                   14845:                 }
                   14846:             } else {
                   14847:                 $error = 'nonumber';
                   14848:             }
                   14849:         }
                   14850:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   14851:     } else {
                   14852:         $error = 'nolock';
                   14853:     }
                   14854:     return ($id,$error);
                   14855: }
                   14856: 
1.372     raeburn  14857: sub modify_proctoring {
                   14858:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   14859:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14860:     my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
                   14861:     my $confname = $dom.'-domainconfig';
                   14862:     my $servadm = $r->dir_config('lonAdmEMail');
                   14863:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   14864:     my %providernames = &proctoring_providernames();
                   14865:     my $maxnum = scalar(keys(%providernames));
                   14866: 
                   14867:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   14868:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   14869:     if (ref($requref) eq 'HASH') {
                   14870:         %requserfields = %{$requref};
                   14871:     }
                   14872:     if (ref($opturef) eq 'HASH') {
                   14873:         %optuserfields = %{$opturef};
                   14874:     }
                   14875:     if (ref($defref) eq 'HASH') {
                   14876:         %defaults = %{$defref};
                   14877:     }
                   14878:     if (ref($extref) eq 'HASH') {
                   14879:         %extended = %{$extref};
                   14880:     }
                   14881:     if (ref($crsref) eq 'HASH') {
                   14882:         %crsconf = %{$crsref};
                   14883:     }
                   14884:     if (ref($rolesref) eq 'ARRAY') {
                   14885:         @courseroles = @{$rolesref};
                   14886:     }
                   14887:     if (ref($ltiref) eq 'ARRAY') {
                   14888:         @ltiroles = @{$ltiref};
                   14889:     }
                   14890: 
                   14891:     if (ref($domconfig{$action}) eq 'HASH') {
                   14892:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
                   14893:         if (@todeleteimages) {
                   14894:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14895:         }
                   14896:     }
                   14897:     my %customadds;
                   14898:     my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
                   14899:     if (@newcustom) {
                   14900:         map { $customadds{$_} = 1; } @newcustom;
                   14901:     }
                   14902:     foreach my $provider (sort(keys(%providernames))) {
                   14903:         $confhash{$provider} = {};
                   14904:         my $pos = $env{'form.proctoring_pos_'.$provider};
                   14905:         $pos =~ s/\D+//g;
                   14906:         $allpos[$pos] = $provider;
                   14907:         my (%current,%currentenc);
                   14908:         my $showroles = 0;
                   14909:         if (ref($domconfig{$action}) eq 'HASH') {
                   14910:             if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   14911:                 %current = %{$domconfig{$action}{$provider}};
                   14912:                 foreach my $item ('key','secret') { 
                   14913:                     $currentenc{$item} = $current{$item};
                   14914:                     delete($current{$item});
                   14915:                 }
                   14916:             }
                   14917:         }
                   14918:         if ($env{'form.proctoring_available_'.$provider}) {
                   14919:             $confhash{$provider}{'available'} = 1;
                   14920:             unless ($current{'available'}) {
                   14921:                 $changes{$provider} = 1;
                   14922:             }
                   14923:         } else {
                   14924:             %{$confhash{$provider}} = %current;
                   14925:             %{$encconfhash{$provider}} = %currentenc;
                   14926:             $confhash{$provider}{'available'} = 0;
                   14927:             if ($current{'available'}) {
                   14928:                 $changes{$provider} = 1;
                   14929:             }
                   14930:         }
                   14931:         if ($confhash{$provider}{'available'}) {
                   14932:             foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
                   14933:                 my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
                   14934:                 if ($field eq 'lifetime') {
                   14935:                     if ($possval =~ /^\d+$/) {
                   14936:                         $confhash{$provider}{$field} = $possval;
                   14937:                     }
                   14938:                 } elsif ($field eq 'version') {
                   14939:                     if ($possval =~ /^\d+\.\d+$/) {
                   14940:                         $confhash{$provider}{$field} = $possval;
                   14941:                     }
                   14942:                 } elsif ($field eq 'sigmethod') {
                   14943:                     if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
                   14944:                         $confhash{$provider}{$field} = $possval;
                   14945:                     }
                   14946:                 } elsif ($field eq 'url') {
                   14947:                     $confhash{$provider}{$field} = $possval;
                   14948:                 } elsif (($field eq 'key') || ($field eq 'secret')) {
                   14949:                     $encconfhash{$provider}{$field} = $possval;
                   14950:                     unless ($currentenc{$field} eq $possval) {
                   14951:                         $changes{$provider} = 1;
                   14952:                     }
                   14953:                 }
                   14954:                 unless (($field eq 'key') || ($field eq 'secret')) {
                   14955:                     unless ($current{$field} eq $confhash{$provider}{$field}) {
                   14956:                         $changes{$provider} = 1;
                   14957:                     }
                   14958:                 }
                   14959:             }
                   14960:             if ($imgdeletions{$provider}) {
                   14961:                 $changes{$provider} = 1;
                   14962:             } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
                   14963:                 my ($imageurl,$error) =
                   14964:                     &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
                   14965:                                               $configuserok,$switchserver,$author_ok);
                   14966:                 if ($imageurl) {
                   14967:                     $confhash{$provider}{'image'} = $imageurl;
                   14968:                     $changes{$provider} = 1; 
                   14969:                 }
                   14970:                 if ($error) {
                   14971:                     &Apache::lonnet::logthis($error);
                   14972:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14973:                 }
                   14974:             } elsif (exists($current{'image'})) {
                   14975:                 $confhash{$provider}{'image'} = $current{'image'};
                   14976:             }
                   14977:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   14978:                 if (@{$requserfields{$provider}} > 0) {
                   14979:                     if (grep(/^user$/,@{$requserfields{$provider}})) {
                   14980:                         if ($env{'form.proctoring_userincdom_'.$provider}) {
                   14981:                             $confhash{$provider}{'incdom'} = 1;
                   14982:                         }
                   14983:                         unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
                   14984:                             $changes{$provider} = 1;
                   14985:                         }
                   14986:                     }
                   14987:                     if (grep(/^roles$/,@{$requserfields{$provider}})) {
                   14988:                         $showroles = 1;
                   14989:                     }
                   14990:                 }
                   14991:             }
                   14992:             $confhash{$provider}{'fields'} = [];
                   14993:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   14994:                 if (@{$optuserfields{$provider}} > 0) {
                   14995:                     my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
                   14996:                     foreach my $field (@{$optuserfields{$provider}}) {
                   14997:                         if (grep(/^\Q$field\E$/,@optfields)) {
                   14998:                             push(@{$confhash{$provider}{'fields'}},$field);
                   14999:                         }
                   15000:                     }
                   15001:                 }
                   15002:                 if (ref($current{'fields'}) eq 'ARRAY') {
                   15003:                     unless ($changes{$provider}) {
                   15004:                         my @new = sort(@{$confhash{$provider}{'fields'}});
                   15005:                         my @old = sort(@{$current{'fields'}}); 
                   15006:                         my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15007:                         if (@diffs) {
                   15008:                             $changes{$provider} = 1;
                   15009:                         }
                   15010:                     }
                   15011:                 } elsif (@{$confhash{$provider}{'fields'}}) {
                   15012:                     $changes{$provider} = 1;
                   15013:                 }
                   15014:             }
                   15015:             if (ref($defaults{$provider}) eq 'ARRAY') {  
                   15016:                 if (@{$defaults{$provider}} > 0) {
                   15017:                     my %options;
                   15018:                     if (ref($extended{$provider}) eq 'HASH') {
                   15019:                         %options = %{$extended{$provider}};
                   15020:                     }
                   15021:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
                   15022:                     foreach my $field (@{$defaults{$provider}}) {
                   15023:                         if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   15024:                             my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
                   15025:                             if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
                   15026:                                 push(@{$confhash{$provider}{'defaults'}},$poss); 
                   15027:                             }
                   15028:                         } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
                   15029:                             foreach my $inner (keys(%{$options{$field}})) {
                   15030:                                 if (ref($options{$field}{$inner}) eq 'ARRAY') {
                   15031:                                     my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15032:                                     if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
                   15033:                                         $confhash{$provider}{'defaults'}{$inner} = $poss;
                   15034:                                     }
                   15035:                                 } else {
                   15036:                                     $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15037:                                 }
                   15038:                             }
                   15039:                         } else {
                   15040:                             if (grep(/^\Q$field\E$/,@checked)) {
                   15041:                                 push(@{$confhash{$provider}{'defaults'}},$field);
                   15042:                             }
                   15043:                         }
                   15044:                     }
                   15045:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15046:                         if (ref($current{'defaults'}) eq 'ARRAY') {
                   15047:                             unless ($changes{$provider}) {
                   15048:                                 my @new = sort(@{$confhash{$provider}{'defaults'}});
                   15049:                                 my @old = sort(@{$current{'defaults'}});
                   15050:                                 my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15051:                                 if (@diffs) {
                   15052:                                     $changes{$provider} = 1; 
                   15053:                                 }
                   15054:                             }
                   15055:                         } elsif (ref($current{'defaults'}) eq 'ARRAY') {
                   15056:                             if (@{$current{'defaults'}}) {
                   15057:                                 $changes{$provider} = 1;
                   15058:                             }
                   15059:                         }
                   15060:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15061:                         if (ref($current{'defaults'}) eq 'HASH') {
                   15062:                             unless ($changes{$provider}) {
                   15063:                                 foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
                   15064:                                     unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
                   15065:                                         $changes{$provider} = 1;
                   15066:                                         last;
                   15067:                                     }
                   15068:                                 }
                   15069:                             }
                   15070:                             unless ($changes{$provider}) {
                   15071:                                 foreach my $key (keys(%{$current{'defaults'}})) {
                   15072:                                     unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
                   15073:                                         $changes{$provider} = 1;
                   15074:                                         last;
                   15075:                                     }
                   15076:                                 }
                   15077:                             }
                   15078:                         } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
                   15079:                             $changes{$provider} = 1;
                   15080:                         }
                   15081:                     }
                   15082:                 }
                   15083:             }
                   15084:             if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15085:                 if (@{$crsconf{$provider}} > 0) {
                   15086:                     $confhash{$provider}{'crsconf'} = [];
                   15087:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
                   15088:                     foreach my $crsfield (@{$crsconf{$provider}}) {
                   15089:                         if (grep(/^\Q$crsfield\E$/,@checked)) {
                   15090:                             push(@{$confhash{$provider}{'crsconf'}},$crsfield);
                   15091:                         }
                   15092:                     }
                   15093:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   15094:                         unless ($changes{$provider}) {  
                   15095:                             my @new = sort(@{$confhash{$provider}{'crsconf'}});
                   15096:                             my @old = sort(@{$current{'crsconf'}});
                   15097:                             my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15098:                             if (@diffs) {
                   15099:                                 $changes{$provider} = 1;
                   15100:                             }
                   15101:                         }
                   15102:                     } elsif (@{$confhash{$provider}{'crsconf'}}) {
                   15103:                         $changes{$provider} = 1;
                   15104:                     }
                   15105:                 }
                   15106:             }
                   15107:             if ($showroles) {
                   15108:                 $confhash{$provider}{'roles'} = {};
                   15109:                 foreach my $role (@courseroles) {
                   15110:                     my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
                   15111:                     if (grep(/^\Q$poss\E$/,@ltiroles)) {
                   15112:                         $confhash{$provider}{'roles'}{$role} = $poss;
                   15113:                     }
                   15114:                 }
                   15115:                 unless ($changes{$provider}) {
                   15116:                     if (ref($current{'roles'}) eq 'HASH') {
                   15117:                         foreach my $role (keys(%{$current{'roles'}})) {
                   15118:                             unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
                   15119:                                 $changes{$provider} = 1;
                   15120:                                 last
                   15121:                             }
                   15122:                         }
                   15123:                         unless ($changes{$provider}) {
                   15124:                             foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
                   15125:                                 unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
                   15126:                                     $changes{$provider} = 1;
                   15127:                                     last;
                   15128:                                 }
                   15129:                             }
                   15130:                         }
                   15131:                     } elsif (keys(%{$confhash{$provider}{'roles'}})) {
                   15132:                         $changes{$provider} = 1;
                   15133:                     }
                   15134:                 }
                   15135:             }
                   15136:             if (ref($current{'custom'}) eq 'HASH') {
                   15137:                 my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
                   15138:                 foreach my $key (keys(%{$current{'custom'}})) {
                   15139:                     if (grep(/^\Q$key\E$/,@customdels)) {
                   15140:                         $changes{$provider} = 1;
                   15141:                     } else {
                   15142:                         $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
                   15143:                         if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
                   15144:                             $changes{$provider} = 1;
                   15145:                         }
                   15146:                     }
                   15147:                 }
                   15148:             }
                   15149:             if ($customadds{$provider}) {
                   15150:                 my $name = $env{'form.proctoring_custom_name_'.$provider};
                   15151:                 $name =~ s/(`)/'/g;
                   15152:                 $name =~ s/^\s+//;
                   15153:                 $name =~ s/\s+$//;
                   15154:                 my $value = $env{'form.proctoring_custom_value_'.$provider};
                   15155:                 $value =~ s/(`)/'/g;
                   15156:                 $value =~ s/^\s+//;
                   15157:                 $value =~ s/\s+$//;
                   15158:                 if ($name ne '') {
                   15159:                     $confhash{$provider}{'custom'}{$name} = $value;
                   15160:                     $changes{$provider} = 1;
                   15161:                 }
                   15162:             }
                   15163:         }
                   15164:     }
                   15165:     if (@allpos > 0) {
                   15166:         my $idx = 0;
                   15167:         foreach my $provider (@allpos) {
                   15168:             if ($provider ne '') {
                   15169:                 $confhash{$provider}{'order'} = $idx;
                   15170:                 unless ($changes{$provider}) {
                   15171:                     if (ref($domconfig{$action}) eq 'HASH') {
                   15172:                         if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   15173:                             if ($domconfig{$action}{$provider}{'order'} ne $idx) {
                   15174:                                 $changes{$provider} = 1;
                   15175:                             }
                   15176:                         }
                   15177:                     }
                   15178:                 }
                   15179:                 $idx ++;
                   15180:             }
                   15181:         }
                   15182:     }
                   15183:     my %proc_hash = (
                   15184:                           $action => { %confhash }
                   15185:                        );
                   15186:     my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
                   15187:                                              $dom);
                   15188:     if ($putresult eq 'ok') {
                   15189:         my %proc_enchash = (
                   15190:                              $action => { %encconfhash }
                   15191:                          );
1.384     raeburn  15192:         &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372     raeburn  15193:         if (keys(%changes) > 0) {
                   15194:             my $cachetime = 24*60*60;
                   15195:             my %procall = %confhash;
                   15196:             foreach my $provider (keys(%procall)) {
                   15197:                 if (ref($encconfhash{$provider}) eq 'HASH') {
                   15198:                     foreach my $key ('key','secret') {
                   15199:                         $procall{$provider}{$key} = $encconfhash{$provider}{$key};
                   15200:                     }
                   15201:                 }
                   15202:             }
                   15203:             &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
                   15204:             if (ref($lastactref) eq 'HASH') {
                   15205:                 $lastactref->{'proctoring'} = 1;
                   15206:             }
                   15207:             $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
                   15208:             my %bynum;
                   15209:             foreach my $provider (sort(keys(%changes))) {
                   15210:                 my $position = $confhash{$provider}{'order'};
                   15211:                 $bynum{$position} = $provider;
                   15212:             }
                   15213:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15214:                 my $provider = $bynum{$pos};
                   15215:                 my %lt = &proctoring_titles($provider);
                   15216:                 my %fieldtitles = &proctoring_fieldtitles($provider);
                   15217:                 if (!$confhash{$provider}{'available'}) {
                   15218:                     $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
                   15219:                 } else {
                   15220:                     $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
                   15221:                     if ($confhash{$provider}{'image'}) {
                   15222:                         $resulttext .= '&nbsp;'.
                   15223:                                        '<img src="'.$confhash{$provider}{'image'}.'"'.
                   15224:                                        ' alt="'.&mt('Proctoring icon').'" />';
                   15225:                     }
                   15226:                     $resulttext .= '<ul>';
                   15227:                     my $position = $pos + 1;
                   15228:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15229:                     foreach my $key ('version','sigmethod','url','lifetime') {
                   15230:                         if ($confhash{$provider}{$key} ne '') {
                   15231:                             $resulttext .= '<li>'.$lt{$key}.':&nbsp;'.$confhash{$provider}{$key}.'</li>';
                   15232:                         }
                   15233:                     }
                   15234:                     if ($encconfhash{$provider}{'key'} ne '') {
                   15235:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfhash{$provider}{'key'}.'</li>';
                   15236:                     }
                   15237:                     if ($encconfhash{$provider}{'secret'} ne '') {
                   15238:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15239:                         my $num = length($encconfhash{$provider}{'secret'});
                   15240:                         $resulttext .= ('*'x$num).'</li>';
                   15241:                     }
                   15242:                     my (@fields,$showroles);
                   15243:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15244:                         push(@fields,@{$requserfields{$provider}});
                   15245:                     }
                   15246:                     if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
                   15247:                         push(@fields,@{$confhash{$provider}{'fields'}});
                   15248:                     } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
                   15249:                         push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
                   15250:                     }
                   15251:                     if (@fields) {
                   15252:                         if (grep(/^roles$/,@fields)) {
                   15253:                             $showroles = 1;
                   15254:                         }
                   15255:                         $resulttext .= '<li>'.$lt{'udsl'}.':&nbsp;"'.
                   15256:                                        join('", "', map { $lt{$_}; } @fields).'"</li>';
                   15257:                     }
                   15258:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15259:                         if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15260:                             if ($confhash{$provider}{'incdom'}) {
                   15261:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
                   15262:                             } else { 
                   15263:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
                   15264:                             }
                   15265:                         }
                   15266:                     }
                   15267:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15268:                         if (@{$confhash{$provider}{'defaults'}} > 0) {
                   15269:                             $resulttext .= '<li>'.$lt{'defa'};
                   15270:                             foreach my $field (@{$confhash{$provider}{'defaults'}}) {
                   15271:                                 $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15272:                             }
                   15273:                             $resulttext =~ s/,$//;
                   15274:                             $resulttext .= '</li>';
                   15275:                         }
                   15276:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15277:                         if (keys(%{$confhash{$provider}{'defaults'}})) {
                   15278:                             $resulttext .= '<li>'.$lt{'defa'}.':&nbsp;<ul>';
                   15279:                             foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
                   15280:                                 if ($confhash{$provider}{'defaults'}{$key} ne '') {
                   15281:                                     $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
                   15282:                                 }
                   15283:                             }
                   15284:                             $resulttext .= '</ul></li>';
                   15285:                         }
                   15286:                     }
                   15287:                     if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15288:                         if (@{$crsconf{$provider}} > 0) {
                   15289:                             $resulttext .= '<li>'.&mt('Configurable in course:');
                   15290:                             my $numconfig = 0;
                   15291:                             if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
                   15292:                                 if (@{$confhash{$provider}{'crsconf'}} > 0) {
                   15293:                                     foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
                   15294:                                         $numconfig ++;
                   15295:                                         if ($provider eq 'examity') {
                   15296:                                             $resulttext .= ' "'.$lt{'crs'.$field}.'",';
                   15297:                                         } else {
                   15298:                                             $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15299:                                         }
                   15300:                                     }
                   15301:                                     $resulttext =~ s/,$//;
                   15302:                                 }
                   15303:                             }
                   15304:                             if (!$numconfig) {
                   15305:                                 $resulttext .= '&nbsp;'.&mt('None');
                   15306:                             }
                   15307:                             $resulttext .= '</li>';
                   15308:                         }
                   15309:                     }
                   15310:                     if ($showroles) {
                   15311:                         if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
                   15312:                             my $rolemaps;
                   15313:                             foreach my $role (@courseroles) {
                   15314:                                 if ($confhash{$provider}{'roles'}{$role}) {
                   15315:                                     $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   15316:                                                  $confhash{$provider}{'roles'}{$role}.',';
                   15317:                                 }
                   15318:                             }
                   15319:                             if ($rolemaps) {
                   15320:                                 $rolemaps =~ s/,$//;
                   15321:                                 $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15322:                             }
                   15323:                         }
                   15324:                     }
                   15325:                     if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
                   15326:                         my $customlist;
                   15327:                         if (keys(%{$confhash{$provider}{'custom'}})) {
                   15328:                             foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
                   15329:                                 $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
                   15330:                             }
                   15331:                             $customlist =~ s/,$//;
                   15332:                         }
                   15333:                         if ($customlist) {
                   15334:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
                   15335:                         }
                   15336:                     } 
                   15337:                     $resulttext .= '</ul></li>';
                   15338:                 }
                   15339:             }
                   15340:             $resulttext .= '</ul>';
                   15341:         } else {
                   15342:             $resulttext = &mt('No changes made.');
                   15343:         }
                   15344:     } else {
                   15345:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15346:     }
                   15347:     if ($errors) {
                   15348:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15349:                        $errors.'</ul>';
                   15350:     }
                   15351:     return $resulttext;
                   15352: }
                   15353: 
                   15354: sub process_proctoring_image {
                   15355:     my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
                   15356:     my $filename = $env{'form.'.$caller.'.filename'};
                   15357:     my ($error,$url);
                   15358:     my ($width,$height) = (21,21);
                   15359:     if ($configuserok eq 'ok') {
                   15360:         if ($switchserver) {
                   15361:             $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
                   15362:                          $switchserver);
                   15363:         } elsif ($author_ok eq 'ok') {
                   15364:             my ($result,$imageurl,$madethumb) =
                   15365:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   15366:                              "proctoring/$provider/icon",$width,$height);
                   15367:             if ($result eq 'ok') {
                   15368:                 if ($madethumb) {
                   15369:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   15370:                     my $imagethumb = "$path/tn-".$imagefile;
                   15371:                     $url = $imagethumb;
                   15372:                 } else {
                   15373:                     $url = $imageurl;
                   15374:                 }
                   15375:             } else {
                   15376:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   15377:             }
                   15378:         } else {
                   15379:             $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);
                   15380:         }
                   15381:     } else {
                   15382:         $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);
                   15383:     }
                   15384:     return ($url,$error);
                   15385: }
                   15386: 
1.320     raeburn  15387: sub modify_lti {
                   15388:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   15389:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15390:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   15391:     my (%posslti,%posslticrs,%posscrstype);
                   15392:     my @courseroles = ('cc','in','ta','ep','st');
                   15393:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   15394:     my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392     raeburn  15395:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  15396:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   15397:                                official   => 'Official',
                   15398:                                unofficial => 'Unofficial',
                   15399:                                community  => 'Community',
                   15400:                                textbook   => 'Textbook',
                   15401:                                placement  => 'Placement Test',
1.392     raeburn  15402:                                lti        => 'LTI Provider',
1.320     raeburn  15403:     );
1.325     raeburn  15404:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320     raeburn  15405:     my %lt = &lti_names();
                   15406:     map { $posslti{$_} = 1; } @ltiroles;
                   15407:     map { $posslticrs{$_} = 1; } @lticourseroles;
                   15408:     map { $posscrstype{$_} = 1; } @coursetypes;
1.325     raeburn  15409: 
1.326     raeburn  15410:     my %menutitles = &ltimenu_titles();
                   15411: 
1.320     raeburn  15412:     my (@items,%deletions,%itemids);
                   15413:     if ($env{'form.lti_add'}) {
                   15414:         my $consumer = $env{'form.lti_consumer_add'};
                   15415:         $consumer =~ s/(`)/'/g;
                   15416:         ($newid,my $error) = &get_lti_id($dom,$consumer);
                   15417:         if ($newid) {
                   15418:             $itemids{'add'} = $newid;
                   15419:             push(@items,'add');
                   15420:             $changes{$newid} = 1;
                   15421:         } else {
                   15422:             my $error = &mt('Failed to acquire unique ID for new LTI configuration');
                   15423:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15424:         }
                   15425:     }
                   15426:     if (ref($domconfig{$action}) eq 'HASH') {
                   15427:         my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
                   15428:         if (@todelete) {
                   15429:             map { $deletions{$_} = 1; } @todelete;
                   15430:         }
                   15431:         my $maxnum = $env{'form.lti_maxnum'};
1.390     raeburn  15432:         for (my $i=0; $i<$maxnum; $i++) {
1.320     raeburn  15433:             my $itemid = $env{'form.lti_id_'.$i};
                   15434:             $itemid =~ s/\D+//g;
                   15435:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15436:                 if ($deletions{$itemid}) {
                   15437:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
                   15438:                 } else {
1.390     raeburn  15439:                     push(@items,$i);
                   15440:                     $itemids{$i} = $itemid;
1.320     raeburn  15441:                 }
                   15442:             }
                   15443:         }
                   15444:     }
                   15445:     foreach my $idx (@items) {
                   15446:         my $itemid = $itemids{$idx};
                   15447:         next unless ($itemid);
1.390     raeburn  15448:         my $position = $env{'form.lti_pos_'.$itemid};
1.320     raeburn  15449:         $position =~ s/\D+//g;
                   15450:         if ($position ne '') {
                   15451:             $allpos[$position] = $itemid;
                   15452:         }
1.391     raeburn  15453:         foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320     raeburn  15454:             my $formitem = 'form.lti_'.$item.'_'.$idx;
                   15455:             $env{$formitem} =~ s/(`)/'/g;
                   15456:             if ($item eq 'lifetime') {
                   15457:                 $env{$formitem} =~ s/[^\d.]//g;
                   15458:             }
                   15459:             if ($env{$formitem} ne '') {
                   15460:                 if (($item eq 'key') || ($item eq 'secret')) {
                   15461:                     $encconfig{$itemid}{$item} = $env{$formitem};
                   15462:                 } else {
                   15463:                     $confhash{$itemid}{$item} = $env{$formitem};
                   15464:                     unless (($idx eq 'add') || ($changes{$itemid})) {
                   15465:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   15466:                             $changes{$itemid} = 1;
                   15467:                         }
                   15468:                     }
                   15469:                 }
                   15470:             }
                   15471:         }
                   15472:         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
                   15473:             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
                   15474:         }
1.345     raeburn  15475:         if ($confhash{$itemid}{'requser'}) {
                   15476:             if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
                   15477:                 $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid'; 
                   15478:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
                   15479:                 $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
                   15480:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
                   15481:                 my $mapuser = $env{'form.lti_customuser_'.$idx};
                   15482:                 $mapuser =~ s/(`)/'/g;
                   15483:                 $mapuser =~ s/^\s+|\s+$//g; 
                   15484:                 $confhash{$itemid}{'mapuser'} = $mapuser; 
                   15485:             }
                   15486:             my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
                   15487:             my @makeuser;
                   15488:             foreach my $ltirole (sort(@possmakeuser)) {
                   15489:                 if ($posslti{$ltirole}) {
                   15490:                     push(@makeuser,$ltirole);
                   15491:                 }
                   15492:             }
                   15493:             $confhash{$itemid}{'makeuser'} = \@makeuser;
                   15494:             if (@makeuser) {
                   15495:                 my $lcauth = $env{'form.lti_lcauth_'.$idx};
                   15496:                 if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
                   15497:                     $confhash{$itemid}{'lcauth'} = $lcauth;
                   15498:                     if ($lcauth ne 'internal') {
                   15499:                         my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
                   15500:                         $lcauthparm =~ s/^(\s+|\s+)$//g;
                   15501:                         $lcauthparm =~ s/`//g;
                   15502:                         if ($lcauthparm ne '') {
                   15503:                             $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
                   15504:                         }
                   15505:                     }
                   15506:                 } else {
                   15507:                     $confhash{$itemid}{'lcauth'} = 'lti';
                   15508:                 }
1.320     raeburn  15509:             }
1.345     raeburn  15510:             my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
                   15511:             if (@possinstdata) {
                   15512:                 foreach my $field (@possinstdata) {
                   15513:                     if (exists($fieldtitles{$field})) {
                   15514:                         push(@{$confhash{$itemid}{'instdata'}});
1.325     raeburn  15515:                     }
                   15516:                 }
                   15517:             }
1.363     raeburn  15518:             if ($env{'form.lti_callback_'.$idx}) {
                   15519:                 if ($env{'form.lti_callbackparam_'.$idx}) {
                   15520:                     my $callback = $env{'form.lti_callbackparam_'.$idx};
                   15521:                     $callback =~ s/^\s+|\s+$//g;
                   15522:                     $confhash{$itemid}{'callback'} = $callback;
                   15523:                 }
                   15524:             }
1.391     raeburn  15525:             foreach my $field ('topmenu','inlinemenu') {
1.345     raeburn  15526:                 if ($env{'form.lti_'.$field.'_'.$idx}) {
                   15527:                     $confhash{$itemid}{$field} = 1;
                   15528:                 }
1.320     raeburn  15529:             }
1.345     raeburn  15530:             if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   15531:                 $confhash{$itemid}{lcmenu} = [];
                   15532:                 my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   15533:                 foreach my $field (@possmenu) {
                   15534:                     if (exists($menutitles{$field})) {
                   15535:                         if ($field eq 'grades') {
                   15536:                             next unless ($env{'form.lti_inlinemenu_'.$idx});
                   15537:                         }
                   15538:                         push(@{$confhash{$itemid}{lcmenu}},$field);
1.326     raeburn  15539:                     }
                   15540:                 }
                   15541:             }
1.391     raeburn  15542:             if ($confhash{$itemid}{'crsinc'}) {
                   15543:                 if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
                   15544:                     ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
                   15545:                     $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
                   15546:                 } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                   15547:                     my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
                   15548:                     $mapcrs =~ s/(`)/'/g;
                   15549:                     $mapcrs =~ s/^\s+|\s+$//g;
                   15550:                     $confhash{$itemid}{'mapcrs'} = $mapcrs;
                   15551:                 }
                   15552:                 my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                   15553:                 my @crstypes;
                   15554:                 foreach my $type (sort(@posstypes)) {
                   15555:                     if ($posscrstype{$type}) {
                   15556:                         push(@crstypes,$type);
                   15557:                     }
                   15558:                 }
                   15559:                 $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392     raeburn  15560:                 if ($env{'form.lti_storecrs_'.$idx}) {
                   15561:                     $confhash{$itemid}{'storecrs'} = 1;
                   15562:                 }       
1.391     raeburn  15563:                 if ($env{'form.lti_makecrs_'.$idx}) {
                   15564:                     $confhash{$itemid}{'makecrs'} = 1;
                   15565:                 }
                   15566:                 foreach my $ltirole (@lticourseroles) {
                   15567:                     my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                   15568:                     if (grep(/^\Q$possrole\E$/,@courseroles)) {
                   15569:                         $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
                   15570:                     }
                   15571:                 }
                   15572:                 my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
                   15573:                 my @selfenroll;
                   15574:                 foreach my $type (sort(@possenroll)) {
                   15575:                     if ($posslticrs{$type}) {
                   15576:                         push(@selfenroll,$type);
                   15577:                     }
                   15578:                 }
                   15579:                 $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                   15580:                 if ($env{'form.lti_crssec_'.$idx}) {
                   15581:                     if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                   15582:                         $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                   15583:                     } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                   15584:                         my $section = $env{'form.lti_customsection_'.$idx};
                   15585:                         $section =~ s/(`)/'/g;
                   15586:                         $section =~ s/^\s+|\s+$//g;
                   15587:                         if ($section ne '') {
                   15588:                             $confhash{$itemid}{'section'} = $section;
                   15589:                         }
                   15590:                     }
                   15591:                 }
                   15592:                 foreach my $field ('passback','roster') {
                   15593:                     if ($env{'form.lti_'.$field.'_'.$idx}) {
                   15594:                         $confhash{$itemid}{$field} = 1;
                   15595:                     }
                   15596:                 }
                   15597:                 if ($env{'form.lti_passback_'.$idx}) {
                   15598:                     if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                   15599:                         $confhash{$itemid}{'passbackformat'} = '1.0';
                   15600:                     } else {
                   15601:                         $confhash{$itemid}{'passbackformat'} = '1.1';
1.337     raeburn  15602:                     }
                   15603:                 }
1.391     raeburn  15604:             }
                   15605:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   15606:                 if ($confhash{$itemid}{'crsinc'}) {
1.392     raeburn  15607:                     foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391     raeburn  15608:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320     raeburn  15609:                             $changes{$itemid} = 1;
                   15610:                         }
1.345     raeburn  15611:                     }
                   15612:                     unless ($changes{$itemid}) {
1.391     raeburn  15613:                         if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
                   15614:                             if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320     raeburn  15615:                                 $changes{$itemid} = 1;
                   15616:                             }
                   15617:                         }
1.345     raeburn  15618:                     }
1.391     raeburn  15619:                     foreach my $field ('mapcrstype','selfenroll') {
                   15620:                         unless ($changes{$itemid}) {
                   15621:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   15622:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15623:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   15624:                                                                                    $confhash{$itemid}{$field});
                   15625:                                     if (@diffs) {
                   15626:                                         $changes{$itemid} = 1;
                   15627:                                     }
                   15628:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   15629:                                     $changes{$itemid} = 1;
                   15630:                                 }
                   15631:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15632:                                 if (@{$confhash{$itemid}{$field}} > 0) {
1.320     raeburn  15633:                                     $changes{$itemid} = 1;
                   15634:                                 }
                   15635:                             }
1.391     raeburn  15636:                         }
                   15637:                     }
                   15638:                     unless ($changes{$itemid}) {
                   15639:                         if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
                   15640:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15641:                                 foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
                   15642:                                     if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne 
                   15643:                                         $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345     raeburn  15644:                                         $changes{$itemid} = 1;
                   15645:                                         last;
                   15646:                                     }
                   15647:                                 }
1.391     raeburn  15648:                                 unless ($changes{$itemid}) {
                   15649:                                     foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                   15650:                                         if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
                   15651:                                             $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
                   15652:                                             $changes{$itemid} = 1;
                   15653:                                             last;
                   15654:                                         }
                   15655:                                     }
                   15656:                                 }
                   15657:                             } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
                   15658:                                 $changes{$itemid} = 1;
1.345     raeburn  15659:                             }
1.391     raeburn  15660:                         } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15661:                             unless ($changes{$itemid}) {
                   15662:                                 if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                   15663:                                     $changes{$itemid} = 1;
                   15664:                                 }
                   15665:                             }
                   15666:                         }
                   15667:                     }
                   15668:                 }
                   15669:                 unless ($changes{$itemid}) {
                   15670:                     foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
                   15671:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345     raeburn  15672:                             $changes{$itemid} = 1;
1.320     raeburn  15673:                         }
1.391     raeburn  15674:                     }
                   15675:                     unless ($changes{$itemid}) {
                   15676:                         foreach my $field ('makeuser','lcmenu') {
                   15677:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   15678:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15679:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   15680:                                                                                    $confhash{$itemid}{$field});
                   15681:                                     if (@diffs) {
                   15682:                                         $changes{$itemid} = 1;
                   15683:                                     }
                   15684:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   15685:                                     $changes{$itemid} = 1;
                   15686:                                 }
                   15687:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15688:                                 if (@{$confhash{$itemid}{$field}} > 0) {
                   15689:                                     $changes{$itemid} = 1;
                   15690:                                 }
1.345     raeburn  15691:                             }
1.320     raeburn  15692:                         }
                   15693:                     }
                   15694:                 }
                   15695:             }
                   15696:         }
                   15697:     }
                   15698:     if (@allpos > 0) {
                   15699:         my $idx = 0;
                   15700:         foreach my $itemid (@allpos) {
                   15701:             if ($itemid ne '') {
                   15702:                 $confhash{$itemid}{'order'} = $idx;
                   15703:                 if (ref($domconfig{$action}) eq 'HASH') {
                   15704:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15705:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   15706:                             $changes{$itemid} = 1;
                   15707:                         }
                   15708:                     }
                   15709:                 }
                   15710:                 $idx ++;
                   15711:             }
                   15712:         }
                   15713:     }
                   15714:     my %ltihash = (
                   15715:                           $action => { %confhash }
                   15716:                        );
                   15717:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
                   15718:                                              $dom);
                   15719:     if ($putresult eq 'ok') {
                   15720:         my %ltienchash = (
                   15721:                              $action => { %encconfig }
                   15722:                          );
1.384     raeburn  15723:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320     raeburn  15724:         if (keys(%changes) > 0) {
                   15725:             my $cachetime = 24*60*60;
                   15726:             my %ltiall = %confhash;
                   15727:             foreach my $id (keys(%ltiall)) {
                   15728:                 if (ref($encconfig{$id}) eq 'HASH') {
                   15729:                     foreach my $item ('key','secret') {
                   15730:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   15731:                     }
                   15732:                 }
                   15733:             }
                   15734:             &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
                   15735:             if (ref($lastactref) eq 'HASH') {
                   15736:                 $lastactref->{'lti'} = 1;
                   15737:             }
                   15738:             $resulttext = &mt('Changes made:').'<ul>';
                   15739:             my %bynum;
                   15740:             foreach my $itemid (sort(keys(%changes))) {
                   15741:                 my $position = $confhash{$itemid}{'order'};
                   15742:                 $bynum{$position} = $itemid;
                   15743:             }
                   15744:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15745:                 my $itemid = $bynum{$pos};
                   15746:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   15747:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   15748:                 } else {
1.390     raeburn  15749:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320     raeburn  15750:                     my $position = $pos + 1;
                   15751:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15752:                     foreach my $item ('version','lifetime') {
                   15753:                         if ($confhash{$itemid}{$item} ne '') {
                   15754:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   15755:                         }
                   15756:                     }
                   15757:                     if ($encconfig{$itemid}{'key'} ne '') {
                   15758:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   15759:                     }
                   15760:                     if ($encconfig{$itemid}{'secret'} ne '') {
                   15761:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15762:                         my $num = length($encconfig{$itemid}{'secret'});
                   15763:                         $resulttext .= ('*'x$num).'</li>';
                   15764:                     }
1.345     raeburn  15765:                     if ($confhash{$itemid}{'requser'}) {
1.391     raeburn  15766:                         if ($confhash{$itemid}{'callback'}) {
                   15767:                             $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
                   15768:                         } else {
1.392     raeburn  15769:                             $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391     raeburn  15770:                         }
1.345     raeburn  15771:                         if ($confhash{$itemid}{'mapuser'}) {
                   15772:                             my $shownmapuser;
                   15773:                             if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                   15774:                                 $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                   15775:                             } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                   15776:                                 $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                   15777:                             } else {
                   15778:                                 $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320     raeburn  15779:                             }
1.345     raeburn  15780:                             $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320     raeburn  15781:                         }
1.345     raeburn  15782:                         if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                   15783:                             if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                   15784:                                 $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                   15785:                                                           join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                   15786:                                 if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                   15787:                                     $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                   15788:                                 } else {
                   15789:                                     $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                   15790:                                                        $confhash{$itemid}{'lcauth'});
                   15791:                                     if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                   15792:                                         $resulttext .= '; '.&mt('a randomly generated password will be created');
                   15793:                                     } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                   15794:                                         if ($confhash{$itemid}{'lcauthparm'} ne '') {
                   15795:                                             $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                   15796:                                         }
                   15797:                                     } else {
                   15798:                                         $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                   15799:                                     }
                   15800:                                 }
                   15801:                                 $resulttext .= '</li>';
                   15802:                             } else {
                   15803:                                 $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                   15804:                             }
1.320     raeburn  15805:                         }
1.345     raeburn  15806:                         if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                   15807:                             if (@{$confhash{$itemid}{'instdata'}} > 0) {
                   15808:                                 $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                   15809:                                                           join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325     raeburn  15810:                             } else {
1.345     raeburn  15811:                                 $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325     raeburn  15812:                             }
1.320     raeburn  15813:                         }
1.391     raeburn  15814:                         foreach my $item ('topmenu','inlinemenu') {
1.345     raeburn  15815:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   15816:                             if ($confhash{$itemid}{$item}) {
                   15817:                                 $resulttext .= &mt('Yes');
                   15818:                             } else {
                   15819:                                 $resulttext .= &mt('No');
1.337     raeburn  15820:                             }
1.345     raeburn  15821:                             $resulttext .= '</li>';
1.320     raeburn  15822:                         }
1.345     raeburn  15823:                         if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   15824:                             if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   15825:                                 $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391     raeburn  15826:                                                join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
                   15827:                             } else {
                   15828:                                 $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
                   15829:                             }
                   15830:                         }
                   15831:                         if ($confhash{$itemid}{'crsinc'}) {
                   15832:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15833:                                 my $rolemaps;
                   15834:                                 foreach my $role (@ltiroles) {
                   15835:                                     if ($confhash{$itemid}{'maproles'}{$role}) {
                   15836:                                         $rolemaps .= ('&nbsp;'x2).$role.'='.
                   15837:                                                      &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                   15838:                                                                                 'Course').',';
                   15839:                                     }
                   15840:                                 }
                   15841:                                 if ($rolemaps) {
                   15842:                                     $rolemaps =~ s/,$//;
                   15843:                                     $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15844:                                 }
                   15845:                             }
                   15846:                             if ($confhash{$itemid}{'mapcrs'}) {
                   15847:                                 $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                   15848:                             }
                   15849:                             if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                   15850:                                 if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                   15851:                                     $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                   15852:                                                    join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                   15853:                                                    '</li>';
                   15854:                                 } else {
                   15855:                                     $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                   15856:                                 }
                   15857:                             }
1.392     raeburn  15858:                             if ($confhash{$itemid}{'storecrs'}) {
                   15859:                                 $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
                   15860:                             }
1.391     raeburn  15861:                             if ($confhash{$itemid}{'makecrs'}) {
                   15862:                                 $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
                   15863:                             } else {
                   15864:                                 $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
                   15865:                             }
                   15866:                             if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                   15867:                                 if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                   15868:                                     $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                   15869:                                                               join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                   15870:                                                    '</li>';
                   15871:                                 } else {
                   15872:                                     $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                   15873:                                 }
                   15874:                             }
                   15875:                             if ($confhash{$itemid}{'section'}) {
                   15876:                                 if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                   15877:                                     $resulttext .= '<li>'.&mt('User section from standard field:').
                   15878:                                                          ' (course_section_sourcedid)'.'</li>';  
                   15879:                                 } else {
                   15880:                                     $resulttext .= '<li>'.&mt('User section from:').' '.
                   15881:                                                           $confhash{$itemid}{'section'}.'</li>';
                   15882:                                 }
1.345     raeburn  15883:                             } else {
1.391     raeburn  15884:                                 $resulttext .= '<li>'.&mt('No section assignment').'</li>';
                   15885:                             }
                   15886:                             foreach my $item ('passback','roster','topmenu','inlinemenu') {
                   15887:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   15888:                                 if ($confhash{$itemid}{$item}) {
                   15889:                                     $resulttext .= &mt('Yes');
                   15890:                                     if ($item eq 'passback') {
                   15891:                                         if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                   15892:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                   15893:                                         } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                   15894:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                   15895:                                         }
                   15896:                                     }
                   15897:                                 } else {
                   15898:                                     $resulttext .= &mt('No');
                   15899:                                 }
                   15900:                                 $resulttext .= '</li>';
                   15901:                             }
                   15902:                             if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   15903:                                 if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   15904:                                     $resulttext .= '<li>'.&mt('Menu items:').' '.
                   15905:                                                    join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                   15906:                                 } else {
                   15907:                                     $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                   15908:                                 }
1.345     raeburn  15909:                             }
1.326     raeburn  15910:                         }
                   15911:                     }
1.320     raeburn  15912:                     $resulttext .= '</ul></li>';
                   15913:                 }
                   15914:             }
                   15915:             $resulttext .= '</ul>';
                   15916:         } else {
                   15917:             $resulttext = &mt('No changes made.');
                   15918:         }
                   15919:     } else {
                   15920:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15921:     }
                   15922:     if ($errors) {
                   15923:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15924:                        $errors.'</ul>';
                   15925:     }
                   15926:     return $resulttext;
                   15927: }
                   15928: 
                   15929: sub get_lti_id {
                   15930:     my ($domain,$consumer) = @_;
                   15931:     # get lock on lti db
                   15932:     my $lockhash = {
                   15933:                       lock => $env{'user.name'}.
                   15934:                               ':'.$env{'user.domain'},
                   15935:                    };
                   15936:     my $tries = 0;
                   15937:     my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   15938:     my ($id,$error);
                   15939: 
                   15940:     while (($gotlock ne 'ok') && ($tries<10)) {
                   15941:         $tries ++;
                   15942:         sleep (0.1);
                   15943:         $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   15944:     }
                   15945:     if ($gotlock eq 'ok') {
                   15946:         my %currids = &Apache::lonnet::dump_dom('lti',$domain);
                   15947:         if ($currids{'lock'}) {
                   15948:             delete($currids{'lock'});
                   15949:             if (keys(%currids)) {
                   15950:                 my @curr = sort { $a <=> $b } keys(%currids);
                   15951:                 if ($curr[-1] =~ /^\d+$/) {
                   15952:                     $id = 1 + $curr[-1];
                   15953:                 }
                   15954:             } else {
                   15955:                 $id = 1;
                   15956:             }
                   15957:             if ($id) {
                   15958:                 unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
                   15959:                     $error = 'nostore';
                   15960:                 }
                   15961:             } else {
                   15962:                 $error = 'nonumber';
                   15963:             }
                   15964:         }
                   15965:         my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
                   15966:     } else {
                   15967:         $error = 'nolock';
                   15968:     }
                   15969:     return ($id,$error);
                   15970: }
                   15971: 
1.3       raeburn  15972: sub modify_autoenroll {
1.205     raeburn  15973:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  15974:     my ($resulttext,%changes);
                   15975:     my %currautoenroll;
                   15976:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   15977:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   15978:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   15979:         }
                   15980:     }
                   15981:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   15982:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  15983:                   sender => 'Sender for notification messages',
1.274     raeburn  15984:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399     raeburn  15985:                   autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  15986:     my @offon = ('off','on');
1.17      raeburn  15987:     my $sender_uname = $env{'form.sender_uname'};
                   15988:     my $sender_domain = $env{'form.sender_domain'};
                   15989:     if ($sender_domain eq '') {
                   15990:         $sender_uname = '';
                   15991:     } elsif ($sender_uname eq '') {
                   15992:         $sender_domain = '';
                   15993:     }
1.129     raeburn  15994:     my $coowners = $env{'form.autoassign_coowners'};
1.399     raeburn  15995:     my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
                   15996:     $autofailsafe =~ s{^\s+|\s+$}{}g;
                   15997:     if ($autofailsafe =~ /\D/) {
                   15998:         undef($autofailsafe);
                   15999:     }
1.274     raeburn  16000:     my $failsafe = $env{'form.autoenroll_failsafe'};
1.399     raeburn  16001:     unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
                   16002:         $failsafe = 'off';
1.400     raeburn  16003:         undef($autofailsafe);
1.274     raeburn  16004:     }
1.1       raeburn  16005:     my %autoenrollhash =  (
1.129     raeburn  16006:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   16007:                                        'sender_uname' => $sender_uname,
                   16008:                                        'sender_domain' => $sender_domain,
                   16009:                                        'co-owners' => $coowners,
1.399     raeburn  16010:                                        'autofailsafe' => $autofailsafe,
1.400     raeburn  16011:                                        'failsafe' => $failsafe,
1.1       raeburn  16012:                                 }
                   16013:                      );
1.4       raeburn  16014:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   16015:                                              $dom);
1.1       raeburn  16016:     if ($putresult eq 'ok') {
                   16017:         if (exists($currautoenroll{'run'})) {
                   16018:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   16019:                  $changes{'run'} = 1;
                   16020:              }
                   16021:         } elsif ($autorun) {
                   16022:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  16023:                  $changes{'run'} = 1;
1.1       raeburn  16024:             }
                   16025:         }
1.17      raeburn  16026:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  16027:             $changes{'sender'} = 1;
                   16028:         }
1.17      raeburn  16029:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  16030:             $changes{'sender'} = 1;
                   16031:         }
1.129     raeburn  16032:         if ($currautoenroll{'co-owners'} ne '') {
                   16033:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   16034:                 $changes{'coowners'} = 1;
                   16035:             }
                   16036:         } elsif ($coowners) {
                   16037:             $changes{'coowners'} = 1;
1.274     raeburn  16038:         }
1.399     raeburn  16039:         if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274     raeburn  16040:             $changes{'autofailsafe'} = 1;
                   16041:         }
1.399     raeburn  16042:         if ($currautoenroll{'failsafe'} ne $failsafe) {
                   16043:             $changes{'failsafe'} = 1;
                   16044:         }
1.1       raeburn  16045:         if (keys(%changes) > 0) {
                   16046:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  16047:             if ($changes{'run'}) {
1.1       raeburn  16048:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   16049:             }
                   16050:             if ($changes{'sender'}) {
1.17      raeburn  16051:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   16052:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   16053:                 } else {
                   16054:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   16055:                 }
1.1       raeburn  16056:             }
1.129     raeburn  16057:             if ($changes{'coowners'}) {
                   16058:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   16059:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16060:                 if (ref($lastactref) eq 'HASH') {
                   16061:                     $lastactref->{'domainconfig'} = 1;
                   16062:                 }
1.129     raeburn  16063:             }
1.274     raeburn  16064:             if ($changes{'autofailsafe'}) {
1.399     raeburn  16065:                 if ($autofailsafe ne '') {
                   16066:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274     raeburn  16067:                 } else {
1.399     raeburn  16068:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274     raeburn  16069:                 }
1.399     raeburn  16070:             }
                   16071:             if ($changes{'failsafe'}) {
                   16072:                 if ($failsafe eq 'off') {
                   16073:                     unless ($changes{'autofailsafe'}) {
                   16074:                         $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
                   16075:                     }
                   16076:                 } elsif ($failsafe eq 'zero') {
                   16077:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
                   16078:                 } else {
                   16079:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
                   16080:                 }
                   16081:             }
                   16082:             if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274     raeburn  16083:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   16084:                 if (ref($lastactref) eq 'HASH') {
                   16085:                     $lastactref->{'domdefaults'} = 1;
                   16086:                 }
                   16087:             }
1.1       raeburn  16088:             $resulttext .= '</ul>';
                   16089:         } else {
                   16090:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   16091:         }
                   16092:     } else {
1.11      albertel 16093:         $resulttext = '<span class="LC_error">'.
                   16094: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16095:     }
1.3       raeburn  16096:     return $resulttext;
1.1       raeburn  16097: }
                   16098: 
                   16099: sub modify_autoupdate {
1.3       raeburn  16100:     my ($dom,%domconfig) = @_;
1.1       raeburn  16101:     my ($resulttext,%currautoupdate,%fields,%changes);
                   16102:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   16103:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   16104:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   16105:         }
                   16106:     }
                   16107:     my @offon = ('off','on');
                   16108:     my %title = &Apache::lonlocal::texthash (
1.385     raeburn  16109:                     run        => 'Auto-update:',
                   16110:                     classlists => 'Updates to user information in classlists?',
                   16111:                     unexpired  => 'Skip updates for users without active or future roles?',
                   16112:                     lastactive => 'Skip updates for inactive users?',
1.1       raeburn  16113:                 );
1.44      raeburn  16114:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  16115:     my %fieldtitles = &Apache::lonlocal::texthash (
                   16116:                         id => 'Student/Employee ID',
1.20      raeburn  16117:                         permanentemail => 'E-mail address',
1.1       raeburn  16118:                         lastname => 'Last Name',
                   16119:                         firstname => 'First Name',
                   16120:                         middlename => 'Middle Name',
1.132     raeburn  16121:                         generation => 'Generation',
1.1       raeburn  16122:                       );
1.142     raeburn  16123:     $othertitle = &mt('All users');
1.1       raeburn  16124:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  16125:         $othertitle = &mt('Other users');
1.1       raeburn  16126:     }
                   16127:     foreach my $key (keys(%env)) {
                   16128:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  16129:             my ($usertype,$item) = ($1,$2);
                   16130:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   16131:                 if ($usertype eq 'default') {   
                   16132:                     push(@{$fields{$1}},$2);
                   16133:                 } elsif (ref($types) eq 'ARRAY') {
                   16134:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   16135:                         push(@{$fields{$1}},$2);
                   16136:                     }
                   16137:                 }
                   16138:             }
1.1       raeburn  16139:         }
                   16140:     }
1.131     raeburn  16141:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   16142:     @lockablenames = sort(@lockablenames);
                   16143:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   16144:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16145:         if (@changed) {
                   16146:             $changes{'lockablenames'} = 1;
                   16147:         }
                   16148:     } else {
                   16149:         if (@lockablenames) {
                   16150:             $changes{'lockablenames'} = 1;
                   16151:         }
                   16152:     }
1.1       raeburn  16153:     my %updatehash = (
                   16154:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   16155:                                       classlists => $env{'form.classlists'},
1.385     raeburn  16156:                                       unexpired  => $env{'form.unexpired'},
1.1       raeburn  16157:                                       fields => {%fields},
1.131     raeburn  16158:                                       lockablenames => \@lockablenames,
1.1       raeburn  16159:                                     }
                   16160:                      );
1.385     raeburn  16161:     my $lastactivedays;
                   16162:     if ($env{'form.lastactive'}) {
                   16163:         $lastactivedays = $env{'form.lastactivedays'};
                   16164:         $lastactivedays =~ s/^\s+|\s+$//g;
                   16165:         unless ($lastactivedays =~ /^\d+$/) {
                   16166:             undef($lastactivedays);
                   16167:             $env{'form.lastactive'} = 0;
                   16168:         }
                   16169:     }
                   16170:     $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1       raeburn  16171:     foreach my $key (keys(%currautoupdate)) {
1.385     raeburn  16172:         if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1       raeburn  16173:             if (exists($updatehash{autoupdate}{$key})) {
                   16174:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   16175:                     $changes{$key} = 1;
                   16176:                 }
                   16177:             }
                   16178:         } elsif ($key eq 'fields') {
                   16179:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  16180:                 foreach my $item (@{$types},'default') {
1.1       raeburn  16181:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   16182:                         my $change = 0;
                   16183:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   16184:                             if (!exists($fields{$item})) {
                   16185:                                 $change = 1;
1.132     raeburn  16186:                                 last;
1.1       raeburn  16187:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  16188:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  16189:                                     $change = 1;
1.132     raeburn  16190:                                     last;
1.1       raeburn  16191:                                 }
                   16192:                             }
                   16193:                         }
                   16194:                         if ($change) {
                   16195:                             push(@{$changes{$key}},$item);
                   16196:                         }
1.26      raeburn  16197:                     } 
1.1       raeburn  16198:                 }
                   16199:             }
1.131     raeburn  16200:         } elsif ($key eq 'lockablenames') {
                   16201:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   16202:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16203:                 if (@changed) {
                   16204:                     $changes{'lockablenames'} = 1;
                   16205:                 }
                   16206:             } else {
                   16207:                 if (@lockablenames) {
                   16208:                     $changes{'lockablenames'} = 1;
                   16209:                 }
                   16210:             }
                   16211:         }
                   16212:     }
                   16213:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   16214:         if (@lockablenames) {
                   16215:             $changes{'lockablenames'} = 1;
1.1       raeburn  16216:         }
                   16217:     }
1.385     raeburn  16218:     unless (grep(/^unexpired$/,keys(%currautoupdate))) {
                   16219:         if ($updatehash{'autoupdate'}{'unexpired'}) {
                   16220:             $changes{'unexpired'} = 1;
                   16221:         }
                   16222:     }
                   16223:     unless (grep(/^lastactive$/,keys(%currautoupdate))) {
                   16224:         if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
                   16225:             $changes{'lastactive'} = 1;
                   16226:         }
                   16227:     }
1.26      raeburn  16228:     foreach my $item (@{$types},'default') {
                   16229:         if (defined($fields{$item})) {
                   16230:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  16231:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   16232:                     my $change = 0;
                   16233:                     if (ref($fields{$item}) eq 'ARRAY') {
                   16234:                         foreach my $type (@{$fields{$item}}) {
                   16235:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   16236:                                 $change = 1;
                   16237:                                 last;
                   16238:                             }
                   16239:                         }
                   16240:                     }
                   16241:                     if ($change) {
                   16242:                         push(@{$changes{'fields'}},$item);
                   16243:                     }
                   16244:                 } else {
1.26      raeburn  16245:                     push(@{$changes{'fields'}},$item);
                   16246:                 }
                   16247:             } else {
                   16248:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  16249:             }
                   16250:         }
                   16251:     }
                   16252:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   16253:                                              $dom);
                   16254:     if ($putresult eq 'ok') {
                   16255:         if (keys(%changes) > 0) {
                   16256:             $resulttext = &mt('Changes made:').'<ul>';
                   16257:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  16258:                 if ($key eq 'lockablenames') {
                   16259:                     $resulttext .= '<li>';
                   16260:                     if (@lockablenames) {
                   16261:                         $usertypes->{'default'} = $othertitle;
                   16262:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   16263:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   16264:                     } else {
                   16265:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   16266:                     }
                   16267:                     $resulttext .= '</li>';
                   16268:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  16269:                     foreach my $item (@{$changes{$key}}) {
                   16270:                         my @newvalues;
                   16271:                         foreach my $type (@{$fields{$item}}) {
                   16272:                             push(@newvalues,$fieldtitles{$type});
                   16273:                         }
1.3       raeburn  16274:                         my $newvaluestr;
                   16275:                         if (@newvalues > 0) {
                   16276:                             $newvaluestr = join(', ',@newvalues);
                   16277:                         } else {
                   16278:                             $newvaluestr = &mt('none');
1.6       raeburn  16279:                         }
1.1       raeburn  16280:                         if ($item eq 'default') {
1.26      raeburn  16281:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  16282:                         } else {
1.26      raeburn  16283:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  16284:                         }
                   16285:                     }
                   16286:                 } else {
                   16287:                     my $newvalue;
                   16288:                     if ($key eq 'run') {
                   16289:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385     raeburn  16290:                     } elsif ($key eq 'lastactive') {
                   16291:                         $newvalue = $offon[$env{'form.lastactive'}];
                   16292:                         unless ($lastactivedays eq '') {
                   16293:                             $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
                   16294:                         }
1.1       raeburn  16295:                     } else {
                   16296:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  16297:                     }
1.1       raeburn  16298:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   16299:                 }
                   16300:             }
                   16301:             $resulttext .= '</ul>';
                   16302:         } else {
1.3       raeburn  16303:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  16304:         }
                   16305:     } else {
1.11      albertel 16306:         $resulttext = '<span class="LC_error">'.
                   16307: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16308:     }
1.3       raeburn  16309:     return $resulttext;
1.1       raeburn  16310: }
                   16311: 
1.125     raeburn  16312: sub modify_autocreate {
                   16313:     my ($dom,%domconfig) = @_;
                   16314:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   16315:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   16316:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   16317:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   16318:         }
                   16319:     }
                   16320:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   16321:                  req => 'Auto-creation of validated requests for official courses',
                   16322:                  xmldc => 'Identity of course creator of courses from XML files',
                   16323:                );
                   16324:     my @types = ('xml','req');
                   16325:     foreach my $item (@types) {
                   16326:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   16327:         $newvals{$item} =~ s/\D//g;
                   16328:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   16329:     }
                   16330:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  16331:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  16332:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   16333:         $newvals{'xmldc'} = '';
                   16334:     } 
                   16335:     %autocreatehash =  (
                   16336:                         autocreate => { xml => $newvals{'xml'},
                   16337:                                         req => $newvals{'req'},
                   16338:                                       }
                   16339:                        );
                   16340:     if ($newvals{'xmldc'} ne '') {
                   16341:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   16342:     }
                   16343:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   16344:                                              $dom);
                   16345:     if ($putresult eq 'ok') {
                   16346:         my @items = @types;
                   16347:         if ($newvals{'xml'}) {
                   16348:             push(@items,'xmldc');
                   16349:         }
                   16350:         foreach my $item (@items) {
                   16351:             if (exists($currautocreate{$item})) {
                   16352:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   16353:                     $changes{$item} = 1;
                   16354:                 }
                   16355:             } elsif ($newvals{$item}) {
                   16356:                 $changes{$item} = 1;
                   16357:             }
                   16358:         }
                   16359:         if (keys(%changes) > 0) {
                   16360:             my @offon = ('off','on'); 
                   16361:             $resulttext = &mt('Changes made:').'<ul>';
                   16362:             foreach my $item (@types) {
                   16363:                 if ($changes{$item}) {
                   16364:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  16365:                     $resulttext .= '<li>'.
                   16366:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   16367:                                        '<b>','</b>').
                   16368:                                    '</li>';
1.125     raeburn  16369:                 }
                   16370:             }
                   16371:             if ($changes{'xmldc'}) {
                   16372:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   16373:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  16374:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  16375:             }
                   16376:             $resulttext .= '</ul>';
                   16377:         } else {
                   16378:             $resulttext = &mt('No changes made to auto-creation settings');
                   16379:         }
                   16380:     } else {
                   16381:         $resulttext = '<span class="LC_error">'.
                   16382:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16383:     }
                   16384:     return $resulttext;
                   16385: }
                   16386: 
1.23      raeburn  16387: sub modify_directorysrch {
1.295     raeburn  16388:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  16389:     my ($resulttext,%changes);
                   16390:     my %currdirsrch;
                   16391:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   16392:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   16393:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   16394:         }
                   16395:     }
1.277     raeburn  16396:     my %title = ( available => 'Institutional directory search available',
                   16397:                   localonly => 'Other domains can search institution',
                   16398:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  16399:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  16400:                   searchby => 'Search types',
                   16401:                   searchtypes => 'Search latitude');
                   16402:     my @offon = ('off','on');
1.24      raeburn  16403:     my @otherdoms = ('Yes','No');
1.23      raeburn  16404: 
1.25      raeburn  16405:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  16406:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   16407:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   16408: 
1.44      raeburn  16409:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  16410:     if (keys(%{$usertypes}) == 0) {
                   16411:         @cansearch = ('default');
                   16412:     } else {
                   16413:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   16414:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   16415:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   16416:                     push(@{$changes{'cansearch'}},$type);
                   16417:                 }
1.23      raeburn  16418:             }
1.26      raeburn  16419:             foreach my $type (@cansearch) {
                   16420:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   16421:                     push(@{$changes{'cansearch'}},$type);
                   16422:                 }
1.23      raeburn  16423:             }
1.26      raeburn  16424:         } else {
                   16425:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  16426:         }
                   16427:     }
                   16428: 
                   16429:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   16430:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   16431:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   16432:                 push(@{$changes{'searchby'}},$by);
                   16433:             }
                   16434:         }
                   16435:         foreach my $by (@searchby) {
                   16436:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   16437:                 push(@{$changes{'searchby'}},$by);
                   16438:             }
                   16439:         }
                   16440:     } else {
                   16441:         push(@{$changes{'searchby'}},@searchby);
                   16442:     }
1.25      raeburn  16443: 
                   16444:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   16445:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   16446:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   16447:                 push(@{$changes{'searchtypes'}},$type);
                   16448:             }
                   16449:         }
                   16450:         foreach my $type (@searchtypes) {
                   16451:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   16452:                 push(@{$changes{'searchtypes'}},$type);
                   16453:             }
                   16454:         }
                   16455:     } else {
                   16456:         if (exists($currdirsrch{'searchtypes'})) {
                   16457:             foreach my $type (@searchtypes) {  
                   16458:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   16459:                     push(@{$changes{'searchtypes'}},$type);
                   16460:                 }
                   16461:             }
                   16462:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   16463:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   16464:             }   
                   16465:         } else {
                   16466:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   16467:         }
                   16468:     }
                   16469: 
1.23      raeburn  16470:     my %dirsrch_hash =  (
                   16471:             directorysrch => { available => $env{'form.dirsrch_available'},
                   16472:                                cansearch => \@cansearch,
1.277     raeburn  16473:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   16474:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   16475:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  16476:                                searchby => \@searchby,
1.25      raeburn  16477:                                searchtypes => \@searchtypes,
1.23      raeburn  16478:                              }
                   16479:             );
                   16480:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   16481:                                              $dom);
                   16482:     if ($putresult eq 'ok') {
                   16483:         if (exists($currdirsrch{'available'})) {
                   16484:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   16485:                  $changes{'available'} = 1;
                   16486:              }
                   16487:         } else {
                   16488:             if ($env{'form.dirsrch_available'} eq '1') {
                   16489:                 $changes{'available'} = 1;
                   16490:             }
                   16491:         }
1.277     raeburn  16492:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  16493:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   16494:                 $changes{'lcavailable'} = 1;
                   16495:             }
1.277     raeburn  16496:         } else {
                   16497:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   16498:                 $changes{'lcavailable'} = 1;
                   16499:             }
                   16500:         }
1.24      raeburn  16501:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  16502:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   16503:                 $changes{'localonly'} = 1;
                   16504:             }
1.24      raeburn  16505:         } else {
1.277     raeburn  16506:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  16507:                 $changes{'localonly'} = 1;
                   16508:             }
                   16509:         }
1.277     raeburn  16510:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  16511:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   16512:                 $changes{'lclocalonly'} = 1;
                   16513:             }
1.277     raeburn  16514:         } else {
                   16515:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   16516:                 $changes{'lclocalonly'} = 1;
                   16517:             }
                   16518:         }
1.23      raeburn  16519:         if (keys(%changes) > 0) {
                   16520:             $resulttext = &mt('Changes made:').'<ul>';
                   16521:             if ($changes{'available'}) {
                   16522:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   16523:             }
1.277     raeburn  16524:             if ($changes{'lcavailable'}) {
                   16525:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   16526:             }
1.24      raeburn  16527:             if ($changes{'localonly'}) {
1.277     raeburn  16528:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  16529:             }
1.277     raeburn  16530:             if ($changes{'lclocalonly'}) {
                   16531:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  16532:             }
1.23      raeburn  16533:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   16534:                 my $chgtext;
1.26      raeburn  16535:                 if (ref($usertypes) eq 'HASH') {
                   16536:                     if (keys(%{$usertypes}) > 0) {
                   16537:                         foreach my $type (@{$types}) {
                   16538:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   16539:                                 $chgtext .= $usertypes->{$type}.'; ';
                   16540:                             }
                   16541:                         }
                   16542:                         if (grep(/^default$/,@cansearch)) {
                   16543:                             $chgtext .= $othertitle;
                   16544:                         } else {
                   16545:                             $chgtext =~ s/\; $//;
                   16546:                         }
1.210     raeburn  16547:                         $resulttext .=
1.178     raeburn  16548:                             '<li>'.
                   16549:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   16550:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   16551:                             '</li>';
1.23      raeburn  16552:                     }
                   16553:                 }
                   16554:             }
                   16555:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   16556:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   16557:                 my $chgtext;
                   16558:                 foreach my $type (@{$titleorder}) {
                   16559:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   16560:                         if (defined($searchtitles->{$type})) {
                   16561:                             $chgtext .= $searchtitles->{$type}.'; ';
                   16562:                         }
                   16563:                     }
                   16564:                 }
                   16565:                 $chgtext =~ s/\; $//;
                   16566:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   16567:             }
1.25      raeburn  16568:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   16569:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   16570:                 my $chgtext;
                   16571:                 foreach my $type (@{$srchtypeorder}) {
                   16572:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   16573:                         if (defined($srchtypes_desc->{$type})) {
                   16574:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   16575:                         }
                   16576:                     }
                   16577:                 }
                   16578:                 $chgtext =~ s/\; $//;
1.178     raeburn  16579:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  16580:             }
                   16581:             $resulttext .= '</ul>';
1.295     raeburn  16582:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   16583:             if (ref($lastactref) eq 'HASH') {
                   16584:                 $lastactref->{'directorysrch'} = 1;
                   16585:             }
1.23      raeburn  16586:         } else {
1.277     raeburn  16587:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  16588:         }
                   16589:     } else {
                   16590:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  16591:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   16592:     }
                   16593:     return $resulttext;
                   16594: }
                   16595: 
1.28      raeburn  16596: sub modify_contacts {
1.205     raeburn  16597:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  16598:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   16599:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   16600:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   16601:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   16602:         }
                   16603:     }
1.286     raeburn  16604:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  16605:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  16606:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350     raeburn  16607:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340     raeburn  16608:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   16609:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286     raeburn  16610:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  16611:     foreach my $type (@mailings) {
                   16612:         @{$newsetting{$type}} = 
                   16613:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   16614:         foreach my $item (@contacts) {
                   16615:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   16616:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   16617:             } else {
                   16618:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   16619:             }
1.289     raeburn  16620:         }
1.28      raeburn  16621:         $others{$type} = $env{'form.'.$type.'_others'};
                   16622:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  16623:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16624:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   16625:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  16626:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   16627:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   16628:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   16629:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   16630:             }
1.134     raeburn  16631:         }
1.28      raeburn  16632:     }
                   16633:     foreach my $item (@contacts) {
                   16634:         $to{$item} = $env{'form.'.$item};
                   16635:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   16636:     }
1.203     raeburn  16637:     foreach my $item (@toggles) {
                   16638:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   16639:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   16640:         }
                   16641:     }
1.340     raeburn  16642:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   16643:     foreach my $item (@lonstatus) {
                   16644:         if ($item eq 'excluded') {
                   16645:             my (%serverhomes,@excluded);
                   16646:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   16647:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   16648:             if (@possexcluded) {
                   16649:                 foreach my $id (sort(@possexcluded)) {
                   16650:                     if ($serverhomes{$id}) {
                   16651:                         push(@excluded,$id);
                   16652:                     }
                   16653:                 }
                   16654:             }
                   16655:             if (@excluded) {
                   16656:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   16657:             }
                   16658:         } elsif ($item eq 'weights') {
1.377     raeburn  16659:             foreach my $type ('E','W','N','U') {
1.340     raeburn  16660:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   16661:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   16662:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   16663:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   16664:                             $env{'form.error'.$item.'_'.$type};
                   16665:                     }
                   16666:                 }
                   16667:             }
                   16668:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   16669:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   16670:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   16671:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   16672:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   16673:                 }
                   16674:             }
                   16675:         }
                   16676:     }
1.286     raeburn  16677:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   16678:         foreach my $field (@{$fields}) {
                   16679:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   16680:                 my $value = $env{'form.helpform_'.$field};
                   16681:                 $value =~ s/^\s+|\s+$//g;
                   16682:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  16683:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  16684:                     if ($field eq 'screenshot') {
                   16685:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   16686:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  16687:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  16688:                         }
                   16689:                     }
                   16690:                 }
                   16691:             }
                   16692:         }
                   16693:     }
1.315     raeburn  16694:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   16695:     my (@statuses,%usertypeshash,@overrides);
                   16696:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   16697:         @statuses = @{$types};
                   16698:         if (ref($usertypes) eq 'HASH') {
                   16699:             %usertypeshash = %{$usertypes};
                   16700:         }
                   16701:     }
                   16702:     if (@statuses) {
                   16703:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   16704:         foreach my $type (@possoverrides) {
                   16705:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   16706:                 push(@overrides,$type);
                   16707:             }
                   16708:         }
                   16709:         if (@overrides) {
                   16710:             foreach my $type (@overrides) {
                   16711:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   16712:                 foreach my $item (@contacts) {
                   16713:                     if (grep(/^\Q$item\E$/,@standard)) {
                   16714:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   16715:                         $newsetting{'override_'.$type}{$item} = 1;
                   16716:                     } else {
                   16717:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   16718:                         $newsetting{'override_'.$type}{$item} = 0;
                   16719:                     }
                   16720:                 }
                   16721:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   16722:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   16723:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   16724:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   16725:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   16726:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   16727:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   16728:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   16729:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   16730:                 }
                   16731:             }     
                   16732:         }
                   16733:     }
1.28      raeburn  16734:     if (keys(%currsetting) > 0) {
                   16735:         foreach my $item (@contacts) {
                   16736:             if ($to{$item} ne $currsetting{$item}) {
                   16737:                 $changes{$item} = 1;
                   16738:             }
                   16739:         }
                   16740:         foreach my $type (@mailings) {
                   16741:             foreach my $item (@contacts) {
                   16742:                 if (ref($currsetting{$type}) eq 'HASH') {
                   16743:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   16744:                         push(@{$changes{$type}},$item);
                   16745:                     }
                   16746:                 } else {
                   16747:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   16748:                 }
                   16749:             }
                   16750:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   16751:                 push(@{$changes{$type}},'others');
                   16752:             }
1.289     raeburn  16753:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16754:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   16755:                     push(@{$changes{$type}},'bcc'); 
                   16756:                 }
1.286     raeburn  16757:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   16758:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   16759:                     push(@{$changes{$type}},'include');
                   16760:                 }
                   16761:             }
                   16762:         }
                   16763:         if (ref($fields) eq 'ARRAY') {
                   16764:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   16765:                 foreach my $field (@{$fields}) {
                   16766:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   16767:                         push(@{$changes{'helpform'}},$field);
                   16768:                     }
                   16769:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16770:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   16771:                             push(@{$changes{'helpform'}},'maxsize');
                   16772:                         }
                   16773:                     }
                   16774:                 }
                   16775:             } else {
                   16776:                 foreach my $field (@{$fields}) {
                   16777:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   16778:                         push(@{$changes{'helpform'}},$field);
                   16779:                     }
                   16780:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16781:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   16782:                             push(@{$changes{'helpform'}},'maxsize');
                   16783:                         }
                   16784:                     }
                   16785:                 }
1.134     raeburn  16786:             }
1.28      raeburn  16787:         }
1.315     raeburn  16788:         if (@statuses) {
                   16789:             if (ref($currsetting{'overrides'}) eq 'HASH') { 
                   16790:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   16791:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   16792:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   16793:                             foreach my $item (@contacts,'bcc','others','include') {
                   16794:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
                   16795:                                     push(@{$changes{'overrides'}},$key);
                   16796:                                     last;
                   16797:                                 }
                   16798:                             }
                   16799:                         } else {
                   16800:                             push(@{$changes{'overrides'}},$key);
                   16801:                         }
                   16802:                     }
                   16803:                 }
                   16804:                 foreach my $key (@overrides) {
                   16805:                     unless (exists($currsetting{'overrides'}{$key})) {
                   16806:                         push(@{$changes{'overrides'}},$key);
                   16807:                     }
                   16808:                 }
                   16809:             } else {
                   16810:                 foreach my $key (@overrides) {
                   16811:                     push(@{$changes{'overrides'}},$key); 
                   16812:                 }
                   16813:             }
                   16814:         }
1.340     raeburn  16815:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   16816:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   16817:                 if ($key eq 'excluded') {
                   16818:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   16819:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   16820:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   16821:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   16822:                             my @diffs =
                   16823:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   16824:                                                                    $currsetting{'lonstatus'}{$key});
                   16825:                             if (@diffs) {
                   16826:                                 push(@{$changes{'lonstatus'}},$key);
                   16827:                             }
                   16828:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   16829:                             push(@{$changes{'lonstatus'}},$key);
                   16830:                         }
                   16831:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   16832:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   16833:                         push(@{$changes{'lonstatus'}},$key);
                   16834:                     }
                   16835:                 } elsif ($key eq 'weights') {
                   16836:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   16837:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   16838:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  16839:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  16840:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   16841:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   16842:                                     push(@{$changes{'lonstatus'}},$key);
                   16843:                                     last;
                   16844:                                 }
                   16845:                             }
                   16846:                         } else {
1.341     raeburn  16847:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  16848:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   16849:                                     push(@{$changes{'lonstatus'}},$key);
                   16850:                                     last;
                   16851:                                 }
                   16852:                             }
                   16853:                         }
                   16854:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  16855:                         foreach my $type ('E','W','N','U') {
1.340     raeburn  16856:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   16857:                                 push(@{$changes{'lonstatus'}},$key);
                   16858:                                 last;
                   16859:                             }
                   16860:                         }
                   16861:                     }
                   16862:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   16863:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16864:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   16865:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   16866:                                 push(@{$changes{'lonstatus'}},$key);
                   16867:                             }
                   16868:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   16869:                             push(@{$changes{'lonstatus'}},$key);
                   16870:                         }
                   16871:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   16872:                         push(@{$changes{'lonstatus'}},$key);
                   16873:                     }
                   16874:                 }
                   16875:             }
                   16876:         } else {
                   16877:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16878:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   16879:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   16880:                         push(@{$changes{'lonstatus'}},$key);
                   16881:                     }
                   16882:                 }
                   16883:             }
                   16884:         }
1.28      raeburn  16885:     } else {
                   16886:         my %default;
                   16887:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   16888:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   16889:         $default{'errormail'} = 'adminemail';
                   16890:         $default{'packagesmail'} = 'adminemail';
                   16891:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  16892:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  16893:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  16894:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  16895:         $default{'updatesmail'} = 'adminemail';
1.350     raeburn  16896:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  16897:         foreach my $item (@contacts) {
                   16898:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  16899:                $changes{$item} = 1;
1.203     raeburn  16900:            }
1.28      raeburn  16901:         }
                   16902:         foreach my $type (@mailings) {
                   16903:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   16904:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   16905:             }
                   16906:             if ($others{$type} ne '') {
                   16907:                 push(@{$changes{$type}},'others');
1.134     raeburn  16908:             }
1.286     raeburn  16909:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16910:                 if ($bcc{$type} ne '') {
                   16911:                     push(@{$changes{$type}},'bcc');
                   16912:                 }
1.286     raeburn  16913:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   16914:                     push(@{$changes{$type}},'include');
                   16915:                 }
1.134     raeburn  16916:             }
1.28      raeburn  16917:         }
1.286     raeburn  16918:         if (ref($fields) eq 'ARRAY') {
                   16919:             foreach my $field (@{$fields}) {
                   16920:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   16921:                     push(@{$changes{'helpform'}},$field);
                   16922:                 }
                   16923:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16924:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   16925:                         push(@{$changes{'helpform'}},'maxsize');
                   16926:                     }
                   16927:                 }
                   16928:             }
1.289     raeburn  16929:         }
1.340     raeburn  16930:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16931:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   16932:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   16933:                     push(@{$changes{'lonstatus'}},$key);
                   16934:                 }
                   16935:             }
                   16936:         }
1.28      raeburn  16937:     }
1.203     raeburn  16938:     foreach my $item (@toggles) {
                   16939:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   16940:             $changes{$item} = 1;
                   16941:         } elsif ((!$env{'form.'.$item}) &&
                   16942:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   16943:             $changes{$item} = 1;
                   16944:         }
                   16945:     }
1.28      raeburn  16946:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   16947:                                              $dom);
                   16948:     if ($putresult eq 'ok') {
                   16949:         if (keys(%changes) > 0) {
1.205     raeburn  16950:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16951:             if (ref($lastactref) eq 'HASH') {
                   16952:                 $lastactref->{'domainconfig'} = 1;
                   16953:             }
1.28      raeburn  16954:             my ($titles,$short_titles)  = &contact_titles();
                   16955:             $resulttext = &mt('Changes made:').'<ul>';
                   16956:             foreach my $item (@contacts) {
                   16957:                 if ($changes{$item}) {
                   16958:                     $resulttext .= '<li>'.$titles->{$item}.
                   16959:                                     &mt(' set to: ').
                   16960:                                     '<span class="LC_cusr_emph">'.
                   16961:                                     $to{$item}.'</span></li>';
                   16962:                 }
                   16963:             }
                   16964:             foreach my $type (@mailings) {
                   16965:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  16966:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  16967:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  16968:                     } else {
                   16969:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   16970:                     }
1.28      raeburn  16971:                     my @text;
                   16972:                     foreach my $item (@{$newsetting{$type}}) {
                   16973:                         push(@text,$short_titles->{$item});
                   16974:                     }
                   16975:                     if ($others{$type} ne '') {
                   16976:                         push(@text,$others{$type});
                   16977:                     }
1.286     raeburn  16978:                     if (@text) {
                   16979:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   16980:                                        join(', ',@text).'</span>';
                   16981:                     }
                   16982:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16983:                         if ($bcc{$type} ne '') {
1.286     raeburn  16984:                             my $bcctext;
                   16985:                             if (@text) {
1.289     raeburn  16986:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  16987:                             } else {
                   16988:                                 $bcctext = '(Bcc)';
                   16989:                             }
                   16990:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   16991:                         } elsif (!@text) {
                   16992:                             $resulttext .= &mt('No one');
                   16993:                         }   
1.289     raeburn  16994:                         if ($includestr{$type} ne '') {
1.286     raeburn  16995:                             if ($includeloc{$type} eq 'b') {
                   16996:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   16997:                             } elsif ($includeloc{$type} eq 's') {
                   16998:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   16999:                             }
1.134     raeburn  17000:                         }
1.286     raeburn  17001:                     } elsif (!@text) {
                   17002:                         $resulttext .= &mt('No recipients');
1.134     raeburn  17003:                     }
                   17004:                     $resulttext .= '</li>';
1.28      raeburn  17005:                 }
                   17006:             }
1.315     raeburn  17007:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   17008:                 my @deletions;
                   17009:                 foreach my $type (@{$changes{'overrides'}}) {
                   17010:                     if ($usertypeshash{$type}) {
                   17011:                         if (grep(/^\Q$type\E/,@overrides)) {
                   17012:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   17013:                                                       $usertypeshash{$type}).'<ul><li>';
                   17014:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   17015:                                 my @text;
                   17016:                                 foreach my $item (@contacts) {
                   17017:                                     if ($newsetting{'override_'.$type}{$item}) { 
                   17018:                                         push(@text,$short_titles->{$item});
                   17019:                                     }
                   17020:                                 }
                   17021:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   17022:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   17023:                                 }
                   17024:   
                   17025:                                 if (@text) {
                   17026:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   17027:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   17028:                                 }
                   17029:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   17030:                                     my $bcctext;
                   17031:                                     if (@text) {
                   17032:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   17033:                                     } else {
                   17034:                                         $bcctext = '(Bcc)';
                   17035:                                     }
                   17036:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   17037:                                 } elsif (!@text) {
                   17038:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   17039:                                 }
                   17040:                                 $resulttext .= '</li>';
                   17041:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   17042:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   17043:                                     if ($loc eq 'b') {
                   17044:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   17045:                                     } elsif ($loc eq 's') {
                   17046:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   17047:                                     }
                   17048:                                 }
                   17049:                             }
                   17050:                             $resulttext .= '</li></ul></li>';
                   17051:                         } else {
                   17052:                             push(@deletions,$usertypeshash{$type});
                   17053:                         }
                   17054:                     }
                   17055:                 }
                   17056:                 if (@deletions) {
                   17057:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   17058:                                               join(', ',@deletions)).'</li>';
                   17059:                 }
                   17060:             }
1.203     raeburn  17061:             my @offon = ('off','on');
1.340     raeburn  17062:             my $corelink = &core_link_msu();
1.203     raeburn  17063:             if ($changes{'reporterrors'}) {
                   17064:                 $resulttext .= '<li>'.
                   17065:                                &mt('E-mail error reports to [_1] set to "'.
                   17066:                                    $offon[$env{'form.reporterrors'}].'".',
1.340     raeburn  17067:                                    $corelink).
1.203     raeburn  17068:                                '</li>';
                   17069:             }
                   17070:             if ($changes{'reportupdates'}) {
                   17071:                 $resulttext .= '<li>'.
                   17072:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   17073:                                     $offon[$env{'form.reportupdates'}].'".',
1.340     raeburn  17074:                                     $corelink).
1.203     raeburn  17075:                                 '</li>';
                   17076:             }
1.340     raeburn  17077:             if ($changes{'reportstatus'}) {
                   17078:                 $resulttext .= '<li>'.
                   17079:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   17080:                                     $offon[$env{'form.reportstatus'}].'".',
                   17081:                                     $corelink).
                   17082:                                 '</li>';
                   17083:             }
                   17084:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   17085:                 $resulttext .= '<li>'.
                   17086:                                &mt('Nightly status check e-mail settings').':<ul>';
                   17087:                 my (%defval,%use_def,%shown);
                   17088:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   17089:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   17090:                 $defval{'weights'} =
1.341     raeburn  17091:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340     raeburn  17092:                 $defval{'excluded'} = &mt('None');
                   17093:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   17094:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   17095:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   17096:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   17097:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   17098:                             } elsif ($item eq 'weights') {
                   17099:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341     raeburn  17100:                                     foreach my $type ('E','W','N','U') {
1.340     raeburn  17101:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   17102:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   17103:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   17104:                                         } else {
                   17105:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   17106:                                         }
                   17107:                                         $shown{$item} .= ', ';
                   17108:                                     }
                   17109:                                     $shown{$item} =~ s/, $//;
                   17110:                                 } else {
                   17111:                                     $shown{$item} = $defval{$item};
                   17112:                                 }
                   17113:                             } elsif ($item eq 'excluded') {
                   17114:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   17115:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   17116:                                 } else {
                   17117:                                     $shown{$item} = $defval{$item};
                   17118:                                 }
                   17119:                             }
                   17120:                         } else {
                   17121:                             $shown{$item} = $defval{$item};
                   17122:                         }
                   17123:                     }
                   17124:                 } else {
                   17125:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   17126:                         $shown{$item} = $defval{$item};
                   17127:                     }
                   17128:                 }
                   17129:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   17130:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   17131:                                           $shown{$item}).'</li>';
                   17132:                 }
                   17133:                 $resulttext .= '</ul></li>';
                   17134:             }
1.286     raeburn  17135:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   17136:                 my (@optional,@required,@unused,$maxsizechg);
                   17137:                 foreach my $field (@{$changes{'helpform'}}) {
                   17138:                     if ($field eq 'maxsize') {
                   17139:                         $maxsizechg = 1;
                   17140:                         next;
                   17141:                     }
                   17142:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  17143:                         push(@optional,$field);
1.286     raeburn  17144:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   17145:                         push(@unused,$field);
                   17146:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  17147:                         push(@required,$field);
1.286     raeburn  17148:                     }
                   17149:                 }
                   17150:                 if (@optional) {
                   17151:                     $resulttext .= '<li>'.
                   17152:                                    &mt('Help form fields changed to "Optional": [_1].',
                   17153:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   17154:                                    '</li>';
                   17155:                 }
                   17156:                 if (@required) {
                   17157:                     $resulttext .= '<li>'.
                   17158:                                    &mt('Help form fields changed to "Required": [_1].',
                   17159:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   17160:                                    '</li>';
                   17161:                 }
                   17162:                 if (@unused) {
                   17163:                     $resulttext .= '<li>'.
                   17164:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   17165:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   17166:                                    '</li>';
                   17167:                 }
                   17168:                 if ($maxsizechg) {
                   17169:                     $resulttext .= '<li>'.
                   17170:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   17171:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   17172:                                    '</li>';
                   17173:                 }
                   17174:             }
1.28      raeburn  17175:             $resulttext .= '</ul>';
                   17176:         } else {
1.288     raeburn  17177:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  17178:         }
                   17179:     } else {
                   17180:         $resulttext = '<span class="LC_error">'.
                   17181:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   17182:     }
                   17183:     return $resulttext;
                   17184: }
                   17185: 
1.357     raeburn  17186: sub modify_privacy {
                   17187:     my ($dom,%domconfig) = @_;
                   17188:     my ($resulttext,%current,%changes);
                   17189:     if (ref($domconfig{'privacy'}) eq 'HASH') {
                   17190:         %current = %{$domconfig{'privacy'}};
                   17191:     }
                   17192:     my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
                   17193:     my @items = ('domain','author','course','community');
                   17194:     my %names = &Apache::lonlocal::texthash (
                   17195:                    domain => 'Assigned domain role(s)',
                   17196:                    author => 'Assigned co-author role(s)',
                   17197:                    course => 'Assigned course role(s)',
                   17198:                    community => 'Assigned community role',
                   17199:                 );
                   17200:     my %roles = &Apache::lonlocal::texthash (
                   17201:                    domain => 'Domain role',
                   17202:                    author => 'Co-author role',
                   17203:                    course => 'Course role',
                   17204:                    community => 'Community role',
                   17205:                 );
                   17206:     my %titles = &Apache::lonlocal::texthash (
                   17207:                   approval => 'Approval for role in different domain',
                   17208:                   othdom   => 'User information available in other domain',
                   17209:                   priv     => 'Information viewable by privileged user in same domain',
                   17210:                   unpriv   => 'Information viewable by unprivileged user in same domain',
                   17211:                   instdom  => 'Other domain shares institution/provider',
                   17212:                   extdom   => 'Other domain has different institution/provider',
                   17213:                   none     => 'Not allowed',
                   17214:                   user     => 'User authorizes',
                   17215:                   domain   => 'Domain Coordinator authorizes',
                   17216:                   auto     => 'Unrestricted',
                   17217:     );
                   17218:     my %fieldnames = &Apache::lonlocal::texthash (
                   17219:                         id => 'Student/Employee ID',
                   17220:                         permanentemail => 'E-mail address',
                   17221:                         lastname => 'Last Name',
                   17222:                         firstname => 'First Name',
                   17223:                         middlename => 'Middle Name',
                   17224:                         generation => 'Generation',
                   17225:     );
                   17226:     my ($othertitle,$usertypes,$types) =
                   17227:         &Apache::loncommon::sorted_inst_types($dom);
                   17228:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   17229:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   17230: 
                   17231:     my %privacyhash = (
                   17232:                        'approval' => {
                   17233:                                        instdom => {},
                   17234:                                        extdom  => {},
                   17235:                                      },
                   17236:                        'othdom'   => {},
                   17237:                        'priv'     => {},
                   17238:                        'unpriv'   => {},
                   17239:                       );
                   17240:     foreach my $item (@items) {
                   17241:         if (@instdoms > 1) {
                   17242:             if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
                   17243:                 $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
                   17244:             }
                   17245:             if (ref($current{'approval'}) eq 'HASH') {
                   17246:                 if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                   17247:                     unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                   17248:                         $changes{'approval'} = 1;
                   17249:                     }
                   17250:                 }
                   17251:             } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   17252:                 $changes{'approval'} = 1;
                   17253:             }
                   17254:         }
                   17255:         if (keys(%by_location) > 0) {
                   17256:             if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   17257:                 $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
                   17258:             }
                   17259:             if (ref($current{'approval'}) eq 'HASH') {
                   17260:                 if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                   17261:                     unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                   17262:                         $changes{'approval'} = 1;
                   17263:                     }
                   17264:                 }
                   17265:             } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   17266:                 $changes{'approval'} = 1;
                   17267:             }
                   17268:         }
                   17269:         foreach my $status ('priv','unpriv') {
                   17270:             my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
                   17271:             my @newvalues;
                   17272:             foreach my $field (@possibles) {
                   17273:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17274:                     $privacyhash{$status}{$item}{$field} = 1;
                   17275:                     push(@newvalues,$field);
                   17276:                 }
                   17277:             }
                   17278:             @newvalues = sort(@newvalues);
                   17279:             if (ref($current{$status}) eq 'HASH') {
                   17280:                 if (ref($current{$status}{$item}) eq 'HASH') {
                   17281:                     my @currvalues = sort(keys(%{$current{$status}{$item}}));
                   17282:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17283:                     if (@diffs > 0) {
                   17284:                         $changes{$status} = 1;
                   17285:                     }
                   17286:                 }
                   17287:             } else {
                   17288:                 my @stdfields;
                   17289:                 foreach my $field (@fields) {
                   17290:                     if ($field eq 'id') {
                   17291:                         next if ($status eq 'unpriv');
                   17292:                         next if (($status eq 'priv') && ($item eq 'community'));
                   17293:                     }
                   17294:                     push(@stdfields,$field);
                   17295:                 }
                   17296:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17297:                 if (@diffs > 0) {
                   17298:                     $changes{$status} = 1;
                   17299:                 }
                   17300:             }
                   17301:         }
                   17302:     }
                   17303:     if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   17304:         my @statuses;
                   17305:         if (ref($types) eq 'ARRAY') {
                   17306:             @statuses = @{$types};
                   17307:         }
                   17308:         foreach my $type (@statuses,'default') {
                   17309:             my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
                   17310:             my @newvalues;
                   17311:             foreach my $field (sort(@possfields)) {
                   17312:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17313:                     $privacyhash{'othdom'}{$type}{$field} = 1;
                   17314:                     push(@newvalues,$field);
                   17315:                 }
                   17316:             }
                   17317:             @newvalues = sort(@newvalues);
                   17318:             if (ref($current{'othdom'}) eq 'HASH') {
                   17319:                 if (ref($current{'othdom'}{$type}) eq 'HASH') {
                   17320:                     my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                   17321:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17322:                     if (@diffs > 0) {
                   17323:                         $changes{'othdom'} = 1;
                   17324:                     }
                   17325:                 }
                   17326:             } else {
                   17327:                 my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   17328:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17329:                 if (@diffs > 0) {
                   17330:                     $changes{'othdom'} = 1;
                   17331:                 }
                   17332:             }
                   17333:         }
                   17334:     }
                   17335:     my %confighash = (
                   17336:                         privacy => \%privacyhash,
                   17337:                      );
                   17338:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   17339:     if ($putresult eq 'ok') {
                   17340:         if (keys(%changes) > 0) {
                   17341:             $resulttext = &mt('Changes made: ').'<ul>';
                   17342:             foreach my $key ('approval','othdom','priv','unpriv') {
                   17343:                 if ($changes{$key}) {
                   17344:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   17345:                     if ($key eq 'approval') {
                   17346:                         if (keys(%{$privacyhash{$key}{instdom}})) {
                   17347:                             $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                   17348:                             foreach my $item (@items) {
                   17349:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                   17350:                             }
                   17351:                             $resulttext .= '</ul></li>';
                   17352:                         }
                   17353:                         if (keys(%{$privacyhash{$key}{extdom}})) {
                   17354:                             $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                   17355:                             foreach my $item (@items) {
                   17356:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                   17357:                             }
                   17358:                             $resulttext .= '</ul></li>';
                   17359:                         }
                   17360:                     } elsif ($key eq 'othdom') {
                   17361:                         my @statuses;
                   17362:                         if (ref($types) eq 'ARRAY') {
                   17363:                             @statuses = @{$types};
                   17364:                         }
                   17365:                         if (ref($privacyhash{$key}) eq 'HASH') {
                   17366:                             foreach my $status (@statuses,'default') {
                   17367:                                 if ($status eq 'default') {
                   17368:                                     $resulttext .= '<li>'.$othertitle.': ';
                   17369:                                 } elsif (ref($usertypes) eq 'HASH') {
                   17370:                                     $resulttext .= '<li>'.$usertypes->{$status}.': ';
                   17371:                                 } else {
                   17372:                                     next;
                   17373:                                 }
                   17374:                                 if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                   17375:                                     if (keys(%{$privacyhash{$key}{$status}})) {
                   17376:                                         $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                   17377:                                     } else {
                   17378:                                         $resulttext .= &mt('none');
                   17379:                                     }
                   17380:                                 }
                   17381:                                 $resulttext .= '</li>';
                   17382:                             }
                   17383:                         }
                   17384:                     } else {
                   17385:                         foreach my $item (@items) {
                   17386:                             if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                   17387:                                 $resulttext .= '<li>'.$names{$item}.': ';
                   17388:                                 if (keys(%{$privacyhash{$key}{$item}})) {
                   17389:                                     $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                   17390:                                 } else {
                   17391:                                     $resulttext .= &mt('none');
                   17392:                                 }
                   17393:                                 $resulttext .= '</li>';
                   17394:                             }
                   17395:                         }
                   17396:                     }
                   17397:                     $resulttext .= '</ul></li>';
                   17398:                 }
                   17399:             }
                   17400:         } else {
                   17401:             $resulttext = &mt('No changes made to user information settings');
                   17402:         }
                   17403:     } else {
                   17404:         $resulttext = '<span class="LC_error">'.
                   17405:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17406:     }
                   17407:     return $resulttext;
                   17408: }
                   17409: 
1.354     raeburn  17410: sub modify_passwords {
                   17411:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355     raeburn  17412:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   17413:         $updatedefaults,$updateconf);
1.354     raeburn  17414:     my $customfn = 'resetpw.html';
                   17415:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   17416:         %current = %{$domconfig{'passwords'}};
                   17417:     }
                   17418:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   17419:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   17420:     if (ref($types) eq 'ARRAY') {
                   17421:         @oktypes = @{$types};
                   17422:     }
                   17423:     push(@oktypes,'default');
                   17424: 
                   17425:     my %titles = &Apache::lonlocal::texthash (
                   17426:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   17427:         intauth_check  => 'Check bcrypt cost if authenticated',
                   17428:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   17429:         permanent      => 'Permanent e-mail address',
                   17430:         critical       => 'Critical notification address',
                   17431:         notify         => 'Notification address',
                   17432:         min            => 'Minimum password length',
                   17433:         max            => 'Maximum password length',
                   17434:         chars          => 'Required characters',
                   17435:         expire         => 'Password expiration (days)',
1.356     raeburn  17436:         numsaved       => 'Number of previous passwords to save',
1.354     raeburn  17437:         reset          => 'Resetting Forgotten Password',
                   17438:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   17439:         rules          => 'Rules for LON-CAPA Passwords',
                   17440:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   17441:         username       => 'Username',
                   17442:         email          => 'E-mail address',
                   17443:     );
                   17444: 
                   17445: #
                   17446: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   17447: #
                   17448:     my (%curr_defaults,%save_defaults);
                   17449:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   17450:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   17451:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   17452:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   17453:             } else {
                   17454:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   17455:             }
                   17456:         }
                   17457:     }
                   17458:     my %staticdefaults = (
                   17459:         'resetlink'      => 2,
                   17460:         'resetcase'      => \@oktypes,
                   17461:         'resetprelink'   => 'both',
                   17462:         'resetemail'     => ['critical','notify','permanent'],
                   17463:         'intauth_cost'   => 10,
                   17464:         'intauth_check'  => 0,
                   17465:         'intauth_switch' => 0,
                   17466:     );
1.365     raeburn  17467:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354     raeburn  17468:     foreach my $type (@oktypes) {
                   17469:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   17470:     }
                   17471:     my $linklife = $env{'form.passwords_link'};
                   17472:     $linklife =~ s/^\s+|\s+$//g;
                   17473:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   17474:         $newvalues{'resetlink'} = $linklife;
                   17475:         if ($current{'resetlink'}) {
                   17476:             if ($current{'resetlink'} ne $linklife) {
                   17477:                 $changes{'reset'} = 1;
                   17478:             }
1.368     raeburn  17479:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17480:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   17481:                 $changes{'reset'} = 1;
                   17482:             }
                   17483:         }
                   17484:     } elsif ($current{'resetlink'}) {
                   17485:         $changes{'reset'} = 1;
                   17486:     }
                   17487:     my @casesens;
                   17488:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   17489:     foreach my $case (sort(@posscase)) {
                   17490:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   17491:             push(@casesens,$case);
                   17492:         }
                   17493:     }
                   17494:     $newvalues{'resetcase'} = \@casesens;
                   17495:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   17496:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   17497:         if (@diffs > 0) {
                   17498:             $changes{'reset'} = 1;
                   17499:         }
1.368     raeburn  17500:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17501:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   17502:         if (@diffs > 0) {
                   17503:             $changes{'reset'} = 1;
                   17504:         }
                   17505:     }
                   17506:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   17507:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   17508:         if (exists($current{'resetprelink'})) {
                   17509:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   17510:                 $changes{'reset'} = 1;
                   17511:             }
1.368     raeburn  17512:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17513:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   17514:                 $changes{'reset'} = 1;
                   17515:             }
                   17516:         }
                   17517:     } elsif ($current{'resetprelink'}) {
                   17518:         $changes{'reset'} = 1;
                   17519:     }
                   17520:     foreach my $type (@oktypes) {
                   17521:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   17522:         my @postlink;
                   17523:         foreach my $item (sort(@possplink)) {
                   17524:             if ($item =~ /^(email|username)$/) {
                   17525:                 push(@postlink,$item);
                   17526:             }
                   17527:         }
                   17528:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   17529:         unless ($changes{'reset'}) {
                   17530:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   17531:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   17532:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   17533:                     if (@diffs > 0) {
                   17534:                         $changes{'reset'} = 1;
                   17535:                     }
                   17536:                 } else {
                   17537:                     $changes{'reset'} = 1;
                   17538:                 }
1.368     raeburn  17539:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17540:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   17541:                 if (@diffs > 0) {
                   17542:                     $changes{'reset'} = 1;
                   17543:                 }
                   17544:             }
                   17545:         }
                   17546:     }
                   17547:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   17548:     my @resetemail;
                   17549:     foreach my $item (sort(@possemailsrc)) {
                   17550:         if ($item =~ /^(permanent|critical|notify)$/) {
                   17551:             push(@resetemail,$item);
                   17552:         }
                   17553:     }
                   17554:     $newvalues{'resetemail'} = \@resetemail;
                   17555:     unless ($changes{'reset'}) {
                   17556:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   17557:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   17558:             if (@diffs > 0) {
                   17559:                 $changes{'reset'} = 1;
                   17560:             }
1.368     raeburn  17561:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17562:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   17563:             if (@diffs > 0) {
                   17564:                 $changes{'reset'} = 1;
                   17565:             }
                   17566:         }
                   17567:     }
                   17568:     if ($env{'form.passwords_stdtext'} == 0) {
                   17569:         $newvalues{'resetremove'} = 1;
                   17570:         unless ($current{'resetremove'}) {
                   17571:             $changes{'reset'} = 1;
                   17572:         }
                   17573:     } elsif ($current{'resetremove'}) {
                   17574:         $changes{'reset'} = 1;
                   17575:     }
                   17576:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   17577:         my $servadm = $r->dir_config('lonAdmEMail');
                   17578:         my ($configuserok,$author_ok,$switchserver) =
                   17579:             &config_check($dom,$confname,$servadm);
                   17580:         my $error;
                   17581:         if ($configuserok eq 'ok') {
                   17582:             if ($switchserver) {
                   17583:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   17584:             } else {
                   17585:                 if ($author_ok eq 'ok') {
                   17586:                     my ($result,$customurl) =
                   17587:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   17588:                                      $confname,'customtext/resetpw','','',$customfn);
                   17589:                     if ($result eq 'ok') {
                   17590:                         $newvalues{'resetcustom'} = $customurl;
                   17591:                         $changes{'reset'} = 1;
                   17592:                     } else {
                   17593:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   17594:                     }
                   17595:                 } else {
                   17596:                     $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);
                   17597:                 }
                   17598:             }
                   17599:         } else {
                   17600:             $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);
                   17601:         }
                   17602:         if ($error) {
                   17603:             &Apache::lonnet::logthis($error);
                   17604:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   17605:         }
                   17606:     } elsif ($current{'resetcustom'}) {
                   17607:         if ($env{'form.passwords_custom_del'}) {
                   17608:             $changes{'reset'} = 1;
                   17609:         } else {
                   17610:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   17611:         }
                   17612:     }
                   17613:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   17614:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   17615:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   17616:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   17617:             $changes{'intauth'} = 1;
                   17618:         }
                   17619:     } else {
                   17620:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   17621:     }
                   17622:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   17623:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   17624:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   17625:             $changes{'intauth'} = 1;
                   17626:         }
                   17627:     } else {
                   17628:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   17629:     }
                   17630:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   17631:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   17632:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   17633:             $changes{'intauth'} = 1;
                   17634:         }
                   17635:     } else {
                   17636:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   17637:     }
                   17638:     foreach my $item ('cost','check','switch') {
                   17639:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   17640:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   17641:             $updatedefaults = 1;
                   17642:         }
                   17643:     }
1.356     raeburn  17644:     foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  17645:         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356     raeburn  17646:         my $ruleok;
                   17647:         if ($rule eq 'expire') {
1.365     raeburn  17648:             if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
                   17649:                 ($env{'form.passwords_'.$rule} ne '0')) {
1.359     raeburn  17650:                 $ruleok = 1;
1.356     raeburn  17651:             }
1.365     raeburn  17652:         } elsif ($rule eq 'min') {
                   17653:             if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   17654:                 if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
                   17655:                     $ruleok = 1;
                   17656:                 }
                   17657:             }
                   17658:         } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
                   17659:                  ($env{'form.passwords_'.$rule} ne '0')) {
1.356     raeburn  17660:             $ruleok = 1;
                   17661:         }
                   17662:         if ($ruleok) {
1.354     raeburn  17663:             $newvalues{$rule} = $env{'form.passwords_'.$rule};
                   17664:             if (exists($current{$rule})) {
                   17665:                 if ($newvalues{$rule} ne $current{$rule}) {
                   17666:                     $changes{'rules'} = 1;
                   17667:                 }
                   17668:             } elsif ($rule eq 'min') {
                   17669:                 if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                   17670:                     $changes{'rules'} = 1;
                   17671:                 }
1.370     raeburn  17672:             } else {
                   17673:                 $changes{'rules'} = 1;
1.354     raeburn  17674:             }
                   17675:         } elsif (exists($current{$rule})) {
                   17676:             $changes{'rules'} = 1;
                   17677:         }
                   17678:     }
                   17679:     my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
                   17680:     my @chars;
                   17681:     foreach my $item (sort(@posschars)) {
                   17682:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   17683:             push(@chars,$item);
                   17684:         }
                   17685:     }
                   17686:     $newvalues{'chars'} = \@chars;
                   17687:     unless ($changes{'rules'}) {
                   17688:         if (ref($current{'chars'}) eq 'ARRAY') {
                   17689:             my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
                   17690:             if (@diffs > 0) {
                   17691:                 $changes{'rules'} = 1;
                   17692:             }
                   17693:         } else {
                   17694:             if (@chars > 0) {
                   17695:                 $changes{'rules'} = 1;
                   17696:             }
                   17697:         }
                   17698:     }
1.359     raeburn  17699:     my %crsownerchg = (
                   17700:                         by => [],
                   17701:                         for => [],
                   17702:                       );
                   17703:     foreach my $item ('by','for') {
                   17704:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   17705:         foreach my $type (sort(@posstypes)) {
                   17706:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   17707:                 push(@{$crsownerchg{$item}},$type);
                   17708:             }
                   17709:         }
                   17710:     }
                   17711:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   17712:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   17713:         foreach my $item ('by','for') {
                   17714:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   17715:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   17716:                 if (@diffs > 0) {
                   17717:                     $changes{'crsownerchg'} = 1;
                   17718:                     last;
                   17719:                 }
                   17720:             }
                   17721:         }
1.368     raeburn  17722:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359     raeburn  17723:         foreach my $item ('by','for') {
                   17724:             if (@{$crsownerchg{$item}} > 0) {
                   17725:                 $changes{'crsownerchg'} = 1;
                   17726:                 last;
                   17727:             }
1.354     raeburn  17728:         }
                   17729:     }
                   17730: 
                   17731:     my %confighash = (
                   17732:                         defaults  => \%save_defaults,
                   17733:                         passwords => \%newvalues,
                   17734:                      );
                   17735:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   17736: 
                   17737:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   17738:     if ($putresult eq 'ok') {
                   17739:         if (keys(%changes) > 0) {
                   17740:             $resulttext = &mt('Changes made: ').'<ul>';
                   17741:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   17742:                 if ($changes{$key}) {
1.355     raeburn  17743:                     unless ($key eq 'intauth') {
                   17744:                         $updateconf = 1;
                   17745:                     }
1.354     raeburn  17746:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   17747:                     if ($key eq 'reset') {
                   17748:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   17749:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   17750:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   17751:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369     raeburn  17752:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   17753:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   17754:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   17755:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   17756:                             }
1.354     raeburn  17757:                         } else {
                   17758:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   17759:                         }
                   17760:                         if ($confighash{'passwords'}{'resetlink'}) {
                   17761:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   17762:                         } else {
                   17763:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   17764:                                                   &mt('Will default to 2 hours').'</li>';
                   17765:                         }
                   17766:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   17767:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   17768:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   17769:                             } else {
                   17770:                                 my $casesens;
                   17771:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   17772:                                     if ($type eq 'default') {
                   17773:                                         $casesens .= $othertitle.', ';
                   17774:                                     } elsif ($usertypes->{$type} ne '') {
                   17775:                                         $casesens .= $usertypes->{$type}.', ';
                   17776:                                     }
                   17777:                                 }
                   17778:                                 $casesens =~ s/\Q, \E$//;
                   17779:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   17780:                             }
                   17781:                         } else {
                   17782:                             $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>';
                   17783:                         }
                   17784:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   17785:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   17786:                         } else {
                   17787:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   17788:                         }
                   17789:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   17790:                             my $output;
                   17791:                             if (ref($types) eq 'ARRAY') {
                   17792:                                 foreach my $type (@{$types}) {
                   17793:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   17794:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   17795:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   17796:                                         } else {
                   17797:                                             $output .= $usertypes->{$type}.' -- '.
                   17798:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   17799:                                         }
                   17800:                                     }
                   17801:                                 }
                   17802:                             }
                   17803:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   17804:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   17805:                                     $output .= $othertitle.' -- '.&mt('none');
                   17806:                                 } else {
                   17807:                                     $output .= $othertitle.' -- '.
                   17808:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   17809:                                 }
                   17810:                             }
                   17811:                             if ($output) {
                   17812:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   17813:                             } else {
                   17814:                                 $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>';
                   17815:                             }
                   17816:                         } else {
                   17817:                             $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>';
                   17818:                         }
                   17819:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   17820:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   17821:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   17822:                             } else {
                   17823:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   17824:                             }
                   17825:                         } else {
1.379     raeburn  17826:                             $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  17827:                         }
                   17828:                         if ($confighash{'passwords'}{'resetremove'}) {
                   17829:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   17830:                         } else {
                   17831:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   17832:                         }
                   17833:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   17834:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369     raeburn  17835:                                                                             &mt('custom text'),600,500,undef,undef,
                   17836:                                                                             undef,undef,'background-color:#ffffff');
                   17837:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354     raeburn  17838:                         } else {
                   17839:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   17840:                         }
                   17841:                     } elsif ($key eq 'intauth') {
                   17842:                         foreach my $item ('cost','switch','check') {
                   17843:                             my $value = $save_defaults{$key.'_'.$item};
                   17844:                             if ($item eq 'switch') {
                   17845:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   17846:                                                      0 => 'No',
                   17847:                                                      1 => 'Yes',
                   17848:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   17849:                                                  );
                   17850:                                 if ($value =~ /^(0|1|2)$/) {
                   17851:                                     $value = $optiondesc{$value};
                   17852:                                 } else {
                   17853:                                     $value = &mt('none -- defaults to No');
                   17854:                                 }
                   17855:                             } elsif ($item eq 'check') {
                   17856:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   17857:                                                      0 => 'No',
                   17858:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   17859:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   17860:                                                  );
                   17861:                                 if ($value =~ /^(0|1|2)$/) {
                   17862:                                     $value = $optiondesc{$value};
                   17863:                                 } else {
                   17864:                                     $value = &mt('none -- defaults to No');
                   17865:                                 }
                   17866:                             }
                   17867:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   17868:                         }
                   17869:                     } elsif ($key eq 'rules') {
1.356     raeburn  17870:                         foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  17871:                             if ($confighash{'passwords'}{$rule} eq '') {
                   17872:                                 if ($rule eq 'min') {
1.356     raeburn  17873:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365     raeburn  17874:                                                    ' '.&mt('Default of [_1] will be used',
                   17875:                                                            $Apache::lonnet::passwdmin).'</li>';
1.356     raeburn  17876:                                 } else {
                   17877:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354     raeburn  17878:                                 }
                   17879:                             } else {
                   17880:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   17881:                             }
                   17882:                         }
1.370     raeburn  17883:                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   17884:                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   17885:                                 my %rulenames = &Apache::lonlocal::texthash(
                   17886:                                                      uc => 'At least one upper case letter',
                   17887:                                                      lc => 'At least one lower case letter',
                   17888:                                                      num => 'At least one number',
                   17889:                                                      spec => 'At least one non-alphanumeric',
                   17890:                                                    );
                   17891:                                 my $needed = '<ul><li>'.
                   17892:                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
                   17893:                                              '</li></ul>'; 
                   17894:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   17895:                             } else {
                   17896:                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   17897:                             }
                   17898:                         } else {
                   17899:                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   17900:                         }
1.354     raeburn  17901:                     } elsif ($key eq 'crsownerchg') {
1.359     raeburn  17902:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   17903:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   17904:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   17905:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   17906:                             } else {
                   17907:                                 my %crsownerstr;
                   17908:                                 foreach my $item ('by','for') {
                   17909:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   17910:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   17911:                                             if ($type eq 'default') {
                   17912:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   17913:                                             } elsif ($usertypes->{$type} ne '') {
                   17914:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   17915:                                             }
                   17916:                                         }
                   17917:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   17918:                                     }
                   17919:                                 }
                   17920:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   17921:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   17922:                             }
1.354     raeburn  17923:                         } else {
1.359     raeburn  17924:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354     raeburn  17925:                         }
                   17926:                     }
                   17927:                     $resulttext .= '</ul></li>';
                   17928:                 }
                   17929:             }
                   17930:             $resulttext .= '</ul>';
                   17931:         } else {
                   17932:             $resulttext = &mt('No changes made to password settings');
                   17933:         }
1.355     raeburn  17934:         my $cachetime = 24*60*60;
1.354     raeburn  17935:         if ($updatedefaults) {
                   17936:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   17937:             if (ref($lastactref) eq 'HASH') {
                   17938:                 $lastactref->{'domdefaults'} = 1;
                   17939:             }
                   17940:         }
1.355     raeburn  17941:         if ($updateconf) {
                   17942:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   17943:             if (ref($lastactref) eq 'HASH') {
                   17944:                 $lastactref->{'passwdconf'} = 1;
                   17945:             }
                   17946:         }
1.354     raeburn  17947:     } else {
                   17948:         $resulttext = '<span class="LC_error">'.
                   17949:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17950:     }
                   17951:     if ($errors) {
                   17952:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   17953:                        $errors.'</ul></p>';
                   17954:     }
                   17955:     return $resulttext;
                   17956: }
                   17957: 
1.28      raeburn  17958: sub modify_usercreation {
1.27      raeburn  17959:     my ($dom,%domconfig) = @_;
1.224     raeburn  17960:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  17961:     my $warningmsg;
1.27      raeburn  17962:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   17963:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  17964:             if ($key eq 'cancreate') {
                   17965:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   17966:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  17967:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   17968:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   17969:                         } else {
1.224     raeburn  17970:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   17971:                         }
                   17972:                     }
                   17973:                 }
                   17974:             } elsif ($key eq 'email_rule') {
                   17975:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   17976:             } else {
                   17977:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   17978:             }
1.27      raeburn  17979:         }
                   17980:     }
                   17981:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  17982:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  17983:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  17984:     foreach my $item(@contexts) {
1.224     raeburn  17985:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  17986:     }
1.34      raeburn  17987:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   17988:         foreach my $item (@contexts) {
1.224     raeburn  17989:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   17990:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  17991:             }
1.27      raeburn  17992:         }
1.34      raeburn  17993:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   17994:         foreach my $item (@contexts) {
1.43      raeburn  17995:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  17996:                 if ($cancreate{$item} ne 'any') {
                   17997:                     push(@{$changes{'cancreate'}},$item);
                   17998:                 }
                   17999:             } else {
                   18000:                 if ($cancreate{$item} ne 'none') {
                   18001:                     push(@{$changes{'cancreate'}},$item);
                   18002:                 }
1.27      raeburn  18003:             }
                   18004:         }
                   18005:     } else {
1.43      raeburn  18006:         foreach my $item (@contexts)  {
1.34      raeburn  18007:             push(@{$changes{'cancreate'}},$item);
                   18008:         }
1.27      raeburn  18009:     }
1.34      raeburn  18010: 
1.27      raeburn  18011:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   18012:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   18013:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   18014:                 push(@{$changes{'username_rule'}},$type);
                   18015:             }
                   18016:         }
                   18017:         foreach my $type (@username_rule) {
                   18018:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   18019:                 push(@{$changes{'username_rule'}},$type);
                   18020:             }
                   18021:         }
                   18022:     } else {
                   18023:         push(@{$changes{'username_rule'}},@username_rule);
                   18024:     }
                   18025: 
1.32      raeburn  18026:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   18027:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   18028:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   18029:                 push(@{$changes{'id_rule'}},$type);
                   18030:             }
                   18031:         }
                   18032:         foreach my $type (@id_rule) {
                   18033:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   18034:                 push(@{$changes{'id_rule'}},$type);
                   18035:             }
                   18036:         }
                   18037:     } else {
                   18038:         push(@{$changes{'id_rule'}},@id_rule);
                   18039:     }
                   18040: 
1.43      raeburn  18041:     my @authen_contexts = ('author','course','domain');
1.325     raeburn  18042:     my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  18043:     my %authhash;
1.43      raeburn  18044:     foreach my $item (@authen_contexts) {
1.28      raeburn  18045:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   18046:         foreach my $auth (@authtypes) {
                   18047:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   18048:                 $authhash{$item}{$auth} = 1;
                   18049:             } else {
                   18050:                 $authhash{$item}{$auth} = 0;
                   18051:             }
                   18052:         }
                   18053:     }
                   18054:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  18055:         foreach my $item (@authen_contexts) {
1.28      raeburn  18056:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   18057:                 foreach my $auth (@authtypes) {
                   18058:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   18059:                         push(@{$changes{'authtypes'}},$item);
                   18060:                         last;
                   18061:                     }
                   18062:                 }
                   18063:             }
                   18064:         }
                   18065:     } else {
1.43      raeburn  18066:         foreach my $item (@authen_contexts) {
1.28      raeburn  18067:             push(@{$changes{'authtypes'}},$item);
                   18068:         }
                   18069:     }
                   18070: 
1.224     raeburn  18071:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   18072:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   18073:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   18074:     $save_usercreate{'id_rule'} = \@id_rule;
                   18075:     $save_usercreate{'username_rule'} = \@username_rule,
                   18076:     $save_usercreate{'authtypes'} = \%authhash;
                   18077: 
1.27      raeburn  18078:     my %usercreation_hash =  (
1.224     raeburn  18079:         usercreation     => \%save_usercreate,
                   18080:     );
1.27      raeburn  18081: 
                   18082:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   18083:                                              $dom);
1.50      raeburn  18084: 
1.224     raeburn  18085:     if ($putresult eq 'ok') {
                   18086:         if (keys(%changes) > 0) {
                   18087:             $resulttext = &mt('Changes made:').'<ul>';
                   18088:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   18089:                 my %lt = &usercreation_types();
                   18090:                 foreach my $type (@{$changes{'cancreate'}}) {
                   18091:                     my $chgtext = $lt{$type}.', ';
                   18092:                     if ($cancreate{$type} eq 'none') {
                   18093:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   18094:                     } elsif ($cancreate{$type} eq 'any') {
                   18095:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   18096:                     } elsif ($cancreate{$type} eq 'official') {
                   18097:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   18098:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   18099:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   18100:                     }
                   18101:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   18102:                 }
                   18103:             }
                   18104:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   18105:                 my ($rules,$ruleorder) = 
                   18106:                     &Apache::lonnet::inst_userrules($dom,'username');
                   18107:                 my $chgtext = '<ul>';
                   18108:                 foreach my $type (@username_rule) {
                   18109:                     if (ref($rules->{$type}) eq 'HASH') {
                   18110:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   18111:                     }
                   18112:                 }
                   18113:                 $chgtext .= '</ul>';
                   18114:                 if (@username_rule > 0) {
                   18115:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   18116:                 } else {
                   18117:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   18118:                 }
                   18119:             }
                   18120:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   18121:                 my ($idrules,$idruleorder) = 
                   18122:                     &Apache::lonnet::inst_userrules($dom,'id');
                   18123:                 my $chgtext = '<ul>';
                   18124:                 foreach my $type (@id_rule) {
                   18125:                     if (ref($idrules->{$type}) eq 'HASH') {
                   18126:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   18127:                     }
                   18128:                 }
                   18129:                 $chgtext .= '</ul>';
                   18130:                 if (@id_rule > 0) {
                   18131:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   18132:                 } else {
                   18133:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   18134:                 }
                   18135:             }
                   18136:             my %authname = &authtype_names();
                   18137:             my %context_title = &context_names();
                   18138:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   18139:                 my $chgtext = '<ul>';
                   18140:                 foreach my $type (@{$changes{'authtypes'}}) {
                   18141:                     my @allowed;
                   18142:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   18143:                     foreach my $auth (@authtypes) {
                   18144:                         if ($authhash{$type}{$auth}) {
                   18145:                             push(@allowed,$authname{$auth});
                   18146:                         }
                   18147:                     }
                   18148:                     if (@allowed > 0) {
                   18149:                         $chgtext .= join(', ',@allowed).'</li>';
                   18150:                     } else {
                   18151:                         $chgtext .= &mt('none').'</li>';
                   18152:                     }
                   18153:                 }
                   18154:                 $chgtext .= '</ul>';
                   18155:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   18156:                 $resulttext .= '</li>';
                   18157:             }
                   18158:             $resulttext .= '</ul>';
                   18159:         } else {
                   18160:             $resulttext = &mt('No changes made to user creation settings');
                   18161:         }
                   18162:     } else {
                   18163:         $resulttext = '<span class="LC_error">'.
                   18164:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18165:     }
                   18166:     if ($warningmsg ne '') {
                   18167:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   18168:     }
                   18169:     return $resulttext;
                   18170: }
                   18171: 
                   18172: sub modify_selfcreation {
1.305     raeburn  18173:     my ($dom,$lastactref,%domconfig) = @_;
                   18174:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   18175:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   18176:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  18177:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   18178:     if (ref($typesref) eq 'ARRAY') {
                   18179:         @types = @{$typesref};
                   18180:     }
                   18181:     if (ref($usertypesref) eq 'HASH') {
                   18182:         %usertypes = %{$usertypesref};
1.228     raeburn  18183:     }
1.303     raeburn  18184:     $usertypes{'default'} = $othertitle;
1.224     raeburn  18185: #
                   18186: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   18187: #
                   18188:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   18189:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   18190:             if ($key eq 'cancreate') {
                   18191:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   18192:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   18193:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  18194:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   18195:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   18196:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   18197:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  18198:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  18199:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18200:                         } else {
                   18201:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18202:                         }
                   18203:                     }
                   18204:                 }
                   18205:             } elsif ($key eq 'email_rule') {
                   18206:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   18207:             } else {
                   18208:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   18209:             }
                   18210:         }
                   18211:     }
                   18212: #
                   18213: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   18214: #
                   18215:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   18216:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   18217:             if ($key eq 'selfcreate') {
                   18218:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18219:             } else {
                   18220:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18221:             }
                   18222:         }
                   18223:     }
1.305     raeburn  18224: #
                   18225: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   18226: #
                   18227:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   18228:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   18229:             if ($key eq 'inststatusguest') {
                   18230:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18231:             } else {
                   18232:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18233:             }
                   18234:         }
                   18235:     }
1.224     raeburn  18236: 
                   18237:     my @contexts = ('selfcreate');
                   18238:     @{$cancreate{'selfcreate'}} = ();
                   18239:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  18240:     if (@types) {
                   18241:         @{$cancreate{'statustocreate'}} = ();
                   18242:     }
1.236     raeburn  18243:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  18244:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  18245:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  18246:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  18247:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  18248:     my %selfcreatetypes = (
                   18249:                              sso   => 'users authenticated by institutional single sign on',
                   18250:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  18251:                              email => 'users verified by e-mail',
1.50      raeburn  18252:                           );
1.224     raeburn  18253: #
                   18254: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   18255: # is permitted.
                   18256: #
1.305     raeburn  18257:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  18258: 
1.305     raeburn  18259:     my (@statuses,%email_rule);
1.228     raeburn  18260:     foreach my $item ('login','sso','email') {
1.224     raeburn  18261:         if ($item eq 'email') {
1.236     raeburn  18262:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  18263:                 if (@types) {
                   18264:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   18265:                     foreach my $status (@poss_statuses) {
                   18266:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   18267:                             push(@statuses,$status);
                   18268:                         }
                   18269:                     }
                   18270:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   18271:                 } else {
                   18272:                     push(@statuses,'default');
                   18273:                 }
                   18274:                 if (@statuses) {
                   18275:                     my %curr_rule;
                   18276:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   18277:                         foreach my $type (@statuses) {
                   18278:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  18279:                         }
1.305     raeburn  18280:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   18281:                         foreach my $type (@statuses) {
                   18282:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   18283:                         }
                   18284:                     }
                   18285:                     push(@{$cancreate{'selfcreate'}},'email');
                   18286:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   18287:                     my %curremaildom;
                   18288:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   18289:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   18290:                     }
                   18291:                     foreach my $type (@statuses) {
                   18292:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   18293:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   18294:                         }
                   18295:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   18296:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   18297:                         }
                   18298:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   18299: #
                   18300: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   18301: #
                   18302:                             my $chosen = $1;
                   18303:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   18304:                                 my $emaildom;
                   18305:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   18306:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                   18307:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   18308:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   18309:                                         if (exists($curremaildom{$type}{$chosen})) {
                   18310:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   18311:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   18312:                                             }
                   18313:                                         } elsif ($emaildom ne '') {
                   18314:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   18315:                                         }
                   18316:                                     } elsif ($emaildom ne '') {
                   18317:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   18318:                                     } 
                   18319:                                 }
                   18320:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   18321:                             } elsif ($chosen eq 'custom') {
                   18322:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   18323:                                 $email_rule{$type} = [];
                   18324:                                 if (ref($emailrules) eq 'HASH') {
                   18325:                                     foreach my $rule (@possemail_rules) {
                   18326:                                         if (exists($emailrules->{$rule})) {
                   18327:                                             push(@{$email_rule{$type}},$rule);
                   18328:                                         }
                   18329:                                     }
                   18330:                                 }
                   18331:                                 if (@{$email_rule{$type}}) {
                   18332:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   18333:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   18334:                                         if (@{$curr_rule{$type}} > 0) {
                   18335:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   18336:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   18337:                                                     push(@{$changes{'email_rule'}},$type);
                   18338:                                                 }
                   18339:                                             }
                   18340:                                         }
                   18341:                                         foreach my $type (@{$email_rule{$type}}) {
                   18342:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   18343:                                                 push(@{$changes{'email_rule'}},$type);
                   18344:                                             }
                   18345:                                         }
                   18346:                                     } else {
                   18347:                                         push(@{$changes{'email_rule'}},$type);
                   18348:                                     }
                   18349:                                 }
                   18350:                             } else {
                   18351:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   18352:                             }
                   18353:                         }
                   18354:                     }
                   18355:                     if (@types) {
                   18356:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18357:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   18358:                             if (@changed) {
                   18359:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   18360:                             }
                   18361:                         } else {
                   18362:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   18363:                         }
                   18364:                     }
                   18365:                 } else {
                   18366:                     delete($env{'form.cancreate_email'});
                   18367:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18368:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   18369:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   18370:                         }
                   18371:                     }
                   18372:                 }
                   18373:             } else {
                   18374:                 $save_inststatus{'inststatusguest'} = [];
                   18375:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18376:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   18377:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  18378:                     }
                   18379:                 }
1.224     raeburn  18380:             }
                   18381:         } else {
                   18382:             if ($env{'form.cancreate_'.$item}) {
                   18383:                 push(@{$cancreate{'selfcreate'}},$item);
                   18384:             }
                   18385:         }
                   18386:     }
1.305     raeburn  18387:     my (%userinfo,%savecaptcha);
1.224     raeburn  18388:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   18389: #
1.228     raeburn  18390: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   18391: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  18392: #
1.236     raeburn  18393: 
1.244     raeburn  18394:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  18395:         push(@contexts,'emailusername');
1.305     raeburn  18396:         if (@statuses) {
                   18397:             foreach my $type (@statuses) {
1.228     raeburn  18398:                 if (ref($infofields) eq 'ARRAY') {
                   18399:                     foreach my $field (@{$infofields}) {
                   18400:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   18401:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   18402:                         }
                   18403:                     }
1.224     raeburn  18404:                 }
                   18405:             }
                   18406:         }
                   18407: #
                   18408: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  18409: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  18410: #
                   18411: 
                   18412:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   18413:         @approvalnotify = sort(@approvalnotify);
                   18414:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   18415:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18416:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   18417:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   18418:                     push(@{$changes{'cancreate'}},'notify');
                   18419:                 }
                   18420:             } else {
                   18421:                 if ($cancreate{'notify'}{'approval'}) {
                   18422:                     push(@{$changes{'cancreate'}},'notify');
                   18423:                 }
                   18424:             }
                   18425:         } elsif ($cancreate{'notify'}{'approval'}) {
                   18426:             push(@{$changes{'cancreate'}},'notify');
                   18427:         }
                   18428: 
                   18429:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   18430:     }
                   18431: #  
1.236     raeburn  18432: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  18433: # institutional log-in.
                   18434: #
                   18435:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   18436:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   18437:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   18438:             $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.').' '.
                   18439:                           &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.');
                   18440:         }
                   18441:     }
                   18442:     my @fields = ('lastname','firstname','middlename','generation',
                   18443:                   'permanentemail','id');
1.240     raeburn  18444:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  18445:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   18446: #
                   18447: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   18448: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   18449: # may self-create accounts 
                   18450: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   18451: # which the user may supply, if institutional data is unavailable.
                   18452: #
                   18453:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  18454:         if (@types) {
1.305     raeburn  18455:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   18456:             push(@contexts,'statustocreate');
1.303     raeburn  18457:             foreach my $type (@types) {
1.224     raeburn  18458:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   18459:                 foreach my $field (@fields) {
                   18460:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   18461:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   18462:                     } else {
                   18463:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   18464:                     }
                   18465:                 }
                   18466:             }
                   18467:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  18468:                 foreach my $type (@types) {
1.224     raeburn  18469:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   18470:                         foreach my $field (@fields) {
                   18471:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   18472:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   18473:                                 push(@{$changes{'selfcreate'}},$type);
                   18474:                                 last;
                   18475:                             }
                   18476:                         }
                   18477:                     }
                   18478:                 }
                   18479:             } else {
1.303     raeburn  18480:                 foreach my $type (@types) {
1.224     raeburn  18481:                     push(@{$changes{'selfcreate'}},$type);
                   18482:                 }
                   18483:             }
                   18484:         }
1.240     raeburn  18485:         foreach my $field (@shibfields) {
                   18486:             if ($env{'form.shibenv_'.$field} ne '') {
                   18487:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   18488:             }
                   18489:         }
                   18490:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18491:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   18492:                 foreach my $field (@shibfields) {
                   18493:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   18494:                         push(@{$changes{'cancreate'}},'shibenv');
                   18495:                     }
                   18496:                 }
                   18497:             } else {
                   18498:                 foreach my $field (@shibfields) {
                   18499:                     if ($env{'form.shibenv_'.$field}) {
                   18500:                         push(@{$changes{'cancreate'}},'shibenv');
                   18501:                         last;
                   18502:                     }
                   18503:                 }
                   18504:             }
                   18505:         }
1.224     raeburn  18506:     }
                   18507:     foreach my $item (@contexts) {
                   18508:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   18509:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   18510:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   18511:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   18512:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18513:                             push(@{$changes{'cancreate'}},$item);
                   18514:                         }
                   18515:                     }
                   18516:                 }
                   18517:             }
                   18518:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   18519:                 foreach my $type (@{$cancreate{$item}}) {
                   18520:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   18521:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18522:                             push(@{$changes{'cancreate'}},$item);
                   18523:                         }
                   18524:                     }
                   18525:                 }
                   18526:             }
                   18527:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   18528:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  18529:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   18530:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   18531:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   18532:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  18533:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18534:                                     push(@{$changes{'cancreate'}},$item);
                   18535:                                 }
                   18536:                             }
                   18537:                         }
1.305     raeburn  18538:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18539:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  18540:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18541:                                 push(@{$changes{'cancreate'}},$item);
                   18542:                             }
1.224     raeburn  18543:                         }
                   18544:                     }
                   18545:                 }
1.305     raeburn  18546:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   18547:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   18548:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   18549:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   18550:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  18551:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18552:                                         push(@{$changes{'cancreate'}},$item);
                   18553:                                     }
                   18554:                                 }
                   18555:                             } else {
                   18556:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18557:                                     push(@{$changes{'cancreate'}},$item);
                   18558:                                 }
                   18559:                             }
                   18560:                         }
1.305     raeburn  18561:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18562:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  18563:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18564:                                 push(@{$changes{'cancreate'}},$item);
                   18565:                             }
1.224     raeburn  18566:                         }
                   18567:                     }
                   18568:                 }
                   18569:             }
                   18570:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   18571:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   18572:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   18573:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18574:                         push(@{$changes{'cancreate'}},$item);
                   18575:                     }
                   18576:                 }
1.305     raeburn  18577:             }
                   18578:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18579:             if (ref($cancreate{$item}) eq 'HASH') {
                   18580:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18581:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  18582:                 }
                   18583:             }
                   18584:         } elsif ($item eq 'emailusername') {
1.228     raeburn  18585:             if (ref($cancreate{$item}) eq 'HASH') {
                   18586:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   18587:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   18588:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   18589:                             if ($cancreate{$item}{$type}{$field}) {
                   18590:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18591:                                     push(@{$changes{'cancreate'}},$item);
                   18592:                                 }
                   18593:                                 last;
                   18594:                             }
                   18595:                         }
                   18596:                     }
                   18597:                 }
1.224     raeburn  18598:             }
                   18599:         }
                   18600:     }
                   18601: #
                   18602: # Populate %save_usercreate hash with updates to self-creation configuration.
                   18603: #
                   18604:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   18605:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  18606:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  18607:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   18608:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   18609:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   18610:     }
1.236     raeburn  18611:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   18612:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   18613:     }
1.303     raeburn  18614:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   18615:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   18616:     }
1.305     raeburn  18617:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   18618:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   18619:     }
1.303     raeburn  18620:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   18621:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   18622:     }
1.224     raeburn  18623:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   18624:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   18625:     }
1.240     raeburn  18626:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   18627:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   18628:     }
1.224     raeburn  18629:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  18630:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  18631: 
                   18632:     my %userconfig_hash = (
                   18633:             usercreation     => \%save_usercreate,
                   18634:             usermodification => \%save_usermodify,
1.305     raeburn  18635:             inststatus       => \%save_inststatus,
1.224     raeburn  18636:     );
1.305     raeburn  18637: 
1.224     raeburn  18638:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   18639:                                              $dom);
                   18640: #
1.305     raeburn  18641: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  18642: #
1.27      raeburn  18643:     if ($putresult eq 'ok') {
                   18644:         if (keys(%changes) > 0) {
                   18645:             $resulttext = &mt('Changes made:').'<ul>';
                   18646:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  18647:                 my %lt = &selfcreation_types();
1.34      raeburn  18648:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  18649:                     my $chgtext = '';
1.45      raeburn  18650:                     if ($type eq 'selfcreate') {
1.50      raeburn  18651:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  18652:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  18653:                         } else {
1.224     raeburn  18654:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   18655:                                         '<ul>';
1.50      raeburn  18656:                             foreach my $case (@{$cancreate{$type}}) {
                   18657:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   18658:                             }
                   18659:                             $chgtext .= '</ul>';
1.100     raeburn  18660:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   18661:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   18662:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   18663:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  18664:                                             $chgtext .= '<span class="LC_warning">'.
                   18665:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   18666:                                                         '</span><br />';
                   18667:                                         }
                   18668:                                     }
                   18669:                                 }
                   18670:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  18671:                                     if (!@statuses) {
                   18672:                                         $chgtext .= '<span class="LC_warning">'.
                   18673:                                                     &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.").
                   18674:                                                     '</span><br />';
1.303     raeburn  18675: 
1.100     raeburn  18676:                                     }
                   18677:                                 }
                   18678:                             }
1.43      raeburn  18679:                         }
1.240     raeburn  18680:                     } elsif ($type eq 'shibenv') {
                   18681:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  18682:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  18683:                         } else {
                   18684:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   18685:                                         '<ul>';
                   18686:                             foreach my $field (@shibfields) {
                   18687:                                 next if ($cancreate{$type}{$field} eq '');
                   18688:                                 if ($field eq 'inststatus') {
                   18689:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   18690:                                 } else {
                   18691:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   18692:                                 }
                   18693:                             }
                   18694:                             $chgtext .= '</ul>';
1.303     raeburn  18695:                         }
1.93      raeburn  18696:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  18697:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   18698:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   18699:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   18700:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  18701:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  18702:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  18703:                                         $chgtext .= '<br />'.
                   18704:                                                     '<span class="LC_warning">'.
                   18705:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   18706:                                                     '</span>';
                   18707:                                     }
1.303     raeburn  18708:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  18709:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  18710:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   18711:                                     } else {
                   18712:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   18713:                                     }
                   18714:                                     $chgtext .= '<ul>';
                   18715:                                     foreach my $case (@{$cancreate{$type}}) {
                   18716:                                         if ($case eq 'default') {
                   18717:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   18718:                                         } else {
1.303     raeburn  18719:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  18720:                                         }
                   18721:                                     }
1.100     raeburn  18722:                                     $chgtext .= '</ul>';
                   18723:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  18724:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  18725:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   18726:                                                     '</span>';
1.100     raeburn  18727:                                     }
                   18728:                                 }
                   18729:                             } else {
                   18730:                                 if (@{$cancreate{$type}} == 0) {
                   18731:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   18732:                                 } else {
                   18733:                                     $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  18734:                                 }
                   18735:                             }
1.303     raeburn  18736:                             $chgtext .= '<br />';
1.93      raeburn  18737:                         }
1.236     raeburn  18738:                     } elsif ($type eq 'selfcreateprocessing') {
                   18739:                         my %choices = &Apache::lonlocal::texthash (
                   18740:                                                                     automatic => 'Automatic approval',
                   18741:                                                                     approval  => 'Queued for approval',
                   18742:                                                                   );
1.305     raeburn  18743:                         if (@types) {
                   18744:                             if (@statuses) {
1.303     raeburn  18745:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
1.309     raeburn  18746:                                             '<ul>';
1.305     raeburn  18747:                                 foreach my $status (@statuses) {
                   18748:                                     if ($status eq 'default') {
                   18749:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  18750:                                     } else {
1.305     raeburn  18751:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  18752:                                     }
                   18753:                                 }
                   18754:                                 $chgtext .= '</ul>';
                   18755:                             }
                   18756:                         } else {
                   18757:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   18758:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   18759:                         }
                   18760:                     } elsif ($type eq 'emailverified') {
                   18761:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  18762:                                                                     all   => 'Same as e-mail',
                   18763:                                                                     first => 'Omit @domain',
                   18764:                                                                     free  => 'Free to choose',
1.303     raeburn  18765:                                                                   );
1.305     raeburn  18766:                         if (@types) {
                   18767:                             if (@statuses) {
1.303     raeburn  18768:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   18769:                                             '<ul>';
1.305     raeburn  18770:                                 foreach my $status (@statuses) {
1.362     raeburn  18771:                                     if ($status eq 'default') {
1.305     raeburn  18772:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  18773:                                     } else {
1.305     raeburn  18774:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  18775:                                     }
                   18776:                                 }
                   18777:                                 $chgtext .= '</ul>';
                   18778:                             }
                   18779:                         } else {
1.305     raeburn  18780:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  18781:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  18782:                         }
1.305     raeburn  18783:                     } elsif ($type eq 'emailoptions') {
                   18784:                         my %options = &Apache::lonlocal::texthash (
                   18785:                                                                     any     => 'Any e-mail',
                   18786:                                                                     inst    => 'Institutional only',
                   18787:                                                                     noninst => 'Non-institutional only',
                   18788:                                                                     custom  => 'Custom restrictions',
                   18789:                                                                   );
                   18790:                         if (@types) {
                   18791:                             if (@statuses) {
                   18792:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   18793:                                             '<ul>';
                   18794:                                 foreach my $status (@statuses) {
                   18795:                                     if ($type eq 'default') {
                   18796:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   18797:                                     } else {
                   18798:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  18799:                                     }
                   18800:                                 }
1.305     raeburn  18801:                                 $chgtext .= '</ul>';
                   18802:                             }
                   18803:                         } else {
                   18804:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   18805:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   18806:                             } else {
                   18807:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   18808:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  18809:                             }
1.305     raeburn  18810:                         }
                   18811:                     } elsif ($type eq 'emaildomain') {
                   18812:                         my $output;
                   18813:                         if (@statuses) {
                   18814:                             foreach my $type (@statuses) {
                   18815:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   18816:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   18817:                                         if ($type eq 'default') {
                   18818:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18819:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   18820:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18821:                                             } else {
                   18822:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   18823:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   18824:                                             }
1.303     raeburn  18825:                                         } else {
1.305     raeburn  18826:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18827:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   18828:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18829:                                             } else {
                   18830:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   18831:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                   18832:                                             }
1.303     raeburn  18833:                                         }
1.305     raeburn  18834:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   18835:                                         if ($type eq 'default') {
                   18836:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18837:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   18838:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18839:                                             } else {
                   18840:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   18841:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   18842:                                             }
1.303     raeburn  18843:                                         } else {
1.305     raeburn  18844:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18845:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   18846:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18847:                                             } else {
                   18848:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   18849:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                   18850:                                             }
1.303     raeburn  18851:                                         }
                   18852:                                     }
                   18853:                                 }
                   18854:                             }
1.305     raeburn  18855:                         }
                   18856:                         if ($output ne '') {
                   18857:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   18858:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  18859:                         }
1.165     raeburn  18860:                     } elsif ($type eq 'captcha') {
1.224     raeburn  18861:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  18862:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   18863:                         } else {
                   18864:                             my %captchas = &captcha_phrases();
1.224     raeburn  18865:                             if ($captchas{$savecaptcha{$type}}) {
                   18866:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  18867:                             } else {
1.210     raeburn  18868:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  18869:                             }
                   18870:                         }
                   18871:                     } elsif ($type eq 'recaptchakeys') {
                   18872:                         my ($privkey,$pubkey);
1.224     raeburn  18873:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   18874:                             $pubkey = $savecaptcha{$type}{'public'};
                   18875:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  18876:                         }
                   18877:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   18878:                         if (!$pubkey) {
                   18879:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   18880:                         } else {
                   18881:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   18882:                         }
                   18883:                         if (!$privkey) {
                   18884:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   18885:                         } else {
                   18886:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   18887:                         }
                   18888:                         $chgtext .= '</ul>';
1.269     raeburn  18889:                     } elsif ($type eq 'recaptchaversion') {
                   18890:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  18891:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  18892:                         }
1.224     raeburn  18893:                     } elsif ($type eq 'emailusername') {
                   18894:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  18895:                             if (@statuses) {
                   18896:                                 foreach my $type (@statuses) {
1.228     raeburn  18897:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   18898:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  18899:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  18900:                                                     '<ul>';
                   18901:                                             foreach my $field (@{$infofields}) {
                   18902:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   18903:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   18904:                                                 }
                   18905:                                             }
1.245     raeburn  18906:                                             $chgtext .= '</ul>';
                   18907:                                         } else {
1.303     raeburn  18908:                                             $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  18909:                                         }
                   18910:                                     } else {
1.303     raeburn  18911:                                         $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  18912:                                     }
                   18913:                                 }
                   18914:                             }
                   18915:                         }
                   18916:                     } elsif ($type eq 'notify') {
1.303     raeburn  18917:                         my $numapprove = 0;
1.224     raeburn  18918:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   18919:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   18920:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  18921:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   18922:                                     $numapprove ++;
1.224     raeburn  18923:                                 }
                   18924:                             }
1.43      raeburn  18925:                         }
1.303     raeburn  18926:                         unless ($numapprove) {
                   18927:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   18928:                         }
1.34      raeburn  18929:                     }
1.224     raeburn  18930:                     if ($chgtext) {
                   18931:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  18932:                     }
                   18933:                 }
                   18934:             }
1.305     raeburn  18935:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  18936:                 my ($emailrules,$emailruleorder) =
                   18937:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  18938:                 foreach my $type (@{$changes{'email_rule'}}) {
                   18939:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   18940:                         my $chgtext = '<ul>';
                   18941:                         foreach my $rule (@{$email_rule{$type}}) {
                   18942:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   18943:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   18944:                             }
                   18945:                         }
                   18946:                         $chgtext .= '</ul>';
1.310     raeburn  18947:                         my $typename;
1.305     raeburn  18948:                         if (@types) {
                   18949:                             if ($type eq 'default') {
                   18950:                                 $typename = $othertitle;
                   18951:                             } else {
                   18952:                                 $typename = $usertypes{$type};
                   18953:                             } 
                   18954:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   18955:                         }
                   18956:                         if (@{$email_rule{$type}} > 0) {
                   18957:                             $resulttext .= '<li>'.
                   18958:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   18959:                                                $usertypes{$type}).
                   18960:                                            $chgtext.
                   18961:                                            '</li>';
                   18962:                         } else {
                   18963:                             $resulttext .= '<li>'.
1.310     raeburn  18964:                                            &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  18965:                                            '</li>'.
1.310     raeburn  18966:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  18967:                         }
1.43      raeburn  18968:                     }
                   18969:                 }
1.305     raeburn  18970:             }
                   18971:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   18972:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18973:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   18974:                         my $chgtext = '<ul>';
                   18975:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   18976:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   18977:                         }
                   18978:                         $chgtext .= '</ul>';
                   18979:                         $resulttext .= '<li>'.
                   18980:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   18981:                                           $chgtext.
                   18982:                                        '</li>';
                   18983:                     } else {
                   18984:                         $resulttext .= '<li>'.
                   18985:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   18986:                                        '</li>';
                   18987:                     }
1.43      raeburn  18988:                 }
                   18989:             }
1.224     raeburn  18990:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   18991:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   18992:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   18993:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   18994:                     my $typename = $type;
1.303     raeburn  18995:                     if (keys(%usertypes) > 0) {
                   18996:                         if ($usertypes{$type} ne '') {
                   18997:                             $typename = $usertypes{$type};
1.224     raeburn  18998:                         }
                   18999:                     }
                   19000:                     my @modifiable;
                   19001:                     $resulttext .= '<li>'.
                   19002:                                     &mt('Self-creation of account by users with status: [_1]',
                   19003:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   19004:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   19005:                     foreach my $field (@fields) {
                   19006:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   19007:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  19008:                         }
                   19009:                     }
1.224     raeburn  19010:                     if (@modifiable > 0) {
                   19011:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  19012:                     } else {
1.224     raeburn  19013:                         $resulttext .= &mt('none');
1.43      raeburn  19014:                     }
1.224     raeburn  19015:                     $resulttext .= '</li>';
1.28      raeburn  19016:                 }
1.224     raeburn  19017:                 $resulttext .= '</ul></li>';
1.28      raeburn  19018:             }
1.27      raeburn  19019:             $resulttext .= '</ul>';
1.305     raeburn  19020:             my $cachetime = 24*60*60;
                   19021:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   19022:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   19023:             if (ref($lastactref) eq 'HASH') {
                   19024:                 $lastactref->{'domdefaults'} = 1;
                   19025:             }
1.27      raeburn  19026:         } else {
1.224     raeburn  19027:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  19028:         }
                   19029:     } else {
                   19030:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  19031:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19032:     }
1.43      raeburn  19033:     if ($warningmsg ne '') {
                   19034:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   19035:     }
1.23      raeburn  19036:     return $resulttext;
                   19037: }
                   19038: 
1.165     raeburn  19039: sub process_captcha {
1.369     raeburn  19040:     my ($container,$changes,$newsettings,$currsettings) = @_;
                   19041:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165     raeburn  19042:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   19043:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   19044:         $newsettings->{'captcha'} = 'original';
                   19045:     }
1.369     raeburn  19046:     my %current;
                   19047:     if (ref($currsettings) eq 'HASH') {
                   19048:         %current = %{$currsettings};
                   19049:     }
                   19050:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  19051:         if ($container eq 'cancreate') {
1.169     raeburn  19052:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19053:                 push(@{$changes->{'cancreate'}},'captcha');
                   19054:             } elsif (!defined($changes->{'cancreate'})) {
                   19055:                 $changes->{'cancreate'} = ['captcha'];
                   19056:             }
1.368     raeburn  19057:         } elsif ($container eq 'passwords') {
                   19058:             $changes->{'reset'} = 1;
1.169     raeburn  19059:         } else {
                   19060:             $changes->{'captcha'} = 1;
1.165     raeburn  19061:         }
                   19062:     }
1.269     raeburn  19063:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  19064:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   19065:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   19066:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  19067:         $newpub =~ s/[^\w\-]//g;
                   19068:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  19069:         $newsettings->{'recaptchakeys'} = {
                   19070:                                              public  => $newpub,
                   19071:                                              private => $newpriv,
                   19072:                                           };
1.269     raeburn  19073:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   19074:         $newversion =~ s/\D//g;
                   19075:         if ($newversion ne '2') {
                   19076:             $newversion = 1;
                   19077:         }
                   19078:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  19079:     }
1.369     raeburn  19080:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   19081:         $currpub = $current{'recaptchakeys'}{'public'};
                   19082:         $currpriv = $current{'recaptchakeys'}{'private'};
1.179     raeburn  19083:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   19084:             $newsettings->{'recaptchakeys'} = {
                   19085:                                                  public  => '',
                   19086:                                                  private => '',
                   19087:                                               }
                   19088:         }
1.165     raeburn  19089:     }
1.369     raeburn  19090:     if ($current{'captcha'} eq 'recaptcha') {
                   19091:         $currversion = $current{'recaptchaversion'};
1.269     raeburn  19092:         if ($currversion ne '2') {
                   19093:             $currversion = 1;
                   19094:         }
                   19095:     }
                   19096:     if ($currversion ne $newversion) {
                   19097:         if ($container eq 'cancreate') {
                   19098:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19099:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   19100:             } elsif (!defined($changes->{'cancreate'})) {
                   19101:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   19102:             }
1.368     raeburn  19103:         } elsif ($container eq 'passwords') {
                   19104:             $changes->{'reset'} = 1;
1.269     raeburn  19105:         } else {
                   19106:             $changes->{'recaptchaversion'} = 1;
                   19107:         }
                   19108:     }
1.165     raeburn  19109:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  19110:         if ($container eq 'cancreate') {
                   19111:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19112:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   19113:             } elsif (!defined($changes->{'cancreate'})) {
                   19114:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   19115:             }
1.368     raeburn  19116:         } elsif ($container eq 'passwords') {
                   19117:             $changes->{'reset'} = 1;
1.169     raeburn  19118:         } else {
1.210     raeburn  19119:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  19120:         }
                   19121:     }
                   19122:     return;
                   19123: }
                   19124: 
1.33      raeburn  19125: sub modify_usermodification {
                   19126:     my ($dom,%domconfig) = @_;
1.224     raeburn  19127:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  19128:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   19129:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  19130:             if ($key eq 'selfcreate') {
                   19131:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   19132:             } else {  
                   19133:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   19134:             }
1.33      raeburn  19135:         }
                   19136:     }
1.224     raeburn  19137:     my @contexts = ('author','course');
1.33      raeburn  19138:     my %context_title = (
                   19139:                            author => 'In author context',
                   19140:                            course => 'In course context',
                   19141:                         );
                   19142:     my @fields = ('lastname','firstname','middlename','generation',
                   19143:                   'permanentemail','id');
                   19144:     my %roles = (
                   19145:                   author => ['ca','aa'],
                   19146:                   course => ['st','ep','ta','in','cr'],
                   19147:                 );
                   19148:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19149:     foreach my $context (@contexts) {
                   19150:         foreach my $role (@{$roles{$context}}) {
                   19151:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   19152:             foreach my $item (@fields) {
                   19153:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   19154:                     $modifyhash{$context}{$role}{$item} = 1;
                   19155:                 } else {
                   19156:                     $modifyhash{$context}{$role}{$item} = 0;
                   19157:                 }
                   19158:             }
                   19159:         }
                   19160:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   19161:             foreach my $role (@{$roles{$context}}) {
                   19162:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   19163:                     foreach my $field (@fields) {
                   19164:                         if ($modifyhash{$context}{$role}{$field} ne 
                   19165:                                 $curr_usermodification{$context}{$role}{$field}) {
                   19166:                             push(@{$changes{$context}},$role);
                   19167:                             last;
                   19168:                         }
                   19169:                     }
                   19170:                 }
                   19171:             }
                   19172:         } else {
                   19173:             foreach my $context (@contexts) {
                   19174:                 foreach my $role (@{$roles{$context}}) {
                   19175:                     push(@{$changes{$context}},$role);
                   19176:                 }
                   19177:             }
                   19178:         }
                   19179:     }
                   19180:     my %usermodification_hash =  (
                   19181:                                    usermodification => \%modifyhash,
                   19182:                                  );
                   19183:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   19184:                                              \%usermodification_hash,$dom);
                   19185:     if ($putresult eq 'ok') {
                   19186:         if (keys(%changes) > 0) {
                   19187:             $resulttext = &mt('Changes made: ').'<ul>';
                   19188:             foreach my $context (@contexts) {
                   19189:                 if (ref($changes{$context}) eq 'ARRAY') {
                   19190:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   19191:                     if (ref($changes{$context}) eq 'ARRAY') {
                   19192:                         foreach my $role (@{$changes{$context}}) {
                   19193:                             my $rolename;
1.224     raeburn  19194:                             if ($role eq 'cr') {
                   19195:                                 $rolename = &mt('Custom');
1.33      raeburn  19196:                             } else {
1.224     raeburn  19197:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  19198:                             }
                   19199:                             my @modifiable;
1.224     raeburn  19200:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  19201:                             foreach my $field (@fields) {
                   19202:                                 if ($modifyhash{$context}{$role}{$field}) {
                   19203:                                     push(@modifiable,$fieldtitles{$field});
                   19204:                                 }
                   19205:                             }
                   19206:                             if (@modifiable > 0) {
                   19207:                                 $resulttext .= join(', ',@modifiable);
                   19208:                             } else {
                   19209:                                 $resulttext .= &mt('none'); 
                   19210:                             }
                   19211:                             $resulttext .= '</li>';
                   19212:                         }
                   19213:                         $resulttext .= '</ul></li>';
                   19214:                     }
                   19215:                 }
                   19216:             }
                   19217:             $resulttext .= '</ul>';
                   19218:         } else {
                   19219:             $resulttext = &mt('No changes made to user modification settings');
                   19220:         }
                   19221:     } else {
                   19222:         $resulttext = '<span class="LC_error">'.
                   19223:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19224:     }
                   19225:     return $resulttext;
                   19226: }
                   19227: 
1.43      raeburn  19228: sub modify_defaults {
1.212     raeburn  19229:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  19230:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  19231:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  19232:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354     raeburn  19233:                  'portal_def');
1.325     raeburn  19234:     my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43      raeburn  19235:     foreach my $item (@items) {
                   19236:         $newvalues{$item} = $env{'form.'.$item};
                   19237:         if ($item eq 'auth_def') {
                   19238:             if ($newvalues{$item} ne '') {
                   19239:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   19240:                     push(@errors,$item);
                   19241:                 }
                   19242:             }
                   19243:         } elsif ($item eq 'lang_def') {
                   19244:             if ($newvalues{$item} ne '') {
                   19245:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   19246:                     my $langcode = $1;
1.103     raeburn  19247:                     if ($langcode ne 'x_chef') {
                   19248:                         if (code2language($langcode) eq '') {
                   19249:                             push(@errors,$item);
                   19250:                         }
1.43      raeburn  19251:                     }
                   19252:                 } else {
                   19253:                     push(@errors,$item);
                   19254:                 }
                   19255:             }
1.54      raeburn  19256:         } elsif ($item eq 'timezone_def') {
                   19257:             if ($newvalues{$item} ne '') {
1.62      raeburn  19258:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  19259:                     push(@errors,$item);   
                   19260:                 }
                   19261:             }
1.68      raeburn  19262:         } elsif ($item eq 'datelocale_def') {
                   19263:             if ($newvalues{$item} ne '') {
                   19264:                 my @datelocale_ids = DateTime::Locale->ids();
                   19265:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   19266:                     push(@errors,$item);
                   19267:                 }
                   19268:             }
1.141     raeburn  19269:         } elsif ($item eq 'portal_def') {
                   19270:             if ($newvalues{$item} ne '') {
                   19271:                 unless ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
                   19272:                     push(@errors,$item);
                   19273:                 }
                   19274:             }
1.43      raeburn  19275:         }
                   19276:         if (grep(/^\Q$item\E$/,@errors)) {
                   19277:             $newvalues{$item} = $domdefaults{$item};
                   19278:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   19279:             $changes{$item} = 1;
                   19280:         }
1.72      raeburn  19281:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  19282:     }
1.354     raeburn  19283:     my %staticdefaults = (
                   19284:                            'intauth_cost'   => 10,
                   19285:                            'intauth_check'  => 0,
                   19286:                            'intauth_switch' => 0,
                   19287:                          );
                   19288:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   19289:         if (exists($domdefaults{$item})) {
                   19290:             $newvalues{$item} = $domdefaults{$item};
                   19291:         } else {
                   19292:             $newvalues{$item} = $staticdefaults{$item};
                   19293:         }
                   19294:     }
1.43      raeburn  19295:     my %defaults_hash = (
1.72      raeburn  19296:                          defaults => \%newvalues,
                   19297:                         );
1.43      raeburn  19298:     my $title = &defaults_titles();
1.236     raeburn  19299: 
                   19300:     my $currinststatus;
                   19301:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   19302:         $currinststatus = $domconfig{'inststatus'};
                   19303:     } else {
                   19304:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   19305:         $currinststatus = {
                   19306:                              inststatustypes => $usertypes,
                   19307:                              inststatusorder => $types,
                   19308:                              inststatusguest => [],
                   19309:                           };
                   19310:     }
                   19311:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   19312:     my @allpos;
                   19313:     my %alltypes;
1.305     raeburn  19314:     my @inststatusguest;
                   19315:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   19316:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   19317:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   19318:                 push(@inststatusguest,$type);
                   19319:             }
                   19320:         }
                   19321:     }
                   19322:     my ($currtitles,$currorder);
1.236     raeburn  19323:     if (ref($currinststatus) eq 'HASH') {
                   19324:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   19325:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   19326:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   19327:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   19328:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   19329:                     }
                   19330:                 }
                   19331:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   19332:                     my $position = $env{'form.inststatus_pos_'.$type};
                   19333:                     $position =~ s/\D+//g;
                   19334:                     $allpos[$position] = $type;
                   19335:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   19336:                     $alltypes{$type} =~ s/`//g;
                   19337:                 }
                   19338:             }
                   19339:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   19340:             $currtitles =~ s/,$//;
                   19341:         }
                   19342:     }
                   19343:     if ($env{'form.addinststatus'}) {
                   19344:         my $newtype = $env{'form.addinststatus'};
                   19345:         $newtype =~ s/\W//g;
                   19346:         unless (exists($alltypes{$newtype})) {
                   19347:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   19348:             $alltypes{$newtype} =~ s/`//g; 
                   19349:             my $position = $env{'form.addinststatus_pos'};
                   19350:             $position =~ s/\D+//g;
                   19351:             if ($position ne '') {
                   19352:                 $allpos[$position] = $newtype;
                   19353:             }
                   19354:         }
                   19355:     }
1.305     raeburn  19356:     my @orderedstatus;
1.236     raeburn  19357:     foreach my $type (@allpos) {
                   19358:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   19359:             push(@orderedstatus,$type);
                   19360:         }
                   19361:     }
                   19362:     foreach my $type (keys(%alltypes)) {
                   19363:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   19364:             delete($alltypes{$type});
                   19365:         }
                   19366:     }
                   19367:     $defaults_hash{'inststatus'} = {
                   19368:                                      inststatustypes => \%alltypes,
                   19369:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  19370:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  19371:                                    };
                   19372:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   19373:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   19374:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   19375:         }
                   19376:     }
                   19377:     if ($currorder ne join(',',@orderedstatus)) {
                   19378:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   19379:     }
                   19380:     my $newtitles;
                   19381:     foreach my $item (@orderedstatus) {
                   19382:         $newtitles .= $alltypes{$item}.',';
                   19383:     }
                   19384:     $newtitles =~ s/,$//;
                   19385:     if ($currtitles ne $newtitles) {
                   19386:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   19387:     }
1.43      raeburn  19388:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   19389:                                              $dom);
                   19390:     if ($putresult eq 'ok') {
                   19391:         if (keys(%changes) > 0) {
                   19392:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  19393:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  19394:             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";
                   19395:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  19396:                 if ($item eq 'inststatus') {
                   19397:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  19398:                         if (@orderedstatus) {
1.236     raeburn  19399:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   19400:                             foreach my $type (@orderedstatus) { 
                   19401:                                 $resulttext .= $alltypes{$type}.', ';
                   19402:                             }
                   19403:                             $resulttext =~ s/, $//;
                   19404:                             $resulttext .= '</li>';
1.305     raeburn  19405:                         } else {
                   19406:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
1.236     raeburn  19407:                         }
                   19408:                     }
                   19409:                 } else {
                   19410:                     my $value = $env{'form.'.$item};
                   19411:                     if ($value eq '') {
                   19412:                         $value = &mt('none');
                   19413:                     } elsif ($item eq 'auth_def') {
                   19414:                         my %authnames = &authtype_names();
                   19415:                         my %shortauth = (
                   19416:                                           internal   => 'int',
                   19417:                                           krb4       => 'krb4',
                   19418:                                           krb5       => 'krb5',
                   19419:                                           localauth  => 'loc',
1.325     raeburn  19420:                                           lti        => 'lti',
1.236     raeburn  19421:                         );
                   19422:                         $value = $authnames{$shortauth{$value}};
                   19423:                     }
                   19424:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   19425:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  19426:                 }
                   19427:             }
                   19428:             $resulttext .= '</ul>';
                   19429:             $mailmsgtext .= "\n";
                   19430:             my $cachetime = 24*60*60;
1.72      raeburn  19431:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  19432:             if (ref($lastactref) eq 'HASH') {
                   19433:                 $lastactref->{'domdefaults'} = 1;
                   19434:             }
1.68      raeburn  19435:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  19436:                 my $notify = 1;
                   19437:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   19438:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   19439:                         $notify = 0;
                   19440:                     }
                   19441:                 }
                   19442:                 if ($notify) {
                   19443:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   19444:                                                "LON-CAPA Domain Settings Change - $dom",
                   19445:                                                $mailmsgtext);
                   19446:                 }
1.54      raeburn  19447:             }
1.43      raeburn  19448:         } else {
1.54      raeburn  19449:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  19450:         }
                   19451:     } else {
                   19452:         $resulttext = '<span class="LC_error">'.
                   19453:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19454:     }
                   19455:     if (@errors > 0) {
                   19456:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   19457:         foreach my $item (@errors) {
                   19458:             $resulttext .= ' "'.$title->{$item}.'",';
                   19459:         }
                   19460:         $resulttext =~ s/,$//;
                   19461:     }
                   19462:     return $resulttext;
                   19463: }
                   19464: 
1.46      raeburn  19465: sub modify_scantron {
1.205     raeburn  19466:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  19467:     my ($resulttext,%confhash,%changes,$errors);
                   19468:     my $custom = 'custom.tab';
                   19469:     my $default = 'default.tab';
                   19470:     my $servadm = $r->dir_config('lonAdmEMail');
1.346     raeburn  19471:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  19472:         &config_check($dom,$confname,$servadm);
                   19473:     if ($env{'form.scantronformat.filename'} ne '') {
                   19474:         my $error;
                   19475:         if ($configuserok eq 'ok') {
                   19476:             if ($switchserver) {
1.130     raeburn  19477:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  19478:             } else {
                   19479:                 if ($author_ok eq 'ok') {
                   19480:                     my ($result,$scantronurl) =
                   19481:                         &publishlogo($r,'upload','scantronformat',$dom,
                   19482:                                      $confname,'scantron','','',$custom);
                   19483:                     if ($result eq 'ok') {
                   19484:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  19485:                         $changes{'scantronformat'} = 1;
1.46      raeburn  19486:                     } else {
                   19487:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   19488:                     }
                   19489:                 } else {
                   19490:                     $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);
                   19491:                 }
                   19492:             }
                   19493:         } else {
                   19494:             $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);
                   19495:         }
                   19496:         if ($error) {
                   19497:             &Apache::lonnet::logthis($error);
                   19498:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   19499:         }
                   19500:     }
1.48      raeburn  19501:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   19502:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   19503:             if ($env{'form.scantronformat_del'}) {
                   19504:                 $confhash{'scantron'}{'scantronformat'} = '';
                   19505:                 $changes{'scantronformat'} = 1;
1.347     raeburn  19506:             } else {
                   19507:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46      raeburn  19508:             }
                   19509:         }
                   19510:     }
1.347     raeburn  19511:     my @options = ('hdr','pad','rem');
1.346     raeburn  19512:     my @fields = &scantroncsv_fields();
                   19513:     my %titles = &scantronconfig_titles();
1.347     raeburn  19514:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346     raeburn  19515:     my ($newdat,$currdat,%newcol,%currcol);
                   19516:     if (grep(/^dat$/,@formats)) {
                   19517:         $confhash{'scantron'}{config}{dat} = 1;
                   19518:         $newdat = 1;
                   19519:     } else {
                   19520:         $newdat = 0;
                   19521:     }
                   19522:     if (grep(/^csv$/,@formats)) {
                   19523:         my %bynum;
                   19524:         foreach my $field (@fields) {
                   19525:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   19526:                 my $posscol = $1;
                   19527:                 if (($posscol < 20) && (!$bynum{$posscol})) {
1.347     raeburn  19528:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346     raeburn  19529:                     $bynum{$posscol} = $field;
                   19530:                     $newcol{$field} = $posscol;
                   19531:                 }
                   19532:             }
                   19533:         }
1.347     raeburn  19534:         if (keys(%newcol)) {
                   19535:             foreach my $option (@options) {
                   19536:                 if ($env{'form.scantroncsv_'.$option}) {
                   19537:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   19538:                 }
                   19539:             }
                   19540:         }
1.346     raeburn  19541:     }
                   19542:     $currdat = 1;
                   19543:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   19544:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347     raeburn  19545:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346     raeburn  19546:                 $currdat = 0;
                   19547:             }
                   19548:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  19549:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   19550:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   19551:                 }
1.346     raeburn  19552:             }
                   19553:         }
                   19554:     }
                   19555:     if ($currdat != $newdat) {
                   19556:         $changes{'config'} = 1;
                   19557:     } else {
                   19558:         foreach my $field (@fields) {
                   19559:             if ($currcol{$field} ne '') {
                   19560:                 if ($currcol{$field} ne $newcol{$field}) {
                   19561:                     $changes{'config'} = 1;
                   19562:                     last;
1.347     raeburn  19563:                 }
1.346     raeburn  19564:             } elsif ($newcol{$field} ne '') {
                   19565:                 $changes{'config'} = 1;
                   19566:                 last;
                   19567:             }
                   19568:         }
                   19569:     }
1.46      raeburn  19570:     if (keys(%confhash) > 0) {
                   19571:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   19572:                                                  $dom);
                   19573:         if ($putresult eq 'ok') {
                   19574:             if (keys(%changes) > 0) {
1.48      raeburn  19575:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   19576:                     $resulttext = &mt('Changes made:').'<ul>';
1.346     raeburn  19577:                     if ($changes{'scantronformat'}) {
                   19578:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   19579:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   19580:                         } else {
                   19581:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   19582:                         }
                   19583:                     }
1.347     raeburn  19584:                     if ($changes{'config'}) {
1.346     raeburn  19585:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   19586:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   19587:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   19588:                             }
                   19589:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  19590:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   19591:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   19592:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   19593:                                         foreach my $field (@fields) {
                   19594:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   19595:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   19596:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   19597:                                             }
                   19598:                                         }
                   19599:                                         $resulttext .= '</ul></li>';
                   19600:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   19601:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   19602:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   19603:                                                 foreach my $option (@options) {
                   19604:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   19605:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   19606:                                                     }
                   19607:                                                 }
                   19608:                                                 $resulttext .= '</ul></li>';
                   19609:                                             }
1.346     raeburn  19610:                                         }
                   19611:                                     }
                   19612:                                 }
                   19613:                             }
                   19614:                         } else {
                   19615:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   19616:                         }
1.46      raeburn  19617:                     }
1.48      raeburn  19618:                     $resulttext .= '</ul>';
                   19619:                 } else {
1.130     raeburn  19620:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  19621:                 }
                   19622:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  19623:                 if (ref($lastactref) eq 'HASH') {
                   19624:                     $lastactref->{'domainconfig'} = 1;
                   19625:                 }
1.46      raeburn  19626:             } else {
1.346     raeburn  19627:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  19628:             }
                   19629:         } else {
                   19630:             $resulttext = '<span class="LC_error">'.
                   19631:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   19632:         }
                   19633:     } else {
1.130     raeburn  19634:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  19635:     }
                   19636:     if ($errors) {
1.353     raeburn  19637:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   19638:                        $errors.'</ul></p>';
1.46      raeburn  19639:     }
                   19640:     return $resulttext;
                   19641: }
                   19642: 
1.48      raeburn  19643: sub modify_coursecategories {
1.239     raeburn  19644:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  19645:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   19646:         $cathash);
1.48      raeburn  19647:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  19648:     my @catitems = ('unauth','auth');
                   19649:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  19650:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  19651:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   19652:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   19653:             $changes{'togglecats'} = 1;
                   19654:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   19655:         }
                   19656:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   19657:             $changes{'categorize'} = 1;
                   19658:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   19659:         }
1.120     raeburn  19660:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   19661:             $changes{'togglecatscomm'} = 1;
                   19662:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   19663:         }
                   19664:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   19665:             $changes{'categorizecomm'} = 1;
                   19666:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  19667: 
                   19668:         }
                   19669:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   19670:             $changes{'togglecatsplace'} = 1;
                   19671:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   19672:         }
                   19673:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   19674:             $changes{'categorizeplace'} = 1;
                   19675:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  19676:         }
1.238     raeburn  19677:         foreach my $item (@catitems) {
                   19678:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   19679:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   19680:                     $changes{$item} = 1;
                   19681:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   19682:                 }
                   19683:             }
                   19684:         }
1.57      raeburn  19685:     } else {
                   19686:         $changes{'togglecats'} = 1;
                   19687:         $changes{'categorize'} = 1;
1.124     raeburn  19688:         $changes{'togglecatscomm'} = 1;
                   19689:         $changes{'categorizecomm'} = 1;
1.272     raeburn  19690:         $changes{'togglecatsplace'} = 1;
                   19691:         $changes{'categorizeplace'} = 1;
1.87      raeburn  19692:         $domconfig{'coursecategories'} = {
                   19693:                                              togglecats => $env{'form.togglecats'},
                   19694:                                              categorize => $env{'form.categorize'},
1.124     raeburn  19695:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   19696:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  19697:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   19698:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  19699:                                          };
1.238     raeburn  19700:         foreach my $item (@catitems) {
                   19701:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   19702:                 $changes{$item} = 1;
                   19703:             }
                   19704:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   19705:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   19706:             }
                   19707:         }
1.57      raeburn  19708:     }
                   19709:     if (ref($cathash) eq 'HASH') {
                   19710:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  19711:             push (@deletecategory,'instcode::0');
                   19712:         }
1.120     raeburn  19713:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   19714:             push(@deletecategory,'communities::0');
                   19715:         }
1.272     raeburn  19716:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   19717:             push(@deletecategory,'placement::0');
                   19718:         }
1.48      raeburn  19719:     }
1.57      raeburn  19720:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   19721:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  19722:         if (@deletecategory > 0) {
                   19723:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  19724:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  19725:             foreach my $item (@deletecategory) {
1.57      raeburn  19726:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   19727:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  19728:                     $deletions{$item} = 1;
1.57      raeburn  19729:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  19730:                 }
                   19731:             }
                   19732:         }
1.57      raeburn  19733:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  19734:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  19735:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  19736:                 $reorderings{$item} = 1;
1.57      raeburn  19737:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  19738:             }
                   19739:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   19740:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   19741:                 my $newdepth = $depth+1;
                   19742:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  19743:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  19744:                 $adds{$newitem} = 1; 
                   19745:             }
                   19746:             if ($env{'form.subcat_'.$item} ne '') {
                   19747:                 my $newcat = $env{'form.subcat_'.$item};
                   19748:                 my $newdepth = $depth+1;
                   19749:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  19750:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  19751:                 $adds{$newitem} = 1;
                   19752:             }
                   19753:         }
                   19754:     }
                   19755:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  19756:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  19757:             my $newitem = 'instcode::0';
1.57      raeburn  19758:             if ($cathash->{$newitem} eq '') {  
                   19759:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  19760:                 $adds{$newitem} = 1;
                   19761:             }
                   19762:         } else {
                   19763:             my $newitem = 'instcode::0';
1.57      raeburn  19764:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  19765:             $adds{$newitem} = 1;
                   19766:         }
                   19767:     }
1.120     raeburn  19768:     if ($env{'form.communities'} eq '1') {
                   19769:         if (ref($cathash) eq 'HASH') {
                   19770:             my $newitem = 'communities::0';
                   19771:             if ($cathash->{$newitem} eq '') {
                   19772:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   19773:                 $adds{$newitem} = 1;
                   19774:             }
                   19775:         } else {
                   19776:             my $newitem = 'communities::0';
                   19777:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   19778:             $adds{$newitem} = 1;
                   19779:         }
                   19780:     }
1.272     raeburn  19781:     if ($env{'form.placement'} eq '1') {
                   19782:         if (ref($cathash) eq 'HASH') {
                   19783:             my $newitem = 'placement::0';
                   19784:             if ($cathash->{$newitem} eq '') {
                   19785:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   19786:                 $adds{$newitem} = 1;
                   19787:             }
                   19788:         } else {
                   19789:             my $newitem = 'placement::0';
                   19790:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   19791:             $adds{$newitem} = 1;
                   19792:         }
                   19793:     }
1.48      raeburn  19794:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  19795:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  19796:             ($env{'form.addcategory_name'} ne 'communities') &&
                   19797:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  19798:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   19799:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   19800:             $adds{$newitem} = 1;
                   19801:         }
1.48      raeburn  19802:     }
1.57      raeburn  19803:     my $putresult;
1.48      raeburn  19804:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19805:         if (keys(%deletions) > 0) {
                   19806:             foreach my $key (keys(%deletions)) {
                   19807:                 if ($predelallitems{$key} ne '') {
                   19808:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   19809:                 }
                   19810:             }
                   19811:         }
                   19812:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  19813:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  19814:         if (ref($chkcats[0]) eq 'ARRAY') {
                   19815:             my $depth = 0;
                   19816:             my $chg = 0;
                   19817:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   19818:                 my $name = $chkcats[0][$i];
                   19819:                 my $item;
                   19820:                 if ($name eq '') {
                   19821:                     $chg ++;
                   19822:                 } else {
                   19823:                     $item = &escape($name).'::0';
                   19824:                     if ($chg) {
1.57      raeburn  19825:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  19826:                     }
                   19827:                     $depth ++; 
1.57      raeburn  19828:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  19829:                     $depth --;
                   19830:                 }
                   19831:             }
                   19832:         }
1.57      raeburn  19833:     }
                   19834:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19835:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  19836:         if ($putresult eq 'ok') {
1.57      raeburn  19837:             my %title = (
1.120     raeburn  19838:                          togglecats     => 'Show/Hide a course in catalog',
                   19839:                          categorize     => 'Assign a category to a course',
                   19840:                          togglecatscomm => 'Show/Hide a community in catalog',
                   19841:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  19842:                         );
                   19843:             my %level = (
1.120     raeburn  19844:                          dom  => 'set in Domain ("Modify Course/Community")',
                   19845:                          crs  => 'set in Course ("Course Configuration")',
                   19846:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  19847:                          none     => 'No catalog',
                   19848:                          std      => 'Standard catalog',
                   19849:                          domonly  => 'Domain-only catalog',
                   19850:                          codesrch => 'Code search form',
1.57      raeburn  19851:                         );
1.48      raeburn  19852:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  19853:             if ($changes{'togglecats'}) {
                   19854:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   19855:             }
                   19856:             if ($changes{'categorize'}) {
                   19857:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  19858:             }
1.120     raeburn  19859:             if ($changes{'togglecatscomm'}) {
                   19860:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   19861:             }
                   19862:             if ($changes{'categorizecomm'}) {
                   19863:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   19864:             }
1.238     raeburn  19865:             if ($changes{'unauth'}) {
                   19866:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   19867:             }
                   19868:             if ($changes{'auth'}) {
                   19869:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   19870:             }
1.57      raeburn  19871:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19872:                 my $cathash;
                   19873:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   19874:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   19875:                 } else {
                   19876:                     $cathash = {};
                   19877:                 } 
                   19878:                 my (@cats,@trails,%allitems);
                   19879:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   19880:                 if (keys(%deletions) > 0) {
                   19881:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   19882:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   19883:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   19884:                     }
                   19885:                     $resulttext .= '</ul></li>';
                   19886:                 }
                   19887:                 if (keys(%reorderings) > 0) {
                   19888:                     my %sort_by_trail;
                   19889:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   19890:                     foreach my $key (keys(%reorderings)) {
                   19891:                         if ($allitems{$key} ne '') {
                   19892:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   19893:                         }
1.48      raeburn  19894:                     }
1.57      raeburn  19895:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   19896:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   19897:                     }
                   19898:                     $resulttext .= '</ul></li>';
1.48      raeburn  19899:                 }
1.57      raeburn  19900:                 if (keys(%adds) > 0) {
                   19901:                     my %sort_by_trail;
                   19902:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   19903:                     foreach my $key (keys(%adds)) {
                   19904:                         if ($allitems{$key} ne '') {
                   19905:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   19906:                         }
                   19907:                     }
                   19908:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   19909:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  19910:                     }
1.57      raeburn  19911:                     $resulttext .= '</ul></li>';
1.48      raeburn  19912:                 }
1.364     raeburn  19913:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   19914:                 if (ref($lastactref) eq 'HASH') {
                   19915:                     $lastactref->{'cats'} = 1;
                   19916:                 }
1.48      raeburn  19917:             }
                   19918:             $resulttext .= '</ul>';
1.239     raeburn  19919:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  19920:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   19921:                 if ($changes{'auth'}) {
                   19922:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   19923:                 }
                   19924:                 if ($changes{'unauth'}) {
                   19925:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   19926:                 }
                   19927:                 my $cachetime = 24*60*60;
                   19928:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  19929:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  19930:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  19931:                 }
                   19932:             }
1.48      raeburn  19933:         } else {
                   19934:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  19935:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  19936:         }
                   19937:     } else {
1.120     raeburn  19938:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  19939:     }
                   19940:     return $resulttext;
                   19941: }
                   19942: 
1.69      raeburn  19943: sub modify_serverstatuses {
                   19944:     my ($dom,%domconfig) = @_;
                   19945:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   19946:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   19947:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   19948:     }
                   19949:     my @pages = &serverstatus_pages();
                   19950:     foreach my $type (@pages) {
                   19951:         $newserverstatus{$type}{'namedusers'} = '';
                   19952:         $newserverstatus{$type}{'machines'} = '';
                   19953:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   19954:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   19955:             my @okusers;
                   19956:             foreach my $user (@users) {
                   19957:                 my ($uname,$udom) = split(/:/,$user);
                   19958:                 if (($udom =~ /^$match_domain$/) &&   
                   19959:                     (&Apache::lonnet::domain($udom)) &&
                   19960:                     ($uname =~ /^$match_username$/)) {
                   19961:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   19962:                         push(@okusers,$user);
                   19963:                     }
                   19964:                 }
                   19965:             }
                   19966:             if (@okusers > 0) {
                   19967:                  @okusers = sort(@okusers);
                   19968:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   19969:             }
                   19970:         }
                   19971:         if (defined($env{'form.'.$type.'_machines'})) {
                   19972:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   19973:             my @okmachines;
                   19974:             foreach my $ip (@machines) {
                   19975:                 my @parts = split(/\./,$ip);
                   19976:                 next if (@parts < 4);
                   19977:                 my $badip = 0;
                   19978:                 for (my $i=0; $i<4; $i++) {
                   19979:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   19980:                         $badip = 1;
                   19981:                         last;
                   19982:                     }
                   19983:                 }
                   19984:                 if (!$badip) {
                   19985:                     push(@okmachines,$ip);     
                   19986:                 }
                   19987:             }
                   19988:             @okmachines = sort(@okmachines);
                   19989:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   19990:         }
                   19991:     }
                   19992:     my %serverstatushash =  (
                   19993:                                 serverstatuses => \%newserverstatus,
                   19994:                             );
                   19995:     foreach my $type (@pages) {
1.83      raeburn  19996:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  19997:             my (@current,@new);
1.83      raeburn  19998:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  19999:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   20000:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   20001:                 }
                   20002:             }
                   20003:             if ($newserverstatus{$type}{$setting} ne '') {
                   20004:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  20005:             }
                   20006:             if (@current > 0) {
                   20007:                 if (@new > 0) {
                   20008:                     foreach my $item (@current) {
                   20009:                         if (!grep(/^\Q$item\E$/,@new)) {
                   20010:                             $changes{$type}{$setting} = 1;
1.82      raeburn  20011:                             last;
                   20012:                         }
                   20013:                     }
1.84      raeburn  20014:                     foreach my $item (@new) {
                   20015:                         if (!grep(/^\Q$item\E$/,@current)) {
                   20016:                             $changes{$type}{$setting} = 1;
                   20017:                             last;
1.82      raeburn  20018:                         }
                   20019:                     }
                   20020:                 } else {
1.83      raeburn  20021:                     $changes{$type}{$setting} = 1;
1.69      raeburn  20022:                 }
1.83      raeburn  20023:             } elsif (@new > 0) {
                   20024:                 $changes{$type}{$setting} = 1;
1.69      raeburn  20025:             }
                   20026:         }
                   20027:     }
                   20028:     if (keys(%changes) > 0) {
1.81      raeburn  20029:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  20030:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   20031:                                                  \%serverstatushash,$dom);
                   20032:         if ($putresult eq 'ok') {
                   20033:             $resulttext .= &mt('Changes made:').'<ul>';
                   20034:             foreach my $type (@pages) {
1.84      raeburn  20035:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  20036:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  20037:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  20038:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   20039:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   20040:                         } else {
                   20041:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   20042:                         }
1.84      raeburn  20043:                     }
                   20044:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  20045:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   20046:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   20047:                         } else {
                   20048:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   20049:                         }
                   20050: 
                   20051:                     }
                   20052:                     $resulttext .= '</ul></li>';
                   20053:                 }
                   20054:             }
                   20055:             $resulttext .= '</ul>';
                   20056:         } else {
                   20057:             $resulttext = '<span class="LC_error">'.
                   20058:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   20059: 
                   20060:         }
                   20061:     } else {
                   20062:         $resulttext = &mt('No changes made to access to server status pages');
                   20063:     }
                   20064:     return $resulttext;
                   20065: }
                   20066: 
1.118     jms      20067: sub modify_helpsettings {
1.285     raeburn  20068:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  20069:     my ($resulttext,$errors,%changes,%helphash);
                   20070:     my %defaultchecked = ('submitbugs' => 'on');
                   20071:     my @offon = ('off','on');
1.118     jms      20072:     my @toggles = ('submitbugs');
1.285     raeburn  20073:     my %current = ('submitbugs' => '',
                   20074:                    'adhoc'      => {},
                   20075:                   );
1.118     jms      20076:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  20077:         %current = %{$domconfig{'helpsettings'}};
                   20078:     }
1.285     raeburn  20079:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  20080:     foreach my $item (@toggles) {
                   20081:         if ($defaultchecked{$item} eq 'on') { 
                   20082:             if ($current{$item} eq '') {
                   20083:                 if ($env{'form.'.$item} eq '0') {
                   20084:                     $changes{$item} = 1;
                   20085:                 }
                   20086:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   20087:                 $changes{$item} = 1;
                   20088:             }
                   20089:         } elsif ($defaultchecked{$item} eq 'off') {
                   20090:             if ($current{$item} eq '') {
                   20091:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  20092:                     $changes{$item} = 1;
                   20093:                 }
1.282     raeburn  20094:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   20095:                 $changes{$item} = 1;
                   20096:             }
                   20097:         }
                   20098:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   20099:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   20100:         }
                   20101:     }
1.285     raeburn  20102:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  20103:     my $confname = $dom.'-domainconfig';
                   20104:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  20105:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   20106:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  20107:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  20108:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  20109:     my %lt = &Apache::lonlocal::texthash(
                   20110:                     s      => 'system',
                   20111:                     d      => 'domain',
                   20112:                     order  => 'Display order',
                   20113:                     access => 'Role usage',
1.291     raeburn  20114:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  20115:                     dh     => 'All with domain helpdesk role',
                   20116:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  20117:                     none   => 'None',
                   20118:                     status => 'Determined based on institutional status',
                   20119:                     inc    => 'Include all, but exclude specific personnel',
                   20120:                     exc    => 'Exclude all, but include specific personnel',
                   20121:     );
                   20122:     for (my $num=0; $num<=$maxnum; $num++) {
                   20123:         my ($prefix,$identifier,$rolename,%curr);
                   20124:         if ($num == $maxnum) {
                   20125:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   20126:             $identifier = 'custhelp'.$num;
                   20127:             $prefix = 'helproles_'.$num;
                   20128:             $rolename = $env{'form.custhelpname'.$num};
                   20129:             $rolename=~s/[^A-Za-z0-9]//gs;
                   20130:             next if ($rolename eq '');
                   20131:             next if (exists($existing{'rolesdef_'.$rolename}));
                   20132:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20133:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20134:                                                      $newprivs{'c'},$confname,$dom);
                   20135:             if ($result ne 'ok') {
                   20136:                 $errors .= '<li><span class="LC_error">'.
                   20137:                            &mt('An error occurred storing the new custom role: [_1]',
                   20138:                            $result).'</span></li>';
                   20139:                 next;
                   20140:             } else {
                   20141:                 $changedprivs{$rolename} = \%newprivs;
                   20142:                 $newrole = $rolename;
                   20143:             }
                   20144:         } else {
                   20145:             $prefix = 'helproles_'.$num;
                   20146:             $rolename = $env{'form.'.$prefix};
                   20147:             next if ($rolename eq '');
                   20148:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   20149:             $identifier = 'custhelp'.$num;
                   20150:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20151:             my %currprivs;
1.289     raeburn  20152:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  20153:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   20154:             foreach my $level ('c','d','s') {
                   20155:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   20156:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20157:                                                              $newprivs{'c'},$confname,$dom);
                   20158:                     if ($result ne 'ok') {
                   20159:                         $errors .= '<li><span class="LC_error">'.
                   20160:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   20161:                                        $rolename,$result).'</span></li>';
                   20162:                     } else {
                   20163:                         $changedprivs{$rolename} = \%newprivs;
                   20164:                     }
                   20165:                     last;
                   20166:                 }
                   20167:             }
                   20168:             if (ref($current{'adhoc'}) eq 'HASH') {
                   20169:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   20170:                     %curr = %{$current{'adhoc'}{$rolename}};
                   20171:                 }
                   20172:             }
                   20173:         }
                   20174:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   20175:         $newpos =~ s/\D+//g;
                   20176:         $allpos[$newpos] = $rolename;
                   20177:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   20178:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   20179:         if ($curr{'desc'}) {
                   20180:             if ($curr{'desc'} ne $newdesc) {
                   20181:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   20182:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   20183:             }
                   20184:         } elsif ($newdesc ne '') {
                   20185:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   20186:             $newsettings{$rolename}{'desc'} = $newdesc;
                   20187:         }
                   20188:         my $access = $env{'form.'.$prefix.'_access'};
                   20189:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   20190:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   20191:             if ($access eq 'status') {
                   20192:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   20193:                 if (scalar(@statuses) == 0) {
1.289     raeburn  20194:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  20195:                 } else {
                   20196:                     my (@shownstatus,$numtypes);
                   20197:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   20198:                     if (ref($types) eq 'ARRAY') {
                   20199:                         $numtypes = scalar(@{$types});
                   20200:                         foreach my $type (sort(@statuses)) {
                   20201:                             if ($type eq 'default') {
                   20202:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   20203:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   20204:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   20205:                                 push(@shownstatus,$usertypes->{$type});
                   20206:                             }
                   20207:                         }
                   20208:                     }
                   20209:                     if (grep(/^default$/,@statuses)) {
                   20210:                         push(@shownstatus,$othertitle);
                   20211:                     }
                   20212:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   20213:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   20214:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   20215:                     } else {
                   20216:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   20217:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   20218:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   20219:                             if (@diffs) {
                   20220:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   20221:                             }
                   20222:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20223:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  20224:                         }
1.166     raeburn  20225:                     }
                   20226:                 }
1.285     raeburn  20227:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   20228:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   20229:                 my @newspecstaff;
                   20230:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   20231:                 foreach my $person (sort(@personnel)) {
                   20232:                     if ($domhelpdesk{$person}) {
                   20233:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   20234:                     }
                   20235:                 }
                   20236:                 if (ref($curr{$access}) eq 'ARRAY') {
                   20237:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   20238:                     if (@diffs) {
                   20239:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   20240:                     }
                   20241:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20242:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   20243:                 }
                   20244:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20245:                     my ($uname,$udom) = split(/:/,$person);
                   20246:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   20247:                 }
                   20248:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  20249:             }
1.285     raeburn  20250:         } else {
                   20251:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   20252:         }
                   20253:         unless ($curr{'access'} eq $access) {
                   20254:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   20255:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  20256:         }
                   20257:     }
1.285     raeburn  20258:     if (@allpos > 0) {
                   20259:         my $idx = 0;
                   20260:         foreach my $rolename (@allpos) {
                   20261:             if ($rolename ne '') {
                   20262:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   20263:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   20264:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   20265:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   20266:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  20267:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  20268:                         }
                   20269:                     }
1.282     raeburn  20270:                 }
1.285     raeburn  20271:                 $idx ++;
1.166     raeburn  20272:             }
                   20273:         }
1.118     jms      20274:     }
1.123     jms      20275:     my $putresult;
                   20276:     if (keys(%changes) > 0) {
1.166     raeburn  20277:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  20278:         if ($putresult eq 'ok') {
1.285     raeburn  20279:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   20280:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   20281:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   20282:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   20283:                 }
                   20284:             }
                   20285:             my $cachetime = 24*60*60;
                   20286:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   20287:             if (ref($lastactref) eq 'HASH') {
                   20288:                 $lastactref->{'domdefaults'} = 1;
                   20289:             }
                   20290:         } else {
                   20291:             $errors .= '<li><span class="LC_error">'.
                   20292:                        &mt('An error occurred storing the settings: [_1]',
                   20293:                            $putresult).'</span></li>';
                   20294:         }
                   20295:     }
                   20296:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   20297:         $resulttext = &mt('Changes made:').'<ul>';
                   20298:         my (%shownprivs,@levelorder);
                   20299:         @levelorder = ('c','d','s');
                   20300:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  20301:             foreach my $item (sort(keys(%changes))) {
                   20302:                 if ($item eq 'submitbugs') {
                   20303:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   20304:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   20305:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  20306:                 } elsif ($item eq 'customrole') {
                   20307:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  20308:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   20309:                         my %keytext = &Apache::lonlocal::texthash(
                   20310:                                                                    order  => 'Order',
                   20311:                                                                    desc   => 'Role description',
                   20312:                                                                    access => 'Role usage',
1.300     droeschl 20313:                                                                    status => 'Allowed institutional types',
1.285     raeburn  20314:                                                                    exc    => 'Allowed personnel',
                   20315:                                                                    inc    => 'Disallowed personnel',
                   20316:                         );
1.282     raeburn  20317:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  20318:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   20319:                                 if ($role eq $newrole) {
                   20320:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   20321:                                                               $role).'<ul>';
                   20322:                                 } else {
                   20323:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   20324:                                                               $role).'<ul>';
                   20325:                                 }
                   20326:                                 foreach my $key (@keyorder) {
                   20327:                                     if ($changes{'customrole'}{$role}{$key}) {
                   20328:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   20329:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   20330:                                                        '</li>';
                   20331:                                     }
                   20332:                                 }
                   20333:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   20334:                                     $shownprivs{$role} = 1;
                   20335:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   20336:                                     foreach my $level (@levelorder) {
                   20337:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   20338:                                             next if ($item eq '');
                   20339:                                             my ($priv) = split(/\&/,$item,2);
                   20340:                                             if (&Apache::lonnet::plaintext($priv)) {
                   20341:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   20342:                                                 unless ($level eq 'c') {
                   20343:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   20344:                                                 }
                   20345:                                                 $resulttext .= '</li>';
                   20346:                                             }
                   20347:                                         }
                   20348:                                     }
                   20349:                                     $resulttext .= '</ul>';
                   20350:                                 }
                   20351:                                 $resulttext .= '</ul></li>';
                   20352:                             }
                   20353:                         }
                   20354:                     }
                   20355:                 }
                   20356:             }
                   20357:         }
                   20358:         if (keys(%changedprivs)) {
                   20359:             foreach my $role (sort(keys(%changedprivs))) {
                   20360:                 unless ($shownprivs{$role}) {
                   20361:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   20362:                                               $role).'<ul>'.
                   20363:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   20364:                     foreach my $level (@levelorder) {
                   20365:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   20366:                             next if ($item eq '');
                   20367:                             my ($priv) = split(/\&/,$item,2);
                   20368:                             if (&Apache::lonnet::plaintext($priv)) {
                   20369:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   20370:                                 unless ($level eq 'c') {
                   20371:                                     $resulttext .= ' ('.$lt{$level}.')';
                   20372:                                 }
                   20373:                                 $resulttext .= '</li>';
                   20374:                             }
1.282     raeburn  20375:                         }
                   20376:                     }
1.285     raeburn  20377:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  20378:                 }
                   20379:             }
                   20380:         }
1.285     raeburn  20381:         $resulttext .= '</ul>';
                   20382:     } else {
                   20383:         $resulttext = &mt('No changes made to help settings');
1.118     jms      20384:     }
                   20385:     if ($errors) {
1.168     raeburn  20386:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  20387:                                     $errors.'</ul>';
1.118     jms      20388:     }
                   20389:     return $resulttext;
                   20390: }
                   20391: 
1.121     raeburn  20392: sub modify_coursedefaults {
1.212     raeburn  20393:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  20394:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  20395:     my %defaultchecked = (
                   20396:                            'canuse_pdfforms' => 'off',
                   20397:                            'uselcmath'       => 'on',
1.398     raeburn  20398:                            'usejsme'         => 'on',
                   20399:                            'inline_chem'     => 'on',
1.257     raeburn  20400:                          );
1.398     raeburn  20401:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.198     raeburn  20402:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  20403:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   20404:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   20405:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  20406:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  20407:     my %staticdefaults = (
                   20408:                            anonsurvey_threshold => 10,
                   20409:                            uploadquota          => 500,
1.257     raeburn  20410:                            postsubmit           => 60,
1.276     raeburn  20411:                            mysqltables          => 172800,
1.198     raeburn  20412:                          );
1.314     raeburn  20413:     my %texoptions = (
                   20414:                         MathJax  => 'MathJax',
                   20415:                         mimetex  => &mt('Convert to Images'),
                   20416:                         tth      => &mt('TeX to HTML'),
                   20417:                      );
1.121     raeburn  20418:     $defaultshash{'coursedefaults'} = {};
                   20419: 
                   20420:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   20421:         if ($domconfig{'coursedefaults'} eq '') {
                   20422:             $domconfig{'coursedefaults'} = {};
                   20423:         }
                   20424:     }
                   20425: 
                   20426:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   20427:         foreach my $item (@toggles) {
                   20428:             if ($defaultchecked{$item} eq 'on') {
                   20429:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   20430:                     ($env{'form.'.$item} eq '0')) {
                   20431:                     $changes{$item} = 1;
1.192     raeburn  20432:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  20433:                     $changes{$item} = 1;
                   20434:                 }
                   20435:             } elsif ($defaultchecked{$item} eq 'off') {
                   20436:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   20437:                     ($env{'form.'.$item} eq '1')) {
                   20438:                     $changes{$item} = 1;
                   20439:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   20440:                     $changes{$item} = 1;
                   20441:                 }
                   20442:             }
                   20443:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   20444:         }
1.198     raeburn  20445:         foreach my $item (@numbers) {
                   20446:             my ($currdef,$newdef);
1.208     raeburn  20447:             $newdef = $env{'form.'.$item};
1.198     raeburn  20448:             if ($item eq 'anonsurvey_threshold') {
                   20449:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   20450:                 $newdef =~ s/\D//g;
                   20451:                 if ($newdef eq '' || $newdef < 1) {
                   20452:                     $newdef = 1;
                   20453:                 }
                   20454:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   20455:             } else {
1.276     raeburn  20456:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   20457:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   20458:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  20459:                 }
                   20460:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  20461:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  20462:             }
                   20463:             if ($currdef ne $newdef) {
                   20464:                 if ($item eq 'anonsurvey_threshold') {
                   20465:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   20466:                         $changes{$item} = 1;
                   20467:                     }
1.276     raeburn  20468:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289     raeburn  20469:                     my $setting = $1;
1.276     raeburn  20470:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   20471:                         $changes{$setting} = 1;
1.198     raeburn  20472:                     }
                   20473:                 }
1.139     raeburn  20474:             }
                   20475:         }
1.314     raeburn  20476:         my $texengine;
                   20477:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   20478:             $texengine = $env{'form.texengine'};
1.349     raeburn  20479:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   20480:             if ($currdef eq '') {
                   20481:                 unless ($texengine eq $Apache::lonnet::deftex) {
1.314     raeburn  20482:                     $changes{'texengine'} = 1;
                   20483:                 }
1.349     raeburn  20484:             } elsif ($currdef ne $texengine) {
1.314     raeburn  20485:                 $changes{'texengine'} = 1;
                   20486:             }
                   20487:         }
                   20488:         if ($texengine ne '') {
                   20489:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   20490:         }
1.264     raeburn  20491:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   20492:         my @currclonecode;
                   20493:         if (ref($currclone) eq 'HASH') {
                   20494:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   20495:                 @currclonecode = @{$currclone->{'instcode'}};
                   20496:             }
                   20497:         }
                   20498:         my $newclone;
1.289     raeburn  20499:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  20500:             $newclone = $env{'form.canclone'};
                   20501:         }
                   20502:         if ($newclone eq 'instcode') {
                   20503:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   20504:             my (%codedefaults,@code_order,@clonecode);
                   20505:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   20506:                                                     \@code_order);
                   20507:             foreach my $item (@code_order) {
                   20508:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   20509:                     push(@clonecode,$item);
                   20510:                 }
                   20511:             }
                   20512:             if (@clonecode) {
                   20513:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   20514:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   20515:                 if (@diffs) {
                   20516:                     $changes{'canclone'} = 1;
                   20517:                 }
                   20518:             } else {
                   20519:                 $newclone eq '';
                   20520:             }
                   20521:         } elsif ($newclone ne '') {
1.289     raeburn  20522:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   20523:         }
1.264     raeburn  20524:         if ($newclone ne $currclone) {
                   20525:             $changes{'canclone'} = 1;
                   20526:         }
1.257     raeburn  20527:         my %credits;
                   20528:         foreach my $type (@types) {
                   20529:             unless ($type eq 'community') {
                   20530:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   20531:                 $credits{$type} =~ s/[^\d.]+//g;
                   20532:             }
                   20533:         }
                   20534:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   20535:             ($env{'form.coursecredits'} eq '1')) {
                   20536:             $changes{'coursecredits'} = 1;
                   20537:             foreach my $type (keys(%credits)) {
                   20538:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   20539:             }
                   20540:         } else {
1.289     raeburn  20541:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  20542:                 foreach my $type (@types) {
                   20543:                     unless ($type eq 'community') {
1.289     raeburn  20544:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  20545:                             $changes{'coursecredits'} = 1;
                   20546:                         }
                   20547:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   20548:                     }
                   20549:                 }
                   20550:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   20551:                 foreach my $type (@types) {
                   20552:                     unless ($type eq 'community') {
                   20553:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   20554:                             $changes{'coursecredits'} = 1;
                   20555:                             last;
                   20556:                         }
                   20557:                     }
                   20558:                 }
                   20559:             }
                   20560:         }
                   20561:         if ($env{'form.postsubmit'} eq '1') {
                   20562:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   20563:             my %currtimeout;
                   20564:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20565:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   20566:                     $changes{'postsubmit'} = 1;
                   20567:                 }
                   20568:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20569:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   20570:                 }
                   20571:             } else {
                   20572:                 $changes{'postsubmit'} = 1;
                   20573:             }
                   20574:             foreach my $type (@types) {
                   20575:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   20576:                 $timeout =~ s/\D//g;
                   20577:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   20578:                     $timeout = '';
                   20579:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   20580:                     $timeout = '0';
                   20581:                 }
                   20582:                 unless ($timeout eq '') {
                   20583:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   20584:                 }
                   20585:                 if (exists($currtimeout{$type})) {
                   20586:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  20587:                         $changes{'postsubmit'} = 1;
1.257     raeburn  20588:                     }
                   20589:                 } elsif ($timeout ne '') {
                   20590:                     $changes{'postsubmit'} = 1;
                   20591:                 }
                   20592:             }
                   20593:         } else {
                   20594:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   20595:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20596:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   20597:                     $changes{'postsubmit'} = 1;
                   20598:                 }
                   20599:             } else {
                   20600:                 $changes{'postsubmit'} = 1;
                   20601:             }
1.192     raeburn  20602:         }
1.121     raeburn  20603:     }
                   20604:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   20605:                                              $dom);
                   20606:     if ($putresult eq 'ok') {
                   20607:         if (keys(%changes) > 0) {
1.213     raeburn  20608:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  20609:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  20610:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398     raeburn  20611:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
                   20612:                 ($changes{'inline_chem'})) {
                   20613:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine') {
1.257     raeburn  20614:                     if ($changes{$item}) {
                   20615:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   20616:                     }
1.289     raeburn  20617:                 }
1.192     raeburn  20618:                 if ($changes{'coursecredits'}) {
                   20619:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  20620:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   20621:                             $domdefaults{$type.'credits'} =
                   20622:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   20623:                         }
                   20624:                     }
                   20625:                 }
                   20626:                 if ($changes{'postsubmit'}) {
                   20627:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20628:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   20629:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20630:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   20631:                                 $domdefaults{$type.'postsubtimeout'} =
                   20632:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   20633:                             }
                   20634:                         }
1.192     raeburn  20635:                     }
                   20636:                 }
1.198     raeburn  20637:                 if ($changes{'uploadquota'}) {
                   20638:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   20639:                         foreach my $type (@types) {
                   20640:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   20641:                         }
                   20642:                     }
                   20643:                 }
1.264     raeburn  20644:                 if ($changes{'canclone'}) {
                   20645:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   20646:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   20647:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   20648:                             if (@clonecodes) {
                   20649:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   20650:                             }
                   20651:                         }
                   20652:                     } else {
                   20653:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   20654:                     }
                   20655:                 }
1.121     raeburn  20656:                 my $cachetime = 24*60*60;
                   20657:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  20658:                 if (ref($lastactref) eq 'HASH') {
                   20659:                     $lastactref->{'domdefaults'} = 1;
                   20660:                 }
1.121     raeburn  20661:             }
                   20662:             $resulttext = &mt('Changes made:').'<ul>';
                   20663:             foreach my $item (sort(keys(%changes))) {
                   20664:                 if ($item eq 'canuse_pdfforms') {
                   20665:                     if ($env{'form.'.$item} eq '1') {
                   20666:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   20667:                     } else {
                   20668:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   20669:                     }
1.257     raeburn  20670:                 } elsif ($item eq 'uselcmath') {
                   20671:                     if ($env{'form.'.$item} eq '1') {
                   20672:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   20673:                     } else {
                   20674:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   20675:                     }
                   20676:                 } elsif ($item eq 'usejsme') {
                   20677:                     if ($env{'form.'.$item} eq '1') {
                   20678:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   20679:                     } else {
1.289     raeburn  20680:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  20681:                     }
1.398     raeburn  20682:                 } elsif ($item eq 'inline_chem') {
                   20683:                     if ($env{'form.'.$item} eq '1') {
                   20684:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
                   20685:                     } else {
                   20686:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
                   20687:                     }
1.314     raeburn  20688:                 } elsif ($item eq 'texengine') {
                   20689:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   20690:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   20691:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   20692:                     }
1.139     raeburn  20693:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  20694:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  20695:                 } elsif ($item eq 'uploadquota') {
                   20696:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   20697:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   20698:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   20699:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  20700:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  20701:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  20702:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   20703:                                        '</ul>'.
                   20704:                                        '</li>';
                   20705:                     } else {
                   20706:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   20707:                     }
1.276     raeburn  20708:                 } elsif ($item eq 'mysqltables') {
                   20709:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   20710:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   20711:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   20712:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   20713:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   20714:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   20715:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   20716:                                        '</ul>'.
                   20717:                                        '</li>';
                   20718:                     } else {
                   20719:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   20720:                     }
1.257     raeburn  20721:                 } elsif ($item eq 'postsubmit') {
                   20722:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   20723:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   20724:                     } else {
                   20725:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  20726:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  20727:                             $resulttext .= &mt('durations:').'<ul>';
                   20728:                             foreach my $type (@types) {
                   20729:                                 $resulttext .= '<li>';
                   20730:                                 my $timeout;
                   20731:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20732:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   20733:                                 }
                   20734:                                 my $display;
                   20735:                                 if ($timeout eq '0') {
                   20736:                                     $display = &mt('unlimited');
                   20737:                                 } elsif ($timeout eq '') {
                   20738:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   20739:                                 } else {
                   20740:                                     $display = &mt('[quant,_1,second]',$timeout);
                   20741:                                 }
                   20742:                                 if ($type eq 'community') {
                   20743:                                     $resulttext .= &mt('Communities');
                   20744:                                 } elsif ($type eq 'official') {
                   20745:                                     $resulttext .= &mt('Official courses');
                   20746:                                 } elsif ($type eq 'unofficial') {
                   20747:                                     $resulttext .= &mt('Unofficial courses');
                   20748:                                 } elsif ($type eq 'textbook') {
                   20749:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  20750:                                 } elsif ($type eq 'placement') {
                   20751:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  20752:                                 }
                   20753:                                 $resulttext .= ' -- '.$display.'</li>';
                   20754:                             }
                   20755:                             $resulttext .= '</ul>';
                   20756:                         }
1.289     raeburn  20757:                         $resulttext .= '</li>';
1.257     raeburn  20758:                     }
1.192     raeburn  20759:                 } elsif ($item eq 'coursecredits') {
                   20760:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   20761:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  20762:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   20763:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  20764:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   20765:                         } else {
                   20766:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   20767:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   20768:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  20769:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  20770:                                            '</ul>'.
                   20771:                                            '</li>';
                   20772:                         }
                   20773:                     } else {
                   20774:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   20775:                     }
1.264     raeburn  20776:                 } elsif ($item eq 'canclone') {
                   20777:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   20778:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   20779:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   20780:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   20781:                         }
                   20782:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   20783:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   20784:                     } else {
1.289     raeburn  20785:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  20786:                     }
1.140     raeburn  20787:                 }
1.121     raeburn  20788:             }
                   20789:             $resulttext .= '</ul>';
                   20790:         } else {
                   20791:             $resulttext = &mt('No changes made to course defaults');
                   20792:         }
                   20793:     } else {
                   20794:         $resulttext = '<span class="LC_error">'.
                   20795:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   20796:     }
                   20797:     return $resulttext;
                   20798: }
                   20799: 
1.231     raeburn  20800: sub modify_selfenrollment {
                   20801:     my ($dom,$lastactref,%domconfig) = @_;
                   20802:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  20803:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  20804:     my %titles = &tool_titles();
1.232     raeburn  20805:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   20806:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  20807:     $ordered{'default'} = ['types','registered','approval','limit'];
                   20808: 
                   20809:     my (%roles,%shown,%toplevel);
                   20810:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   20811: 
                   20812:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   20813:         if ($domconfig{'selfenrollment'} eq '') {
                   20814:             $domconfig{'selfenrollment'} = {};
                   20815:         }
                   20816:     }
                   20817:     %toplevel = (
                   20818:                   admin      => 'Configuration Rights',
                   20819:                   default    => 'Default settings',
                   20820:                   validation => 'Validation of self-enrollment requests',
                   20821:                 );
1.233     raeburn  20822:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  20823: 
                   20824:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   20825:         foreach my $item (@{$ordered{'admin'}}) {
                   20826:             foreach my $type (@types) {
                   20827:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   20828:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   20829:                 } else {
                   20830:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   20831:                 }
                   20832:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   20833:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   20834:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   20835:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   20836:                             push(@{$changes{'admin'}{$type}},$item);
                   20837:                         }
                   20838:                     } else {
                   20839:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   20840:                             push(@{$changes{'admin'}{$type}},$item);
                   20841:                         }
                   20842:                     }
                   20843:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   20844:                     push(@{$changes{'admin'}{$type}},$item);
                   20845:                 }
                   20846:             }
                   20847:         }
                   20848:     }
                   20849: 
                   20850:     foreach my $item (@{$ordered{'default'}}) {
                   20851:         foreach my $type (@types) {
                   20852:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   20853:             if ($item eq 'types') {
                   20854:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   20855:                     $value = '';
                   20856:                 }
                   20857:             } elsif ($item eq 'registered') {
                   20858:                 unless ($value eq '1') {
                   20859:                     $value = 0;
                   20860:                 }
                   20861:             } elsif ($item eq 'approval') {
                   20862:                 unless ($value =~ /^[012]$/) {
                   20863:                     $value = 0;
                   20864:                 }
                   20865:             } else {
                   20866:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   20867:                     $value = 'none';
                   20868:                 }
                   20869:             }
                   20870:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   20871:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   20872:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   20873:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   20874:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   20875:                          push(@{$changes{'default'}{$type}},$item);
                   20876:                     }
                   20877:                 } else {
                   20878:                     push(@{$changes{'default'}{$type}},$item);
                   20879:                 }
                   20880:             } else {
                   20881:                 push(@{$changes{'default'}{$type}},$item);
                   20882:             }
                   20883:             if ($item eq 'limit') {
                   20884:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   20885:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   20886:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   20887:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   20888:                     }
                   20889:                 } else {
                   20890:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   20891:                 }
                   20892:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   20893:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   20894:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   20895:                          push(@{$changes{'default'}{$type}},'cap');
                   20896:                     }
                   20897:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   20898:                     push(@{$changes{'default'}{$type}},'cap');
                   20899:                 }
                   20900:             }
                   20901:         }
                   20902:     }
                   20903: 
                   20904:     foreach my $item (@{$itemsref}) {
                   20905:         if ($item eq 'fields') {
                   20906:             my @changed;
                   20907:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   20908:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   20909:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   20910:             }
                   20911:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   20912:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   20913:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   20914:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   20915:                 } else {
                   20916:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   20917:                 }
                   20918:             } else {
                   20919:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   20920:             }
                   20921:             if (@changed) {
                   20922:                 if ($selfenrollhash{'validation'}{$item}) { 
                   20923:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   20924:                 } else {
                   20925:                     $changes{'validation'}{$item} = &mt('None');
                   20926:                 }
                   20927:             }
                   20928:         } else {
                   20929:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   20930:             if ($item eq 'markup') {
                   20931:                if ($env{'form.selfenroll_validation_'.$item}) {
                   20932:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   20933:                }
                   20934:             }
                   20935:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   20936:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   20937:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   20938:                 }
                   20939:             }
                   20940:         }
                   20941:     }
                   20942: 
                   20943:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   20944:                                              $dom);
                   20945:     if ($putresult eq 'ok') {
                   20946:         if (keys(%changes) > 0) {
                   20947:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   20948:             $resulttext = &mt('Changes made:').'<ul>';
                   20949:             foreach my $key ('admin','default','validation') {
                   20950:                 if (ref($changes{$key}) eq 'HASH') {
                   20951:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   20952:                     if ($key eq 'validation') {
                   20953:                         foreach my $item (@{$itemsref}) {
                   20954:                             if (exists($changes{$key}{$item})) {
                   20955:                                 if ($item eq 'markup') {
                   20956:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   20957:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   20958:                                 } else {  
                   20959:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   20960:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   20961:                                 }
                   20962:                             }
                   20963:                         }
                   20964:                     } else {
                   20965:                         foreach my $type (@types) {
                   20966:                             if ($type eq 'community') {
                   20967:                                 $roles{'1'} = &mt('Community personnel');
                   20968:                             } else {
                   20969:                                 $roles{'1'} = &mt('Course personnel');
                   20970:                             }
                   20971:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  20972:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   20973:                                     if ($key eq 'admin') {
                   20974:                                         my @mgrdc = ();
                   20975:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   20976:                                             foreach my $item (@{$ordered{'admin'}}) {
                   20977:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   20978:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   20979:                                                         push(@mgrdc,$item);
                   20980:                                                     }
                   20981:                                                 }
                   20982:                                             }
                   20983:                                             if (@mgrdc) {
                   20984:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   20985:                                             } else {
                   20986:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   20987:                                             }
                   20988:                                         }
                   20989:                                     } else {
                   20990:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   20991:                                             foreach my $item (@{$ordered{$key}}) {
                   20992:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   20993:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   20994:                                                         $selfenrollhash{$key}{$type}{$item};
                   20995:                                                 }
                   20996:                                             }
                   20997:                                         }
                   20998:                                     }
                   20999:                                 }
1.231     raeburn  21000:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   21001:                                 foreach my $item (@{$ordered{$key}}) {
                   21002:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   21003:                                         $resulttext .= '<li>';
                   21004:                                         if ($key eq 'admin') {
                   21005:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   21006:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   21007:                                         } else {
                   21008:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   21009:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   21010:                                         }
                   21011:                                         $resulttext .= '</li>';
                   21012:                                     }
                   21013:                                 }
                   21014:                                 $resulttext .= '</ul></li>';
                   21015:                             }
                   21016:                         }
                   21017:                         $resulttext .= '</ul></li>'; 
                   21018:                     }
                   21019:                 }
1.305     raeburn  21020:             }
                   21021:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   21022:                 my $cachetime = 24*60*60;
                   21023:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21024:                 if (ref($lastactref) eq 'HASH') {
                   21025:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  21026:                 }
1.231     raeburn  21027:             }
                   21028:             $resulttext .= '</ul>';
                   21029:         } else {
                   21030:             $resulttext = &mt('No changes made to self-enrollment settings');
                   21031:         }
                   21032:     } else {
                   21033:         $resulttext = '<span class="LC_error">'.
                   21034:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   21035:     }
                   21036:     return $resulttext;
                   21037: }
                   21038: 
1.373     raeburn  21039: sub modify_wafproxy {
                   21040:     my ($dom,$action,$lastactref,%domconfig) = @_;
                   21041:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  21042:     my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
                   21043:         %wafproxy,%changes,%expirecache,%expiresaml);
1.373     raeburn  21044:     foreach my $server (sort(keys(%servers))) {
                   21045:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   21046:         if ($serverhome eq $server) {
                   21047:             my $serverdom = &Apache::lonnet::host_domain($server);
                   21048:             if ($serverdom eq $dom) {
                   21049:                 $canset{$server} = 1;
                   21050:             }
                   21051:         }
                   21052:     }
1.381     raeburn  21053:     if (ref($domconfig{'wafproxy'}) eq 'HASH') {
                   21054:         %{$values{$dom}} = ();
                   21055:         if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
                   21056:             %curralias = %{$domconfig{'wafproxy'}{'alias'}};
                   21057:         }
1.388     raeburn  21058:         if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
                   21059:             %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
                   21060:         }
1.382     raeburn  21061:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381     raeburn  21062:             $currvalue{$item} = $domconfig{'wafproxy'}{$item};
                   21063:         }
                   21064:     }
1.373     raeburn  21065:     my $output;
                   21066:     if (keys(%canset)) {
                   21067:         %{$wafproxy{'alias'}} = ();
1.388     raeburn  21068:         %{$wafproxy{'saml'}} = ();
1.373     raeburn  21069:         foreach my $key (sort(keys(%canset))) {
1.381     raeburn  21070:             if ($env{'form.wafproxy_'.$dom}) {
                   21071:                 $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
                   21072:                 $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
                   21073:                 if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
                   21074:                     $changes{'alias'} = 1;
                   21075:                 }
1.388     raeburn  21076:                 if ($env{'form.wafproxy_alias_saml_'.$key}) {
                   21077:                     $wafproxy{'saml'}{$key} = 1;
                   21078:                 }
                   21079:                 if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
                   21080:                     $changes{'saml'} = 1;
                   21081:                 }
1.381     raeburn  21082:             } else {
                   21083:                 $wafproxy{'alias'}{$key} = '';
1.388     raeburn  21084:                 $wafproxy{'saml'}{$key} = '';
1.381     raeburn  21085:                 if ($curralias{$key}) {
                   21086:                     $changes{'alias'} = 1;
                   21087:                 }
1.388     raeburn  21088:                 if ($currsaml{$key}) {
                   21089:                     $changes{'saml'} = 1;
                   21090:                 }
1.373     raeburn  21091:             }
                   21092:             if ($wafproxy{'alias'}{$key} eq '') {
                   21093:                 if ($curralias{$key}) {
                   21094:                     $expirecache{$key} = 1;
                   21095:                 }
                   21096:                 delete($wafproxy{'alias'}{$key});
                   21097:             }
1.388     raeburn  21098:             if ($wafproxy{'saml'}{$key} eq '') {
                   21099:                 if ($currsaml{$key}) {
                   21100:                     $expiresaml{$key} = 1;
                   21101:                 }
                   21102:                 delete($wafproxy{'saml'}{$key});
                   21103:             }
1.373     raeburn  21104:         }
                   21105:         unless (keys(%{$wafproxy{'alias'}})) {
                   21106:             delete($wafproxy{'alias'});
                   21107:         }
1.388     raeburn  21108:         unless (keys(%{$wafproxy{'saml'}})) {
                   21109:             delete($wafproxy{'saml'});
                   21110:         }
                   21111:         # Localization for values in %warn occurs in &mt() calls separately.
1.373     raeburn  21112:         my %warn = (
                   21113:                      trusted => 'trusted IP range(s)',
1.381     raeburn  21114:                      vpnint => 'internal IP range(s) for VPN sessions(s)',
                   21115:                      vpnext => 'IP range(s) for backend WAF connections',
1.373     raeburn  21116:                    );
1.382     raeburn  21117:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21118:             my $possible = $env{'form.wafproxy_'.$item};
                   21119:             $possible =~ s/^\s+|\s+$//g;
                   21120:             if ($possible ne '') {
1.381     raeburn  21121:                 if ($item eq 'remoteip') {
                   21122:                     if ($possible =~ /^[mhn]$/) {
                   21123:                         $wafproxy{$item} = $possible;
                   21124:                     }
                   21125:                 } elsif ($item eq 'ipheader') {
                   21126:                     if ($wafproxy{'remoteip'} eq 'h') {
                   21127:                         $wafproxy{$item} = $possible;
                   21128:                     }
1.382     raeburn  21129:                 } elsif ($item eq 'sslopt') {
                   21130:                     if ($possible =~ /^0|1$/) {
                   21131:                         $wafproxy{$item} = $possible;
                   21132:                     }
1.373     raeburn  21133:                 } else {
                   21134:                     my (@ok,$count);
1.381     raeburn  21135:                     if (($item eq 'vpnint') || ($item eq 'vpnext')) {
                   21136:                         unless ($env{'form.wafproxy_vpnaccess'}) {
                   21137:                             $possible = '';
                   21138:                         }
                   21139:                     } elsif ($item eq 'trusted') {
                   21140:                         unless ($wafproxy{'remoteip'} eq 'h') {
                   21141:                             $possible = '';
                   21142:                         }
                   21143:                     }
                   21144:                     unless ($possible eq '') {
                   21145:                         $possible =~ s/[\r\n]+/\s/g;
                   21146:                         $possible =~ s/\s*-\s*/-/g;
                   21147:                         $possible =~ s/\s+/,/g;
1.393     raeburn  21148:                         $possible =~ s/,+/,/g;
1.381     raeburn  21149:                     }
1.373     raeburn  21150:                     $count = 0;
1.381     raeburn  21151:                     if ($possible ne '') {
1.373     raeburn  21152:                         foreach my $poss (split(/\,/,$possible)) {
                   21153:                             $count ++;
1.393     raeburn  21154:                             $poss = &validate_ip_pattern($poss);
                   21155:                             if ($poss ne '') {
1.373     raeburn  21156:                                 push(@ok,$poss);
                   21157:                             }
                   21158:                         }
                   21159:                         my $diff = $count - scalar(@ok);
                   21160:                         if ($diff) {
                   21161:                             push(@warnings,'<li>'.
                   21162:                                  &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
                   21163:                                      $diff,$warn{$item}).
                   21164:                                  '</li>');
                   21165:                         }
1.393     raeburn  21166:                         if (@ok) {
                   21167:                             my @cidr_list;
                   21168:                             foreach my $item (@ok) {
                   21169:                                 @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   21170:                             }
                   21171:                             $wafproxy{$item} = join(',',@cidr_list);
                   21172:                         }
1.373     raeburn  21173:                     }
                   21174:                 }
1.381     raeburn  21175:                 if ($wafproxy{$item} ne $currvalue{$item}) {
1.373     raeburn  21176:                     $changes{$item} = 1;
                   21177:                 }
1.381     raeburn  21178:             } elsif ($currvalue{$item}) {
                   21179:                 $changes{$item} = 1;
                   21180:             } 
                   21181:         }
                   21182:     } else {
                   21183:         if (keys(%curralias)) {
                   21184:             $changes{'alias'} = 1;
1.388     raeburn  21185:         }
                   21186:         if (keys(%currsaml)) {
                   21187:             $changes{'saml'} = 1;
1.381     raeburn  21188:         } 
                   21189:         if (keys(%currvalue)) {
                   21190:             foreach my $key (keys(%currvalue)) {
                   21191:                 $changes{$key} = 1;
1.373     raeburn  21192:             }
                   21193:         }
                   21194:     }
                   21195:     if (keys(%changes)) {
                   21196:         my %defaultshash = (
                   21197:                               wafproxy => \%wafproxy,
                   21198:                            ); 
                   21199:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21200:                                                  $dom);
                   21201:         if ($putresult eq 'ok') {
                   21202:             my $cachetime = 24*60*60;
                   21203:             my (%domdefaults,$updatedomdefs);
1.382     raeburn  21204:             foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21205:                 if ($changes{$item}) {
                   21206:                     unless ($updatedomdefs) {
                   21207:                         %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   21208:                         $updatedomdefs = 1;
                   21209:                     }
                   21210:                     if ($wafproxy{$item}) {
                   21211:                         $domdefaults{'waf_'.$item} = $wafproxy{$item};
                   21212:                     } elsif (exists($domdefaults{'waf_'.$item})) {
                   21213:                         delete($domdefaults{'waf_'.$item});
                   21214:                     } 
                   21215:                 }
                   21216:             }
                   21217:             if ($updatedomdefs) {
                   21218:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21219:                 if (ref($lastactref) eq 'HASH') {
                   21220:                     $lastactref->{'domdefaults'} = 1;
                   21221:                 }
                   21222:             }
                   21223:             if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
                   21224:                 my %updates = %expirecache;
                   21225:                 foreach my $key (keys(%expirecache)) {
                   21226:                     &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
                   21227:                 }
                   21228:                 if (ref($wafproxy{'alias'}) eq 'HASH') {
                   21229:                     my $cachetime = 24*60*60;
                   21230:                     foreach my $key (keys(%{$wafproxy{'alias'}})) {
                   21231:                         $updates{$key} = 1;
                   21232:                         &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
                   21233:                                                       $cachetime);
                   21234:                     }
                   21235:                 }
                   21236:                 if (ref($lastactref) eq 'HASH') {
                   21237:                     $lastactref->{'proxyalias'} = \%updates;
                   21238:                 }
                   21239:             }
1.388     raeburn  21240:             if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
                   21241:                 my %samlupdates = %expiresaml;
                   21242:                 foreach my $key (keys(%expiresaml)) {
                   21243:                     &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
                   21244:                 }
                   21245:                 if (ref($wafproxy{'saml'}) eq 'HASH') {
                   21246:                     my $cachetime = 24*60*60;
                   21247:                     foreach my $key (keys(%{$wafproxy{'saml'}})) {
                   21248:                         $samlupdates{$key} = 1;
                   21249:                         &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
                   21250:                                                       $cachetime);
                   21251:                     }
                   21252:                 }
                   21253:                 if (ref($lastactref) eq 'HASH') {
                   21254:                     $lastactref->{'proxysaml'} = \%samlupdates;
                   21255:                 }
                   21256:             }
1.373     raeburn  21257:             $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401   ! raeburn  21258:             foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21259:                 if ($changes{$item}) {
                   21260:                     if ($item eq 'alias') {
                   21261:                         my $numaliased = 0;
                   21262:                         if (ref($wafproxy{'alias'}) eq 'HASH') {
                   21263:                             my $shown;
                   21264:                             if (keys(%{$wafproxy{'alias'}})) {
                   21265:                                 foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
                   21266:                                     $shown .= '<li>'.&mt('[_1] aliased by [_2]',
                   21267:                                                          &Apache::lonnet::hostname($server),
                   21268:                                                          $wafproxy{'alias'}{$server}).'</li>';
                   21269:                                     $numaliased ++;
                   21270:                                 }
                   21271:                                 if ($numaliased) {
                   21272:                                     $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
                   21273:                                                           '<ul>'.$shown.'</ul>').'</li>';
                   21274:                                 }
                   21275:                             }
                   21276:                         }
                   21277:                         unless ($numaliased) {
                   21278:                             $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
                   21279:                         }
1.388     raeburn  21280:                     } elsif ($item eq 'saml') {
                   21281:                         my $shown; 
                   21282:                         if (ref($wafproxy{'saml'}) eq 'HASH') {
                   21283:                             if (keys(%{$wafproxy{'saml'}})) {
                   21284:                                 $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
                   21285:                             }
                   21286:                         }
                   21287:                         if ($shown) {
1.396     raeburn  21288:                             $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388     raeburn  21289:                                                   $shown).'</li>';
                   21290:                         } else {
1.396     raeburn  21291:                             $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388     raeburn  21292:                         }
1.373     raeburn  21293:                     } else {
1.381     raeburn  21294:                         if ($item eq 'remoteip') {
                   21295:                             my %ip_methods = &remoteip_methods();
                   21296:                             if ($wafproxy{$item} =~ /^[mh]$/) {
                   21297:                                 $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
                   21298:                                                       $ip_methods{$wafproxy{$item}}).'</li>';
                   21299:                             } else {
                   21300:                                 if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
                   21301:                                     $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
                   21302:                                                '</li>';
                   21303:                                 } else {
                   21304:                                     $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
                   21305:                                 }
                   21306:                             }
                   21307:                         } elsif ($item eq 'ipheader') {
1.373     raeburn  21308:                             if ($wafproxy{$item}) {
1.381     raeburn  21309:                                 $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373     raeburn  21310:                                                       $wafproxy{$item}).'</li>';
                   21311:                             } else {
1.381     raeburn  21312:                                 $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373     raeburn  21313:                             }
                   21314:                         } elsif ($item eq 'trusted') {
                   21315:                             if ($wafproxy{$item}) {
1.381     raeburn  21316:                                 $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373     raeburn  21317:                                                       $wafproxy{$item}).'</li>';
                   21318:                             } else {
                   21319:                                 $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
                   21320:                             }
1.381     raeburn  21321:                         } elsif ($item eq 'vpnint') {
                   21322:                             if ($wafproxy{$item}) {
                   21323:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
                   21324:                                                        $wafproxy{$item}).'</li>';
                   21325:                             } else {
                   21326:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
                   21327:                             }
                   21328:                         } elsif ($item eq 'vpnext') {
1.373     raeburn  21329:                             if ($wafproxy{$item}) {
1.381     raeburn  21330:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373     raeburn  21331:                                                        $wafproxy{$item}).'</li>';
                   21332:                             } else {
1.381     raeburn  21333:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373     raeburn  21334:                             }
1.382     raeburn  21335:                         } elsif ($item eq 'sslopt') {
                   21336:                             if ($wafproxy{$item}) {
                   21337:                                 $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>';
                   21338:                             } else {
                   21339:                                 $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>';
                   21340:                             }
1.373     raeburn  21341:                         }
                   21342:                     }
                   21343:                 }
                   21344:             }
                   21345:         } else {
                   21346:             $output = '<span class="LC_error">'.
                   21347:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   21348:         }
                   21349:     } elsif (keys(%canset)) {
                   21350:         $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
                   21351:     }
                   21352:     if (@warnings) {
                   21353:         $output .= '<br />'.&mt('Warnings:').'<ul>'.
                   21354:                        join("\n",@warnings).'</ul>';
                   21355:     }
                   21356:     return $output;
                   21357: }
                   21358: 
                   21359: sub validate_ip_pattern {
                   21360:     my ($pattern) = @_;
                   21361:     if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
                   21362:         my ($start,$end) = ($1,$2);
                   21363:         if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393     raeburn  21364:             if (($start !~ m{/}) && ($end !~ m{/})) {
                   21365:                 return $start.'-'.$end;
                   21366:             }
                   21367:         }
                   21368:     } elsif ($pattern ne '') {
                   21369:         $pattern = &Net::CIDR::cidrvalidate($pattern);
                   21370:         if ($pattern ne '') {
                   21371:             return $pattern;
1.373     raeburn  21372:         }
                   21373:     }
1.393     raeburn  21374:     return;
1.373     raeburn  21375: }
                   21376: 
1.137     raeburn  21377: sub modify_usersessions {
1.212     raeburn  21378:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  21379:     my @hostingtypes = ('version','excludedomain','includedomain');
                   21380:     my @offloadtypes = ('primary','default');
                   21381:     my %types = (
                   21382:                   remote => \@hostingtypes,
                   21383:                   hosted => \@hostingtypes,
                   21384:                   spares => \@offloadtypes,
                   21385:                 );
                   21386:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  21387:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  21388:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21389:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  21390:     my @locations = sort(keys(%by_location));
1.137     raeburn  21391:     my (%defaultshash,%changes);
                   21392:     foreach my $prefix (@prefixes) {
                   21393:         $defaultshash{'usersessions'}{$prefix} = {};
                   21394:     }
1.212     raeburn  21395:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  21396:     my $resulttext;
1.138     raeburn  21397:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  21398:     foreach my $prefix (@prefixes) {
1.145     raeburn  21399:         next if ($prefix eq 'spares');
                   21400:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  21401:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21402:             if ($type eq 'version') {
                   21403:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   21404:                 my $okvalue;
                   21405:                 if ($value ne '') {
                   21406:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   21407:                         $okvalue = $value;
                   21408:                     }
                   21409:                 }
                   21410:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21411:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   21412:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   21413:                             if ($inuse == 0) {
                   21414:                                 $changes{$prefix}{$type} = 1;
                   21415:                             } else {
                   21416:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   21417:                                     $changes{$prefix}{$type} = 1;
                   21418:                                 }
                   21419:                                 if ($okvalue ne '') {
                   21420:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21421:                                 } 
                   21422:                             }
                   21423:                         } else {
                   21424:                             if (($inuse == 1) && ($okvalue ne '')) {
                   21425:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21426:                                 $changes{$prefix}{$type} = 1;
                   21427:                             }
                   21428:                         }
                   21429:                     } else {
                   21430:                         if (($inuse == 1) && ($okvalue ne '')) {
                   21431:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21432:                             $changes{$prefix}{$type} = 1;
                   21433:                         }
                   21434:                     }
                   21435:                 } else {
                   21436:                     if (($inuse == 1) && ($okvalue ne '')) {
                   21437:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21438:                         $changes{$prefix}{$type} = 1;
                   21439:                     }
                   21440:                 }
                   21441:             } else {
                   21442:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21443:                 my @okvals;
                   21444:                 foreach my $val (@vals) {
1.138     raeburn  21445:                     if ($val =~ /:/) {
                   21446:                         my @items = split(/:/,$val);
                   21447:                         foreach my $item (@items) {
                   21448:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   21449:                                 push(@okvals,$item);
                   21450:                             }
                   21451:                         }
                   21452:                     } else {
                   21453:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   21454:                             push(@okvals,$val);
                   21455:                         }
1.137     raeburn  21456:                     }
                   21457:                 }
                   21458:                 @okvals = sort(@okvals);
                   21459:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21460:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   21461:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   21462:                             if ($inuse == 0) {
                   21463:                                 $changes{$prefix}{$type} = 1; 
                   21464:                             } else {
                   21465:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21466:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   21467:                                 if (@changed > 0) {
                   21468:                                     $changes{$prefix}{$type} = 1;
                   21469:                                 }
                   21470:                             }
                   21471:                         } else {
                   21472:                             if ($inuse == 1) {
                   21473:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21474:                                 $changes{$prefix}{$type} = 1;
                   21475:                             }
                   21476:                         } 
                   21477:                     } else {
                   21478:                         if ($inuse == 1) {
                   21479:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21480:                             $changes{$prefix}{$type} = 1;
                   21481:                         }
                   21482:                     }
                   21483:                 } else {
                   21484:                     if ($inuse == 1) {
                   21485:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21486:                         $changes{$prefix}{$type} = 1;
                   21487:                     }
                   21488:                 }
                   21489:             }
                   21490:         }
                   21491:     }
1.145     raeburn  21492: 
                   21493:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  21494:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  21495:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   21496:     my $savespares;
                   21497: 
                   21498:     foreach my $lonhost (sort(keys(%servers))) {
                   21499:         my $serverhomeID =
                   21500:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  21501:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  21502:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   21503:         my %spareschg;
                   21504:         foreach my $type (@{$types{'spares'}}) {
                   21505:             my @okspares;
                   21506:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   21507:             foreach my $server (@checked) {
1.152     raeburn  21508:                 if (&Apache::lonnet::hostname($server) ne '') {
                   21509:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   21510:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   21511:                             push(@okspares,$server);
                   21512:                         }
1.145     raeburn  21513:                     }
                   21514:                 }
                   21515:             }
                   21516:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   21517:             my $newspare;
1.152     raeburn  21518:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   21519:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  21520:                     $newspare = $new;
                   21521:                 }
                   21522:             }
1.152     raeburn  21523:             my @spares;
                   21524:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   21525:                 @spares = sort(@okspares,$newspare);
                   21526:             } else {
                   21527:                 @spares = sort(@okspares);
                   21528:             }
                   21529:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  21530:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   21531:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  21532:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  21533:                     if (@diffs > 0) {
                   21534:                         $spareschg{$type} = 1;
                   21535:                     }
                   21536:                 }
                   21537:             }
                   21538:         }
                   21539:         if (keys(%spareschg) > 0) {
                   21540:             $changes{'spares'}{$lonhost} = \%spareschg;
                   21541:         }
                   21542:     }
1.261     raeburn  21543:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371     raeburn  21544:     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261     raeburn  21545:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   21546:     my @okoffload;
                   21547:     if (@offloadnow) {
                   21548:         foreach my $server (@offloadnow) {
                   21549:             if (&Apache::lonnet::hostname($server) ne '') {
                   21550:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   21551:                     push(@okoffload,$server);
                   21552:                 }
                   21553:             }
                   21554:         }
                   21555:         if (@okoffload) {
                   21556:             foreach my $lonhost (@okoffload) {
                   21557:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   21558:             }
                   21559:         }
                   21560:     }
1.371     raeburn  21561:     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   21562:     my @okoffloadoth;
                   21563:     if (@offloadoth) {
                   21564:         foreach my $server (@offloadoth) {
                   21565:             if (&Apache::lonnet::hostname($server) ne '') {
                   21566:                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   21567:                     push(@okoffloadoth,$server);
                   21568:                 }
                   21569:             }
                   21570:         }
                   21571:         if (@okoffloadoth) {
                   21572:             foreach my $lonhost (@okoffloadoth) {
                   21573:                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   21574:             }
                   21575:         }
                   21576:     }
1.145     raeburn  21577:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21578:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   21579:             if (ref($changes{'spares'}) eq 'HASH') {
                   21580:                 if (keys(%{$changes{'spares'}}) > 0) {
                   21581:                     $savespares = 1;
                   21582:                 }
                   21583:             }
                   21584:         } else {
                   21585:             $savespares = 1;
                   21586:         }
1.371     raeburn  21587:         foreach my $offload ('offloadnow','offloadoth') {
                   21588:             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   21589:                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   21590:                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   21591:                         $changes{$offload} = 1;
                   21592:                         last;
                   21593:                     }
1.261     raeburn  21594:                 }
1.371     raeburn  21595:                 unless ($changes{$offload}) {
                   21596:                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   21597:                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   21598:                             $changes{$offload} = 1;
                   21599:                             last;
                   21600:                         }
1.261     raeburn  21601:                     }
                   21602:                 }
1.371     raeburn  21603:             } else {
                   21604:                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   21605:                      $changes{'offloadnow'} = 1;
                   21606:                 }
                   21607:                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   21608:                     $changes{'offloadoth'} = 1;
                   21609:                 }
                   21610:             } 
                   21611:         }
                   21612:     } else {
                   21613:         if (@okoffload) {
1.261     raeburn  21614:             $changes{'offloadnow'} = 1;
                   21615:         }
1.371     raeburn  21616:         if (@okoffloadoth) {
                   21617:             $changes{'offloadoth'} = 1;
                   21618:         }
1.145     raeburn  21619:     }
1.147     raeburn  21620:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   21621:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  21622:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21623:                                                  $dom);
                   21624:         if ($putresult eq 'ok') {
                   21625:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   21626:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   21627:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   21628:                 }
                   21629:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   21630:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   21631:                 }
1.261     raeburn  21632:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   21633:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   21634:                 }
1.371     raeburn  21635:                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   21636:                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   21637:                 }
1.137     raeburn  21638:             }
                   21639:             my $cachetime = 24*60*60;
                   21640:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  21641:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  21642:             if (ref($lastactref) eq 'HASH') {
                   21643:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  21644:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  21645:             }
1.147     raeburn  21646:             if (keys(%changes) > 0) {
                   21647:                 my %lt = &usersession_titles();
                   21648:                 $resulttext = &mt('Changes made:').'<ul>';
                   21649:                 foreach my $prefix (@prefixes) {
                   21650:                     if (ref($changes{$prefix}) eq 'HASH') {
                   21651:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   21652:                         if ($prefix eq 'spares') {
                   21653:                             if (ref($changes{$prefix}) eq 'HASH') {
                   21654:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   21655:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  21656:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  21657:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   21658:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  21659:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   21660:                                         foreach my $type (@{$types{$prefix}}) {
                   21661:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   21662:                                                 my $offloadto = &mt('None');
                   21663:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   21664:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   21665:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   21666:                                                     }
1.145     raeburn  21667:                                                 }
1.147     raeburn  21668:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  21669:                                             }
1.137     raeburn  21670:                                         }
                   21671:                                     }
1.147     raeburn  21672:                                     $resulttext .= '</li>';
1.137     raeburn  21673:                                 }
                   21674:                             }
1.147     raeburn  21675:                         } else {
                   21676:                             foreach my $type (@{$types{$prefix}}) {
                   21677:                                 if (defined($changes{$prefix}{$type})) {
1.344     raeburn  21678:                                     my ($newvalue,$notinuse);
1.147     raeburn  21679:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   21680:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   21681:                                             if ($type eq 'version') {
                   21682:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344     raeburn  21683:                                             } else {
                   21684:                                                 if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   21685:                                                     if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   21686:                                                         $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   21687:                                                     }
                   21688:                                                 } else {
                   21689:                                                     $notinuse = 1;
1.147     raeburn  21690:                                                 }
1.145     raeburn  21691:                                             }
                   21692:                                         }
                   21693:                                     }
1.147     raeburn  21694:                                     if ($newvalue eq '') {
                   21695:                                         if ($type eq 'version') {
                   21696:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344     raeburn  21697:                                         } elsif ($notinuse) {
                   21698:                                             $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147     raeburn  21699:                                         } else {
                   21700:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   21701:                                         }
1.145     raeburn  21702:                                     } else {
1.147     raeburn  21703:                                         if ($type eq 'version') {
1.344     raeburn  21704:                                             $newvalue .= ' '.&mt('(or later)');
1.147     raeburn  21705:                                         }
                   21706:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  21707:                                     }
1.137     raeburn  21708:                                 }
                   21709:                             }
                   21710:                         }
1.147     raeburn  21711:                         $resulttext .= '</ul>';
1.137     raeburn  21712:                     }
                   21713:                 }
1.261     raeburn  21714:                 if ($changes{'offloadnow'}) {
                   21715:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   21716:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371     raeburn  21717:                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261     raeburn  21718:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   21719:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   21720:                             }
                   21721:                             $resulttext .= '</ul>';
                   21722:                         } else {
1.371     raeburn  21723:                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   21724:                         }
                   21725:                     } else {
                   21726:                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   21727:                     }
                   21728:                 }
                   21729:                 if ($changes{'offloadoth'}) {
                   21730:                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   21731:                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   21732:                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   21733:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   21734:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   21735:                             }
                   21736:                             $resulttext .= '</ul>';
                   21737:                         } else {
                   21738:                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261     raeburn  21739:                         }
                   21740:                     } else {
1.371     raeburn  21741:                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261     raeburn  21742:                     }
                   21743:                 }
1.147     raeburn  21744:                 $resulttext .= '</ul>';
                   21745:             } else {
                   21746:                 $resulttext = $nochgmsg;
1.137     raeburn  21747:             }
                   21748:         } else {
                   21749:             $resulttext = '<span class="LC_error">'.
                   21750:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   21751:         }
                   21752:     } else {
1.147     raeburn  21753:         $resulttext = $nochgmsg;
1.137     raeburn  21754:     }
                   21755:     return $resulttext;
                   21756: }
                   21757: 
1.275     raeburn  21758: sub modify_ssl {
                   21759:     my ($dom,$lastactref,%domconfig) = @_;
                   21760:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21761:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   21762:     my @locations = sort(keys(%by_location));
                   21763:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   21764:     my (%defaultshash,%changes);
                   21765:     my $action = 'ssl';
1.293     raeburn  21766:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  21767:     foreach my $prefix (@prefixes) {
                   21768:         $defaultshash{$action}{$prefix} = {};
                   21769:     }
                   21770:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   21771:     my $resulttext;
                   21772:     my %iphost = &Apache::lonnet::get_iphost();
                   21773:     my @reptypes = ('certreq','nocertreq');
                   21774:     my @connecttypes = ('dom','intdom','other');
                   21775:     my %types = (
1.293     raeburn  21776:                   connto      => \@connecttypes,
                   21777:                   connfrom    => \@connecttypes,
                   21778:                   replication => \@reptypes,
1.275     raeburn  21779:                 );
                   21780:     foreach my $prefix (sort(keys(%types))) {
                   21781:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  21782:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  21783:                 my $value = 'yes';
                   21784:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   21785:                     $value = $env{'form.'.$prefix.'_'.$type};
                   21786:                 }
1.335     raeburn  21787:                 if (ref($domconfig{$action}) eq 'HASH') {
                   21788:                     if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   21789:                         if ($domconfig{$action}{$prefix}{$type} ne '') {
                   21790:                             if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   21791:                                 $changes{$prefix}{$type} = 1;
                   21792:                             }
                   21793:                             $defaultshash{$action}{$prefix}{$type} = $value;
                   21794:                         } else {
                   21795:                             $defaultshash{$action}{$prefix}{$type} = $value;
1.275     raeburn  21796:                             $changes{$prefix}{$type} = 1;
                   21797:                         }
                   21798:                     } else {
                   21799:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   21800:                         $changes{$prefix}{$type} = 1;
                   21801:                     }
                   21802:                 } else {
                   21803:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   21804:                     $changes{$prefix}{$type} = 1;
                   21805:                 }
                   21806:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   21807:                     delete($changes{$prefix}{$type});
                   21808:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   21809:                     delete($changes{$prefix}{$type});
                   21810:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   21811:                     delete($changes{$prefix}{$type});
                   21812:                 }
                   21813:             } elsif ($prefix eq 'replication') {
                   21814:                 if (@locations > 0) {
                   21815:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21816:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21817:                     my @okvals;
                   21818:                     foreach my $val (@vals) {
                   21819:                         if ($val =~ /:/) {
                   21820:                             my @items = split(/:/,$val);
                   21821:                             foreach my $item (@items) {
                   21822:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   21823:                                     push(@okvals,$item);
                   21824:                                 }
                   21825:                             }
                   21826:                         } else {
                   21827:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   21828:                                 push(@okvals,$val);
                   21829:                             }
                   21830:                         }
                   21831:                     }
                   21832:                     @okvals = sort(@okvals);
                   21833:                     if (ref($domconfig{$action}) eq 'HASH') {
                   21834:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   21835:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   21836:                                 if ($inuse == 0) {
                   21837:                                     $changes{$prefix}{$type} = 1;
                   21838:                                 } else {
                   21839:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21840:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   21841:                                     if (@changed > 0) {
                   21842:                                         $changes{$prefix}{$type} = 1;
                   21843:                                     }
                   21844:                                 }
                   21845:                             } else {
                   21846:                                 if ($inuse == 1) {
                   21847:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21848:                                     $changes{$prefix}{$type} = 1;
                   21849:                                 }
                   21850:                             }
                   21851:                         } else {
                   21852:                             if ($inuse == 1) {
                   21853:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21854:                                 $changes{$prefix}{$type} = 1;
                   21855:                             }
                   21856:                         }
                   21857:                     } else {
                   21858:                         if ($inuse == 1) {
                   21859:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21860:                             $changes{$prefix}{$type} = 1;
                   21861:                         }
                   21862:                     }
                   21863:                 }
                   21864:             }
                   21865:         }
                   21866:     }
1.336     raeburn  21867:     if (keys(%changes)) {
                   21868:         foreach my $prefix (keys(%changes)) {
                   21869:             if (ref($changes{$prefix}) eq 'HASH') {
                   21870:                 if (scalar(keys(%{$changes{$prefix}})) == 0) {
                   21871:                     delete($changes{$prefix});
                   21872:                 }
                   21873:             } else {
                   21874:                 delete($changes{$prefix});
                   21875:             }
                   21876:         }
                   21877:     }
1.275     raeburn  21878:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   21879:     if (keys(%changes) > 0) {
                   21880:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21881:                                                  $dom);
                   21882:         if ($putresult eq 'ok') {
                   21883:             if (ref($defaultshash{$action}) eq 'HASH') {
                   21884:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   21885:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   21886:                 }
1.293     raeburn  21887:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335     raeburn  21888:                     $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293     raeburn  21889:                 }
                   21890:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335     raeburn  21891:                     $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275     raeburn  21892:                 }
                   21893:             }
                   21894:             my $cachetime = 24*60*60;
                   21895:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21896:             if (ref($lastactref) eq 'HASH') {
                   21897:                 $lastactref->{'domdefaults'} = 1;
                   21898:             }
                   21899:             if (keys(%changes) > 0) {
                   21900:                 my %titles = &ssl_titles();
                   21901:                 $resulttext = &mt('Changes made:').'<ul>';
                   21902:                 foreach my $prefix (@prefixes) {
                   21903:                     if (ref($changes{$prefix}) eq 'HASH') {
                   21904:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   21905:                         foreach my $type (@{$types{$prefix}}) {
                   21906:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  21907:                                 my ($newvalue,$notinuse);
1.275     raeburn  21908:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   21909:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  21910:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  21911:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344     raeburn  21912:                                         } else {
                   21913:                                             if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   21914:                                                 if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   21915:                                                     $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   21916:                                                 }
                   21917:                                             } else {
                   21918:                                                 $notinuse = 1;
1.275     raeburn  21919:                                             }
                   21920:                                         }
                   21921:                                     }
1.344     raeburn  21922:                                     if ($notinuse) {
                   21923:                                         $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                   21924:                                     } elsif ($newvalue eq '') {
1.275     raeburn  21925:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   21926:                                     } else {
                   21927:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   21928:                                     }
                   21929:                                 }
                   21930:                             }
                   21931:                         }
                   21932:                         $resulttext .= '</ul>';
                   21933:                     }
                   21934:                 }
                   21935:             } else {
                   21936:                 $resulttext = $nochgmsg;
                   21937:             }
                   21938:         } else {
                   21939:             $resulttext = '<span class="LC_error">'.
                   21940:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   21941:         }
                   21942:     } else {
                   21943:         $resulttext = $nochgmsg;
                   21944:     }
                   21945:     return $resulttext;
                   21946: }
                   21947: 
1.279     raeburn  21948: sub modify_trust {
                   21949:     my ($dom,$lastactref,%domconfig) = @_;
                   21950:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21951:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   21952:     my @locations = sort(keys(%by_location));
                   21953:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   21954:     my @types = ('exc','inc');
                   21955:     my (%defaultshash,%changes);
                   21956:     foreach my $prefix (@prefixes) {
                   21957:         $defaultshash{'trust'}{$prefix} = {};
                   21958:     }
                   21959:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   21960:     my $resulttext;
                   21961:     foreach my $prefix (@prefixes) {
                   21962:         foreach my $type (@types) {
                   21963:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21964:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21965:             my @okvals;
                   21966:             foreach my $val (@vals) {
                   21967:                 if ($val =~ /:/) {
                   21968:                     my @items = split(/:/,$val);
                   21969:                     foreach my $item (@items) {
                   21970:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   21971:                             push(@okvals,$item);
                   21972:                         }
                   21973:                     }
                   21974:                 } else {
                   21975:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   21976:                         push(@okvals,$val);
                   21977:                     }
                   21978:                 }
                   21979:             }
                   21980:             @okvals = sort(@okvals);
                   21981:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   21982:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   21983:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   21984:                         if ($inuse == 0) {
                   21985:                             $changes{$prefix}{$type} = 1;
                   21986:                         } else {
                   21987:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   21988:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   21989:                             if (@changed > 0) {
                   21990:                                 $changes{$prefix}{$type} = 1;
                   21991:                             }
                   21992:                         }
                   21993:                     } else {
                   21994:                         if ($inuse == 1) {
                   21995:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   21996:                             $changes{$prefix}{$type} = 1;
                   21997:                         }
                   21998:                     }
                   21999:                 } else {
                   22000:                     if ($inuse == 1) {
                   22001:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22002:                         $changes{$prefix}{$type} = 1;
                   22003:                     }
                   22004:                 }
                   22005:             } else {
                   22006:                 if ($inuse == 1) {
                   22007:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22008:                     $changes{$prefix}{$type} = 1;
                   22009:                 }
                   22010:             }
                   22011:         }
                   22012:     }
                   22013:     my $nochgmsg = &mt('No changes made to trust settings.');
                   22014:     if (keys(%changes) > 0) {
                   22015:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22016:                                                  $dom);
                   22017:         if ($putresult eq 'ok') {
                   22018:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   22019:                 foreach my $prefix (@prefixes) {
                   22020:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   22021:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   22022:                     }
                   22023:                 }
                   22024:             }
                   22025:             my $cachetime = 24*60*60;
                   22026:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   22027:             if (ref($lastactref) eq 'HASH') {
                   22028:                 $lastactref->{'domdefaults'} = 1;
                   22029:             }
                   22030:             if (keys(%changes) > 0) {
                   22031:                 my %lt = &trust_titles();
                   22032:                 $resulttext = &mt('Changes made:').'<ul>';
                   22033:                 foreach my $prefix (@prefixes) {
                   22034:                     if (ref($changes{$prefix}) eq 'HASH') {
                   22035:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   22036:                         foreach my $type (@types) {
                   22037:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  22038:                                 my ($newvalue,$notinuse);
1.279     raeburn  22039:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   22040:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   22041:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   22042:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   22043:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   22044:                                             }
1.344     raeburn  22045:                                         } else {
                   22046:                                             $notinuse = 1;
1.279     raeburn  22047:                                         }
                   22048:                                     }
                   22049:                                 }
1.344     raeburn  22050:                                 if ($notinuse) {
                   22051:                                     $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                   22052:                                 } elsif ($newvalue eq '') {
1.279     raeburn  22053:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   22054:                                 } else {
                   22055:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   22056:                                 }
                   22057:                             }
                   22058:                         }
                   22059:                         $resulttext .= '</ul>';
                   22060:                     }
                   22061:                 }
                   22062:                 $resulttext .= '</ul>';
                   22063:             } else {
                   22064:                 $resulttext = $nochgmsg;
                   22065:             }
                   22066:         } else {
                   22067:             $resulttext = '<span class="LC_error">'.
                   22068:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   22069:         }
                   22070:     } else {
                   22071:         $resulttext = $nochgmsg;
                   22072:     }
                   22073:     return $resulttext;
                   22074: }
                   22075: 
1.150     raeburn  22076: sub modify_loadbalancing {
                   22077:     my ($dom,%domconfig) = @_;
                   22078:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   22079:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   22080:     my ($othertitle,$usertypes,$types) =
                   22081:         &Apache::loncommon::sorted_inst_types($dom);
                   22082:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  22083:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  22084:     my @sparestypes = ('primary','default');
                   22085:     my %typetitles = &sparestype_titles();
                   22086:     my $resulttext;
1.342     raeburn  22087:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  22088:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   22089:         %existing = %{$domconfig{'loadbalancing'}};
                   22090:     }
                   22091:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  22092:                               \%currtargets,\%currrules,\%currcookies);
1.171     raeburn  22093:     my ($saveloadbalancing,%defaultshash,%changes);
                   22094:     my ($alltypes,$othertypes,$titles) =
                   22095:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   22096:     my %ruletitles = &offloadtype_text();
                   22097:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   22098:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   22099:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   22100:         if ($balancer eq '') {
                   22101:             next;
                   22102:         }
1.210     raeburn  22103:         if (!exists($servers{$balancer})) {
1.171     raeburn  22104:             if (exists($currbalancer{$balancer})) {
                   22105:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  22106:             }
1.171     raeburn  22107:             next;
                   22108:         }
                   22109:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   22110:             push(@{$changes{'delete'}},$balancer);
                   22111:             next;
                   22112:         }
                   22113:         if (!exists($currbalancer{$balancer})) {
                   22114:             push(@{$changes{'add'}},$balancer);
                   22115:         }
                   22116:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   22117:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   22118:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   22119:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   22120:             $saveloadbalancing = 1;
                   22121:         }
                   22122:         foreach my $sparetype (@sparestypes) {
                   22123:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   22124:             my @offloadto;
                   22125:             foreach my $target (@targets) {
                   22126:                 if (($servers{$target}) && ($target ne $balancer)) {
                   22127:                     if ($sparetype eq 'default') {
                   22128:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   22129:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  22130:                         }
                   22131:                     }
1.171     raeburn  22132:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   22133:                         push(@offloadto,$target);
                   22134:                     }
1.150     raeburn  22135:                 }
                   22136:             }
1.284     raeburn  22137:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   22138:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   22139:                     push(@offloadto,$balancer);
                   22140:                 }
                   22141:             }
                   22142:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  22143:         }
1.342     raeburn  22144:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   22145:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   22146:             if (exists($currbalancer{$balancer})) { 
                   22147:                 unless ($currcookies{$balancer}) {
                   22148:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   22149:                 }
                   22150:             }
                   22151:         } elsif (exists($currbalancer{$balancer})) {
                   22152:             if ($currcookies{$balancer}) {
                   22153:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   22154:             }
                   22155:         }
1.171     raeburn  22156:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  22157:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  22158:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   22159:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  22160:                     if (@targetdiffs > 0) {
1.171     raeburn  22161:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  22162:                     }
1.171     raeburn  22163:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22164:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22165:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  22166:                     }
                   22167:                 }
                   22168:             }
                   22169:         } else {
1.171     raeburn  22170:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  22171:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  22172:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22173:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22174:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   22175:                         }
1.150     raeburn  22176:                     }
                   22177:                 }
1.210     raeburn  22178:             }
1.150     raeburn  22179:         }
                   22180:         my $ishomedom;
1.171     raeburn  22181:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   22182:             $ishomedom = 1;
1.150     raeburn  22183:         }
                   22184:         if (ref($alltypes) eq 'ARRAY') {
                   22185:             foreach my $type (@{$alltypes}) {
                   22186:                 my $rule;
1.210     raeburn  22187:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  22188:                          (!$ishomedom)) {
1.171     raeburn  22189:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   22190:                 }
                   22191:                 if ($rule eq 'specific') {
1.255     raeburn  22192:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  22193:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  22194:                         $rule = $specifiedhost;
                   22195:                     }
1.150     raeburn  22196:                 }
1.171     raeburn  22197:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   22198:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   22199:                     if ($rule ne $currrules{$balancer}{$type}) {
                   22200:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  22201:                     }
                   22202:                 } elsif ($rule ne '') {
1.171     raeburn  22203:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  22204:                 }
                   22205:             }
                   22206:         }
1.171     raeburn  22207:     }
                   22208:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   22209:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   22210:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   22211:             $defaultshash{'loadbalancing'} = {};
                   22212:         }
                   22213:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   22214:                                                  \%defaultshash,$dom);
                   22215:         if ($putresult eq 'ok') {
                   22216:             if (keys(%changes) > 0) {
1.252     raeburn  22217:                 my %toupdate;
1.171     raeburn  22218:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   22219:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   22220:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  22221:                         $toupdate{$balancer} = 1;
1.150     raeburn  22222:                     }
1.171     raeburn  22223:                 }
                   22224:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  22225:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  22226:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  22227:                         $toupdate{$balancer} = 1;
1.171     raeburn  22228:                     }
                   22229:                 }
                   22230:                 if (ref($changes{'curr'}) eq 'HASH') {
                   22231:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  22232:                         $toupdate{$balancer} = 1;
1.171     raeburn  22233:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   22234:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   22235:                                 my %offloadstr;
                   22236:                                 foreach my $sparetype (@sparestypes) {
                   22237:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22238:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22239:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   22240:                                         }
                   22241:                                     }
1.150     raeburn  22242:                                 }
1.171     raeburn  22243:                                 if (keys(%offloadstr) == 0) {
                   22244:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  22245:                                 } else {
1.171     raeburn  22246:                                     my $showoffload;
                   22247:                                     foreach my $sparetype (@sparestypes) {
                   22248:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   22249:                                         if (defined($offloadstr{$sparetype})) {
                   22250:                                             $showoffload .= $offloadstr{$sparetype};
                   22251:                                         } else {
                   22252:                                             $showoffload .= &mt('None');
                   22253:                                         }
                   22254:                                         $showoffload .= ('&nbsp;'x3);
                   22255:                                     }
                   22256:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  22257:                                 }
                   22258:                             }
                   22259:                         }
1.171     raeburn  22260:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   22261:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   22262:                                 foreach my $type (@{$alltypes}) {
                   22263:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   22264:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   22265:                                         my $balancetext;
                   22266:                                         if ($rule eq '') {
                   22267:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  22268:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  22269:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  22270:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  22271:                                                 foreach my $sparetype (@sparestypes) {
                   22272:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22273:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   22274:                                                     }
                   22275:                                                 }
1.253     raeburn  22276:                                                 foreach my $item (@{$alltypes}) {
                   22277:                                                     next if ($item =~  /^_LC_ipchange/);
                   22278:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   22279:                                                     if ($hasrule eq 'homeserver') {
                   22280:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   22281:                                                     } else {
                   22282:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   22283:                                                             if ($servers{$hasrule}) {
                   22284:                                                                 $toupdate{$hasrule} = 1;
                   22285:                                                             }
                   22286:                                                         }
                   22287:                                                     }
                   22288:                                                 }
1.254     raeburn  22289:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   22290:                                                     $balancetext =  $ruletitles{$rule};
                   22291:                                                 } else {
                   22292:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   22293:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   22294:                                                     if ($receiver) {
                   22295:                                                         $toupdate{$receiver};
                   22296:                                                     }
                   22297:                                                 }
                   22298:                                             } else {
                   22299:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  22300:                                             }
1.171     raeburn  22301:                                         } else {
                   22302:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   22303:                                         }
1.210     raeburn  22304:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  22305:                                     }
                   22306:                                 }
                   22307:                             }
                   22308:                         }
1.342     raeburn  22309:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389     raeburn  22310:                             if ($currcookies{$balancer}) {
                   22311:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
                   22312:                                                           $balancer).'</li>';
                   22313:                             } else {
                   22314:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   22315:                                                           $balancer).'</li>';
                   22316:                             }
1.342     raeburn  22317:                         }
1.375     raeburn  22318:                     }
                   22319:                 }
                   22320:                 if (keys(%toupdate)) {
                   22321:                     my %thismachine;
                   22322:                     my $updatedhere;
                   22323:                     my $cachetime = 60*60*24;
                   22324:                     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   22325:                     foreach my $lonhost (keys(%toupdate)) {
                   22326:                         if ($thismachine{$lonhost}) {
                   22327:                             unless ($updatedhere) {
                   22328:                                 &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   22329:                                                               $defaultshash{'loadbalancing'},
                   22330:                                                               $cachetime);
                   22331:                                 $updatedhere = 1;
1.252     raeburn  22332:                             }
1.375     raeburn  22333:                         } else {
                   22334:                             my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   22335:                             &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252     raeburn  22336:                         }
1.150     raeburn  22337:                     }
1.171     raeburn  22338:                 }
                   22339:                 if ($resulttext ne '') {
                   22340:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  22341:                 } else {
                   22342:                     $resulttext = $nochgmsg;
                   22343:                 }
                   22344:             } else {
1.171     raeburn  22345:                 $resulttext = $nochgmsg;
1.150     raeburn  22346:             }
                   22347:         } else {
1.171     raeburn  22348:             $resulttext = '<span class="LC_error">'.
                   22349:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  22350:         }
                   22351:     } else {
1.171     raeburn  22352:         $resulttext = $nochgmsg;
1.150     raeburn  22353:     }
                   22354:     return $resulttext;
                   22355: }
                   22356: 
1.48      raeburn  22357: sub recurse_check {
                   22358:     my ($chkcats,$categories,$depth,$name) = @_;
                   22359:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   22360:         my $chg = 0;
                   22361:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   22362:             my $category = $chkcats->[$depth]{$name}[$j];
                   22363:             my $item;
                   22364:             if ($category eq '') {
                   22365:                 $chg ++;
                   22366:             } else {
                   22367:                 my $deeper = $depth + 1;
                   22368:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   22369:                 if ($chg) {
                   22370:                     $categories->{$item} -= $chg;
                   22371:                 }
                   22372:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   22373:                 $deeper --;
                   22374:             }
                   22375:         }
                   22376:     }
                   22377:     return;
                   22378: }
                   22379: 
                   22380: sub recurse_cat_deletes {
                   22381:     my ($item,$coursecategories,$deletions) = @_;
                   22382:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   22383:     my $subdepth = $depth + 1;
                   22384:     if (ref($coursecategories) eq 'HASH') {
                   22385:         foreach my $subitem (keys(%{$coursecategories})) {
                   22386:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   22387:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   22388:                 delete($coursecategories->{$subitem});
                   22389:                 $deletions->{$subitem} = 1;
                   22390:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  22391:             }
1.48      raeburn  22392:         }
                   22393:     }
                   22394:     return;
                   22395: }
                   22396: 
1.125     raeburn  22397: sub active_dc_picker {
1.191     raeburn  22398:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  22399:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  22400:     my @domcoord = keys(%domcoords);
                   22401:     if (keys(%currhash)) {
                   22402:         foreach my $dc (keys(%currhash)) {
                   22403:             unless (exists($domcoords{$dc})) {
                   22404:                 push(@domcoord,$dc);
                   22405:             }
                   22406:         }
                   22407:     }
                   22408:     @domcoord = sort(@domcoord);
1.210     raeburn  22409:     my $numdcs = scalar(@domcoord);
1.191     raeburn  22410:     my $rows = 0;
                   22411:     my $table;
1.125     raeburn  22412:     if ($numdcs > 1) {
1.191     raeburn  22413:         $table = '<table>';
                   22414:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  22415:             my $rem = $i%($numinrow);
                   22416:             if ($rem == 0) {
                   22417:                 if ($i > 0) {
1.191     raeburn  22418:                     $table .= '</tr>';
1.125     raeburn  22419:                 }
1.191     raeburn  22420:                 $table .= '<tr>';
                   22421:                 $rows ++;
1.125     raeburn  22422:             }
1.191     raeburn  22423:             my $check = '';
                   22424:             if ($inputtype eq 'radio') {
                   22425:                 if (keys(%currhash) == 0) {
                   22426:                     if (!$i) {
                   22427:                         $check = ' checked="checked"';
                   22428:                     }
                   22429:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   22430:                     $check = ' checked="checked"';
                   22431:                 }
                   22432:             } else {
                   22433:                 if (exists($currhash{$domcoord[$i]})) {
                   22434:                     $check = ' checked="checked"';
1.125     raeburn  22435:                 }
                   22436:             }
1.191     raeburn  22437:             if ($i == @domcoord - 1) {
1.125     raeburn  22438:                 my $colsleft = $numinrow - $rem;
                   22439:                 if ($colsleft > 1) {
1.191     raeburn  22440:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  22441:                 } else {
1.191     raeburn  22442:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  22443:                 }
                   22444:             } else {
1.191     raeburn  22445:                 $table .= '<td class="LC_left_item">';
                   22446:             }
                   22447:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   22448:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   22449:             $table .= '<span class="LC_nobreak"><label>'.
                   22450:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   22451:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   22452:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  22453:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  22454:             }
1.219     raeburn  22455:             $table .= '</label></span></td>';
1.191     raeburn  22456:         }
                   22457:         $table .= '</tr></table>';
                   22458:     } elsif ($numdcs == 1) {
1.219     raeburn  22459:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   22460:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  22461:         if ($inputtype eq 'radio') {
1.247     raeburn  22462:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  22463:             if ($user ne $dcname.':'.$dcdom) {
                   22464:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   22465:             }
1.191     raeburn  22466:         } else {
                   22467:             my $check;
                   22468:             if (exists($currhash{$domcoord[0]})) {
                   22469:                 $check = ' checked="checked"';
1.125     raeburn  22470:             }
1.247     raeburn  22471:             $table = '<span class="LC_nobreak"><label>'.
                   22472:                      '<input type="checkbox" name="'.$name.'" '.
                   22473:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  22474:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  22475:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  22476:             }
1.220     raeburn  22477:             $table .= '</label></span>';
1.191     raeburn  22478:             $rows ++;
1.125     raeburn  22479:         }
                   22480:     }
1.191     raeburn  22481:     return ($numdcs,$table,$rows);
1.125     raeburn  22482: }
                   22483: 
1.137     raeburn  22484: sub usersession_titles {
                   22485:     return &Apache::lonlocal::texthash(
                   22486:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   22487:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  22488:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  22489:                version => 'LON-CAPA version requirement',
1.138     raeburn  22490:                excludedomain => 'Allow all, but exclude specific domains',
                   22491:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  22492:                primary => 'Primary (checked first)',
1.154     raeburn  22493:                default => 'Default',
1.137     raeburn  22494:            );
                   22495: }
                   22496: 
1.152     raeburn  22497: sub id_for_thisdom {
                   22498:     my (%servers) = @_;
                   22499:     my %altids;
                   22500:     foreach my $server (keys(%servers)) {
                   22501:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   22502:         if ($serverhome ne $server) {
                   22503:             $altids{$serverhome} = $server;
                   22504:         }
                   22505:     }
                   22506:     return %altids;
                   22507: }
                   22508: 
1.150     raeburn  22509: sub count_servers {
                   22510:     my ($currbalancer,%servers) = @_;
                   22511:     my (@spares,$numspares);
                   22512:     foreach my $lonhost (sort(keys(%servers))) {
                   22513:         next if ($currbalancer eq $lonhost);
                   22514:         push(@spares,$lonhost);
                   22515:     }
                   22516:     if ($currbalancer) {
                   22517:         $numspares = scalar(@spares);
                   22518:     } else {
                   22519:         $numspares = scalar(@spares) - 1;
                   22520:     }
                   22521:     return ($numspares,@spares);
                   22522: }
                   22523: 
                   22524: sub lonbalance_targets_js {
1.171     raeburn  22525:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  22526:     my $select = &mt('Select');
                   22527:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   22528:     if (ref($servers) eq 'HASH') {
                   22529:         $alltargets = join("','",sort(keys(%{$servers})));
                   22530:         my @homedoms;
                   22531:         foreach my $server (sort(keys(%{$servers}))) {
                   22532:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   22533:                 push(@homedoms,'1');
                   22534:             } else {
                   22535:                 push(@homedoms,'0');
                   22536:             }
                   22537:         }
                   22538:         $allishome = join("','",@homedoms);
                   22539:     }
                   22540:     if (ref($types) eq 'ARRAY') {
                   22541:         if (@{$types} > 0) {
                   22542:             @alltypes = @{$types};
                   22543:         }
                   22544:     }
                   22545:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   22546:     $allinsttypes = join("','",@alltypes);
1.342     raeburn  22547:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  22548:     if (ref($settings) eq 'HASH') {
                   22549:         %existing = %{$settings};
                   22550:     }
                   22551:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342     raeburn  22552:                               \%currtargets,\%currrules,\%currcookies);
1.210     raeburn  22553:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  22554:     return <<"END";
                   22555: 
                   22556: <script type="text/javascript">
                   22557: // <![CDATA[
                   22558: 
1.171     raeburn  22559: currBalancers = new Array('$balancers');
                   22560: 
                   22561: function toggleTargets(balnum) {
                   22562:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   22563:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   22564:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   22565:     var prevbalancer = prevhostitem.value;
                   22566:     var baltotal = document.getElementById('loadbalancing_total').value;
                   22567:     prevhostitem.value = balancer;
                   22568:     if (prevbalancer != '') {
                   22569:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   22570:         if (prevIdx != -1) {
                   22571:             currBalancers.splice(prevIdx,1);
                   22572:         }
                   22573:     }
1.150     raeburn  22574:     if (balancer == '') {
1.171     raeburn  22575:         hideSpares(balnum);
1.150     raeburn  22576:     } else {
1.171     raeburn  22577:         var currIdx = currBalancers.indexOf(balancer);
                   22578:         if (currIdx == -1) {
                   22579:             currBalancers.push(balancer);
                   22580:         }
1.150     raeburn  22581:         var homedoms = new Array('$allishome');
1.171     raeburn  22582:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   22583:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  22584:     }
1.171     raeburn  22585:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  22586:     return;
                   22587: }
                   22588: 
1.171     raeburn  22589: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  22590:     var alltargets = new Array('$alltargets');
                   22591:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  22592:     var offloadtypes = new Array('primary','default');
                   22593: 
1.171     raeburn  22594:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   22595:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  22596:  
1.151     raeburn  22597:     for (var i=0; i<offloadtypes.length; i++) {
                   22598:         var count = 0;
                   22599:         for (var j=0; j<alltargets.length; j++) {
                   22600:             if (alltargets[j] != balancer) {
1.171     raeburn  22601:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   22602:                 item.value = alltargets[j];
                   22603:                 item.style.textAlign='left';
                   22604:                 item.style.textFace='normal';
                   22605:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   22606:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   22607:                     item.disabled = '';
                   22608:                 } else {
                   22609:                     item.disabled = 'disabled';
                   22610:                     item.checked = false;
                   22611:                 }
1.151     raeburn  22612:                 count ++;
                   22613:             }
1.150     raeburn  22614:         }
                   22615:     }
1.151     raeburn  22616:     for (var k=0; k<insttypes.length; k++) {
                   22617:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  22618:             if (ishomedom == 1) {
1.171     raeburn  22619:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   22620:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  22621:             } else {
1.171     raeburn  22622:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   22623:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  22624:             }
                   22625:         } else {
1.171     raeburn  22626:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   22627:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  22628:         }
1.151     raeburn  22629:         if ((insttypes[k] != '_LC_external') && 
                   22630:             ((insttypes[k] != '_LC_internetdom') ||
                   22631:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  22632:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   22633:             item.options.length = 0;
                   22634:             item.options[0] = new Option("","",true,true);
1.210     raeburn  22635:             var idx = 0;
1.151     raeburn  22636:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  22637:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   22638:                     idx ++;
                   22639:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  22640:                 }
                   22641:             }
                   22642:         }
                   22643:     }
                   22644:     return;
                   22645: }
                   22646: 
1.171     raeburn  22647: function hideSpares(balnum) {
1.150     raeburn  22648:     var alltargets = new Array('$alltargets');
                   22649:     var insttypes = new Array('$allinsttypes');
                   22650:     var offloadtypes = new Array('primary','default');
                   22651: 
1.171     raeburn  22652:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   22653:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  22654: 
                   22655:     var total = alltargets.length - 1;
                   22656:     for (var i=0; i<offloadtypes; i++) {
                   22657:         for (var j=0; j<total; j++) {
1.171     raeburn  22658:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   22659:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   22660:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  22661:         }
1.150     raeburn  22662:     }
                   22663:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  22664:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   22665:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  22666:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  22667:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   22668:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  22669:         }
                   22670:     }
                   22671:     return;
                   22672: }
                   22673: 
1.171     raeburn  22674: function checkOffloads(item,balnum,type) {
1.150     raeburn  22675:     var alltargets = new Array('$alltargets');
                   22676:     var offloadtypes = new Array('primary','default');
                   22677:     if (item.checked) {
                   22678:         var total = alltargets.length - 1;
                   22679:         var other;
                   22680:         if (type == offloadtypes[0]) {
1.151     raeburn  22681:             other = offloadtypes[1];
1.150     raeburn  22682:         } else {
1.151     raeburn  22683:             other = offloadtypes[0];
1.150     raeburn  22684:         }
                   22685:         for (var i=0; i<total; i++) {
1.171     raeburn  22686:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  22687:             if (server == item.value) {
1.171     raeburn  22688:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   22689:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  22690:                 }
                   22691:             }
                   22692:         }
                   22693:     }
                   22694:     return;
                   22695: }
                   22696: 
1.171     raeburn  22697: function singleServerToggle(balnum,type) {
                   22698:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  22699:     if (offloadtoSelIdx == 0) {
1.171     raeburn  22700:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   22701:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  22702: 
                   22703:     } else {
1.171     raeburn  22704:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   22705:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  22706:     }
                   22707:     return;
                   22708: }
                   22709: 
1.171     raeburn  22710: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  22711:     if (type == '_LC_external') {
1.171     raeburn  22712:         return;
1.150     raeburn  22713:     }
1.171     raeburn  22714:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  22715:     for (var i=0; i<typesRules.length; i++) {
                   22716:         if (formname.elements[typesRules[i]].checked) {
                   22717:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  22718:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   22719:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  22720:             } else {
1.171     raeburn  22721:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   22722:             }
                   22723:         }
                   22724:     }
                   22725:     return;
                   22726: }
                   22727: 
                   22728: function balancerDeleteChange(balnum) {
                   22729:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   22730:     var baltotal = document.getElementById('loadbalancing_total').value;
                   22731:     var addtarget;
                   22732:     var removetarget;
                   22733:     var action = 'delete';
                   22734:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   22735:         var lonhost = hostitem.value;
                   22736:         var currIdx = currBalancers.indexOf(lonhost);
                   22737:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   22738:             if (currIdx != -1) {
                   22739:                 currBalancers.splice(currIdx,1);
                   22740:             }
                   22741:             addtarget = lonhost;
                   22742:         } else {
                   22743:             if (currIdx == -1) {
                   22744:                 currBalancers.push(lonhost);
                   22745:             }
                   22746:             removetarget = lonhost;
                   22747:             action = 'undelete';
                   22748:         }
                   22749:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   22750:     }
                   22751:     return;
                   22752: }
                   22753: 
                   22754: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   22755:     if (baltotal > 1) {
                   22756:         var offloadtypes = new Array('primary','default');
                   22757:         var alltargets = new Array('$alltargets');
                   22758:         var insttypes = new Array('$allinsttypes');
                   22759:         for (var i=0; i<baltotal; i++) {
                   22760:             if (i != balnum) {
                   22761:                 for (var j=0; j<offloadtypes.length; j++) {
                   22762:                     var total = alltargets.length - 1;
                   22763:                     for (var k=0; k<total; k++) {
                   22764:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   22765:                         var server = serveritem.value;
                   22766:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   22767:                             if (server == addtarget) {
                   22768:                                 serveritem.disabled = '';
                   22769:                             }
                   22770:                         }
                   22771:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   22772:                             if (server == removetarget) {
                   22773:                                 serveritem.disabled = 'disabled';
                   22774:                                 serveritem.checked = false;
                   22775:                             }
                   22776:                         }
                   22777:                     }
                   22778:                 }
                   22779:                 for (var j=0; j<insttypes.length; j++) {
                   22780:                     if (insttypes[j] != '_LC_external') {
                   22781:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   22782:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   22783:                             var currSel = singleserver.selectedIndex;
                   22784:                             var currVal = singleserver.options[currSel].value;
                   22785:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   22786:                                 var numoptions = singleserver.options.length;
                   22787:                                 var needsnew = 1;
                   22788:                                 for (var k=0; k<numoptions; k++) {
                   22789:                                     if (singleserver.options[k] == addtarget) {
                   22790:                                         needsnew = 0;
                   22791:                                         break;
                   22792:                                     }
                   22793:                                 }
                   22794:                                 if (needsnew == 1) {
                   22795:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   22796:                                 }
                   22797:                             }
                   22798:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   22799:                                 singleserver.options.length = 0;
                   22800:                                 if ((currVal) && (currVal != removetarget)) {
                   22801:                                     singleserver.options[0] = new Option("","",false,false);
                   22802:                                 } else {
                   22803:                                     singleserver.options[0] = new Option("","",true,true);
                   22804:                                 }
                   22805:                                 var idx = 0;
                   22806:                                 for (var m=0; m<alltargets.length; m++) {
                   22807:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   22808:                                         idx ++;
                   22809:                                         if (currVal == alltargets[m]) {
                   22810:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   22811:                                         } else {
                   22812:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   22813:                                         }
                   22814:                                     }
                   22815:                                 }
                   22816:                             }
                   22817:                         }
                   22818:                     }
                   22819:                 }
1.150     raeburn  22820:             }
                   22821:         }
                   22822:     }
                   22823:     return;
                   22824: }
                   22825: 
1.152     raeburn  22826: // ]]>
                   22827: </script>
                   22828: 
                   22829: END
                   22830: }
                   22831: 
1.372     raeburn  22832: 
1.152     raeburn  22833: sub new_spares_js {
                   22834:     my @sparestypes = ('primary','default');
                   22835:     my $types = join("','",@sparestypes);
                   22836:     my $select = &mt('Select');
                   22837:     return <<"END";
                   22838: 
                   22839: <script type="text/javascript">
                   22840: // <![CDATA[
                   22841: 
                   22842: function updateNewSpares(formname,lonhost) {
                   22843:     var types = new Array('$types');
                   22844:     var include = new Array();
                   22845:     var exclude = new Array();
                   22846:     for (var i=0; i<types.length; i++) {
                   22847:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   22848:         for (var j=0; j<spareboxes.length; j++) {
                   22849:             if (formname.elements[spareboxes[j]].checked) {
                   22850:                 exclude.push(formname.elements[spareboxes[j]].value);
                   22851:             } else {
                   22852:                 include.push(formname.elements[spareboxes[j]].value);
                   22853:             }
                   22854:         }
                   22855:     }
                   22856:     for (var i=0; i<types.length; i++) {
                   22857:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   22858:         var selIdx = newSpare.selectedIndex;
                   22859:         var currnew = newSpare.options[selIdx].value;
                   22860:         var okSpares = new Array();
                   22861:         for (var j=0; j<newSpare.options.length; j++) {
                   22862:             var possible = newSpare.options[j].value;
                   22863:             if (possible != '') {
                   22864:                 if (exclude.indexOf(possible) == -1) {
                   22865:                     okSpares.push(possible);
                   22866:                 } else {
                   22867:                     if (currnew == possible) {
                   22868:                         selIdx = 0;
                   22869:                     }
                   22870:                 }
                   22871:             }
                   22872:         }
                   22873:         for (var k=0; k<include.length; k++) {
                   22874:             if (okSpares.indexOf(include[k]) == -1) {
                   22875:                 okSpares.push(include[k]);
                   22876:             }
                   22877:         }
                   22878:         okSpares.sort();
                   22879:         newSpare.options.length = 0;
                   22880:         if (selIdx == 0) {
                   22881:             newSpare.options[0] = new Option("$select","",true,true);
                   22882:         } else {
                   22883:             newSpare.options[0] = new Option("$select","",false,false);
                   22884:         }
                   22885:         for (var m=0; m<okSpares.length; m++) {
                   22886:             var idx = m+1;
                   22887:             var selThis = 0;
                   22888:             if (selIdx != 0) {
                   22889:                 if (okSpares[m] == currnew) {
                   22890:                     selThis = 1;
                   22891:                 }
                   22892:             }
                   22893:             if (selThis == 1) {
                   22894:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   22895:             } else {
                   22896:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   22897:             }
                   22898:         }
                   22899:     }
                   22900:     return;
                   22901: }
                   22902: 
                   22903: function checkNewSpares(lonhost,type) {
                   22904:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   22905:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
1.372     raeburn  22906:     if (chosen != '') {
1.152     raeburn  22907:         var othertype;
                   22908:         var othernewSpare;
                   22909:         if (type == 'primary') {
                   22910:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   22911:         }
                   22912:         if (type == 'default') {
                   22913:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   22914:         }
                   22915:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   22916:             othernewSpare.selectedIndex = 0;
                   22917:         }
                   22918:     }
                   22919:     return;
                   22920: }
                   22921: 
                   22922: // ]]>
                   22923: </script>
                   22924: 
                   22925: END
                   22926: 
                   22927: }
                   22928: 
                   22929: sub common_domprefs_js {
                   22930:     return <<"END";
                   22931: 
                   22932: <script type="text/javascript">
                   22933: // <![CDATA[
                   22934: 
1.150     raeburn  22935: function getIndicesByName(formname,item) {
1.152     raeburn  22936:     var group = new Array();
1.150     raeburn  22937:     for (var i=0;i<formname.elements.length;i++) {
                   22938:         if (formname.elements[i].name == item) {
1.152     raeburn  22939:             group.push(formname.elements[i].id);
1.150     raeburn  22940:         }
                   22941:     }
1.152     raeburn  22942:     return group;
1.150     raeburn  22943: }
                   22944: 
                   22945: // ]]>
                   22946: </script>
                   22947: 
                   22948: END
1.152     raeburn  22949: 
1.150     raeburn  22950: }
                   22951: 
1.165     raeburn  22952: sub recaptcha_js {
                   22953:     my %lt = &captcha_phrases();
                   22954:     return <<"END";
                   22955: 
                   22956: <script type="text/javascript">
                   22957: // <![CDATA[
                   22958: 
                   22959: function updateCaptcha(caller,context) {
                   22960:     var privitem;
                   22961:     var pubitem;
                   22962:     var privtext;
                   22963:     var pubtext;
1.269     raeburn  22964:     var versionitem;
                   22965:     var versiontext;
1.165     raeburn  22966:     if (document.getElementById(context+'_recaptchapub')) {
                   22967:         pubitem = document.getElementById(context+'_recaptchapub');
                   22968:     } else {
                   22969:         return;
                   22970:     }
                   22971:     if (document.getElementById(context+'_recaptchapriv')) {
                   22972:         privitem = document.getElementById(context+'_recaptchapriv');
                   22973:     } else {
                   22974:         return;
                   22975:     }
                   22976:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   22977:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   22978:     } else {
                   22979:         return;
                   22980:     }
                   22981:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   22982:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   22983:     } else {
                   22984:         return;
                   22985:     }
1.269     raeburn  22986:     if (document.getElementById(context+'_recaptchaversion')) {
                   22987:         versionitem = document.getElementById(context+'_recaptchaversion');
                   22988:     } else {
                   22989:         return;
                   22990:     }
                   22991:     if (document.getElementById(context+'_recaptchavertxt')) {
                   22992:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   22993:     } else {
                   22994:         return;
                   22995:     }
1.165     raeburn  22996:     if (caller.checked) {
                   22997:         if (caller.value == 'recaptcha') {
                   22998:             pubitem.type = 'text';
                   22999:             privitem.type = 'text';
                   23000:             pubitem.size = '40';
                   23001:             privitem.size = '40';
                   23002:             pubtext.innerHTML = "$lt{'pub'}";
                   23003:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  23004:             versionitem.type = 'text';
                   23005:             versionitem.size = '3';
1.289     raeburn  23006:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  23007:         } else {
                   23008:             pubitem.type = 'hidden';
                   23009:             privitem.type = 'hidden';
1.269     raeburn  23010:             versionitem.type = 'hidden';
1.165     raeburn  23011:             pubtext.innerHTML = '';
                   23012:             privtext.innerHTML = '';
1.269     raeburn  23013:             versiontext.innerHTML = '';
1.165     raeburn  23014:         }
                   23015:     }
                   23016:     return;
                   23017: }
                   23018: 
                   23019: // ]]>
                   23020: </script>
                   23021: 
                   23022: END
                   23023: 
                   23024: }
                   23025: 
1.236     raeburn  23026: sub toggle_display_js {
1.192     raeburn  23027:     return <<"END";
                   23028: 
                   23029: <script type="text/javascript">
                   23030: // <![CDATA[
                   23031: 
1.236     raeburn  23032: function toggleDisplay(domForm,caller) {
                   23033:     if (document.getElementById(caller)) {
                   23034:         var divitem = document.getElementById(caller);
                   23035:         var optionsElement = domForm.coursecredits;
1.264     raeburn  23036:         var checkval = 1;
                   23037:         var dispval = 'block';
1.303     raeburn  23038:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  23039:         if (caller == 'emailoptions') {
1.372     raeburn  23040:             optionsElement = domForm.cancreate_email;
1.236     raeburn  23041:         }
1.257     raeburn  23042:         if (caller == 'studentsubmission') {
                   23043:             optionsElement = domForm.postsubmit;
                   23044:         }
1.264     raeburn  23045:         if (caller == 'cloneinstcode') {
                   23046:             optionsElement = domForm.canclone;
                   23047:             checkval = 'instcode';
                   23048:         }
1.303     raeburn  23049:         if (selfcreateRegExp.test(caller)) {
                   23050:             optionsElement = domForm.elements[caller];
                   23051:             checkval = 'other';
                   23052:             dispval = 'inline'
                   23053:         }
1.236     raeburn  23054:         if (optionsElement.length) {
1.192     raeburn  23055:             var currval;
1.236     raeburn  23056:             for (var i=0; i<optionsElement.length; i++) {
                   23057:                 if (optionsElement[i].checked) {
                   23058:                    currval = optionsElement[i].value;
1.192     raeburn  23059:                 }
                   23060:             }
1.264     raeburn  23061:             if (currval == checkval) {
                   23062:                 divitem.style.display = dispval;
1.192     raeburn  23063:             } else {
1.236     raeburn  23064:                 divitem.style.display = 'none';
1.192     raeburn  23065:             }
                   23066:         }
                   23067:     }
                   23068:     return;
                   23069: }
                   23070: 
                   23071: // ]]>
                   23072: </script>
                   23073: 
                   23074: END
                   23075: 
                   23076: }
                   23077: 
1.165     raeburn  23078: sub captcha_phrases {
                   23079:     return &Apache::lonlocal::texthash (
                   23080:                  priv => 'Private key',
                   23081:                  pub  => 'Public key',
                   23082:                  original  => 'original (CAPTCHA)',
                   23083:                  recaptcha => 'successor (ReCAPTCHA)',
                   23084:                  notused   => 'unused',
1.289     raeburn  23085:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  23086:     );
                   23087: }
                   23088: 
1.205     raeburn  23089: sub devalidate_remote_domconfs {
1.212     raeburn  23090:     my ($dom,$cachekeys) = @_;
                   23091:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  23092:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   23093:     my %thismachine;
                   23094:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355     raeburn  23095:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394     raeburn  23096:                       'directorysrch','passwdconf','cats','proxyalias','proxysaml',
                   23097:                       'ipaccess');
1.386     raeburn  23098:     my %cache_by_lonhost;
                   23099:     if (exists($cachekeys->{'samllanding'})) {
                   23100:         if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
                   23101:             my %landing = %{$cachekeys->{'samllanding'}};
                   23102:             my %domservers = &Apache::lonnet::get_servers($dom);
                   23103:             if (keys(%domservers)) {
                   23104:                 foreach my $server (keys(%domservers)) {
                   23105:                     my @cached;
                   23106:                     next if ($thismachine{$server});
                   23107:                     if ($landing{$server}) {
                   23108:                         push(@cached,&escape('samllanding').':'.&escape($server));
                   23109:                     }
                   23110:                     if (@cached) {
                   23111:                         $cache_by_lonhost{$server} = \@cached;
                   23112:                     }
                   23113:                 }
                   23114:             }
                   23115:         }
                   23116:     }
1.260     raeburn  23117:     if (keys(%servers)) {
1.205     raeburn  23118:         foreach my $server (keys(%servers)) {
                   23119:             next if ($thismachine{$server});
1.212     raeburn  23120:             my @cached;
                   23121:             foreach my $name (@posscached) {
                   23122:                 if ($cachekeys->{$name}) {
1.388     raeburn  23123:                     if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386     raeburn  23124:                         if (ref($cachekeys->{$name}) eq 'HASH') {
1.373     raeburn  23125:                             foreach my $key (keys(%{$cachekeys->{$name}})) {
                   23126:                                 push(@cached,&escape($name).':'.&escape($key));
                   23127:                             }
                   23128:                         }
                   23129:                     } else {
                   23130:                         push(@cached,&escape($name).':'.&escape($dom));
                   23131:                     }
1.212     raeburn  23132:                 }
                   23133:             }
1.386     raeburn  23134:             if ((exists($cache_by_lonhost{$server})) &&
                   23135:                 (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
                   23136:                 push(@cached,@{$cache_by_lonhost{$server}});
                   23137:             }
1.212     raeburn  23138:             if (@cached) {
                   23139:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   23140:             }
1.205     raeburn  23141:         }
                   23142:     }
                   23143:     return;
                   23144: }
                   23145: 
1.3       raeburn  23146: 1;

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