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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.402   ! raeburn     4: # $Id: domainprefs.pm,v 1.401 2021/12/30 02:39:01 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');
1.402   ! raeburn  1360:         my @alttext = ('img','logo','domlogo');
1.168     raeburn  1361:         my @logintext = ('textcol','bgcol');
                   1362:         my @bgs = ('pgbg','mainbg','sidebg');
                   1363:         my @links = ('link','alink','vlink');
                   1364:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1365:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1366:         my (%is_custom,%designs);
                   1367:         my %defaults = (
                   1368:                        font => $defaultdesign{'login.font'},
                   1369:                        );
1.6       raeburn  1370:         foreach my $item (@images) {
1.168     raeburn  1371:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1372:             $defaults{'showlogo'}{$item} = 1;
                   1373:         }
                   1374:         foreach my $item (@bgs) {
                   1375:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1376:         }
1.41      raeburn  1377:         foreach my $item (@logintext) {
1.168     raeburn  1378:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1379:         }
1.168     raeburn  1380:         foreach my $item (@links) {
                   1381:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1382:         }
1.168     raeburn  1383:         if (ref($settings) eq 'HASH') {
                   1384:             foreach my $item (@toggles) {
                   1385:                 if ($settings->{$item} eq '1') {
                   1386:                     $checkedon{$item} =  ' checked="checked" ';
                   1387:                     $checkedoff{$item} = ' ';
                   1388:                 } elsif ($settings->{$item} eq '0') {
                   1389:                     $checkedoff{$item} =  ' checked="checked" ';
                   1390:                     $checkedon{$item} = ' ';
                   1391:                 }
                   1392:             }
                   1393:             foreach my $item (@images) {
                   1394:                 if (defined($settings->{$item})) {
                   1395:                     $designs{$item} = $settings->{$item};
                   1396:                     $is_custom{$item} = 1;
                   1397:                 }
                   1398:                 if (defined($settings->{'showlogo'}{$item})) {
                   1399:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1400:                 }
                   1401:             }
1.402   ! raeburn  1402:             foreach my $item (@alttext) {
        !          1403:                 if (ref($settings->{'alttext'}) eq 'HASH') {
        !          1404:                     if ($settings->{'alttext'}->{$item} ne '') {
        !          1405:                         $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
        !          1406:                     }
        !          1407:                 }
        !          1408:             }
1.168     raeburn  1409:             foreach my $item (@logintext) {
                   1410:                 if ($settings->{$item} ne '') {
                   1411:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1412:                     $is_custom{$item} = 1;
                   1413:                 }
                   1414:             }
                   1415:             if ($settings->{'font'} ne '') {
                   1416:                 $designs{'font'} = $settings->{'font'};
                   1417:                 $is_custom{'font'} = 1;
                   1418:             }
                   1419:             foreach my $item (@bgs) {
                   1420:                 if ($settings->{$item} ne '') {
                   1421:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1422:                     $is_custom{$item} = 1;
                   1423:                 }
                   1424:             }
                   1425:             foreach my $item (@links) {
                   1426:                 if ($settings->{$item} ne '') {
                   1427:                     $designs{'links'}{$item} = $settings->{$item};
                   1428:                     $is_custom{$item} = 1;
                   1429:                 }
                   1430:             }
                   1431:         } else {
                   1432:             if ($designhash{$dom.'.login.font'} ne '') {
                   1433:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1434:                 $is_custom{'font'} = 1;
                   1435:             }
                   1436:             foreach my $item (@images) {
                   1437:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1438:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1439:                     $is_custom{$item} = 1;
                   1440:                 }
                   1441:             }
                   1442:             foreach my $item (@bgs) {
                   1443:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1444:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1445:                     $is_custom{$item} = 1;
                   1446:                 }
1.6       raeburn  1447:             }
1.168     raeburn  1448:             foreach my $item (@links) {
                   1449:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1450:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1451:                     $is_custom{$item} = 1;
                   1452:                 }
1.6       raeburn  1453:             }
                   1454:         }
1.168     raeburn  1455:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1456:                                                       logo => 'Institution Logo',
                   1457:                                                       domlogo => 'Domain Logo',
                   1458:                                                       login => 'Login box');
                   1459:         my $itemcount = 1;
                   1460:         foreach my $item (@toggles) {
                   1461:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1462:             $datatable .=  
                   1463:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1464:                 '</td><td>'.
                   1465:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1466:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1467:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1468:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1469:                 '</tr>';
                   1470:             $itemcount ++;
1.6       raeburn  1471:         }
1.168     raeburn  1472:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1473:         $datatable .= '</tr></table></td></tr>';
                   1474:     } elsif ($caller eq 'help') {
1.386     raeburn  1475:         my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168     raeburn  1476:         my $itemcount = 1;
                   1477:         $defaulturl = '/adm/loginproblems.html';
                   1478:         $defaulttype = 'default';
                   1479:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1480:         my @currlangs;
                   1481:         if (ref($settings) eq 'HASH') {
                   1482:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1483:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1484:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1485:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1486:                     $type{$key} = 'custom';
                   1487:                     unless ($key eq 'nolang') {
                   1488:                         push(@currlangs,$key);
                   1489:                     }
                   1490:                 }
                   1491:             } elsif ($settings->{'helpurl'} ne '') {
                   1492:                 $type{'nolang'} = 'custom';
                   1493:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1494:             }
                   1495:         }
1.168     raeburn  1496:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1497:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1498:             $datatable .= '<tr'.$css_class.'>';
                   1499:             if ($url{$lang} eq '') {
                   1500:                 $url{$lang} = $defaulturl;
                   1501:             }
                   1502:             if ($type{$lang} eq '') {
                   1503:                 $type{$lang} = $defaulttype;
                   1504:             }
                   1505:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1506:             if ($lang eq 'nolang') {
                   1507:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1508:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1509:             } else {
                   1510:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1511:                                   $langchoices{$lang},
                   1512:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1513:             }
                   1514:             $datatable .= '</span></td>'."\n".
                   1515:                           '<td class="LC_left_item">';
                   1516:             if ($type{$lang} eq 'custom') {
                   1517:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1518:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1519:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1520:             } else {
                   1521:                 $datatable .= $lt{'upl'};
                   1522:             }
                   1523:             $datatable .='<br />';
                   1524:             if ($switchserver) {
                   1525:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1526:             } else {
                   1527:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1528:             }
1.168     raeburn  1529:             $datatable .= '</td></tr>';
                   1530:             $itemcount ++;
1.6       raeburn  1531:         }
1.168     raeburn  1532:         my @addlangs;
                   1533:         foreach my $lang (sort(keys(%langchoices))) {
                   1534:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1535:             push(@addlangs,$lang);
                   1536:         }
                   1537:         if (@addlangs > 0) {
                   1538:             my %toadd;
                   1539:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1540:             $toadd{''} = &mt('Select');
                   1541:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1542:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1543:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1544:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1545:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1546:             if ($switchserver) {
                   1547:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1548:             } else {
                   1549:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1550:             }
1.168     raeburn  1551:             $datatable .= '</td></tr>';
1.169     raeburn  1552:             $itemcount ++;
1.6       raeburn  1553:         }
1.169     raeburn  1554:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1555:     } elsif ($caller eq 'headtag') {
                   1556:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1557:         my $choice = $choices{'headtag'};
                   1558:         $css_class = ' class="LC_odd_row"';
                   1559:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1560:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1561:                       '<th>'.$choices{'current'}.'</th>'.
                   1562:                       '<th>'.$choices{'action'}.'</th>'.
                   1563:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1564:         my (%currurls,%currexempt);
                   1565:         if (ref($settings) eq 'HASH') {
                   1566:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1567:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1568:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1569:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1570:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1571:                     }
                   1572:                 }
                   1573:             }
                   1574:         }
                   1575:         foreach my $lonhost (sort(keys(%domservers))) {
                   1576:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1577:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1578:             if ($currurls{$lonhost}) {
                   1579:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1580:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1581:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1582:                               '">'.$lt{'curr'}.'</a></td>'.
                   1583:                               '<td><span class="LC_nobreak"><label>'.
                   1584:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1585:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1586:             } else {
                   1587:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1588:             }
                   1589:             $datatable .='<br />';
                   1590:             if ($switchserver) {
                   1591:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1592:             } else {
                   1593:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1594:             }
1.330     raeburn  1595:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256     raeburn  1596:         }
                   1597:         $datatable .= '</table></td></tr>';
1.386     raeburn  1598:     } elsif ($caller eq 'saml') {
                   1599:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1600:         $datatable .= '<tr><td colspan="3" style="text-align: left">'.
                   1601:                       '<table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1602:                       '<th>'.$choices{'samllanding'}.'</th>'.
                   1603:                       '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
                   1604:         my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
                   1605:         foreach my $lonhost (keys(%domservers)) {
                   1606:             $samlurl{$lonhost} = '/adm/sso';
                   1607:             $styleon{$lonhost} = 'display:none';
                   1608:             $styleoff{$lonhost} = '';
                   1609:         }
                   1610:         if (ref($settings->{'saml'}) eq 'HASH') {
                   1611:             foreach my $lonhost (keys(%{$settings->{'saml'}})) {
                   1612:                 if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
                   1613:                     $saml{$lonhost} = 1;
                   1614:                     $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
                   1615:                     $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
                   1616:                     $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                   1617:                     $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                   1618:                     $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
                   1619:                     $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                   1620:                     $styleon{$lonhost} = '';
                   1621:                     $styleoff{$lonhost} = 'display:none';
                   1622:                 } else {
                   1623:                     $styleon{$lonhost} = 'display:none';
                   1624:                     $styleoff{$lonhost} = '';
                   1625:                 }
                   1626:             }
                   1627:         }
                   1628:         my $itemcount = 1;
                   1629:         foreach my $lonhost (sort(keys(%domservers))) {
                   1630:             my $samlon = ' ';
                   1631:             my $samloff = ' checked="checked" ';
                   1632:             if ($saml{$lonhost}) {
                   1633:                 $samlon = $samloff;
                   1634:                 $samloff = ' ';
                   1635:             }
                   1636:             my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1637:             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
                   1638:                           '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
                   1639:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
                   1640:                           &mt('No').'</label>'.('&nbsp;'x2).
                   1641:                           '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
                   1642:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
                   1643:                           &mt('Yes').'</label></span></td>'.
                   1644:                           '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
                   1645:                           '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
                   1646:                           '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
                   1647:                           '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
                   1648:                           '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
                   1649:                           '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
                   1650:                           '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
                   1651:                           $samltext{$lonhost}.'" /></td><td>';
                   1652:             if ($samlimg{$lonhost}) {
                   1653:                 $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
                   1654:                               '<span class="LC_nobreak"><label>'.
                   1655:                               '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
                   1656:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1657:             } else {
                   1658:                 $datatable .= $lt{'upl'};
                   1659:             }
                   1660:             $datatable .='<br />';
                   1661:             if ($switchserver) {
                   1662:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1663:             } else {
                   1664:                 $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
                   1665:             }
                   1666:             $datatable .= '</td>'.
                   1667:                           '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
                   1668:                           'value="'.$samlalt{$lonhost}.'" /></td>'.
                   1669:                           '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
                   1670:                           'value="'.$samlurl{$lonhost}.'" /></td>'.
                   1671:                           '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
                   1672:                           $samltitle{$lonhost}.'</textarea></td>'.
                   1673:                           '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
                   1674:                           'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                   1675:                           '</table></td>'.
                   1676:                           '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%">&nbsp;</td></tr>';
                   1677:            $itemcount ++;
                   1678:         }
                   1679:         $datatable .= '</table></td></tr>';
1.1       raeburn  1680:     }
1.6       raeburn  1681:     return $datatable;
                   1682: }
                   1683: 
                   1684: sub login_choices {
                   1685:     my %choices =
                   1686:         &Apache::lonlocal::texthash (
1.116     bisitz   1687:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1688:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1689:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1690:             disallowlogin => "Login page requests redirected",
                   1691:             hostid        => "Server",
1.128     raeburn  1692:             server        => "Redirect to:",
                   1693:             serverpath    => "Path",
                   1694:             custompath    => "Custom", 
                   1695:             exempt        => "Exempt IP(s)",
1.110     raeburn  1696:             directlogin   => "No redirect",
                   1697:             newuser       => "Link to create a user account",
                   1698:             img           => "Header",
                   1699:             logo          => "Main Logo",
                   1700:             domlogo       => "Domain Logo",
                   1701:             login         => "Log-in Header", 
                   1702:             textcol       => "Text color",
                   1703:             bgcol         => "Box color",
                   1704:             bgs           => "Background colors",
                   1705:             links         => "Link colors",
                   1706:             font          => "Font color",
                   1707:             pgbg          => "Header",
                   1708:             mainbg        => "Page",
                   1709:             sidebg        => "Login box",
                   1710:             link          => "Link",
                   1711:             alink         => "Active link",
                   1712:             vlink         => "Visited link",
1.256     raeburn  1713:             headtag       => "Custom markup",
                   1714:             action        => "Action",
                   1715:             current       => "Current",
1.386     raeburn  1716:             samllanding   => "Dual login?",
                   1717:             samloptions   => "Options",
1.402   ! raeburn  1718:             alttext       => "Alt text",
1.6       raeburn  1719:         );
                   1720:     return %choices;
                   1721: }
                   1722: 
1.386     raeburn  1723: sub login_file_options {
                   1724:       return &Apache::lonlocal::texthash(
                   1725:                                            del     => 'Delete?',
                   1726:                                            rep     => 'Replace:',
                   1727:                                            upl     => 'Upload:',
                   1728:                                            curr    => 'View contents',
                   1729:                                            default => 'Default',
                   1730:                                            custom  => 'Custom',
                   1731:                                            none    => 'None',
                   1732:       );
                   1733: }
                   1734: 
1.394     raeburn  1735: sub print_ipaccess {
                   1736:     my ($dom,$settings,$rowtotal) = @_;
                   1737:     my $css_class;
                   1738:     my $itemcount = 0;
                   1739:     my $datatable;
                   1740:     my %ordered;
                   1741:     if (ref($settings) eq 'HASH') {
                   1742:         foreach my $item (keys(%{$settings})) {
                   1743:             if (ref($settings->{$item}) eq 'HASH') {
                   1744:                 my $num = $settings->{$item}{'order'};
                   1745:                 if ($num eq '') {
                   1746:                     $num = scalar(keys(%{$settings}));
                   1747:                 }
                   1748:                 $ordered{$num} = $item;
                   1749:             }
                   1750:         }
                   1751:     }
                   1752:     my $maxnum = scalar(keys(%ordered));
                   1753:     if (keys(%ordered)) {
                   1754:         my @items = sort { $a <=> $b } keys(%ordered);
                   1755:         for (my $i=0; $i<@items; $i++) {
                   1756:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1757:             my $item = $ordered{$items[$i]};
                   1758:             my ($name,$ipranges,%commblocks,%courses);
                   1759:             if (ref($settings->{$item}) eq 'HASH') {
                   1760:                 $name = $settings->{$item}->{'name'};
                   1761:                 $ipranges = $settings->{$item}->{'ip'};
                   1762:                 if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
                   1763:                     %commblocks = %{$settings->{$item}->{'commblocks'}};
                   1764:                 }
                   1765:                 if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
                   1766:                     %courses = %{$settings->{$item}->{'courses'}};
                   1767:                 }
                   1768:             }
                   1769:             my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
                   1770:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   1771:                          .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
                   1772:             for (my $k=0; $k<=$maxnum; $k++) {
                   1773:                 my $vpos = $k+1;
                   1774:                 my $selstr;
                   1775:                 if ($k == $i) {
                   1776:                     $selstr = ' selected="selected" ';
                   1777:                 }
                   1778:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1779:             }
                   1780:             $datatable .= '</select>'.('&nbsp;'x2).
                   1781:                 '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
                   1782:                 &mt('Delete?').'</label></span></td>'.
                   1783:                 '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
                   1784:                 &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
                   1785:                 '</td></tr>';
                   1786:             $itemcount ++;
                   1787:         }
                   1788:     }
                   1789:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1790:     my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
                   1791:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   1792:                   '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
                   1793:                   '<select name="ipaccess_pos_add"'.$chgstr.'>';
                   1794:     for (my $k=0; $k<$maxnum+1; $k++) {
                   1795:         my $vpos = $k+1;
                   1796:         my $selstr;
                   1797:         if ($k == $maxnum) {
                   1798:             $selstr = ' selected="selected" ';
                   1799:         }
                   1800:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1801:     }
                   1802:     $datatable .= '</select>&nbsp;'."\n".
                   1803:                   '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   1804:                   '<td colspan="2">'.
                   1805:                   &ipaccess_options('add',$itemcount,$dom).
                   1806:                   '</td>'."\n".
                   1807:                   '</tr>'."\n";
                   1808:     $$rowtotal ++;
                   1809:     return $datatable;
                   1810: }
                   1811: 
                   1812: sub ipaccess_options {
                   1813:     my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
                   1814:     my (%currblocks,%currcourses,$output);
                   1815:     if (ref($blocksref) eq 'HASH') {
                   1816:         %currblocks = %{$blocksref};
                   1817:     }
                   1818:     if (ref($coursesref) eq 'HASH') {
                   1819:         %currcourses = %{$coursesref};
                   1820:     }
                   1821:     $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
                   1822:               '<span class="LC_nobreak">'.&mt('Name').':&nbsp;'.
                   1823:               '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
                   1824:               '</span></fieldset>'.
                   1825:               '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
                   1826:               &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   1827:               &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
                   1828:               '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
                   1829:               $ipranges.'</textarea></fieldset>'.
                   1830:               '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
                   1831:               &blocker_checkboxes($num,$blocksref).'</fieldset>'.
                   1832:               '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
                   1833:               '<table>';
                   1834:     foreach my $cid (sort(keys(%currcourses))) {
                   1835:         my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   1836:         $output .= '<tr><td><span class="LC_nobreak">'.
                   1837:                    '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
                   1838:                    &mt('Delete?').'&nbsp;<span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
                   1839:                    ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
                   1840:     }
                   1841:     $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').':&nbsp;'.
                   1842:                '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
                   1843:                 &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
                   1844:                '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
                   1845:                '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
                   1846:                '</span></td></tr></table>'."\n".
                   1847:                '</fieldset>';
                   1848:     return $output;
                   1849: }
                   1850: 
                   1851: sub blocker_checkboxes {
                   1852:     my ($num,$blocks) = @_;
                   1853:     my ($typeorder,$types) = &commblocktype_text();
                   1854:     my $numinrow = 6;
                   1855:     my $output = '<table>';
                   1856:     for (my $i=0; $i<@{$typeorder}; $i++) {
                   1857:         my $block = $typeorder->[$i];
                   1858:         my $blockstatus;
                   1859:         if (ref($blocks) eq 'HASH') {
                   1860:             if ($blocks->{$block} eq 'on') {
                   1861:                 $blockstatus = 'checked="checked"';
                   1862:             }
                   1863:         }
                   1864:         my $rem = $i%($numinrow);
                   1865:         if ($rem == 0) {
                   1866:             if ($i > 0) {
                   1867:                 $output .= '</tr>';
                   1868:             }
                   1869:             $output .= '<tr>';
                   1870:         }
                   1871:         if ($i == scalar(@{$typeorder})-1) {
                   1872:             my $colsleft = $numinrow-$rem;
                   1873:             if ($colsleft > 1) {
                   1874:                 $output .= '<td colspan="'.$colsleft.'">';
                   1875:             } else {
                   1876:                 $output .= '<td>';
                   1877:             }
                   1878:         } else {
                   1879:             $output .= '<td>';
                   1880:         }
                   1881:         my $item = 'ipaccess_block_'.$num;
                   1882:         if ($blockstatus) {
                   1883:             $blockstatus = ' '.$blockstatus;
                   1884:         }
                   1885:         $output .= '<span class="LC_nobreak"><label>'."\n".
                   1886:                    '<input type="checkbox" name="'.$item.'"'.
                   1887:                    $blockstatus.' value="'.$block.'"'.' />'.
                   1888:                    $types->{$block}.'</label></span>'."\n".
                   1889:                    '<br /></td>';
                   1890:     }
                   1891:     $output .= '</tr></table>';
                   1892:     return $output;
                   1893: }
                   1894: 
                   1895: sub commblocktype_text {
                   1896:     my %types = &Apache::lonlocal::texthash(
                   1897:         'com' => 'Messaging',
                   1898:         'chat' => 'Chat Room',
                   1899:         'boards' => 'Discussion',
                   1900:         'port' => 'Portfolio',
                   1901:         'groups' => 'Groups',
                   1902:         'blogs' => 'Blogs',
                   1903:         'about' => 'User Information',
                   1904:         'printout' => 'Printouts',
                   1905:         'passwd' => 'Change Password',
                   1906:         'grades' => 'Gradebook',
1.397     raeburn  1907:         'search' => 'Course search',
                   1908:         'wishlist' => 'Stored links',
                   1909:         'annotate' => 'Annotations',
1.394     raeburn  1910:     );
1.397     raeburn  1911:     my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394     raeburn  1912:     return ($typeorder,\%types);
                   1913: }
                   1914: 
1.6       raeburn  1915: sub print_rolecolors {
1.30      raeburn  1916:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1917:     my %choices = &color_font_choices();
                   1918:     my @bgs = ('pgbg','tabbg','sidebg');
                   1919:     my @links = ('link','alink','vlink');
                   1920:     my @images = ('img');
                   1921:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1922:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1923:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1924:     my (%is_custom,%designs);
1.200     raeburn  1925:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1926:     if (ref($settings) eq 'HASH') {
                   1927:         if (ref($settings->{$role}) eq 'HASH') {
                   1928:             if ($settings->{$role}->{'img'} ne '') {
                   1929:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1930:                 $is_custom{'img'} = 1;
                   1931:             }
                   1932:             if ($settings->{$role}->{'font'} ne '') {
                   1933:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1934:                 $is_custom{'font'} = 1;
                   1935:             }
1.97      tempelho 1936:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1937:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1938:                 $is_custom{'fontmenu'} = 1;
                   1939:             }
1.6       raeburn  1940:             foreach my $item (@bgs) {
                   1941:                 if ($settings->{$role}->{$item} ne '') {
                   1942:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1943:                     $is_custom{$item} = 1;
                   1944:                 }
                   1945:             }
                   1946:             foreach my $item (@links) {
                   1947:                 if ($settings->{$role}->{$item} ne '') {
                   1948:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1949:                     $is_custom{$item} = 1;
                   1950:                 }
                   1951:             }
                   1952:         }
                   1953:     } else {
                   1954:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1955:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1956:             $is_custom{'img'} = 1;
                   1957:         }
1.97      tempelho 1958:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1959:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1960:             $is_custom{'fontmenu'} = 1; 
                   1961:         }
1.6       raeburn  1962:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1963:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1964:             $is_custom{'font'} = 1;
                   1965:         }
                   1966:         foreach my $item (@bgs) {
                   1967:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1968:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1969:                 $is_custom{$item} = 1;
                   1970:             
                   1971:             }
                   1972:         }
                   1973:         foreach my $item (@links) {
                   1974:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1975:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1976:                 $is_custom{$item} = 1;
                   1977:             }
                   1978:         }
                   1979:     }
                   1980:     my $itemcount = 1;
1.30      raeburn  1981:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1982:     $datatable .= '</tr></table></td></tr>';
                   1983:     return $datatable;
                   1984: }
                   1985: 
1.200     raeburn  1986: sub role_defaults {
                   1987:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1988:     my %defaults;
                   1989:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1990:         return %defaults;
                   1991:     }
                   1992:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1993:     if ($role eq 'login') {
                   1994:         %defaults = (
                   1995:                        font => $defaultdesign{$role.'.font'},
                   1996:                     );
                   1997:         if (ref($logintext) eq 'ARRAY') {
                   1998:             foreach my $item (@{$logintext}) {
                   1999:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   2000:             }
                   2001:         }
                   2002:         foreach my $item (@{$images}) {
                   2003:             $defaults{'showlogo'}{$item} = 1;
                   2004:         }
                   2005:     } else {
                   2006:         %defaults = (
                   2007:                        img => $defaultdesign{$role.'.img'},
                   2008:                        font => $defaultdesign{$role.'.font'},
                   2009:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   2010:                     );
                   2011:     }
                   2012:     foreach my $item (@{$bgs}) {
                   2013:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   2014:     }
                   2015:     foreach my $item (@{$links}) {
                   2016:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   2017:     }
                   2018:     foreach my $item (@{$images}) {
                   2019:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   2020:     }
                   2021:     return %defaults;
                   2022: }
                   2023: 
1.6       raeburn  2024: sub display_color_options {
1.9       raeburn  2025:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   2026:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  2027:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  2028:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  2029:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  2030:         '<td>'.$choices->{'font'}.'</td>';
                   2031:     if (!$is_custom->{'font'}) {
1.329     raeburn  2032:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  2033:     } else {
                   2034:         $datatable .= '<td>&nbsp;</td>';
                   2035:     }
1.174     foxr     2036:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   2037: 
1.8       raeburn  2038:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2039:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  2040:                   ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2041:                   '&nbsp;</span></td></tr>';
1.107     raeburn  2042:     unless ($role eq 'login') { 
                   2043:         $datatable .= '<tr'.$css_class.'>'.
                   2044:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   2045:         if (!$is_custom->{'fontmenu'}) {
1.329     raeburn  2046:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  2047:         } else {
                   2048:             $datatable .= '<td>&nbsp;</td>';
                   2049:         }
1.202     raeburn  2050: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     2051: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  2052:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2053:                       '<input class="colorchooser" type="text" size="10" name="'
                   2054: 		      .$role.'_fontmenu"'.
                   2055:                       ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2056:                       '&nbsp;</span></td></tr>';
1.97      tempelho 2057:     }
1.9       raeburn  2058:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  2059:     foreach my $img (@{$images}) {
1.18      albertel 2060: 	$itemcount ++;
1.6       raeburn  2061:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  2062:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  2063:                       '<td>'.$choices->{$img};
1.402   ! raeburn  2064:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70      raeburn  2065:         if ($role eq 'login') {
                   2066:             if ($img eq 'login') {
                   2067:                 $login_hdr_pick =
1.135     bisitz   2068:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  2069:                 $logincolors =
                   2070:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  2071:                                        $designs,$defaults);
1.402   ! raeburn  2072:             } else {
        !          2073:                 if ($img ne 'domlogo') {
        !          2074:                     $datatable.= &logo_display_options($img,$defaults,$designs);
        !          2075:                 }
        !          2076:                 if (ref($designs->{'alttext'}) eq 'HASH') {
        !          2077:                     $alttext = $designs->{'alttext'}{$img};
        !          2078:                 }
1.70      raeburn  2079:             }
                   2080:         }
                   2081:         $datatable .= '</td>';
1.6       raeburn  2082:         if ($designs->{$img} ne '') {
                   2083:             $imgfile = $designs->{$img};
1.18      albertel 2084: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  2085:         } else {
                   2086:             $imgfile = $defaults->{$img};
                   2087:         }
                   2088:         if ($imgfile) {
1.9       raeburn  2089:             my ($showfile,$fullsize);
                   2090:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  2091:                 my $urldir = $1;
                   2092:                 my $filename = $2;
                   2093:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   2094:                 if (@info) {
                   2095:                     my $thumbfile = 'tn-'.$filename;
                   2096:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   2097:                     if (@thumb) {
                   2098:                         $showfile = $urldir.'/'.$thumbfile;
                   2099:                     } else {
                   2100:                         $showfile = $imgfile;
                   2101:                     }
                   2102:                 } else {
                   2103:                     $showfile = '';
                   2104:                 }
                   2105:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  2106:                 $showfile = $imgfile;
1.6       raeburn  2107:                 my $imgdir = $1;
                   2108:                 my $filename = $2;
1.159     raeburn  2109:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  2110:                     $showfile = "/$imgdir/tn-".$filename;
                   2111:                 } else {
1.159     raeburn  2112:                     my $input = $londocroot.$imgfile;
                   2113:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  2114:                     if (!-e $output) {
1.9       raeburn  2115:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  2116:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   2117:                         if ($fullwidth ne '' && $fullheight ne '') {
                   2118:                             if ($fullwidth > $width && $fullheight > $height) { 
                   2119:                                 my $size = $width.'x'.$height;
1.316     raeburn  2120:                                 my @args = ('convert','-sample',$size,$input,$output);
                   2121:                                 system({$args[0]} @args);
1.159     raeburn  2122:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  2123:                             }
                   2124:                         }
1.6       raeburn  2125:                     }
                   2126:                 }
1.16      raeburn  2127:             }
1.6       raeburn  2128:             if ($showfile) {
1.40      raeburn  2129:                 if ($showfile =~ m{^/(adm|res)/}) {
                   2130:                     if ($showfile =~ m{^/res/}) {
                   2131:                         my $local_showfile =
                   2132:                             &Apache::lonnet::filelocation('',$showfile);
                   2133:                         &Apache::lonnet::repcopy($local_showfile);
                   2134:                     }
                   2135:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   2136:                 }
                   2137:                 if ($imgfile) {
                   2138:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   2139:                         if ($imgfile =~ m{^/res/}) {
                   2140:                             my $local_imgfile =
                   2141:                                 &Apache::lonnet::filelocation('',$imgfile);
                   2142:                             &Apache::lonnet::repcopy($local_imgfile);
                   2143:                         }
                   2144:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   2145:                     } else {
                   2146:                         $fullsize = $imgfile;
                   2147:                     }
                   2148:                 }
1.41      raeburn  2149:                 $datatable .= '<td>';
                   2150:                 if ($img eq 'login') {
1.135     bisitz   2151:                     $datatable .= $login_hdr_pick;
                   2152:                 } 
1.41      raeburn  2153:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   2154:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  2155:             } else {
1.201     raeburn  2156:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2157:                               &mt('Upload:').'<br />';
1.6       raeburn  2158:             }
                   2159:         } else {
1.201     raeburn  2160:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2161:                           &mt('Upload:').'<br />';
1.6       raeburn  2162:         }
1.9       raeburn  2163:         if ($switchserver) {
                   2164:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2165:         } else {
1.135     bisitz   2166:             if ($img ne 'login') { # suppress file selection for Log-in header
                   2167:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   2168:             }
1.9       raeburn  2169:         }
1.402   ! raeburn  2170:         if (($role eq 'login') && ($img ne 'login')) {
        !          2171:             $datatable .= ('&nbsp;' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
        !          2172:                           '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
        !          2173:                           '</label></span>';
        !          2174:         }
1.9       raeburn  2175:         $datatable .= '</td></tr>';
1.6       raeburn  2176:     }
                   2177:     $itemcount ++;
                   2178:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2179:     $datatable .= '<tr'.$css_class.'>'.
                   2180:                   '<td>'.$choices->{'bgs'}.'</td>';
                   2181:     my $bgs_def;
                   2182:     foreach my $item (@{$bgs}) {
                   2183:         if (!$is_custom->{$item}) {
1.329     raeburn  2184:             $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  2185:         }
                   2186:     }
                   2187:     if ($bgs_def) {
1.8       raeburn  2188:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  2189:     } else {
                   2190:         $datatable .= '<td>&nbsp;</td>';
                   2191:     }
                   2192:     $datatable .= '<td class="LC_right_item">'.
                   2193:                   '<table border="0"><tr>';
1.174     foxr     2194: 
1.6       raeburn  2195:     foreach my $item (@{$bgs}) {
1.306     raeburn  2196:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     2197: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  2198:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     2199:             $datatable .= '&nbsp;';
1.6       raeburn  2200:         }
1.174     foxr     2201:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  2202:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  2203:     }
                   2204:     $datatable .= '</tr></table></td></tr>';
                   2205:     $itemcount ++;
                   2206:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2207:     $datatable .= '<tr'.$css_class.'>'.
                   2208:                   '<td>'.$choices->{'links'}.'</td>';
                   2209:     my $links_def;
                   2210:     foreach my $item (@{$links}) {
                   2211:         if (!$is_custom->{$item}) {
1.329     raeburn  2212:             $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  2213:         }
                   2214:     }
                   2215:     if ($links_def) {
1.8       raeburn  2216:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  2217:     } else {
                   2218:         $datatable .= '<td>&nbsp;</td>';
                   2219:     }
                   2220:     $datatable .= '<td class="LC_right_item">'.
                   2221:                   '<table border="0"><tr>';
                   2222:     foreach my $item (@{$links}) {
1.234     raeburn  2223: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  2224:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  2225:         if ($designs->{'links'}{$item}) {
1.174     foxr     2226:             $datatable.='&nbsp;';
1.6       raeburn  2227:         }
1.174     foxr     2228:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  2229:                       '" /></td>';
                   2230:     }
1.30      raeburn  2231:     $$rowtotal += $itemcount;
1.3       raeburn  2232:     return $datatable;
                   2233: }
                   2234: 
1.70      raeburn  2235: sub logo_display_options {
                   2236:     my ($img,$defaults,$designs) = @_;
                   2237:     my $checkedon;
                   2238:     if (ref($defaults) eq 'HASH') {
                   2239:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   2240:             if ($defaults->{'showlogo'}{$img}) {
                   2241:                 $checkedon = 'checked="checked" ';     
                   2242:             }
                   2243:         } 
                   2244:     }
                   2245:     if (ref($designs) eq 'HASH') {
                   2246:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   2247:             if (defined($designs->{'showlogo'}{$img})) {
                   2248:                 if ($designs->{'showlogo'}{$img} == 0) {
                   2249:                     $checkedon = '';
                   2250:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   2251:                     $checkedon = 'checked="checked" ';
                   2252:                 }
                   2253:             }
                   2254:         }
                   2255:     }
                   2256:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   2257:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   2258:            &mt('show').'</label>'."\n";
                   2259: }
                   2260: 
1.41      raeburn  2261: sub login_header_options  {
1.135     bisitz   2262:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   2263:     my $output = '';
1.41      raeburn  2264:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   2265:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  2266:         if (!$is_custom->{'textcol'}) {
                   2267:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   2268:                        '&nbsp;&nbsp;&nbsp;';
                   2269:         }
                   2270:         if (!$is_custom->{'bgcol'}) {
                   2271:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   2272:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   2273:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   2274:         }
                   2275:         $output .= '<br />';
                   2276:     }
                   2277:     $output .='<br />';
                   2278:     return $output;
                   2279: }
                   2280: 
                   2281: sub login_text_colors {
1.201     raeburn  2282:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  2283:     my $color_menu = '<table border="0"><tr>';
                   2284:     foreach my $item (@{$logintext}) {
1.306     raeburn  2285:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  2286:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   2287:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   2288:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  2289:     }
                   2290:     $color_menu .= '</tr></table><br />';
                   2291:     return $color_menu;
                   2292: }
                   2293: 
                   2294: sub image_changes {
                   2295:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   2296:     my $output;
1.135     bisitz   2297:     if ($img eq 'login') {
1.331     raeburn  2298:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   2299:     } elsif (!$is_custom) {
1.70      raeburn  2300:         if ($img ne 'domlogo') {
1.331     raeburn  2301:             $output = &mt('Default image:').'<br />';
1.41      raeburn  2302:         } else {
1.331     raeburn  2303:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  2304:         }
                   2305:     }
1.331     raeburn  2306:     if ($img ne 'login') {
1.135     bisitz   2307:         if ($img_import) {
                   2308:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   2309:         }
                   2310:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   2311:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   2312:         if ($is_custom) {
                   2313:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   2314:                        '<input type="checkbox" name="'.
                   2315:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   2316:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   2317:         } else {
1.306     raeburn  2318:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   2319:         }
1.41      raeburn  2320:     }
                   2321:     return $output;
                   2322: }
                   2323: 
1.3       raeburn  2324: sub print_quotas {
1.86      raeburn  2325:     my ($dom,$settings,$rowtotal,$action) = @_;
                   2326:     my $context;
                   2327:     if ($action eq 'quotas') {
                   2328:         $context = 'tools';
                   2329:     } else {
                   2330:         $context = $action;
                   2331:     }
1.197     raeburn  2332:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  2333:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  2334:     my $typecount = 0;
1.101     raeburn  2335:     my ($css_class,%titles);
1.86      raeburn  2336:     if ($context eq 'requestcourses') {
1.325     raeburn  2337:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  2338:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  2339:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   2340:         %titles = &courserequest_titles();
1.163     raeburn  2341:     } elsif ($context eq 'requestauthor') {
                   2342:         @usertools = ('author');
                   2343:         @options = ('norequest','approval','automatic');
1.210     raeburn  2344:         %titles = &authorrequest_titles();
1.86      raeburn  2345:     } else {
1.162     raeburn  2346:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  2347:         %titles = &tool_titles();
1.86      raeburn  2348:     }
1.26      raeburn  2349:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  2350:         foreach my $type (@{$types}) {
1.197     raeburn  2351:             my ($currdefquota,$currauthorquota);
1.163     raeburn  2352:             unless (($context eq 'requestcourses') ||
                   2353:                     ($context eq 'requestauthor')) {
1.86      raeburn  2354:                 if (ref($settings) eq 'HASH') {
                   2355:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  2356:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  2357:                     } else {
                   2358:                         $currdefquota = $settings->{$type};
                   2359:                     }
1.197     raeburn  2360:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   2361:                         $currauthorquota = $settings->{authorquota}->{$type};
                   2362:                     }
1.78      raeburn  2363:                 }
1.72      raeburn  2364:             }
1.3       raeburn  2365:             if (defined($usertypes->{$type})) {
                   2366:                 $typecount ++;
                   2367:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  2368:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  2369:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  2370:                               '<td class="LC_left_item">';
1.101     raeburn  2371:                 if ($context eq 'requestcourses') {
                   2372:                     $datatable .= '<table><tr>';
                   2373:                 }
                   2374:                 my %cell;  
1.72      raeburn  2375:                 foreach my $item (@usertools) {
1.101     raeburn  2376:                     if ($context eq 'requestcourses') {
                   2377:                         my ($curroption,$currlimit);
                   2378:                         if (ref($settings) eq 'HASH') {
                   2379:                             if (ref($settings->{$item}) eq 'HASH') {
                   2380:                                 $curroption = $settings->{$item}->{$type};
                   2381:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2382:                                     $currlimit = $1; 
                   2383:                                 }
                   2384:                             }
                   2385:                         }
                   2386:                         if (!$curroption) {
                   2387:                             $curroption = 'norequest';
                   2388:                         }
                   2389:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2390:                         foreach my $option (@options) {
                   2391:                             my $val = $option;
                   2392:                             if ($option eq 'norequest') {
                   2393:                                 $val = 0;  
                   2394:                             }
                   2395:                             if ($option eq 'validate') {
                   2396:                                 my $canvalidate = 0;
                   2397:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2398:                                     if ($validations{$item}{$type}) {
                   2399:                                         $canvalidate = 1;
                   2400:                                     }
                   2401:                                 }
                   2402:                                 next if (!$canvalidate);
                   2403:                             }
                   2404:                             my $checked = '';
                   2405:                             if ($option eq $curroption) {
                   2406:                                 $checked = ' checked="checked"';
                   2407:                             } elsif ($option eq 'autolimit') {
                   2408:                                 if ($curroption =~ /^autolimit/) {
                   2409:                                     $checked = ' checked="checked"';
                   2410:                                 }                       
                   2411:                             } 
                   2412:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2413:                                   '<input type="radio" name="crsreq_'.$item.
                   2414:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2415:                                   $titles{$option}.'</label>';
1.101     raeburn  2416:                             if ($option eq 'autolimit') {
1.127     raeburn  2417:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2418:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2419:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2420:                             }
1.127     raeburn  2421:                             $cell{$item} .= '</span> ';
1.103     raeburn  2422:                             if ($option eq 'autolimit') {
1.127     raeburn  2423:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2424:                             }
1.101     raeburn  2425:                         }
1.163     raeburn  2426:                     } elsif ($context eq 'requestauthor') {
                   2427:                         my $curroption;
                   2428:                         if (ref($settings) eq 'HASH') {
                   2429:                             $curroption = $settings->{$type};
                   2430:                         }
                   2431:                         if (!$curroption) {
                   2432:                             $curroption = 'norequest';
                   2433:                         }
                   2434:                         foreach my $option (@options) {
                   2435:                             my $val = $option;
                   2436:                             if ($option eq 'norequest') {
                   2437:                                 $val = 0;
                   2438:                             }
                   2439:                             my $checked = '';
                   2440:                             if ($option eq $curroption) {
                   2441:                                 $checked = ' checked="checked"';
                   2442:                             }
                   2443:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2444:                                   '<input type="radio" name="authorreq_'.$type.
                   2445:                                   '" value="'.$val.'"'.$checked.' />'.
                   2446:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2447:                         }
1.101     raeburn  2448:                     } else {
                   2449:                         my $checked = 'checked="checked" ';
                   2450:                         if (ref($settings) eq 'HASH') {
                   2451:                             if (ref($settings->{$item}) eq 'HASH') {
                   2452:                                 if ($settings->{$item}->{$type} == 0) {
                   2453:                                     $checked = '';
                   2454:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2455:                                     $checked =  'checked="checked" ';
                   2456:                                 }
1.78      raeburn  2457:                             }
1.72      raeburn  2458:                         }
1.101     raeburn  2459:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2460:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2461:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2462:                                       '</label></span>&nbsp; ';
1.72      raeburn  2463:                     }
1.101     raeburn  2464:                 }
                   2465:                 if ($context eq 'requestcourses') {
                   2466:                     $datatable .= '</tr><tr>';
                   2467:                     foreach my $item (@usertools) {
1.106     raeburn  2468:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2469:                     }
                   2470:                     $datatable .= '</tr></table>';
1.72      raeburn  2471:                 }
1.86      raeburn  2472:                 $datatable .= '</td>';
1.163     raeburn  2473:                 unless (($context eq 'requestcourses') ||
                   2474:                         ($context eq 'requestauthor')) {
1.86      raeburn  2475:                     $datatable .= 
1.197     raeburn  2476:                               '<td class="LC_right_item">'.
                   2477:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2478:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2479:                               '" value="'.$currdefquota.
1.197     raeburn  2480:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2481:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2482:                               '<input type="text" name="authorquota_'.$type.
                   2483:                               '" value="'.$currauthorquota.
                   2484:                               '" size="5" /></span></td>';
1.86      raeburn  2485:                 }
                   2486:                 $datatable .= '</tr>';
1.3       raeburn  2487:             }
                   2488:         }
                   2489:     }
1.163     raeburn  2490:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2491:         $defaultquota = '20';
1.197     raeburn  2492:         $authorquota = '500';
1.86      raeburn  2493:         if (ref($settings) eq 'HASH') {
                   2494:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2495:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2496:             } elsif (defined($settings->{'default'})) {
                   2497:                 $defaultquota = $settings->{'default'};
                   2498:             }
1.197     raeburn  2499:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2500:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2501:             }
1.3       raeburn  2502:         }
                   2503:     }
                   2504:     $typecount ++;
                   2505:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2506:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2507:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2508:                   '<td class="LC_left_item">';
1.101     raeburn  2509:     if ($context eq 'requestcourses') {
                   2510:         $datatable .= '<table><tr>';
                   2511:     }
                   2512:     my %defcell;
1.72      raeburn  2513:     foreach my $item (@usertools) {
1.101     raeburn  2514:         if ($context eq 'requestcourses') {
                   2515:             my ($curroption,$currlimit);
                   2516:             if (ref($settings) eq 'HASH') {
                   2517:                 if (ref($settings->{$item}) eq 'HASH') {
                   2518:                     $curroption = $settings->{$item}->{'default'};
                   2519:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2520:                         $currlimit = $1;
                   2521:                     }
                   2522:                 }
                   2523:             }
                   2524:             if (!$curroption) {
                   2525:                 $curroption = 'norequest';
                   2526:             }
                   2527:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2528:             foreach my $option (@options) {
                   2529:                 my $val = $option;
                   2530:                 if ($option eq 'norequest') {
                   2531:                     $val = 0;
                   2532:                 }
                   2533:                 if ($option eq 'validate') {
                   2534:                     my $canvalidate = 0;
                   2535:                     if (ref($validations{$item}) eq 'HASH') {
                   2536:                         if ($validations{$item}{'default'}) {
                   2537:                             $canvalidate = 1;
                   2538:                         }
                   2539:                     }
                   2540:                     next if (!$canvalidate);
                   2541:                 }
                   2542:                 my $checked = '';
                   2543:                 if ($option eq $curroption) {
                   2544:                     $checked = ' checked="checked"';
                   2545:                 } elsif ($option eq 'autolimit') {
                   2546:                     if ($curroption =~ /^autolimit/) {
                   2547:                         $checked = ' checked="checked"';
                   2548:                     }
                   2549:                 }
                   2550:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2551:                                   '<input type="radio" name="crsreq_'.$item.
                   2552:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2553:                                   $titles{$option}.'</label>';
                   2554:                 if ($option eq 'autolimit') {
1.127     raeburn  2555:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2556:                                        $item.'_limit_default" size="1" '.
                   2557:                                        'value="'.$currlimit.'" />';
                   2558:                 }
1.127     raeburn  2559:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2560:                 if ($option eq 'autolimit') {
1.127     raeburn  2561:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2562:                 }
1.101     raeburn  2563:             }
1.163     raeburn  2564:         } elsif ($context eq 'requestauthor') {
                   2565:             my $curroption;
                   2566:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2567:                 $curroption = $settings->{'default'};
1.163     raeburn  2568:             }
                   2569:             if (!$curroption) {
                   2570:                 $curroption = 'norequest';
                   2571:             }
                   2572:             foreach my $option (@options) {
                   2573:                 my $val = $option;
                   2574:                 if ($option eq 'norequest') {
                   2575:                     $val = 0;
                   2576:                 }
                   2577:                 my $checked = '';
                   2578:                 if ($option eq $curroption) {
                   2579:                     $checked = ' checked="checked"';
                   2580:                 }
                   2581:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2582:                               '<input type="radio" name="authorreq_default"'.
                   2583:                               ' value="'.$val.'"'.$checked.' />'.
                   2584:                               $titles{$option}.'</label></span>&nbsp; ';
                   2585:             }
1.101     raeburn  2586:         } else {
                   2587:             my $checked = 'checked="checked" ';
                   2588:             if (ref($settings) eq 'HASH') {
                   2589:                 if (ref($settings->{$item}) eq 'HASH') {
                   2590:                     if ($settings->{$item}->{'default'} == 0) {
                   2591:                         $checked = '';
                   2592:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2593:                         $checked = 'checked="checked" ';
                   2594:                     }
1.78      raeburn  2595:                 }
1.72      raeburn  2596:             }
1.101     raeburn  2597:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2598:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2599:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2600:                           '</label></span>&nbsp; ';
                   2601:         }
                   2602:     }
                   2603:     if ($context eq 'requestcourses') {
                   2604:         $datatable .= '</tr><tr>';
                   2605:         foreach my $item (@usertools) {
1.106     raeburn  2606:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2607:         }
1.101     raeburn  2608:         $datatable .= '</tr></table>';
1.72      raeburn  2609:     }
1.86      raeburn  2610:     $datatable .= '</td>';
1.163     raeburn  2611:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2612:         $datatable .= '<td class="LC_right_item">'.
                   2613:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2614:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2615:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2616:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2617:                       '<input type="text" name="authorquota" value="'.
                   2618:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2619:     }
                   2620:     $datatable .= '</tr>';
1.72      raeburn  2621:     $typecount ++;
                   2622:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2623:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2624:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2625:     if ($context eq 'requestcourses') {
1.109     raeburn  2626:         $datatable .= &mt('(overrides affiliation, if set)').
                   2627:                       '</td>'.
                   2628:                       '<td class="LC_left_item">'.
                   2629:                       '<table><tr>';
1.101     raeburn  2630:     } else {
1.109     raeburn  2631:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2632:                       '</td>'.
                   2633:                       '<td class="LC_left_item" colspan="2">'.
                   2634:                       '<br />';
1.101     raeburn  2635:     }
                   2636:     my %advcell;
1.72      raeburn  2637:     foreach my $item (@usertools) {
1.101     raeburn  2638:         if ($context eq 'requestcourses') {
                   2639:             my ($curroption,$currlimit);
                   2640:             if (ref($settings) eq 'HASH') {
                   2641:                 if (ref($settings->{$item}) eq 'HASH') {
                   2642:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2643:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2644:                         $currlimit = $1;
                   2645:                     }
                   2646:                 }
                   2647:             }
                   2648:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2649:             my $checked = '';
                   2650:             if ($curroption eq '') {
                   2651:                 $checked = ' checked="checked"';
                   2652:             }
                   2653:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2654:                                '<input type="radio" name="crsreq_'.$item.
                   2655:                                '__LC_adv" value=""'.$checked.' />'.
                   2656:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2657:             foreach my $option (@options) {
                   2658:                 my $val = $option;
                   2659:                 if ($option eq 'norequest') {
                   2660:                     $val = 0;
                   2661:                 }
                   2662:                 if ($option eq 'validate') {
                   2663:                     my $canvalidate = 0;
                   2664:                     if (ref($validations{$item}) eq 'HASH') {
                   2665:                         if ($validations{$item}{'_LC_adv'}) {
                   2666:                             $canvalidate = 1;
                   2667:                         }
                   2668:                     }
                   2669:                     next if (!$canvalidate);
                   2670:                 }
                   2671:                 my $checked = '';
1.104     raeburn  2672:                 if ($val eq $curroption) {
1.101     raeburn  2673:                     $checked = ' checked="checked"';
                   2674:                 } elsif ($option eq 'autolimit') {
                   2675:                     if ($curroption =~ /^autolimit/) {
                   2676:                         $checked = ' checked="checked"';
                   2677:                     }
                   2678:                 }
                   2679:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2680:                                   '<input type="radio" name="crsreq_'.$item.
                   2681:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2682:                                   $titles{$option}.'</label>';
                   2683:                 if ($option eq 'autolimit') {
1.127     raeburn  2684:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2685:                                        $item.'_limit__LC_adv" size="1" '.
                   2686:                                        'value="'.$currlimit.'" />';
                   2687:                 }
1.127     raeburn  2688:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2689:                 if ($option eq 'autolimit') {
1.127     raeburn  2690:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2691:                 }
1.101     raeburn  2692:             }
1.163     raeburn  2693:         } elsif ($context eq 'requestauthor') {
                   2694:             my $curroption;
                   2695:             if (ref($settings) eq 'HASH') {
                   2696:                 $curroption = $settings->{'_LC_adv'};
                   2697:             }
                   2698:             my $checked = '';
                   2699:             if ($curroption eq '') {
                   2700:                 $checked = ' checked="checked"';
                   2701:             }
                   2702:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2703:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2704:                           ' value=""'.$checked.' />'.
                   2705:                           &mt('No override set').'</label></span>&nbsp; ';
                   2706:             foreach my $option (@options) {
                   2707:                 my $val = $option;
                   2708:                 if ($option eq 'norequest') {
                   2709:                     $val = 0;
                   2710:                 }
                   2711:                 my $checked = '';
                   2712:                 if ($val eq $curroption) {
                   2713:                     $checked = ' checked="checked"';
                   2714:                 }
                   2715:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2716:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2717:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2718:                               $titles{$option}.'</label></span>&nbsp; ';
                   2719:             }
1.101     raeburn  2720:         } else {
                   2721:             my $checked = 'checked="checked" ';
                   2722:             if (ref($settings) eq 'HASH') {
                   2723:                 if (ref($settings->{$item}) eq 'HASH') {
                   2724:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2725:                         $checked = '';
                   2726:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2727:                         $checked = 'checked="checked" ';
                   2728:                     }
1.79      raeburn  2729:                 }
1.72      raeburn  2730:             }
1.101     raeburn  2731:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2732:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2733:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2734:                           '</label></span>&nbsp; ';
                   2735:         }
                   2736:     }
                   2737:     if ($context eq 'requestcourses') {
                   2738:         $datatable .= '</tr><tr>';
                   2739:         foreach my $item (@usertools) {
1.106     raeburn  2740:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2741:         }
1.101     raeburn  2742:         $datatable .= '</tr></table>';
1.72      raeburn  2743:     }
1.98      raeburn  2744:     $datatable .= '</td></tr>';
1.30      raeburn  2745:     $$rowtotal += $typecount;
1.3       raeburn  2746:     return $datatable;
                   2747: }
                   2748: 
1.163     raeburn  2749: sub print_requestmail {
1.305     raeburn  2750:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2751:     my ($now,$datatable,%currapp);
1.102     raeburn  2752:     $now = time;
                   2753:     if (ref($settings) eq 'HASH') {
                   2754:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2755:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2756:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2757:             }
                   2758:         }
                   2759:     }
1.191     raeburn  2760:     my $numinrow = 2;
1.224     raeburn  2761:     my $css_class;
1.305     raeburn  2762:     if ($$rowtotal%2) {
                   2763:         $css_class = 'LC_odd_row';
                   2764:     }
                   2765:     if ($customcss) {
                   2766:         $css_class .= " $customcss";
                   2767:     }
                   2768:     $css_class =~ s/^\s+//;
                   2769:     if ($css_class) {
                   2770:         $css_class = ' class="'.$css_class.'"';
                   2771:     }
                   2772:     if ($rowstyle) {
                   2773:         $css_class .= ' style="'.$rowstyle.'"';
                   2774:     }
1.163     raeburn  2775:     my $text;
                   2776:     if ($action eq 'requestcourses') {
                   2777:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2778:     } elsif ($action eq 'requestauthor') {
                   2779:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2780:     } else {
1.224     raeburn  2781:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2782:     }
1.224     raeburn  2783:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2784:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2785:                  ' <td class="LC_left_item">';
1.191     raeburn  2786:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2787:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2788:     if ($numdc > 0) {
                   2789:         $datatable .= $table;
1.102     raeburn  2790:     } else {
                   2791:         $datatable .= &mt('There are no active Domain Coordinators');
                   2792:     }
                   2793:     $datatable .='</td></tr>';
                   2794:     return $datatable;
                   2795: }
                   2796: 
1.216     raeburn  2797: sub print_studentcode {
                   2798:     my ($settings,$rowtotal) = @_;
                   2799:     my $rownum = 0; 
1.218     raeburn  2800:     my ($output,%current);
1.325     raeburn  2801:     my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248     raeburn  2802:     if (ref($settings) eq 'HASH') {
                   2803:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2804:             foreach my $type (@crstypes) {
                   2805:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2806:             }
1.218     raeburn  2807:         }
                   2808:     }
                   2809:     $output .= '<tr>'.
                   2810:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2811:                '<td class="LC_left_item">';
                   2812:     foreach my $type (@crstypes) {
                   2813:         my $check = ' ';
                   2814:         if ($current{$type}) {
                   2815:             $check = ' checked="checked" ';
                   2816:         }
                   2817:         $output .= '<span class="LC_nobreak"><label>'.
                   2818:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2819:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2820:     }
                   2821:     $output .= '</td></tr>';
                   2822:     $$rowtotal ++;
                   2823:     return $output;
1.216     raeburn  2824: }
                   2825: 
                   2826: sub print_textbookcourses {
1.242     raeburn  2827:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2828:     my $rownum = 0;
                   2829:     my $css_class;
                   2830:     my $itemcount = 1;
                   2831:     my $maxnum = 0;
                   2832:     my $bookshash;
                   2833:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2834:         $bookshash = $settings->{$type};
1.216     raeburn  2835:     }
                   2836:     my %ordered;
                   2837:     if (ref($bookshash) eq 'HASH') {
                   2838:         foreach my $item (keys(%{$bookshash})) {
                   2839:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2840:                 my $num = $bookshash->{$item}{'order'};
                   2841:                 $ordered{$num} = $item;
                   2842:             }
                   2843:         }
                   2844:     }
                   2845:     my $confname = $dom.'-domainconfig';
                   2846:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2847:     my $maxnum = scalar(keys(%ordered));
                   2848:     my $datatable;
1.216     raeburn  2849:     if (keys(%ordered)) {
                   2850:         my @items = sort { $a <=> $b } keys(%ordered);
                   2851:         for (my $i=0; $i<@items; $i++) {
                   2852:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2853:             my $key = $ordered{$items[$i]};
                   2854:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2855:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2856:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2857:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2858:                 $subject = $bookshash->{$key}->{'subject'};
                   2859:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2860:                 if ($type eq 'textbooks') {
1.243     raeburn  2861:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2862:                     $author = $bookshash->{$key}->{'author'};
                   2863:                     $image = $bookshash->{$key}->{'image'};
                   2864:                     if ($image ne '') {
                   2865:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2866:                         my $imagethumb = "$path/tn-".$imagefile;
                   2867:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2868:                     }
1.216     raeburn  2869:                 }
                   2870:             }
1.242     raeburn  2871:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2872:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2873:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2874:             for (my $k=0; $k<=$maxnum; $k++) {
                   2875:                 my $vpos = $k+1;
                   2876:                 my $selstr;
                   2877:                 if ($k == $i) {
                   2878:                     $selstr = ' selected="selected" ';
                   2879:                 }
                   2880:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2881:             }
                   2882:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2883:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2884:                 &mt('Delete?').'</label></span></td>'.
                   2885:                 '<td colspan="2">'.
1.242     raeburn  2886:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2887:                 ('&nbsp;'x2).
1.242     raeburn  2888:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2889:             if ($type eq 'textbooks') {
                   2890:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2891:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2892:                               ('&nbsp;'x2).
1.242     raeburn  2893:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2894:                               ('&nbsp;'x2).
                   2895:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2896:                 if ($image) {
1.267     raeburn  2897:                     $datatable .= $imgsrc.
1.242     raeburn  2898:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2899:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2900:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2901:                 }
                   2902:                 if ($switchserver) {
                   2903:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2904:                 } else {
                   2905:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2906:                 }
1.216     raeburn  2907:             }
1.242     raeburn  2908:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2909:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2910:                           $coursetitle.'</span></td></tr>'."\n";
                   2911:             $itemcount ++;
                   2912:         }
                   2913:     }
                   2914:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2915:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2916:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2917:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2918:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2919:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2920:         my $vpos = $k+1;
                   2921:         my $selstr;
                   2922:         if ($k == $maxnum) {
                   2923:             $selstr = ' selected="selected" ';
                   2924:         }
                   2925:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2926:     }
                   2927:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  2928:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216     raeburn  2929:                   '<td colspan="2">'.
1.242     raeburn  2930:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2931:                   ('&nbsp;'x2).
1.242     raeburn  2932:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2933:                   ('&nbsp;'x2);
                   2934:     if ($type eq 'textbooks') {
1.243     raeburn  2935:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2936:                       ('&nbsp;'x2).
                   2937:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2938:                       ('&nbsp;'x2).
                   2939:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2940:         if ($switchserver) {
                   2941:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2942:         } else {
                   2943:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2944:         }
1.334     raeburn  2945:         $datatable .= '</span>'."\n";
1.216     raeburn  2946:     }
1.334     raeburn  2947:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2948:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2949:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2950:                   &Apache::loncommon::selectcourse_link
1.334     raeburn  2951:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216     raeburn  2952:                   '</span></td>'."\n".
                   2953:                   '</tr>'."\n";
                   2954:     $itemcount ++;
                   2955:     return $datatable;
                   2956: }
                   2957: 
1.217     raeburn  2958: sub textbookcourses_javascript {
1.242     raeburn  2959:     my ($settings) = @_;
                   2960:     return unless(ref($settings) eq 'HASH');
                   2961:     my (%ordered,%total,%jstext);
                   2962:     foreach my $type ('textbooks','templates') {
                   2963:         $total{$type} = 0;
                   2964:         if (ref($settings->{$type}) eq 'HASH') {
                   2965:             foreach my $item (keys(%{$settings->{$type}})) {
                   2966:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2967:                     my $num = $settings->{$type}->{$item}{'order'};
                   2968:                     $ordered{$type}{$num} = $item;
                   2969:                 }
                   2970:             }
                   2971:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2972:         }
                   2973:         my @jsarray = ();
                   2974:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2975:             push(@jsarray,$ordered{$type}{$item});
                   2976:         }
                   2977:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2978:     }
                   2979:     return <<"ENDSCRIPT";
                   2980: <script type="text/javascript">
                   2981: // <![CDATA[
1.242     raeburn  2982: function reorderBooks(form,item,caller) {
1.217     raeburn  2983:     var changedVal;
1.242     raeburn  2984: $jstext{'textbooks'};
                   2985: $jstext{'templates'};
                   2986:     var newpos;
                   2987:     var maxh;
                   2988:     if (caller == 'textbooks') {  
                   2989:         newpos = 'textbooks_addbook_pos';
                   2990:         maxh = 1 + $total{'textbooks'};
                   2991:     } else {
                   2992:         newpos = 'templates_addbook_pos';
                   2993:         maxh = 1 + $total{'templates'};
                   2994:     }
1.217     raeburn  2995:     var current = new Array;
                   2996:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2997:     if (item == newpos) {
                   2998:         changedVal = newitemVal;
                   2999:     } else {
                   3000:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3001:         current[newitemVal] = newpos;
                   3002:     }
1.242     raeburn  3003:     if (caller == 'textbooks') {
                   3004:         for (var i=0; i<textbooks.length; i++) {
                   3005:             var elementName = 'textbooks_'+textbooks[i];
                   3006:             if (elementName != item) {
                   3007:                 if (form.elements[elementName]) {
                   3008:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3009:                     current[currVal] = elementName;
                   3010:                 }
                   3011:             }
                   3012:         }
                   3013:     }
                   3014:     if (caller == 'templates') {
                   3015:         for (var i=0; i<templates.length; i++) {
                   3016:             var elementName = 'templates_'+templates[i];
                   3017:             if (elementName != item) {
                   3018:                 if (form.elements[elementName]) {
                   3019:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3020:                     current[currVal] = elementName;
                   3021:                 }
1.217     raeburn  3022:             }
                   3023:         }
                   3024:     }
                   3025:     var oldVal;
                   3026:     for (var j=0; j<maxh; j++) {
                   3027:         if (current[j] == undefined) {
                   3028:             oldVal = j;
                   3029:         }
                   3030:     }
                   3031:     if (oldVal < changedVal) {
                   3032:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3033:            var elementName = current[k];
                   3034:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3035:         }
                   3036:     } else {
                   3037:         for (var k=changedVal; k<oldVal; k++) {
                   3038:             var elementName = current[k];
                   3039:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3040:         }
                   3041:     }
                   3042:     return;
                   3043: }
                   3044: 
                   3045: // ]]>
                   3046: </script>
                   3047: 
                   3048: ENDSCRIPT
                   3049: }
                   3050: 
1.267     raeburn  3051: sub ltitools_javascript {
                   3052:     my ($settings) = @_;
1.319     raeburn  3053:     my $togglejs = &ltitools_toggle_js();
                   3054:     unless (ref($settings) eq 'HASH') {
                   3055:         return $togglejs;
                   3056:     }
1.267     raeburn  3057:     my (%ordered,$total,%jstext);
                   3058:     $total = 0;
                   3059:     foreach my $item (keys(%{$settings})) {
                   3060:         if (ref($settings->{$item}) eq 'HASH') {
                   3061:             my $num = $settings->{$item}{'order'};
                   3062:             $ordered{$num} = $item;
                   3063:         }
                   3064:     }
                   3065:     $total = scalar(keys(%{$settings}));
                   3066:     my @jsarray = ();
                   3067:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3068:         push(@jsarray,$ordered{$item});
                   3069:     }
                   3070:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3071:     return <<"ENDSCRIPT";
                   3072: <script type="text/javascript">
                   3073: // <![CDATA[
1.319     raeburn  3074: function reorderLTITools(form,item) {
1.267     raeburn  3075:     var changedVal;
                   3076: $jstext
                   3077:     var newpos = 'ltitools_add_pos';
                   3078:     var maxh = 1 + $total;
                   3079:     var current = new Array;
                   3080:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3081:     if (item == newpos) {
                   3082:         changedVal = newitemVal;
                   3083:     } else {
                   3084:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3085:         current[newitemVal] = newpos;
                   3086:     }
                   3087:     for (var i=0; i<ltitools.length; i++) {
                   3088:         var elementName = 'ltitools_'+ltitools[i];
                   3089:         if (elementName != item) {
                   3090:             if (form.elements[elementName]) {
                   3091:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3092:                 current[currVal] = elementName;
                   3093:             }
                   3094:         }
                   3095:     }
                   3096:     var oldVal;
                   3097:     for (var j=0; j<maxh; j++) {
                   3098:         if (current[j] == undefined) {
                   3099:             oldVal = j;
                   3100:         }
                   3101:     }
                   3102:     if (oldVal < changedVal) {
                   3103:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3104:            var elementName = current[k];
                   3105:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3106:         }
                   3107:     } else {
                   3108:         for (var k=changedVal; k<oldVal; k++) {
                   3109:             var elementName = current[k];
                   3110:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3111:         }
                   3112:     }
                   3113:     return;
                   3114: }
                   3115: 
                   3116: // ]]>
                   3117: </script>
                   3118: 
1.319     raeburn  3119: $togglejs
                   3120: 
                   3121: ENDSCRIPT
                   3122: }
                   3123: 
                   3124: sub ltitools_toggle_js {
                   3125:     return <<"ENDSCRIPT";
                   3126: <script type="text/javascript">
                   3127: // <![CDATA[
                   3128: 
                   3129: function toggleLTITools(form,setting,item) {
                   3130:     var radioname = '';
                   3131:     var divid = '';
                   3132:     if ((setting == 'passback') || (setting == 'roster')) {
                   3133:         radioname = 'ltitools_'+setting+'_'+item;
                   3134:         divid = 'ltitools_'+setting+'time_'+item;
                   3135:         var num = form.elements[radioname].length;
                   3136:         if (num) {
                   3137:             var setvis = '';
                   3138:             for (var i=0; i<num; i++) {
                   3139:                 if (form.elements[radioname][i].checked) {
                   3140:                     if (form.elements[radioname][i].value == '1') {
                   3141:                         if (document.getElementById(divid)) {
                   3142:                             document.getElementById(divid).style.display = 'inline-block';
                   3143:                         }
                   3144:                         setvis = 1;
                   3145:                     }
                   3146:                     break;
                   3147:                 }
                   3148:             }
                   3149:         }
                   3150:         if (!setvis) {
                   3151:             if (document.getElementById(divid)) {
                   3152:                 document.getElementById(divid).style.display = 'none';
                   3153:             }
                   3154:         }
                   3155:     }
1.324     raeburn  3156:     if (setting == 'user') {
                   3157:         divid = 'ltitools_'+setting+'_div_'+item;
                   3158:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   3159:         if (document.getElementById(divid)) {
                   3160:             if (document.getElementById(checkid)) {
                   3161:                 if (document.getElementById(checkid).checked) {
                   3162:                     document.getElementById(divid).style.display = 'inline-block';
                   3163:                 } else {
                   3164:                     document.getElementById(divid).style.display = 'none';
                   3165:                 }
                   3166:             }
                   3167:         }
                   3168:     }
1.319     raeburn  3169:     return;
                   3170: }
                   3171: // ]]>
                   3172: </script>
                   3173: 
1.267     raeburn  3174: ENDSCRIPT
                   3175: }
                   3176: 
1.381     raeburn  3177: sub wafproxy_javascript {
                   3178:     my ($dom) = @_;
                   3179:     return <<"ENDSCRIPT";
                   3180: <script type="text/javascript">
                   3181: // <![CDATA[
                   3182: function updateWAF() {
                   3183:     if (document.getElementById('wafproxy_remoteip')) {
                   3184:         var wafremote = 0;
                   3185:         if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
                   3186:             wafremote = 1;
                   3187:         }
                   3188:         var fields = new Array('header','trust');
                   3189:         for (var i=0; i<fields.length; i++) {
                   3190:             if (document.getElementById('wafproxy_'+fields[i])) {
                   3191:                 if (wafremote == 1) {
                   3192:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
                   3193:                 }
                   3194:                 else {
                   3195:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
                   3196:                 }
                   3197:             }
                   3198:         }
                   3199:         if (document.getElementById('wafproxyranges_$dom')) {
                   3200:             if (wafremote == 1) {
                   3201:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3202:             } else {
                   3203:                 for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3204:                     if (document.display.wafproxy_vpnaccess[i].checked) {
                   3205:                         if (document.display.wafproxy_vpnaccess[i].value == 0) {
                   3206:                             document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3207:                         }
                   3208:                     }
                   3209:                 }
                   3210:             }
                   3211:         }
                   3212:     }
                   3213:     return;
                   3214: }
                   3215: 
                   3216: function checkWAF() {
                   3217:     if (document.getElementById('wafproxy_remoteip')) {
                   3218:         var wafvpn = 0;
                   3219:         for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3220:             if (document.display.wafproxy_vpnaccess[i].checked) {
                   3221:                 if (document.display.wafproxy_vpnaccess[i].value == 1) {
                   3222:                     wafvpn = 1;
                   3223:                 }
                   3224:                 break;
                   3225:             }
                   3226:         }
                   3227:         var vpn = new Array('vpnint','vpnext');
                   3228:         for (var i=0; i<vpn.length; i++) {
                   3229:             if (document.getElementById('wafproxy_show_'+vpn[i])) {
                   3230:                 if (wafvpn == 1) {
                   3231:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
                   3232:                 }
                   3233:                 else {
                   3234:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
                   3235:                 }
                   3236:             }
                   3237:         }
                   3238:         if (document.getElementById('wafproxyranges_$dom')) {
                   3239:             if (wafvpn == 1) {
                   3240:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3241:             }
                   3242:             else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
                   3243:                 document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3244:             }
                   3245:         }
                   3246:     }
                   3247:     return;
                   3248: }
                   3249: 
                   3250: function toggleWAF() {
                   3251:     if (document.getElementById('wafproxy_table')) {
                   3252:         var wafproxy = 0;
                   3253:         for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
                   3254:              if (document.display.wafproxy_${dom}[i].checked) {
                   3255:                  if (document.display.wafproxy_${dom}[i].value == 1) {
                   3256:                      wafproxy = 1;
                   3257:                      break;
                   3258:                 }
                   3259:             }
                   3260:         }
                   3261:         if (wafproxy == 1) {
                   3262:             document.getElementById('wafproxy_table').style.display='inline';
                   3263:         }
                   3264:         else {
                   3265:            document.getElementById('wafproxy_table').style.display='none';
                   3266:         }
                   3267:         if (document.getElementById('wafproxyrow_${dom}')) {
                   3268:             if (wafproxy == 1) {
                   3269:                 document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
                   3270:             }
                   3271:             else {
                   3272:                 document.getElementById('wafproxyrow_${dom}').style.display = 'none';
                   3273:             }
                   3274:         }
                   3275:         if (document.getElementById('nowafproxyrow_$dom')) {
                   3276:             if (wafproxy == 1) {
                   3277:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
                   3278:             }
                   3279:             else {
                   3280:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
                   3281:             }
                   3282:         }
                   3283:     }
                   3284:     return;
                   3285: }
                   3286: // ]]>
                   3287: </script>
                   3288: 
                   3289: ENDSCRIPT
                   3290: }
                   3291: 
1.372     raeburn  3292: sub proctoring_javascript {
                   3293:     my ($settings) = @_;
                   3294:     my (%ordered,$total,%jstext);
                   3295:     $total = 0;
                   3296:     if (ref($settings) eq 'HASH') {
                   3297:         foreach my $item (keys(%{$settings})) {
                   3298:             if (ref($settings->{$item}) eq 'HASH') {
                   3299:                 my $num = $settings->{$item}{'order'};
                   3300:                 $ordered{$num} = $item;
                   3301:             }
                   3302:         }
                   3303:         $total = scalar(keys(%{$settings}));
                   3304:     } else {
                   3305:         %ordered = (
                   3306:                        0 => 'proctorio',
                   3307:                        1 => 'examity',
                   3308:                    );
                   3309:         $total = 2; 
                   3310:     }
                   3311:     my @jsarray = ();
                   3312:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3313:         push(@jsarray,$ordered{$item});
                   3314:     }
                   3315:     my $jstext = '    var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3316:     return <<"ENDSCRIPT";
                   3317: <script type="text/javascript">
                   3318: // <![CDATA[
                   3319: function reorderProctoring(form,item) {
                   3320:     var changedVal;
                   3321: $jstext
                   3322:     var maxh = $total;
                   3323:     var current = new Array;
                   3324:     var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3325:     for (var i=0; i<proctors.length; i++) {
                   3326:         var elementName = 'proctoring_pos_'+proctors[i];
                   3327:         if (elementName != item) {
                   3328:             if (form.elements[elementName]) {
                   3329:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3330:                 current[currVal] = elementName;
                   3331:             }
                   3332:         }
                   3333:     }
                   3334:     var oldVal;
                   3335:     for (var j=0; j<maxh; j++) {
                   3336:         if (current[j] == undefined) {
                   3337:             oldVal = j;
                   3338:         }
                   3339:     }
                   3340:     if (oldVal < changedVal) {
                   3341:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3342:            var elementName = current[k];
                   3343:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3344:         }
                   3345:     } else {
                   3346:         for (var k=changedVal; k<oldVal; k++) {
                   3347:             var elementName = current[k];
                   3348:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3349:         }
                   3350:     }
                   3351:     return;
                   3352: }
                   3353: 
                   3354: function toggleProctoring(form,item) {
                   3355:     var fieldsets = document.getElementsByClassName('proctoring_'+item);
                   3356:     if (fieldsets.length) {
                   3357:         var radioname = 'proctoring_available_'+item;
                   3358:         var num = form.elements[radioname].length;
                   3359:         if (num) {
                   3360:             var setvis = '';
                   3361:             for (var i=0; i<num; i++) {
                   3362:                 if (form.elements[radioname][i].checked) {
                   3363:                     if (form.elements[radioname][i].value == '1') {
                   3364:                        setvis = 1;
                   3365:                        break;
                   3366:                     }
                   3367:                 }
                   3368:             }
                   3369:             for (var j=0; j<fieldsets.length; j++) {
                   3370:                 if (setvis) {
                   3371:                     fieldsets[j].style.display = 'block';
                   3372:                 } else {
                   3373:                     fieldsets[j].style.display = 'none';
                   3374:                 }
                   3375:             }
                   3376:         }
                   3377:     }
                   3378:     return;
                   3379: }
                   3380: 
                   3381: // ]]>
                   3382: </script>
                   3383: 
                   3384: ENDSCRIPT
                   3385: }
                   3386: 
                   3387: 
1.320     raeburn  3388: sub lti_javascript {
                   3389:     my ($settings) = @_;
                   3390:     my $togglejs = &lti_toggle_js();
                   3391:     unless (ref($settings) eq 'HASH') {
                   3392:         return $togglejs;
                   3393:     }
                   3394:     my (%ordered,$total,%jstext);
1.390     raeburn  3395:     $total = scalar(keys(%{$settings}));
1.320     raeburn  3396:     foreach my $item (keys(%{$settings})) {
                   3397:         if (ref($settings->{$item}) eq 'HASH') {
                   3398:             my $num = $settings->{$item}{'order'};
1.390     raeburn  3399:             if ($num eq '') {
                   3400:                 $num = $total - 1;
                   3401:             }
1.320     raeburn  3402:             $ordered{$num} = $item;
                   3403:         }
                   3404:     }
                   3405:     my @jsarray = ();
                   3406:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3407:         push(@jsarray,$ordered{$item});
                   3408:     }
                   3409:     my $jstext = '    var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3410:     return <<"ENDSCRIPT";
                   3411: <script type="text/javascript">
                   3412: // <![CDATA[
                   3413: function reorderLTI(form,item) {
                   3414:     var changedVal;
                   3415: $jstext
                   3416:     var newpos = 'lti_pos_add';
                   3417:     var maxh = 1 + $total;
                   3418:     var current = new Array;
                   3419:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3420:     if (item == newpos) {
                   3421:         changedVal = newitemVal;
                   3422:     } else {
                   3423:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3424:         current[newitemVal] = newpos;
                   3425:     }
                   3426:     for (var i=0; i<lti.length; i++) {
                   3427:         var elementName = 'lti_pos_'+lti[i];
                   3428:         if (elementName != item) {
                   3429:             if (form.elements[elementName]) {
                   3430:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3431:                 current[currVal] = elementName;
                   3432:             }
                   3433:         }
                   3434:     }
                   3435:     var oldVal;
                   3436:     for (var j=0; j<maxh; j++) {
                   3437:         if (current[j] == undefined) {
                   3438:             oldVal = j;
                   3439:         }
                   3440:     }
                   3441:     if (oldVal < changedVal) {
                   3442:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3443:            var elementName = current[k];
                   3444:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3445:         }
                   3446:     } else {
                   3447:         for (var k=changedVal; k<oldVal; k++) {
                   3448:             var elementName = current[k];
                   3449:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3450:         }
                   3451:     }
                   3452:     return;
                   3453: }
                   3454: // ]]>
                   3455: </script>
                   3456: 
                   3457: $togglejs
                   3458: 
                   3459: ENDSCRIPT
                   3460: }
                   3461: 
                   3462: sub lti_toggle_js {
1.325     raeburn  3463:     my %lcauthparmtext = &Apache::lonlocal::texthash (
                   3464:                             localauth => 'Local auth argument',
                   3465:                             krb       => 'Kerberos domain',
                   3466:                          );
1.391     raeburn  3467:     my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
                   3468:     &js_escape(\$crsincalert);
1.320     raeburn  3469:     return <<"ENDSCRIPT";
                   3470: <script type="text/javascript">
                   3471: // <![CDATA[
                   3472: 
                   3473: function toggleLTI(form,setting,item) {
1.391     raeburn  3474:     if ((setting == 'requser') || (setting == 'crsinc')) {
                   3475:         var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
                   3476:         var setvis = '';
                   3477:         var radioname = 'lti_requser_'+item;
                   3478:         var num = form.elements[radioname].length;
                   3479:         if (num) {
                   3480:             for (var i=0; i<num; i++) {
                   3481:                 if (form.elements[radioname][i].checked) {
                   3482:                     if (form.elements[radioname][i].value == '1') {
                   3483:                         setvis = 1;
                   3484:                         break;
                   3485:                     }
                   3486:                 }
                   3487:             }
                   3488:         }
                   3489:         if (usrfieldsets.length) {
                   3490:             for (var j=0; j<usrfieldsets.length; j++) {
                   3491:                 if (setvis) {
                   3492:                     usrfieldsets[j].style.display = 'block';
                   3493:                 } else {
                   3494:                     usrfieldsets[j].style.display = 'none';
                   3495:                 }
                   3496:             }
                   3497:         }
                   3498:         var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
                   3499:         if (crsfieldsets.length) {
                   3500:             radioname = 'lti_crsinc_'+item;
1.345     raeburn  3501:             var num = form.elements[radioname].length;
                   3502:             if (num) {
1.391     raeburn  3503:                 var crsvis = '';
1.345     raeburn  3504:                 for (var i=0; i<num; i++) {
                   3505:                     if (form.elements[radioname][i].checked) {
                   3506:                         if (form.elements[radioname][i].value == '1') {
1.391     raeburn  3507:                             if (setvis == '') {
                   3508:                                 if (setting == 'crsinc'){
                   3509:                                     alert("$crsincalert");
                   3510:                                     form.elements[radioname][0].checked = true;
                   3511:                                 }
                   3512:                             } else {
                   3513:                                 crsvis = 1;
                   3514:                             }
                   3515:                             break;
1.345     raeburn  3516:                         }
                   3517:                     }
                   3518:                 }
1.391     raeburn  3519:                 setvis = crsvis;
                   3520:             }
                   3521:             for (var j=0; j<crsfieldsets.length; j++) {
                   3522:                 if (setvis) {
                   3523:                     crsfieldsets[j].style.display = 'block';
                   3524:                 } else {
                   3525:                     crsfieldsets[j].style.display = 'none';
1.345     raeburn  3526:                 }
                   3527:             }
                   3528:         }
1.363     raeburn  3529:     } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320     raeburn  3530:         var radioname = '';
                   3531:         var divid = '';
                   3532:         if (setting == 'user') {
                   3533:             radioname = 'lti_mapuser_'+item;
                   3534:             divid = 'lti_userfield_'+item;
1.343     raeburn  3535:         } else if (setting == 'crs') {
1.320     raeburn  3536:             radioname = 'lti_mapcrs_'+item;
                   3537:             divid = 'lti_crsfield_'+item;
1.363     raeburn  3538:         } else if (setting == 'callback') {
                   3539:             radioname = 'lti_callback_'+item;
                   3540:             divid = 'lti_callbackfield_'+item;
1.337     raeburn  3541:         } else {
1.351     raeburn  3542:             radioname = 'lti_passback_'+item;
1.337     raeburn  3543:             divid =  'lti_passback_'+item;
1.320     raeburn  3544:         }
                   3545:         var num = form.elements[radioname].length;
                   3546:         if (num) {
                   3547:             var setvis = '';
                   3548:             for (var i=0; i<num; i++) {
                   3549:                if (form.elements[radioname][i].checked) {
1.363     raeburn  3550:                    if ((setting == 'passback') || (setting == 'callback')) {
1.337     raeburn  3551:                        if (form.elements[radioname][i].value == '1') {
                   3552:                            if (document.getElementById(divid)) {
                   3553:                                document.getElementById(divid).style.display = 'inline-block';
                   3554:                            }
                   3555:                            setvis = 1;
                   3556:                            break;
                   3557:                        }
                   3558:                    } else {
                   3559:                        if (form.elements[radioname][i].value == 'other') {
                   3560:                            if (document.getElementById(divid)) {
                   3561:                                document.getElementById(divid).style.display = 'inline-block';
                   3562:                            }
                   3563:                            setvis = 1;
                   3564:                            break;
1.320     raeburn  3565:                        }
                   3566:                    }
                   3567:                } 
                   3568:             }
                   3569:             if (!setvis) {
                   3570:                 if (document.getElementById(divid)) {
                   3571:                     document.getElementById(divid).style.display = 'none';
                   3572:                 }
                   3573:             }
                   3574:         }
                   3575:     } else if ((setting == 'sec') || (setting == 'secsrc')) {
                   3576:         var numsec = form.elements['lti_crssec_'+item].length;
                   3577:         if (numsec) {
                   3578:             var setvis = '';
                   3579:             for (var i=0; i<numsec; i++) {
                   3580:                 if (form.elements['lti_crssec_'+item][i].checked) {
                   3581:                     if (form.elements['lti_crssec_'+item][i].value == '1') {
                   3582:                         if (document.getElementById('lti_crssecfield_'+item)) {
                   3583:                             document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
                   3584:                             setvis = 1;
                   3585:                             var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
                   3586:                             if (numsrcsec) {
                   3587:                                 var setsrcvis = '';
                   3588:                                 for (var j=0; j<numsrcsec; j++) {
                   3589:                                     if (form.elements['lti_crssecsrc_'+item][j].checked) {
                   3590:                                         if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
                   3591:                                             if (document.getElementById('lti_secsrcfield_'+item)) {
                   3592:                                                 document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
                   3593:                                                 setsrcvis = 1;
                   3594:                                             }
                   3595:                                         }
                   3596:                                     }
                   3597:                                 }
                   3598:                                 if (!setsrcvis) {
                   3599:                                     if (document.getElementById('lti_secsrcfield_'+item)) {
                   3600:                                         document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3601:                                     }
                   3602:                                 }
                   3603:                             }
                   3604:                         }
                   3605:                     }
                   3606:                 }
                   3607:             }
                   3608:             if (!setvis) {
                   3609:                 if (document.getElementById('lti_crssecfield_'+item)) {
                   3610:                     document.getElementById('lti_crssecfield_'+item).style.display = 'none';
                   3611:                 }
                   3612:                 if (document.getElementById('lti_secsrcfield_'+item)) {
                   3613:                     document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3614:                 }
                   3615:             }
                   3616:         }
1.325     raeburn  3617:     } else if (setting == 'lcauth') {
                   3618:         var numauth = form.elements['lti_lcauth_'+item].length;
                   3619:         if (numauth) {
                   3620:             for (var i=0; i<numauth; i++) {
                   3621:                 if (form.elements['lti_lcauth_'+item][i].checked) {
                   3622:                     if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                   3623:                         if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                   3624:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                   3625:                         } else {
                   3626:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                   3627:                             if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                   3628:                                 if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                   3629:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                   3630:                                 } else {
                   3631:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                   3632:                                 }
                   3633:                             }
                   3634:                         }
                   3635:                     }
                   3636:                 }
                   3637:             }
                   3638:         }
1.326     raeburn  3639:     } else if (setting == 'lcmenu') {
                   3640:         var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
                   3641:         var divid = 'lti_menufield_'+item;
                   3642:         var setvis = '';
                   3643:         for (var i=0; i<menus.length; i++) {
                   3644:             var radioname = menus[i];  
                   3645:             var num = form.elements[radioname].length;
                   3646:             if (num) {
                   3647:                 for (var j=0; j<num; j++) {
                   3648:                     if (form.elements[radioname][j].checked) {
                   3649:                         if (form.elements[radioname][j].value == '1') {
                   3650:                             if (document.getElementById(divid)) {
                   3651:                                 document.getElementById(divid).style.display = 'inline-block';
                   3652:                             }
                   3653:                             setvis = 1;
                   3654:                             break;
                   3655:                         }
                   3656:                     }
                   3657:                 }
                   3658:             }
                   3659:             if (setvis == 1) {
                   3660:                 break;
                   3661:             }
                   3662:         }
                   3663:         if (!setvis) {
                   3664:             if (document.getElementById(divid)) {
                   3665:                 document.getElementById(divid).style.display = 'none';
                   3666:             }
                   3667:         }
1.320     raeburn  3668:     }
                   3669:     return;
                   3670: }
                   3671: // ]]>
                   3672: </script>
                   3673: 
                   3674: ENDSCRIPT
                   3675: }
                   3676: 
1.385     raeburn  3677: sub autoupdate_javascript {
                   3678:     return <<"ENDSCRIPT";
                   3679: <script type="text/javascript">
                   3680: // <![CDATA[
                   3681: function toggleLastActiveDays(form) {
                   3682:     var radioname = 'lastactive';
                   3683:     var divid = 'lastactive_div';
                   3684:     var num = form.elements[radioname].length;
                   3685:     if (num) {
                   3686:         var setvis = '';
                   3687:         for (var i=0; i<num; i++) {
                   3688:             if (form.elements[radioname][i].checked) {
                   3689:                 if (form.elements[radioname][i].value == '1') {
                   3690:                     if (document.getElementById(divid)) {
                   3691:                         document.getElementById(divid).style.display = 'inline-block';
                   3692:                     }
                   3693:                     setvis = 1;
                   3694:                 }
                   3695:                 break;
                   3696:             }
                   3697:         }
                   3698:         if (!setvis) {
                   3699:             if (document.getElementById(divid)) {
                   3700:                 document.getElementById(divid).style.display = 'none';
                   3701:             }
                   3702:         }
                   3703:     }
                   3704:     return;
                   3705: }
                   3706: // ]]>
                   3707: </script>
                   3708: 
                   3709: ENDSCRIPT
                   3710: }
                   3711: 
1.399     raeburn  3712: sub autoenroll_javascript {
                   3713:     return <<"ENDSCRIPT";
                   3714: <script type="text/javascript">
                   3715: // <![CDATA[
                   3716: function toggleFailsafe(form) {
                   3717:     var radioname = 'autoenroll_failsafe';
                   3718:     var divid = 'autoenroll_failsafe_div';
                   3719:     var num = form.elements[radioname].length;
                   3720:     if (num) {
                   3721:         var setvis = '';
                   3722:         for (var i=0; i<num; i++) {
                   3723:             if (form.elements[radioname][i].checked) {
                   3724:                 if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
                   3725:                     if (document.getElementById(divid)) {
                   3726:                         document.getElementById(divid).style.display = 'inline-block';
                   3727:                     }
                   3728:                     setvis = 1;
                   3729:                 }
                   3730:                 break;
                   3731:             }
                   3732:         }
                   3733:         if (!setvis) {
                   3734:             if (document.getElementById(divid)) {
                   3735:                 document.getElementById(divid).style.display = 'none';
                   3736:             }
                   3737:         }
                   3738:     }
                   3739:     return;
                   3740: }
                   3741: // ]]>
                   3742: </script>
                   3743: 
                   3744: ENDSCRIPT
                   3745: }
                   3746: 
1.386     raeburn  3747: sub saml_javascript {
                   3748:     return <<"ENDSCRIPT";
                   3749: <script type="text/javascript">
                   3750: // <![CDATA[
                   3751: function toggleSamlOptions(form,hostid) { 
                   3752:     var radioname = 'saml_'+hostid;
                   3753:     var tablecellon = 'samloptionson_'+hostid;
                   3754:     var tablecelloff = 'samloptionsoff_'+hostid;
                   3755:     var num = form.elements[radioname].length;
                   3756:     if (num) {
                   3757:         var setvis = ''; 
                   3758:         for (var i=0; i<num; i++) {
                   3759:             if (form.elements[radioname][i].checked) {
                   3760:                 if (form.elements[radioname][i].value == '1') { 
                   3761:                     if (document.getElementById(tablecellon)) {
                   3762:                         document.getElementById(tablecellon).style.display='';
                   3763:                     }
                   3764:                     if (document.getElementById(tablecelloff)) {
                   3765:                         document.getElementById(tablecelloff).style.display='none';
                   3766:                     }
                   3767:                     setvis = 1;
                   3768:                 }
                   3769:                 break;
                   3770:             }
                   3771:         }
                   3772:         if (!setvis) {
                   3773:             if (document.getElementById(tablecellon)) {
                   3774:                 document.getElementById(tablecellon).style.display='none';
                   3775:             }
                   3776:             if (document.getElementById(tablecelloff)) {
                   3777:                 document.getElementById(tablecelloff).style.display='';
                   3778:             }
                   3779:         }
                   3780:     }
                   3781:     return;
                   3782: }
                   3783: // ]]>
                   3784: </script>
                   3785: 
                   3786: ENDSCRIPT
                   3787: }
                   3788: 
1.394     raeburn  3789: sub ipaccess_javascript {
                   3790:     my ($settings) = @_;
                   3791:     my (%ordered,$total,%jstext);
                   3792:     $total = 0;
                   3793:     if (ref($settings) eq 'HASH') {
                   3794:         foreach my $item (keys(%{$settings})) {
                   3795:             if (ref($settings->{$item}) eq 'HASH') {
                   3796:                 my $num = $settings->{$item}{'order'};
                   3797:                 $ordered{$num} = $item;
                   3798:             }
                   3799:         }
                   3800:         $total = scalar(keys(%{$settings}));
                   3801:     }
                   3802:     my @jsarray = ();
                   3803:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3804:         push(@jsarray,$ordered{$item});
                   3805:     }
                   3806:     my $jstext = '    var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3807:     return <<"ENDSCRIPT";
                   3808: <script type="text/javascript">
                   3809: // <![CDATA[
                   3810: function reorderIPaccess(form,item) {
                   3811:     var changedVal;
                   3812: $jstext
                   3813:     var newpos = 'ipaccess_pos_add';
                   3814:     var maxh = 1 + $total;
                   3815:     var current = new Array;
                   3816:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3817:     if (item == newpos) {
                   3818:         changedVal = newitemVal;
                   3819:     } else {
                   3820:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3821:         current[newitemVal] = newpos;
                   3822:     }
                   3823:     for (var i=0; i<ipaccess.length; i++) {
                   3824:         var elementName = 'ipaccess_pos_'+ipaccess[i];
                   3825:         if (elementName != item) {
                   3826:             if (form.elements[elementName]) {
                   3827:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3828:                 current[currVal] = elementName;
                   3829:             }
                   3830:         }
                   3831:     }
                   3832:     var oldVal;
                   3833:     for (var j=0; j<maxh; j++) {
                   3834:         if (current[j] == undefined) {
                   3835:             oldVal = j;
                   3836:         }
                   3837:     }
                   3838:     if (oldVal < changedVal) {
                   3839:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3840:            var elementName = current[k];
                   3841:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3842:         }
                   3843:     } else {
                   3844:         for (var k=changedVal; k<oldVal; k++) {
                   3845:             var elementName = current[k];
                   3846:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3847:         }
                   3848:     }
                   3849:     return;
                   3850: }
                   3851: // ]]>
                   3852: </script>
                   3853: 
                   3854: ENDSCRIPT
                   3855: }
                   3856: 
1.3       raeburn  3857: sub print_autoenroll {
1.30      raeburn  3858:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  3859:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399     raeburn  3860:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
                   3861:         $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
                   3862:     $failsafesty = 'none';
                   3863:     %failsafechecked = (
                   3864:         off => ' checked="checked"',
                   3865:     );
1.3       raeburn  3866:     if (ref($settings) eq 'HASH') {
                   3867:         if (exists($settings->{'run'})) {
                   3868:             if ($settings->{'run'} eq '0') {
                   3869:                 $runoff = ' checked="checked" ';
                   3870:                 $runon = ' ';
                   3871:             } else {
                   3872:                 $runon = ' checked="checked" ';
                   3873:                 $runoff = ' ';
                   3874:             }
                   3875:         } else {
                   3876:             if ($autorun) {
                   3877:                 $runon = ' checked="checked" ';
                   3878:                 $runoff = ' ';
                   3879:             } else {
                   3880:                 $runoff = ' checked="checked" ';
                   3881:                 $runon = ' ';
                   3882:             }
                   3883:         }
1.129     raeburn  3884:         if (exists($settings->{'co-owners'})) {
                   3885:             if ($settings->{'co-owners'} eq '0') {
                   3886:                 $coownersoff = ' checked="checked" ';
                   3887:                 $coownerson = ' ';
                   3888:             } else {
                   3889:                 $coownerson = ' checked="checked" ';
                   3890:                 $coownersoff = ' ';
                   3891:             }
                   3892:         } else {
                   3893:             $coownersoff = ' checked="checked" ';
                   3894:             $coownerson = ' ';
                   3895:         }
1.3       raeburn  3896:         if (exists($settings->{'sender_domain'})) {
                   3897:             $defdom = $settings->{'sender_domain'};
                   3898:         }
1.399     raeburn  3899:         if (exists($settings->{'failsafe'})) {
                   3900:             $failsafe = $settings->{'failsafe'};
                   3901:             if ($failsafe eq 'zero') {
1.400     raeburn  3902:                 $failsafechecked{'zero'} = ' checked="checked"';
1.399     raeburn  3903:                 $failsafechecked{'off'} = '';
                   3904:                 $failsafesty = 'inline-block';
                   3905:             } elsif ($failsafe eq 'any') {
                   3906:                 $failsafechecked{'any'} = ' checked="checked"';
                   3907:                 $failsafechecked{'off'} = '';
                   3908:             }
                   3909:             $autofailsafe = $settings->{'autofailsafe'};
                   3910:         } elsif (exists($settings->{'autofailsafe'})) {
                   3911:             $autofailsafe = $settings->{'autofailsafe'};
                   3912:             if ($autofailsafe ne '') {
                   3913:                 $failsafechecked{'zero'} = ' checked="checked"';
                   3914:                 $failsafe = 'zero';
1.400     raeburn  3915:                 $failsafechecked{'off'} = '';
1.399     raeburn  3916:             }
1.274     raeburn  3917:         }
1.14      raeburn  3918:     } else {
                   3919:         if ($autorun) {
                   3920:             $runon = ' checked="checked" ';
                   3921:             $runoff = ' ';
                   3922:         } else {
                   3923:             $runoff = ' checked="checked" ';
                   3924:             $runon = ' ';
                   3925:         }
1.3       raeburn  3926:     }
                   3927:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  3928:     my $notif_sender;
                   3929:     if (ref($settings) eq 'HASH') {
                   3930:         $notif_sender = $settings->{'sender_uname'};
                   3931:     }
1.3       raeburn  3932:     my $datatable='<tr class="LC_odd_row">'.
                   3933:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  3934:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3935:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  3936:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3937:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  3938:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3939:                   '</tr><tr>'.
                   3940:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  3941:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  3942:                   &mt('username').':&nbsp;'.
                   3943:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  3944:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  3945:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   3946:                   '<tr class="LC_odd_row">'.
                   3947:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   3948:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3949:                   '<input type="radio" name="autoassign_coowners"'.
                   3950:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3951:                   '<label><input type="radio" name="autoassign_coowners"'.
                   3952:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  3953:                   '</tr><tr>'.
                   3954:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400     raeburn  3955:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3956:                   '<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; '.
                   3957:                   '<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 />'.
                   3958:                   '<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  3959:                   '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
                   3960:                   '<span class="LC_nobreak">'.
                   3961:                   &mt('Threshold for number of students in section to drop: [_1]',
                   3962:                       '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
                   3963:                   '</span></div></td></tr>';
1.274     raeburn  3964:     $$rowtotal += 4;
1.3       raeburn  3965:     return $datatable;
                   3966: }
                   3967: 
                   3968: sub print_autoupdate {
1.30      raeburn  3969:     my ($position,$dom,$settings,$rowtotal) = @_;
1.385     raeburn  3970:     my ($enable,$datatable);
1.3       raeburn  3971:     if ($position eq 'top') {
1.385     raeburn  3972:         my %choices = &Apache::lonlocal::texthash (
                   3973:                           run        => 'Auto-update active?',
                   3974:                           classlists => 'Update information in classlists?',
                   3975:                           unexpired  => 'Skip updates for users without active or future roles?',
                   3976:                           lastactive => 'Skip updates for inactive users?',
                   3977:         );
                   3978:         my $itemcount = 0;
1.3       raeburn  3979:         my $updateon = ' ';
                   3980:         my $updateoff = ' checked="checked" ';
                   3981:         if (ref($settings) eq 'HASH') {
                   3982:             if ($settings->{'run'} eq '1') {
                   3983:                 $updateon = $updateoff;
                   3984:                 $updateoff = ' ';
                   3985:             }
                   3986:         }
1.385     raeburn  3987:         $enable = '<tr class="LC_odd_row">'.
                   3988:                   '<td>'.$choices{'run'}.'</td>'.
                   3989:                   '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3990:                   '<input type="radio" name="autoupdate_run"'.
1.397     raeburn  3991:                   $updateoff.'value="0" />'.&mt('No').'</label>&nbsp;'.
1.8       raeburn  3992:                   '<label><input type="radio" name="autoupdate_run"'.
1.385     raeburn  3993:                   $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3       raeburn  3994:                   '</tr>';
1.385     raeburn  3995:         my @toggles = ('classlists','unexpired');
                   3996:         my %defaultchecked = ('classlists' => 'off',
                   3997:                               'unexpired'  => 'off'
                   3998:                               );
                   3999:         $$rowtotal ++;
                   4000:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4001:                                                      \%choices,$itemcount,'','','left','no');
                   4002:         $datatable = $enable.$datatable;
                   4003:         $$rowtotal += $itemcount;
                   4004:         my $lastactiveon = ' ';
                   4005:         my $lastactiveoff = ' checked="checked" ';
                   4006:         my $lastactivestyle = 'none';
                   4007:         my $lastactivedays;
                   4008:         my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
                   4009:         if (ref($settings) eq 'HASH') {
                   4010:             if ($settings->{'lastactive'} =~ /^\d+$/) {
                   4011:                 $lastactiveon = $lastactiveoff;
                   4012:                 $lastactiveoff = ' ';
                   4013:                 $lastactivestyle = 'inline-block';
                   4014:                 $lastactivedays = $settings->{'lastactive'};
                   4015:             }
                   4016:         }
                   4017:         my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4018:         $datatable .= '<tr'.$css_class.'>'.
                   4019:                       '<td>'.$choices{'lastactive'}.'</td>'.
                   4020:                       '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                   4021:                       '<input type="radio" name="lastactive"'.
                   4022:                       $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   4023:                       '&nbsp;<label>'.
                   4024:                       '<input type="radio" name="lastactive"'.
                   4025:                       $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
                   4026:                       '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
                   4027:                       ':&nbsp;'.&mt('inactive = no activity in last [_1] days',
                   4028:                           '<input type="text" size="5" name="lastactivedays" value="'.
                   4029:                           $lastactivedays.'" />').
                   4030:                       '</span></td>'.
                   4031:                       '</tr>';
                   4032:         $$rowtotal ++;
1.131     raeburn  4033:     } elsif ($position eq 'middle') {
                   4034:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4035:         my $numinrow = 3;
                   4036:         my $locknamesettings;
                   4037:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   4038:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  4039:                                     'lockablenames',$rowtotal);
1.131     raeburn  4040:         $$rowtotal ++;
1.3       raeburn  4041:     } else {
1.44      raeburn  4042:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  4043:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  4044:                       'permanentemail','id');
1.33      raeburn  4045:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  4046:         my $numrows = 0;
1.26      raeburn  4047:         if (ref($types) eq 'ARRAY') {
                   4048:             if (@{$types} > 0) {
                   4049:                 $datatable = 
                   4050:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   4051:                                          \@fields,$types,\$numrows);
1.30      raeburn  4052:                     $$rowtotal += @{$types}; 
1.26      raeburn  4053:             }
1.3       raeburn  4054:         }
                   4055:         $datatable .= 
                   4056:             &usertype_update_row($settings,{'default' => $othertitle},
                   4057:                                  \%fieldtitles,\@fields,['default'],
                   4058:                                  \$numrows);
1.30      raeburn  4059:         $$rowtotal ++;     
1.3       raeburn  4060:     }
                   4061:     return $datatable;
                   4062: }
                   4063: 
1.125     raeburn  4064: sub print_autocreate {
                   4065:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  4066:     my (%createon,%createoff,%currhash);
1.125     raeburn  4067:     my @types = ('xml','req');
                   4068:     if (ref($settings) eq 'HASH') {
                   4069:         foreach my $item (@types) {
                   4070:             $createoff{$item} = ' checked="checked" ';
                   4071:             $createon{$item} = ' ';
                   4072:             if (exists($settings->{$item})) {
                   4073:                 if ($settings->{$item}) {
                   4074:                     $createon{$item} = ' checked="checked" ';
                   4075:                     $createoff{$item} = ' ';
                   4076:                 }
                   4077:             }
                   4078:         }
1.210     raeburn  4079:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  4080:             $currhash{$settings->{'xmldc'}} = 1;
                   4081:         }
1.125     raeburn  4082:     } else {
                   4083:         foreach my $item (@types) {
                   4084:             $createoff{$item} = ' checked="checked" ';
                   4085:             $createon{$item} = ' ';
                   4086:         }
                   4087:     }
                   4088:     $$rowtotal += 2;
1.191     raeburn  4089:     my $numinrow = 2;
1.125     raeburn  4090:     my $datatable='<tr class="LC_odd_row">'.
                   4091:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   4092:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4093:                   '<input type="radio" name="autocreate_xml"'.
                   4094:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4095:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  4096:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   4097:                   '</td></tr><tr>'.
                   4098:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   4099:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4100:                   '<input type="radio" name="autocreate_req"'.
                   4101:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4102:                   '<label><input type="radio" name="autocreate_req"'.
                   4103:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  4104:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4105:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  4106:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  4107:     if ($numdc > 1) {
1.247     raeburn  4108:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   4109:                       '</td><td class="LC_left_item">';
1.125     raeburn  4110:     } else {
1.247     raeburn  4111:         $datatable .= &mt('Course creation processed as:').
                   4112:                       '</td><td class="LC_right_item">';
1.125     raeburn  4113:     }
1.247     raeburn  4114:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  4115:     $$rowtotal += $rows;
1.125     raeburn  4116:     return $datatable;
                   4117: }
                   4118: 
1.23      raeburn  4119: sub print_directorysrch {
1.277     raeburn  4120:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4121:     my $datatable;
                   4122:     if ($position eq 'top') {
                   4123:         my $instsrchon = ' ';
                   4124:         my $instsrchoff = ' checked="checked" ';
                   4125:         my ($exacton,$containson,$beginson);
                   4126:         my $instlocalon = ' ';
                   4127:         my $instlocaloff = ' checked="checked" ';
                   4128:         if (ref($settings) eq 'HASH') {
                   4129:             if ($settings->{'available'} eq '1') {
                   4130:                 $instsrchon = $instsrchoff;
                   4131:                 $instsrchoff = ' ';
                   4132:             }
                   4133:             if ($settings->{'localonly'} eq '1') {
                   4134:                 $instlocalon = $instlocaloff;
                   4135:                 $instlocaloff = ' ';
                   4136:             }
                   4137:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   4138:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   4139:                     if ($type eq 'exact') {
                   4140:                         $exacton = ' checked="checked" ';
                   4141:                     } elsif ($type eq 'contains') {
                   4142:                         $containson = ' checked="checked" ';
                   4143:                     } elsif ($type eq 'begins') {
                   4144:                         $beginson = ' checked="checked" ';
                   4145:                     }
                   4146:                 }
                   4147:             } else {
                   4148:                 if ($settings->{'searchtypes'} eq 'exact') {
                   4149:                     $exacton = ' checked="checked" ';
                   4150:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   4151:                     $containson = ' checked="checked" ';
                   4152:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  4153:                     $exacton = ' checked="checked" ';
                   4154:                     $containson = ' checked="checked" ';
                   4155:                 }
                   4156:             }
1.277     raeburn  4157:         }
                   4158:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   4159:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4160: 
                   4161:         my $numinrow = 4;
                   4162:         my $cansrchrow = 0;
                   4163:         $datatable='<tr class="LC_odd_row">'.
                   4164:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   4165:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4166:                    '<input type="radio" name="dirsrch_available"'.
                   4167:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4168:                    '<label><input type="radio" name="dirsrch_available"'.
                   4169:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4170:                    '</tr><tr>'.
                   4171:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   4172:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4173:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   4174:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4175:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   4176:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4177:                    '</tr>';
                   4178:         $$rowtotal += 2;
                   4179:         if (ref($usertypes) eq 'HASH') {
                   4180:             if (keys(%{$usertypes}) > 0) {
                   4181:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  4182:                                              $numinrow,$othertitle,'cansearch',
                   4183:                                              $rowtotal);
1.277     raeburn  4184:                 $cansrchrow = 1;
1.25      raeburn  4185:             }
1.23      raeburn  4186:         }
1.277     raeburn  4187:         if ($cansrchrow) {
                   4188:             $$rowtotal ++;
                   4189:             $datatable .= '<tr>';
                   4190:         } else {
                   4191:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  4192:         }
1.277     raeburn  4193:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   4194:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   4195:         foreach my $title (@{$titleorder}) {
                   4196:             if (defined($searchtitles->{$title})) {
                   4197:                 my $check = ' ';
                   4198:                 if (ref($settings) eq 'HASH') {
                   4199:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   4200:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   4201:                             $check = ' checked="checked" ';
                   4202:                         }
1.39      raeburn  4203:                     }
1.25      raeburn  4204:                 }
1.277     raeburn  4205:                 $datatable .= '<td class="LC_left_item">'.
                   4206:                               '<span class="LC_nobreak"><label>'.
                   4207:                               '<input type="checkbox" name="searchby" '.
                   4208:                               'value="'.$title.'"'.$check.'/>'.
                   4209:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  4210:             }
                   4211:         }
1.277     raeburn  4212:         $datatable .= '</tr></table></td></tr>';
                   4213:         $$rowtotal ++;
                   4214:         if ($cansrchrow) {
                   4215:             $datatable .= '<tr class="LC_odd_row">';
                   4216:         } else {
                   4217:             $datatable .= '<tr>';
                   4218:         }
                   4219:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   4220:                       '<td class="LC_left_item" colspan="2">'.
                   4221:                       '<span class="LC_nobreak"><label>'.
                   4222:                       '<input type="checkbox" name="searchtypes" '.
                   4223:                       $exacton.' value="exact" />'.&mt('Exact match').
                   4224:                       '</label>&nbsp;'.
                   4225:                       '<label><input type="checkbox" name="searchtypes" '.
                   4226:                       $beginson.' value="begins" />'.&mt('Begins with').
                   4227:                       '</label>&nbsp;'.
                   4228:                       '<label><input type="checkbox" name="searchtypes" '.
                   4229:                       $containson.' value="contains" />'.&mt('Contains').
                   4230:                       '</label></span></td></tr>';
                   4231:         $$rowtotal ++;
1.26      raeburn  4232:     } else {
1.277     raeburn  4233:         my $domsrchon = ' checked="checked" ';
                   4234:         my $domsrchoff = ' ';
                   4235:         my $domlocalon = ' ';
                   4236:         my $domlocaloff = ' checked="checked" ';
                   4237:         if (ref($settings) eq 'HASH') {
                   4238:             if ($settings->{'lclocalonly'} eq '1') {
                   4239:                 $domlocalon = $domlocaloff;
                   4240:                 $domlocaloff = ' ';
                   4241:             }
                   4242:             if ($settings->{'lcavailable'} eq '0') {
                   4243:                 $domsrchoff = $domsrchon;
                   4244:                 $domsrchon = ' ';
                   4245:             }
                   4246:         }
                   4247:         $datatable='<tr class="LC_odd_row">'.
                   4248:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   4249:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4250:                       '<input type="radio" name="dirsrch_domavailable"'.
                   4251:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4252:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   4253:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4254:                       '</tr><tr>'.
                   4255:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   4256:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4257:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   4258:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4259:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   4260:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4261:                       '</tr>';
                   4262:         $$rowtotal += 2;
1.26      raeburn  4263:     }
1.25      raeburn  4264:     return $datatable;
                   4265: }
                   4266: 
1.28      raeburn  4267: sub print_contacts {
1.286     raeburn  4268:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  4269:     my $datatable;
                   4270:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  4271:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340     raeburn  4272:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286     raeburn  4273:     if ($position eq 'top') {
                   4274:         if (ref($settings) eq 'HASH') {
                   4275:             foreach my $item (@contacts) {
                   4276:                 if (exists($settings->{$item})) {
                   4277:                     $to{$item} = $settings->{$item};
                   4278:                 }
                   4279:             }
                   4280:         }
                   4281:     } elsif ($position eq 'middle') {
                   4282:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350     raeburn  4283:                      'updatesmail','idconflictsmail','hostipmail');
1.288     raeburn  4284:         foreach my $type (@mailings) {
                   4285:             $otheremails{$type} = '';
                   4286:         }
1.340     raeburn  4287:     } elsif ($position eq 'lower') {
                   4288:         if (ref($settings) eq 'HASH') {
                   4289:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   4290:                 %lonstatus = %{$settings->{'lonstatus'}};
                   4291:             }
                   4292:         }
1.286     raeburn  4293:     } else {
                   4294:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  4295:         foreach my $type (@mailings) {
                   4296:             $otheremails{$type} = '';
                   4297:         }
1.286     raeburn  4298:         $bccemails{'helpdeskmail'} = '';
                   4299:         $bccemails{'otherdomsmail'} = '';
                   4300:         $includestr{'helpdeskmail'} = '';
                   4301:         $includestr{'otherdomsmail'} = '';
                   4302:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   4303:     }
1.28      raeburn  4304:     if (ref($settings) eq 'HASH') {
1.340     raeburn  4305:         unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4306:             foreach my $type (@mailings) {
                   4307:                 if (exists($settings->{$type})) {
                   4308:                     if (ref($settings->{$type}) eq 'HASH') {
                   4309:                         foreach my $item (@contacts) {
                   4310:                             if ($settings->{$type}{$item}) {
                   4311:                                 $checked{$type}{$item} = ' checked="checked" ';
                   4312:                             }
                   4313:                         }
                   4314:                         $otheremails{$type} = $settings->{$type}{'others'};
                   4315:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4316:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   4317:                             if ($settings->{$type}{'include'} ne '') {
                   4318:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4319:                                 $includestr{$type} = &unescape($includestr{$type});
                   4320:                             }
                   4321:                         }
                   4322:                     }
                   4323:                 } elsif ($type eq 'lonstatusmail') {
                   4324:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   4325:                 }
1.28      raeburn  4326:             }
                   4327:         }
1.286     raeburn  4328:         if ($position eq 'bottom') {
                   4329:             foreach my $type (@mailings) {
                   4330:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   4331:                 if ($settings->{$type}{'include'} ne '') {
                   4332:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4333:                     $includestr{$type} = &unescape($includestr{$type});
                   4334:                 }
                   4335:             }
                   4336:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   4337:                 if (ref($fields) eq 'ARRAY') {
                   4338:                     foreach my $field (@{$fields}) {
                   4339:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  4340:                     }
1.286     raeburn  4341:                 }
                   4342:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   4343:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   4344:                 } else {
1.289     raeburn  4345:                     $maxsize = '1.0';
1.286     raeburn  4346:                 }
                   4347:             } else {
                   4348:                 if (ref($fields) eq 'ARRAY') {
                   4349:                     foreach my $field (@{$fields}) {
                   4350:                         $currfield{$field} = 'yes';
1.134     raeburn  4351:                     }
1.28      raeburn  4352:                 }
1.286     raeburn  4353:                 $maxsize = '1.0';
1.28      raeburn  4354:             }
                   4355:         }
                   4356:     } else {
1.286     raeburn  4357:         if ($position eq 'top') {
                   4358:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   4359:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   4360:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   4361:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  4362:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4363:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   4364:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   4365:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350     raeburn  4366:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4367:         } elsif ($position eq 'bottom') {
                   4368:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   4369:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   4370:             if (ref($fields) eq 'ARRAY') {
                   4371:                 foreach my $field (@{$fields}) {
                   4372:                     $currfield{$field} = 'yes';
                   4373:                 }
                   4374:             }
                   4375:             $maxsize = '1.0';
                   4376:         }
1.28      raeburn  4377:     }
                   4378:     my ($titles,$short_titles) = &contact_titles();
                   4379:     my $rownum = 0;
                   4380:     my $css_class;
1.286     raeburn  4381:     if ($position eq 'top') {
                   4382:         foreach my $item (@contacts) {
                   4383:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4384:             $datatable .= '<tr'.$css_class.'>'. 
                   4385:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   4386:                           '</span></td><td class="LC_right_item">'.
                   4387:                           '<input type="text" name="'.$item.'" value="'.
                   4388:                           $to{$item}.'" /></td></tr>';
                   4389:             $rownum ++;
                   4390:         }
1.315     raeburn  4391:     } elsif ($position eq 'bottom') {
                   4392:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4393:         $datatable .= '<tr'.$css_class.'>'.
                   4394:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   4395:                       &mt('(e-mail, subject, and description always shown)').
                   4396:                       '</td><td class="LC_left_item">';
                   4397:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   4398:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   4399:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   4400:             foreach my $field (@{$fields}) {
                   4401:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   4402:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   4403:                     $datatable .= ' '.&mt('(logged-in users)');
                   4404:                 }
                   4405:                 $datatable .='</td><td>';
                   4406:                 my $clickaction;
                   4407:                 if ($field eq 'screenshot') {
                   4408:                     $clickaction = ' onclick="screenshotSize(this);"';
                   4409:                 }
                   4410:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   4411:                     foreach my $option (@{$possoptions->{$field}}) {
                   4412:                         my $checked;
                   4413:                         if ($currfield{$field} eq $option) {
                   4414:                             $checked = ' checked="checked"';
                   4415:                         }
                   4416:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   4417:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   4418:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   4419:                                       '</label></span>'.('&nbsp;'x2);
                   4420:                     }
                   4421:                 }
                   4422:                 if ($field eq 'screenshot') {
                   4423:                     my $display;
                   4424:                     if ($currfield{$field} eq 'no') {
                   4425:                         $display = ' style="display:none"';
                   4426:                     }
1.334     raeburn  4427:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315     raeburn  4428:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   4429:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   4430:                 }
                   4431:                 $datatable .= '</td></tr>';
                   4432:             }
                   4433:             $datatable .= '</table>';
                   4434:         }
                   4435:         $datatable .= '</td></tr>'."\n";
                   4436:         $rownum ++;
                   4437:     }
1.340     raeburn  4438:     unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4439:         foreach my $type (@mailings) {
                   4440:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4441:             $datatable .= '<tr'.$css_class.'>'.
                   4442:                           '<td><span class="LC_nobreak">'.
                   4443:                           $titles->{$type}.': </span></td>'.
                   4444:                           '<td class="LC_left_item">';
                   4445:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4446:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   4447:             }
                   4448:             $datatable .= '<span class="LC_nobreak">';
                   4449:             foreach my $item (@contacts) {
                   4450:                 $datatable .= '<label>'.
                   4451:                               '<input type="checkbox" name="'.$type.'"'.
                   4452:                               $checked{$type}{$item}.
                   4453:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   4454:                               '</label>&nbsp;';
                   4455:             }
                   4456:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4457:                           '<input type="text" name="'.$type.'_others" '.
                   4458:                           'value="'.$otheremails{$type}.'"  />';
                   4459:             my %locchecked;
                   4460:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4461:                 foreach my $loc ('s','b') {
                   4462:                     if ($includeloc{$type} eq $loc) {
                   4463:                         $locchecked{$loc} = ' checked="checked"';
                   4464:                         last;
                   4465:                     }
                   4466:                 }
                   4467:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4468:                               '<input type="text" name="'.$type.'_bcc" '.
                   4469:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   4470:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4471:                               &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4472:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286     raeburn  4473:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4474:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4475:                               ('&nbsp;'x2).
                   4476:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4477:                               '</span></fieldset>';
                   4478:             }
                   4479:             $datatable .= '</td></tr>'."\n";
                   4480:             $rownum ++;
                   4481:         }
1.28      raeburn  4482:     }
1.286     raeburn  4483:     if ($position eq 'middle') {
                   4484:         my %choices;
1.340     raeburn  4485:         my $corelink = &core_link_msu();
                   4486:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286     raeburn  4487:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340     raeburn  4488:                                         $corelink);
                   4489:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   4490:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286     raeburn  4491:         my %defaultchecked = ('reporterrors'  => 'on',
1.340     raeburn  4492:                               'reportupdates' => 'on',
                   4493:                               'reportstatus'  => 'on');
1.286     raeburn  4494:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4495:                                                    \%choices,$rownum);
                   4496:         $datatable .= $reports;
1.340     raeburn  4497:     } elsif ($position eq 'lower') {
1.378     raeburn  4498:         my (%current,%excluded,%weights);
1.340     raeburn  4499:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   4500:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378     raeburn  4501:             $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340     raeburn  4502:         } else {
1.378     raeburn  4503:             $current{'errorthreshold'} = $defaults->{'threshold'};
1.340     raeburn  4504:         }
                   4505:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378     raeburn  4506:             $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340     raeburn  4507:         } else {
1.378     raeburn  4508:             $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340     raeburn  4509:         }
                   4510:         if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341     raeburn  4511:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4512:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   4513:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   4514:                 } else {
                   4515:                     $weights{$type} = $defaults->{$type};
                   4516:                 }
                   4517:             }
                   4518:         } else {
1.341     raeburn  4519:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4520:                 $weights{$type} = $defaults->{$type};
                   4521:             }
                   4522:         }
                   4523:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   4524:             if (@{$lonstatus{'excluded'}} > 0) {
                   4525:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   4526:             }
                   4527:         }
1.378     raeburn  4528:         foreach my $item ('errorthreshold','errorsysmail') { 
                   4529:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4530:             $datatable .= '<tr'.$css_class.'>'.
                   4531:                           '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4532:                           $titles->{$item}.
                   4533:                           '</span></td><td class="LC_left_item">'.
                   4534:                           '<input type="text" name="'.$item.'" value="'.
                   4535:                           $current{$item}.'" size="5" /></td></tr>';
                   4536:             $rownum ++;
                   4537:         }
1.340     raeburn  4538:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4539:         $datatable .= '<tr'.$css_class.'>'.
                   4540:                       '<td class="LC_left_item">'.
                   4541:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   4542:                       '</span></td><td class="LC_left_item"><table><tr>';
1.341     raeburn  4543:         foreach my $type ('E','W','N','U') {
1.340     raeburn  4544:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   4545:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   4546:                           $weights{$type}.'" size="5" /></td>';
                   4547:         }
                   4548:         $datatable .= '</tr></table></tr>';
                   4549:         $rownum ++;
                   4550:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4551:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   4552:                       $titles->{'errorexcluded'}.'</td>'.
                   4553:                       '<td class="LC_left_item"><table>';
                   4554:         my $numinrow = 4;
                   4555:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   4556:         for (my $i=0; $i<@ids; $i++) {
                   4557:             my $rem = $i%($numinrow);
                   4558:             if ($rem == 0) {
                   4559:                 if ($i > 0) {
                   4560:                     $datatable .= '</tr>';
                   4561:                 }
                   4562:                 $datatable .= '<tr>';
                   4563:             }
                   4564:             my $check;
                   4565:             if ($excluded{$ids[$i]}) {
                   4566:                 $check = ' checked="checked" ';
                   4567:             }
                   4568:             $datatable .= '<td class="LC_left_item">'.
                   4569:                           '<span class="LC_nobreak"><label>'.
                   4570:                           '<input type="checkbox" name="errorexcluded" '.
                   4571:                           'value="'.$ids[$i].'"'.$check.' />'.
                   4572:                           $ids[$i].'</label></span></td>';
                   4573:         }
                   4574:         my $colsleft = $numinrow - @ids%($numinrow);
                   4575:         if ($colsleft > 1 ) {
                   4576:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4577:                           '&nbsp;</td>';
                   4578:         } elsif ($colsleft == 1) {
                   4579:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4580:         }
                   4581:         $datatable .= '</tr></table></td></tr>';
                   4582:         $rownum ++;
1.286     raeburn  4583:     } elsif ($position eq 'bottom') {
1.315     raeburn  4584:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4585:         my (@posstypes,%usertypeshash);
                   4586:         if (ref($types) eq 'ARRAY') {
                   4587:             @posstypes = @{$types};
                   4588:         }
                   4589:         if (@posstypes) {
                   4590:             if (ref($usertypes) eq 'HASH') {
                   4591:                 %usertypeshash = %{$usertypes};
                   4592:             }
                   4593:             my @overridden;
                   4594:             my $numinrow = 4;
                   4595:             if (ref($settings) eq 'HASH') {
                   4596:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   4597:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   4598:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   4599:                             push(@overridden,$key);
                   4600:                             foreach my $item (@contacts) {
                   4601:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   4602:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   4603:                                 }
                   4604:                             }
                   4605:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   4606:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   4607:                             $includeloc{'override_'.$key} = '';
                   4608:                             $includestr{'override_'.$key} = '';
                   4609:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   4610:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
                   4611:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   4612:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   4613:                             }
1.286     raeburn  4614:                         }
                   4615:                     }
                   4616:                 }
1.315     raeburn  4617:             }
                   4618:             my $customclass = 'LC_helpdesk_override';
                   4619:             my $optionsprefix = 'LC_options_helpdesk_';
                   4620: 
                   4621:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   4622:  
                   4623:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   4624:                                          $numinrow,$othertitle,'overrides',
                   4625:                                          \$rownum,$onclicktypes,$customclass);
                   4626:             $rownum ++;
                   4627:             $usertypeshash{'default'} = $othertitle;
                   4628:             foreach my $status (@posstypes) {
                   4629:                 my $css_class;
                   4630:                 if ($rownum%2) {
                   4631:                     $css_class = 'LC_odd_row ';
                   4632:                 }
                   4633:                 $css_class .= $customclass;
                   4634:                 my $rowid = $optionsprefix.$status;
                   4635:                 my $hidden = 1;
                   4636:                 my $currstyle = 'display:none';
                   4637:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   4638:                     $currstyle = 'display:table-row';
                   4639:                     $hidden = 0;
                   4640:                 }
                   4641:                 my $key = 'override_'.$status;
                   4642:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   4643:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   4644:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   4645:                                                   \@contacts,$short_titles);
                   4646:                 unless ($hidden) {
                   4647:                     $rownum ++;
1.286     raeburn  4648:                 }
                   4649:             }
1.134     raeburn  4650:         }
1.28      raeburn  4651:     }
1.30      raeburn  4652:     $$rowtotal += $rownum;
1.28      raeburn  4653:     return $datatable;
                   4654: }
                   4655: 
1.340     raeburn  4656: sub core_link_msu {
                   4657:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   4658:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   4659: }
                   4660: 
1.315     raeburn  4661: sub overridden_helpdesk {
                   4662:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   4663:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   4664:     my $class = 'LC_left_item';
                   4665:     if ($css_class) {
                   4666:         $css_class = ' class="'.$css_class.'"';
                   4667:     }
                   4668:     if ($rowid) {
                   4669:         $rowid = ' id="'.$rowid.'"';
                   4670:     }
                   4671:     if ($rowstyle) {
                   4672:         $rowstyle = ' style="'.$rowstyle.'"';
                   4673:     }
                   4674:     my ($output,$description);
                   4675:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   4676:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   4677:               "<td>$description</td>\n".
                   4678:               '<td class="'.$class.'" colspan="2">'.
                   4679:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   4680:               '<span class="LC_nobreak">';
                   4681:     if (ref($contacts) eq 'ARRAY') {
                   4682:         foreach my $item (@{$contacts}) {
                   4683:             my $check;
                   4684:             if (ref($checked) eq 'HASH') {
                   4685:                $check = $checked->{$item};
                   4686:             }
                   4687:             my $title;
                   4688:             if (ref($short_titles) eq 'HASH') {
                   4689:                 $title = $short_titles->{$item}; 
                   4690:             }
                   4691:             $output .= '<label>'.
                   4692:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   4693:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   4694:         }
                   4695:     }
                   4696:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4697:                '<input type="text" name="override_'.$type.'_others" '.
                   4698:                'value="'.$otheremails.'"  />';
                   4699:     my %locchecked;
                   4700:     foreach my $loc ('s','b') {
                   4701:         if ($includeloc eq $loc) {
                   4702:             $locchecked{$loc} = ' checked="checked"';
                   4703:             last;
                   4704:         }
                   4705:     }
                   4706:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4707:                '<input type="text" name="override_'.$type.'_bcc" '.
                   4708:                'value="'.$bccemails.'"  /></fieldset>'.
                   4709:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4710:                &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4711:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315     raeburn  4712:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4713:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4714:                ('&nbsp;'x2).
                   4715:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4716:                '</span></fieldset>'.
                   4717:                '</td></tr>'."\n";
                   4718:     return $output;
                   4719: }
                   4720: 
1.286     raeburn  4721: sub contacts_javascript {
                   4722:     return <<"ENDSCRIPT";
                   4723: 
                   4724: <script type="text/javascript">
                   4725: // <![CDATA[
                   4726: 
                   4727: function screenshotSize(field) {
                   4728:     if (document.getElementById('help_screenshotsize')) {
                   4729:         if (field.value == 'no') {
1.289     raeburn  4730:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  4731:         } else {
                   4732:             document.getElementById('help_screenshotsize').style.display="";
                   4733:         }
                   4734:     }
                   4735:     return;
                   4736: }
                   4737: 
1.315     raeburn  4738: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   4739:     if (form.elements[checkbox].length != undefined) {
                   4740:         var count = 0;
                   4741:         if (docount) {
                   4742:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   4743:                 if (form.elements[checkbox][i].checked) {
                   4744:                     count ++;
                   4745:                 }
                   4746:             }
                   4747:         }
                   4748:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   4749:             var type = form.elements[checkbox][i].value;
                   4750:             if (document.getElementById(prefix+type)) {
                   4751:                 if (form.elements[checkbox][i].checked) {
                   4752:                     document.getElementById(prefix+type).style.display = 'table-row';
                   4753:                     if (count % 2 == 1) {
                   4754:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   4755:                     } else {
                   4756:                         document.getElementById(prefix+type).className = target;
                   4757:                     }
                   4758:                     count ++;
                   4759:                 } else {
                   4760:                     document.getElementById(prefix+type).style.display = 'none';
                   4761:                 }
                   4762:             }
                   4763:         }
                   4764:     }
                   4765:     return;
                   4766: }
                   4767: 
                   4768: 
1.286     raeburn  4769: // ]]>
                   4770: </script>
                   4771: 
                   4772: ENDSCRIPT
                   4773: }
                   4774: 
1.118     jms      4775: sub print_helpsettings {
1.282     raeburn  4776:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4777:     my $confname = $dom.'-domainconfig';
1.285     raeburn  4778:     my $formname = 'display';
1.168     raeburn  4779:     my ($datatable,$itemcount);
1.282     raeburn  4780:     if ($position eq 'top') {
                   4781:         $itemcount = 1;
                   4782:         my (%choices,%defaultchecked,@toggles);
                   4783:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   4784:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   4785:                                      &mt('LON-CAPA bug tracker'),600,500));
                   4786:         %defaultchecked = ('submitbugs' => 'on');
                   4787:         @toggles = ('submitbugs');
                   4788:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4789:                                                      \%choices,$itemcount);
                   4790:         $$rowtotal ++;
                   4791:     } else {
                   4792:         my $css_class;
                   4793:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  4794:         my (%customroles,%ordered,%current);
1.301     raeburn  4795:         if (ref($settings) eq 'HASH') {
                   4796:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   4797:                 %current = %{$settings->{'adhoc'}};
                   4798:             }
1.285     raeburn  4799:         }
                   4800:         my $count = 0;
                   4801:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  4802:             if ($key=~/^rolesdef\_(\w+)$/) {
                   4803:                 my $rolename = $1;
1.285     raeburn  4804:                 my (%privs,$order);
1.282     raeburn  4805:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   4806:                 $customroles{$rolename} = \%privs;
1.285     raeburn  4807:                 if (ref($current{$rolename}) eq 'HASH') {
                   4808:                     $order = $current{$rolename}{'order'};
                   4809:                 }
                   4810:                 if ($order eq '') {
                   4811:                     $order = $count;
                   4812:                 }
                   4813:                 $ordered{$order} = $rolename;
                   4814:                 $count++;
                   4815:             }
                   4816:         }
                   4817:         my $maxnum = scalar(keys(%ordered));
                   4818:         my @roles_by_num = ();
                   4819:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   4820:             push(@roles_by_num,$item);
                   4821:         }
                   4822:         my $context = 'domprefs';
                   4823:         my $crstype = 'Course';
                   4824:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  4825:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  4826:         my ($numstatustypes,@jsarray);
                   4827:         if (ref($types) eq 'ARRAY') {
                   4828:             if (@{$types} > 0) {
                   4829:                 $numstatustypes = scalar(@{$types});
                   4830:                 push(@accesstypes,'status');
                   4831:                 @jsarray = ('bystatus');
1.282     raeburn  4832:             }
                   4833:         }
1.290     raeburn  4834:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  4835:         if (keys(%domhelpdesk)) {
                   4836:             push(@accesstypes,('inc','exc'));
                   4837:             push(@jsarray,('notinc','notexc'));
                   4838:         }
                   4839:         my $hiddenstr = join("','",@jsarray);
1.282     raeburn  4840:         my $context = 'domprefs';
                   4841:         my $crstype = 'Course';
1.285     raeburn  4842:         my $prefix = 'helproles_';
                   4843:         my $add_class = 'LC_hidden';
                   4844:         foreach my $num (@roles_by_num) {
                   4845:             my $role = $ordered{$num};
                   4846:             my ($desc,$access,@statuses);
                   4847:             if (ref($current{$role}) eq 'HASH') {
                   4848:                 $desc = $current{$role}{'desc'};
                   4849:                 $access = $current{$role}{'access'};
                   4850:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   4851:                     @statuses = @{$current{$role}{'insttypes'}};
                   4852:                 }
                   4853:             }
                   4854:             if ($desc eq '') {
                   4855:                 $desc = $role;
                   4856:             }
                   4857:             my $identifier = 'custhelp'.$num;
1.282     raeburn  4858:             my %full=();
                   4859:             my %levels= (
                   4860:                          course => {},
                   4861:                          domain => {},
                   4862:                          system => {},
                   4863:                         );
                   4864:             my %levelscurrent=(
                   4865:                                course => {},
                   4866:                                domain => {},
                   4867:                                system => {},
                   4868:                               );
                   4869:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   4870:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   4871:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  4872:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  4873:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  4874:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   4875:             for (my $k=0; $k<=$maxnum; $k++) {
                   4876:                 my $vpos = $k+1;
                   4877:                 my $selstr;
                   4878:                 if ($k == $num) {
                   4879:                     $selstr = ' selected="selected" ';
                   4880:                 }
                   4881:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4882:             }
                   4883:             $datatable .= '</select>'.('&nbsp;'x2).
                   4884:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   4885:                           '</td>'.
                   4886:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4887:                           &mt('Name shown to users:').
                   4888:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   4889:                           '</fieldset>'.
                   4890:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   4891:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   4892:                           '<fieldset>'.
                   4893:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  4894:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  4895:                                                                    \%levelscurrent,$identifier,
                   4896:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   4897:                           '</fieldset></td>';
1.282     raeburn  4898:             $itemcount ++;
                   4899:         }
                   4900:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4901:         my $newcust = 'custhelp'.$count;
                   4902:         my (%privs,%levelscurrent);
                   4903:         my %full=();
                   4904:         my %levels= (
                   4905:                      course => {},
                   4906:                      domain => {},
                   4907:                      system => {},
                   4908:                     );
                   4909:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   4910:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  4911:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  4912:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  4913:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   4914:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   4915:         for (my $k=0; $k<$maxnum+1; $k++) {
                   4916:             my $vpos = $k+1;
                   4917:             my $selstr;
                   4918:             if ($k == $maxnum) {
                   4919:                 $selstr = ' selected="selected" ';
                   4920:             }
                   4921:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4922:         }
                   4923:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  4924:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   4925:                       '</label></span></td>'.
1.285     raeburn  4926:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4927:                       '<span class="LC_nobreak">'.
                   4928:                       &mt('Internal name:').
                   4929:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   4930:                       '</span>'.('&nbsp;'x4).
                   4931:                       '<span class="LC_nobreak">'.
                   4932:                       &mt('Name shown to users:').
                   4933:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   4934:                       '</span></fieldset>'.
                   4935:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   4936:                                              $usertypes,$types,\%domhelpdesk).
                   4937:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  4938:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   4939:                                                                 \@templateroles,$newcust).
                   4940:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   4941:                                                                \%levelscurrent,$newcust).
1.334     raeburn  4942:                       '</fieldset>'.
                   4943:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   4944:                       '</td></tr>';
1.282     raeburn  4945:         $count ++;
                   4946:         $$rowtotal += $count;
                   4947:     }
1.166     raeburn  4948:     return $datatable;
1.121     raeburn  4949: }
                   4950: 
1.285     raeburn  4951: sub adhocbutton {
                   4952:     my ($prefix,$num,$field,$visibility) = @_;
                   4953:     my %lt = &Apache::lonlocal::texthash(
                   4954:                                           show => 'Show details',
                   4955:                                           hide => 'Hide details',
                   4956:                                         );
                   4957:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   4958:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   4959:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   4960:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   4961: }
                   4962: 
                   4963: sub helpsettings_javascript {
                   4964:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   4965:     return unless(ref($roles_by_num) eq 'ARRAY');
                   4966:     my %html_js_lt = &Apache::lonlocal::texthash(
                   4967:                                           show => 'Show details',
                   4968:                                           hide => 'Hide details',
                   4969:                                         );
                   4970:     &html_escape(\%html_js_lt);
                   4971:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   4972:     return <<"ENDSCRIPT";
                   4973: <script type="text/javascript">
                   4974: // <![CDATA[
                   4975: 
                   4976: function reorderHelpRoles(form,item) {
                   4977:     var changedVal;
                   4978: $jstext
                   4979:     var newpos = 'helproles_${total}_pos';
                   4980:     var maxh = 1 + $total;
                   4981:     var current = new Array();
                   4982:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4983:     if (item == newpos) {
                   4984:         changedVal = newitemVal;
                   4985:     } else {
                   4986:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4987:         current[newitemVal] = newpos;
                   4988:     }
                   4989:     for (var i=0; i<helproles.length; i++) {
                   4990:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   4991:         if (elementName != item) {
                   4992:             if (form.elements[elementName]) {
                   4993:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4994:                 current[currVal] = elementName;
                   4995:             }
                   4996:         }
                   4997:     }
                   4998:     var oldVal;
                   4999:     for (var j=0; j<maxh; j++) {
                   5000:         if (current[j] == undefined) {
                   5001:             oldVal = j;
                   5002:         }
                   5003:     }
                   5004:     if (oldVal < changedVal) {
                   5005:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   5006:            var elementName = current[k];
                   5007:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   5008:         }
                   5009:     } else {
                   5010:         for (var k=changedVal; k<oldVal; k++) {
                   5011:             var elementName = current[k];
                   5012:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   5013:         }
                   5014:     }
                   5015:     return;
                   5016: }
                   5017: 
                   5018: function helpdeskAccess(num) {
                   5019:     var curraccess = null;
                   5020:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   5021:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   5022:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   5023:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   5024:             }
                   5025:         }
                   5026:     }
                   5027:     var shown = Array();
                   5028:     var hidden = Array();
                   5029:     if (curraccess == 'none') {
                   5030:         hidden = Array('$hiddenstr');
                   5031:     } else {
                   5032:         if (curraccess == 'status') {
                   5033:             shown = Array('bystatus');
                   5034:             hidden = Array('notinc','notexc');
                   5035:         } else {
                   5036:             if (curraccess == 'exc') {
                   5037:                 shown = Array('notexc');
                   5038:                 hidden = Array('notinc','bystatus');
                   5039:             }
                   5040:             if (curraccess == 'inc') {
                   5041:                 shown = Array('notinc');
                   5042:                 hidden = Array('notexc','bystatus');
                   5043:             }
1.293     raeburn  5044:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  5045:                 hidden = Array('notinc','notexc','bystatus');
                   5046:             }
                   5047:         }
                   5048:     }
                   5049:     if (hidden.length > 0) {
                   5050:         for (var i=0; i<hidden.length; i++) {
                   5051:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   5052:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   5053:             }
                   5054:         }
                   5055:     }
                   5056:     if (shown.length > 0) {
                   5057:         for (var i=0; i<shown.length; i++) {
                   5058:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   5059:                 if (shown[i] == 'privs') {
                   5060:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   5061:                 } else {
                   5062:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   5063:                 }
                   5064:             }
                   5065:         }
                   5066:     }
                   5067:     return;
                   5068: }
                   5069: 
                   5070: function toggleHelpdeskItem(num,field) {
                   5071:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   5072:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  5073:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  5074:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   5075:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5076:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   5077:             }
                   5078:         } else {
                   5079:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   5080:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   5081:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   5082:             }
                   5083:         }
                   5084:     }
                   5085:     return;
                   5086: }
                   5087: 
                   5088: // ]]>
                   5089: </script>
                   5090: 
                   5091: ENDSCRIPT
                   5092: }
                   5093: 
                   5094: sub helpdeskroles_access {
                   5095:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   5096:         $usertypes,$types,$domhelpdesk) = @_;
                   5097:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   5098:     my %lt = &Apache::lonlocal::texthash(
                   5099:                     'rou'    => 'Role usage',
                   5100:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  5101:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   5102:                     'dh'     => 'All with domain helpdesk role',
                   5103:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  5104:                     'none'   => 'None',
                   5105:                     'status' => 'Determined based on institutional status',
                   5106:                     'inc'    => 'Include all, but exclude specific personnel',
                   5107:                     'exc'    => 'Exclude all, but include specific personnel',
                   5108:                   );
                   5109:     my %usecheck = (
                   5110:                      all => ' checked="checked"',
                   5111:                    );
                   5112:     my %displaydiv = (
                   5113:                       status => 'none',
                   5114:                       inc    => 'none',
                   5115:                       exc    => 'none',
                   5116:                       priv   => 'block',
                   5117:                      );
                   5118:     my $output;
                   5119:     if (ref($current) eq 'HASH') {
                   5120:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   5121:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   5122:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   5123:                 delete($usecheck{'all'});
                   5124:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   5125:                     my $access = $1;
                   5126:                     $displaydiv{$access} = 'inline';
                   5127:                 } elsif ($current->{access} eq 'none') {
                   5128:                     $displaydiv{'priv'} = 'none';
                   5129:                 }
                   5130:             }
                   5131:         }
                   5132:     }
                   5133:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   5134:               '<p>'.$lt{'whi'}.'</p>';
                   5135:     foreach my $access (@{$accesstypes}) {
                   5136:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   5137:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   5138:                    $lt{$access}.'</label>';
                   5139:         if ($access eq 'status') {
                   5140:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   5141:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   5142:                                                                  $othertitle,$usertypes,$types).
                   5143:                        '</div>';
                   5144:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   5145:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   5146:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5147:                        '</div>';
                   5148:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   5149:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   5150:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5151:                        '</div>';
                   5152:         }
                   5153:         $output .= '</p>';
                   5154:     }
                   5155:     $output .= '</fieldset>';
                   5156:     return $output;
                   5157: }
                   5158: 
1.121     raeburn  5159: sub radiobutton_prefs {
1.192     raeburn  5160:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385     raeburn  5161:         $additional,$align,$firstval) = @_;
1.121     raeburn  5162:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   5163:                    (ref($choices) eq 'HASH'));
                   5164: 
1.170     raeburn  5165:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  5166: 
                   5167:     foreach my $item (@{$toggles}) {
                   5168:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      5169:             $checkedon{$item} = ' checked="checked" ';
                   5170:             $checkedoff{$item} = ' ';
1.121     raeburn  5171:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      5172:             $checkedoff{$item} = ' checked="checked" ';
                   5173:             $checkedon{$item} = ' ';
                   5174:         }
                   5175:     }
                   5176:     if (ref($settings) eq 'HASH') {
1.121     raeburn  5177:         foreach my $item (@{$toggles}) {
1.118     jms      5178:             if ($settings->{$item} eq '1') {
                   5179:                 $checkedon{$item} =  ' checked="checked" ';
                   5180:                 $checkedoff{$item} = ' ';
                   5181:             } elsif ($settings->{$item} eq '0') {
                   5182:                 $checkedoff{$item} =  ' checked="checked" ';
                   5183:                 $checkedon{$item} = ' ';
                   5184:             }
                   5185:         }
1.121     raeburn  5186:     }
1.192     raeburn  5187:     if ($onclick) {
                   5188:         $onclick = ' onclick="'.$onclick.'"';
                   5189:     }
1.121     raeburn  5190:     foreach my $item (@{$toggles}) {
1.118     jms      5191:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  5192:         $datatable .=
1.306     raeburn  5193:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  5194:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  5195:             '</span></td>';
                   5196:         if ($align eq 'left') {
                   5197:             $datatable .= '<td class="LC_left_item">';
                   5198:         } else {
                   5199:             $datatable .= '<td class="LC_right_item">';
                   5200:         }
1.385     raeburn  5201:         $datatable .= '<span class="LC_nobreak">';
                   5202:         if ($firstval eq 'no') {
                   5203:             $datatable .=
                   5204:                 '<label><input type="radio" name="'.
                   5205:                 $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
                   5206:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5207:                 $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
                   5208:         } else {
                   5209:             $datatable .=
                   5210:                 '<label><input type="radio" name="'.
                   5211:                 $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
                   5212:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5213:                 $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
                   5214:         }
                   5215:         $datatable .= '</span>'.$additional.'</td></tr>';
1.118     jms      5216:         $itemcount ++;
1.121     raeburn  5217:     }
                   5218:     return ($datatable,$itemcount);
                   5219: }
                   5220: 
1.267     raeburn  5221: sub print_ltitools {
                   5222:     my ($dom,$settings,$rowtotal) = @_;
                   5223:     my $rownum = 0;
                   5224:     my $css_class;
                   5225:     my $itemcount = 1;
                   5226:     my $maxnum = 0;
                   5227:     my %ordered;
                   5228:     if (ref($settings) eq 'HASH') {
                   5229:         foreach my $item (keys(%{$settings})) {
                   5230:             if (ref($settings->{$item}) eq 'HASH') {
                   5231:                 my $num = $settings->{$item}{'order'};
                   5232:                 $ordered{$num} = $item;
                   5233:             }
                   5234:         }
                   5235:     }
                   5236:     my $confname = $dom.'-domainconfig';
                   5237:     my $switchserver = &check_switchserver($dom,$confname);
                   5238:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  5239:     my $datatable;
1.267     raeburn  5240:     my %lt = &ltitools_names();
                   5241:     my @courseroles = ('cc','in','ta','ep','st');
                   5242:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324     raeburn  5243:     my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267     raeburn  5244:     if (keys(%ordered)) {
                   5245:         my @items = sort { $a <=> $b } keys(%ordered);
                   5246:         for (my $i=0; $i<@items; $i++) {
                   5247:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5248:             my $item = $ordered{$items[$i]};
1.323     raeburn  5249:             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267     raeburn  5250:             if (ref($settings->{$item}) eq 'HASH') {
                   5251:                 $title = $settings->{$item}->{'title'};
                   5252:                 $url = $settings->{$item}->{'url'};
                   5253:                 $key = $settings->{$item}->{'key'};
                   5254:                 $secret = $settings->{$item}->{'secret'};
1.322     raeburn  5255:                 $lifetime = $settings->{$item}->{'lifetime'};
1.267     raeburn  5256:                 my $image = $settings->{$item}->{'image'};
                   5257:                 if ($image ne '') {
                   5258:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   5259:                 }
1.323     raeburn  5260:                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   5261:                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   5262:                 } else {
                   5263:                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   5264:                 }
1.267     raeburn  5265:             }
1.319     raeburn  5266:             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267     raeburn  5267:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5268:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   5269:             for (my $k=0; $k<=$maxnum; $k++) {
                   5270:                 my $vpos = $k+1;
                   5271:                 my $selstr;
                   5272:                 if ($k == $i) {
                   5273:                     $selstr = ' selected="selected" ';
                   5274:                 }
                   5275:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5276:             }
                   5277:             $datatable .= '</select>'.('&nbsp;'x2).
                   5278:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   5279:                 &mt('Delete?').'</label></span></td>'.
                   5280:                 '<td colspan="2">'.
                   5281:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5282:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267     raeburn  5283:                 ('&nbsp;'x2).
                   5284:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   5285:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   5286:                 ('&nbsp;'x2).
                   5287:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   5288:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5289:                 ('&nbsp;'x2).
                   5290:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   5291:                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   5292:                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267     raeburn  5293:                 '<br /><br />'.
1.323     raeburn  5294:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267     raeburn  5295:                 ' value="'.$url.'" /></span>'.
                   5296:                 ('&nbsp;'x2).
1.319     raeburn  5297:                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267     raeburn  5298:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   5299:                 ('&nbsp;'x2).
1.322     raeburn  5300:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   5301:                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   5302:                 ('&nbsp;'x2).
1.267     raeburn  5303:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   5304:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   5305:                 '<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>'.
                   5306:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   5307:                 '</fieldset>'.
                   5308:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5309:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   5310:             my %currdisp;
                   5311:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   5312:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   5313:                     $currdisp{'window'} = ' checked="checked"';
1.298     raeburn  5314:                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   5315:                     $currdisp{'tab'} = ' checked="checked"';
1.267     raeburn  5316:                 } else {
                   5317:                     $currdisp{'iframe'} = ' checked="checked"';
                   5318:                 }
                   5319:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   5320:                     $currdisp{'width'} = $1;
                   5321:                 }
                   5322:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   5323:                      $currdisp{'height'} = $1;
                   5324:                 }
1.296     raeburn  5325:                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   5326:                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267     raeburn  5327:             } else {
                   5328:                 $currdisp{'iframe'} = ' checked="checked"';
                   5329:             }
1.298     raeburn  5330:             foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5331:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   5332:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5333:             }
                   5334:             $datatable .= ('&nbsp;'x4);
                   5335:             foreach my $dimen ('width','height') {
                   5336:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5337:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   5338:                               ('&nbsp;'x2);
                   5339:             }
1.334     raeburn  5340:             $datatable .= '</span><br />'.
1.296     raeburn  5341:                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5342:                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296     raeburn  5343:                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   5344:                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   5345:                           '</textarea></div><div style=""></div><br />';
1.319     raeburn  5346:             my %units = (
                   5347:                           'passback' => 'days',
                   5348:                           'roster'   => 'seconds',
                   5349:                         );
1.267     raeburn  5350:             foreach my $extra ('passback','roster') {
1.319     raeburn  5351:                 my $validsty = 'none';
                   5352:                 my $currvalid;
1.267     raeburn  5353:                 my $checkedon = '';
                   5354:                 my $checkedoff = ' checked="checked"';
                   5355:                 if ($settings->{$item}->{$extra}) {
                   5356:                     $checkedon = $checkedoff;
                   5357:                     $checkedoff = '';
1.319     raeburn  5358:                     $validsty = 'inline-block';
                   5359:                     if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
                   5360:                         $currvalid = $settings->{$item}->{$extra.'valid'};
                   5361:                     }
                   5362:                 }
                   5363:                 my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
                   5364:                 $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5365:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
                   5366:                               &mt('No').'</label>'.('&nbsp;'x2).
                   5367:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
                   5368:                               &mt('Yes').'</label></span></div>'.
                   5369:                               '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
                   5370:                               '<span class="LC_nobreak">'.
                   5371:                               &mt("at least [_1] $units{$extra} after launch",
                   5372:                                   '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
                   5373:                               '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5374:             }
1.319     raeburn  5375:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
1.267     raeburn  5376:             if ($imgsrc) {
                   5377:                 $datatable .= $imgsrc.
                   5378:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   5379:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   5380:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   5381:             } else {
                   5382:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5383:             }
                   5384:             if ($switchserver) {
                   5385:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5386:             } else {
                   5387:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   5388:             }
                   5389:             $datatable .= '</span></fieldset>';
1.324     raeburn  5390:             my (%checkedfields,%rolemaps,$userincdom);
1.267     raeburn  5391:             if (ref($settings->{$item}) eq 'HASH') {
                   5392:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   5393:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   5394:                 }
1.324     raeburn  5395:                 $userincdom = $settings->{$item}->{'incdom'};
1.267     raeburn  5396:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   5397:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   5398:                     $checkedfields{'roles'} = 1;
                   5399:                 }
                   5400:             }
                   5401:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5402:                           '<span class="LC_nobreak">';
1.324     raeburn  5403:             my $userfieldstyle = 'display:none;';
                   5404:             my $seluserdom = '';
                   5405:             my $unseluserdom = ' selected="selected"';
1.267     raeburn  5406:             foreach my $field (@fields) {
1.324     raeburn  5407:                 my ($checked,$onclick,$id,$spacer);
1.267     raeburn  5408:                 if ($checkedfields{$field}) {
                   5409:                     $checked = ' checked="checked"';
                   5410:                 }
1.324     raeburn  5411:                 if ($field eq 'user') {
                   5412:                     $id = ' id="ltitools_user_field_'.$i.'"';
                   5413:                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   5414:                     if ($checked) {
                   5415:                         $userfieldstyle = 'display:inline-block';
                   5416:                         if ($userincdom) {
                   5417:                             $seluserdom = $unseluserdom;
                   5418:                             $unseluserdom = '';
                   5419:                         }
                   5420:                     }
                   5421:                 } else {
                   5422:                     $spacer = ('&nbsp;' x2);
                   5423:                 }
1.267     raeburn  5424:                 $datatable .= '<label>'.
1.324     raeburn  5425:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   5426:                               $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5427:             }
1.324     raeburn  5428:             $datatable .= '</span>';
                   5429:             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   5430:                           '<span class="LC_nobreak"> : '.
                   5431:                           '<select name="ltitools_userincdom_'.$i.'">'.
                   5432:                           '<option value="">'.&mt('Select').'</option>'.
                   5433:                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   5434:                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   5435:                           '</select></span></div>';
                   5436:             $datatable .= '</fieldset>'.
1.267     raeburn  5437:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   5438:             foreach my $role (@courseroles) {
                   5439:                 my ($selected,$selectnone);
                   5440:                 if (!$rolemaps{$role}) {
                   5441:                     $selectnone = ' selected="selected"';
                   5442:                 }
1.306     raeburn  5443:                 $datatable .= '<td style="text-align: center">'. 
1.267     raeburn  5444:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5445:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   5446:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5447:                 foreach my $ltirole (@ltiroles) {
                   5448:                     unless ($selectnone) {
                   5449:                         if ($rolemaps{$role} eq $ltirole) {
                   5450:                             $selected = ' selected="selected"';
                   5451:                         } else {
                   5452:                             $selected = '';
                   5453:                         }
                   5454:                     }
                   5455:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   5456:                 }
                   5457:                 $datatable .= '</select></td>';
                   5458:             }
1.273     raeburn  5459:             $datatable .= '</tr></table></fieldset>';
                   5460:             my %courseconfig;
                   5461:             if (ref($settings->{$item}) eq 'HASH') {
                   5462:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   5463:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   5464:                 }
                   5465:             }
                   5466:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5467:             foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  5468:                 my $checked;
                   5469:                 if ($courseconfig{$item}) {
                   5470:                     $checked = ' checked="checked"';
                   5471:                 }
                   5472:                 $datatable .= '<label>'.
                   5473:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372     raeburn  5474:                        $lt{'crs'.$item}.'</label>&nbsp; '."\n";
1.273     raeburn  5475:             }
                   5476:             $datatable .= '</span></fieldset>'.
1.267     raeburn  5477:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5478:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   5479:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   5480:                 my %custom = %{$settings->{$item}->{'custom'}};
                   5481:                 if (keys(%custom) > 0) {
                   5482:                     foreach my $key (sort(keys(%custom))) {
                   5483:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5484:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   5485:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   5486:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   5487:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   5488:                     }
                   5489:                 }
                   5490:             }
                   5491:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5492:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   5493:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   5494:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   5495:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   5496:             $itemcount ++;
                   5497:         }
                   5498:     }
                   5499:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319     raeburn  5500:     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267     raeburn  5501:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   5502:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   5503:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   5504:     for (my $k=0; $k<$maxnum+1; $k++) {
                   5505:         my $vpos = $k+1;
                   5506:         my $selstr;
                   5507:         if ($k == $maxnum) {
                   5508:             $selstr = ' selected="selected" ';
                   5509:         }
                   5510:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5511:     }
                   5512:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  5513:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267     raeburn  5514:                   '<td colspan="2">'.
                   5515:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5516:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267     raeburn  5517:                   ('&nbsp;'x2).
                   5518:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   5519:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   5520:                   ('&nbsp;'x2).
                   5521:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   5522:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5523:                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   5524:                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5525:                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267     raeburn  5526:                   '<br />'.
1.323     raeburn  5527:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267     raeburn  5528:                   ('&nbsp;'x2).
                   5529:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   5530:                   ('&nbsp;'x2).
1.322     raeburn  5531:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   5532:                   ('&nbsp;'x2).
1.267     raeburn  5533:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   5534:                   '<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".
                   5535:                   '</fieldset>'.
                   5536:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5537:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   5538:     my %defaultdisp;
                   5539:     $defaultdisp{'iframe'} = ' checked="checked"';
1.298     raeburn  5540:     foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5541:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   5542:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5543:     }
                   5544:     $datatable .= ('&nbsp;'x4);
                   5545:     foreach my $dimen ('width','height') {
                   5546:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5547:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   5548:                       ('&nbsp;'x2);
                   5549:     }
1.334     raeburn  5550:     $datatable .= '</span><br />'.
1.296     raeburn  5551:                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5552:                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296     raeburn  5553:                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334     raeburn  5554:                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296     raeburn  5555:                   '</div><div style=""></div><br />';
1.319     raeburn  5556:     my %units = (
                   5557:                   'passback' => 'days',
                   5558:                   'roster'   => 'seconds',
                   5559:                 );
                   5560:     my %defaulttimes = (
                   5561:                      'passback' => '7',
1.322     raeburn  5562:                      'roster'   => '300',
1.319     raeburn  5563:                    );
1.267     raeburn  5564:     foreach my $extra ('passback','roster') {
1.319     raeburn  5565:         my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
                   5566:         $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5567:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
                   5568:                       &mt('No').'</label></span>'.('&nbsp;'x2).'<span class="LC_nobreak">'.
                   5569:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
                   5570:                       &mt('Yes').'</label></span></div>'.
                   5571:                       '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
                   5572:                       '<span class="LC_nobreak">'.
                   5573:                       &mt("at least [_1] $units{$extra} after launch",
                   5574:                           '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
                   5575:                       '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5576:     }
1.319     raeburn  5577:     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
1.267     raeburn  5578:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5579:     if ($switchserver) {
                   5580:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5581:     } else {
                   5582:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   5583:     }
                   5584:     $datatable .= '</span></fieldset>'.
                   5585:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5586:                   '<span class="LC_nobreak">';
                   5587:     foreach my $field (@fields) {
1.324     raeburn  5588:         my ($id,$onclick,$spacer);
                   5589:         if ($field eq 'user') {
                   5590:             $id = ' id="ltitools_user_field_add"';
                   5591:             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   5592:         } else {
                   5593:             $spacer = ('&nbsp;' x2);
                   5594:         }
1.267     raeburn  5595:         $datatable .= '<label>'.
1.324     raeburn  5596:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   5597:                       $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5598:     }
1.324     raeburn  5599:     $datatable .= '</span>'.
                   5600:                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   5601:                   '<span class="LC_nobreak"> : '.
                   5602:                   '<select name="ltitools_userincdom_add">'.
                   5603:                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   5604:                   '<option value="0">'.&mt('username').'</option>'.
                   5605:                   '<option value="1">'.&mt('username:domain').'</option>'.
                   5606:                   '</select></span></div></fieldset>';
                   5607:     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267     raeburn  5608:     foreach my $role (@courseroles) {
                   5609:         my ($checked,$checkednone);
1.306     raeburn  5610:         $datatable .= '<td style="text-align: center">'.
1.267     raeburn  5611:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5612:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   5613:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   5614:         foreach my $ltirole (@ltiroles) {
                   5615:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   5616:         }
                   5617:         $datatable .= '</select></td>';
                   5618:     }
                   5619:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  5620:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5621:     foreach my $item ('label','title','target','linktext','explanation','append') {
1.296     raeburn  5622:         $datatable .= '<label>'.
                   5623:                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   5624:                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
1.273     raeburn  5625:     }
                   5626:     $datatable .= '</span></fieldset>'.
1.267     raeburn  5627:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5628:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   5629:                   '<tr><td><span class="LC_nobreak">'.
                   5630:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   5631:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   5632:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334     raeburn  5633:                   '</table></fieldset>'."\n".
1.267     raeburn  5634:                   '</td>'."\n".
                   5635:                   '</tr>'."\n";
                   5636:     $itemcount ++;
                   5637:     return $datatable;
                   5638: }
                   5639: 
                   5640: sub ltitools_names {
                   5641:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  5642:                                           'title'          => 'Title',
                   5643:                                           'version'        => 'Version',
                   5644:                                           'msgtype'        => 'Message Type',
1.323     raeburn  5645:                                           'sigmethod'      => 'Signature Method',
1.296     raeburn  5646:                                           'url'            => 'URL',
                   5647:                                           'key'            => 'Key',
1.322     raeburn  5648:                                           'lifetime'       => 'Nonce lifetime (s)',
1.296     raeburn  5649:                                           'secret'         => 'Secret',
                   5650:                                           'icon'           => 'Icon',   
1.324     raeburn  5651:                                           'user'           => 'User',
1.296     raeburn  5652:                                           'fullname'       => 'Full Name',
                   5653:                                           'firstname'      => 'First Name',
                   5654:                                           'lastname'       => 'Last Name',
                   5655:                                           'email'          => 'E-mail',
                   5656:                                           'roles'          => 'Role',
1.298     raeburn  5657:                                           'window'         => 'Window',
                   5658:                                           'tab'            => 'Tab',
1.296     raeburn  5659:                                           'iframe'         => 'iFrame',
                   5660:                                           'height'         => 'Height',
                   5661:                                           'width'          => 'Width',
                   5662:                                           'linktext'       => 'Default Link Text',
                   5663:                                           'explanation'    => 'Default Explanation',
                   5664:                                           'passback'       => 'Tool can return grades:',
                   5665:                                           'roster'         => 'Tool can retrieve roster:',
                   5666:                                           'crstarget'      => 'Display target',
                   5667:                                           'crslabel'       => 'Course label',
                   5668:                                           'crstitle'       => 'Course title', 
                   5669:                                           'crslinktext'    => 'Link Text',
                   5670:                                           'crsexplanation' => 'Explanation',
1.318     raeburn  5671:                                           'crsappend'      => 'Provider URL',
1.267     raeburn  5672:                                         );
                   5673:     return %lt;
                   5674: }
                   5675: 
1.372     raeburn  5676: sub print_proctoring {
                   5677:     my ($dom,$settings,$rowtotal) = @_;
                   5678:     my $itemcount = 1;
                   5679:     my (%ordered,%providernames,%current,%currentdef);
                   5680:     my $confname = $dom.'-domainconfig';
                   5681:     my $switchserver = &check_switchserver($dom,$confname);
                   5682:     if (ref($settings) eq 'HASH') {
                   5683:         foreach my $item (keys(%{$settings})) {
                   5684:             if (ref($settings->{$item}) eq 'HASH') {
                   5685:                 my $num = $settings->{$item}{'order'};
                   5686:                 $ordered{$num} = $item;
                   5687:             }
                   5688:         }
                   5689:     } else {
                   5690:         %ordered = (
                   5691:                      1 => 'proctorio',
                   5692:                      2 => 'examity',
                   5693:                    );
                   5694:     }
                   5695:     %providernames = &proctoring_providernames();
                   5696:     my $maxnum = scalar(keys(%ordered));
                   5697:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   5698:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   5699:     if (ref($requref) eq 'HASH') {
                   5700:         %requserfields = %{$requref};
                   5701:     }
                   5702:     if (ref($opturef) eq 'HASH') {
                   5703:         %optuserfields = %{$opturef};
                   5704:     }
                   5705:     if (ref($defref) eq 'HASH') {
                   5706:         %defaults = %{$defref};
                   5707:     }
                   5708:     if (ref($extref) eq 'HASH') {
                   5709:         %extended = %{$extref};
                   5710:     }
                   5711:     if (ref($crsref) eq 'HASH') {
                   5712:         %crsconf = %{$crsref};
                   5713:     }
                   5714:     if (ref($rolesref) eq 'ARRAY') {
                   5715:         @courseroles = @{$rolesref};
                   5716:     }
                   5717:     if (ref($ltiref) eq 'ARRAY') {
                   5718:         @ltiroles = @{$ltiref};
                   5719:     }
                   5720:     my $datatable;
                   5721:     my $css_class;
                   5722:     if (keys(%ordered)) {
                   5723:         my @items = sort { $a <=> $b } keys(%ordered);
                   5724:         for (my $i=0; $i<@items; $i++) {
                   5725:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5726:             my $provider = $ordered{$items[$i]};
                   5727:             my $optionsty = 'none';
                   5728:             my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
                   5729:                 %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
                   5730:             if (ref($settings) eq 'HASH') {
                   5731:                 if (ref($settings->{$provider}) eq 'HASH') {
                   5732:                     %current = %{$settings->{$provider}};
                   5733:                     if ($current{'available'}) {
                   5734:                         $optionsty = 'block';
                   5735:                         $available = 1;
                   5736:                     }
                   5737:                     if ($current{'lifetime'} =~ /^\d+$/) {
                   5738:                         $lifetime = $current{'lifetime'};
                   5739:                     }
                   5740:                     if ($current{'version'} =~ /^\d+\.\d+$/) {
                   5741:                         $version = $current{'version'};
                   5742:                     }
                   5743:                     if ($current{'image'} ne '') {
                   5744:                         $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
                   5745:                     }
                   5746:                     if (ref($current{'fields'}) eq 'ARRAY') {
                   5747:                         map { $checkedfields{$_} = 1; } @{$current{'fields'}};
                   5748:                     }
                   5749:                     $userincdom = $current{'incdom'};
                   5750:                     if (ref($current{'roles'}) eq 'HASH') {
                   5751:                         %rolemaps = %{$current{'roles'}};
                   5752:                         $checkedfields{'roles'} = 1;
                   5753:                     }
                   5754:                     if (ref($current{'defaults'}) eq 'ARRAY') {
                   5755:                         foreach my $val (@{$current{'defaults'}}) {
                   5756:                             if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
                   5757:                                 $inuse{$val} = 1;
                   5758:                             } else {
                   5759:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5760:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5761:                                         if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
                   5762:                                             $inuse{$poss} = $val;
                   5763:                                             last;
                   5764:                                         }
                   5765:                                     }
                   5766:                                 }
                   5767:                             }
                   5768:                         }
                   5769:                     } elsif (ref($current{'defaults'}) eq 'HASH') {
                   5770:                         foreach my $key (keys(%{$current{'defaults'}})) {
                   5771:                             my $currval = $current{'defaults'}{$key}; 
                   5772:                             if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
                   5773:                                 $inuse{$key} = 1;
                   5774:                             } else {
                   5775:                                 my $match;
                   5776:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5777:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5778:                                         if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
                   5779:                                             $inuse{$poss} = $key;
                   5780:                                             last;
                   5781:                                         }
                   5782:                                     } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
                   5783:                                         foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
                   5784:                                             if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
                   5785:                                                 if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
                   5786:                                                     $currentdef{$inner} = $currval;
                   5787:                                                     $match = 1;
                   5788:                                                     last;
                   5789:                                                 }
                   5790:                                             } elsif ($inner eq $key) {
                   5791:                                                 $currentdef{$key} = $currval;
                   5792:                                                 $match = 1;
                   5793:                                                 last;
                   5794:                                             }
                   5795:                                         }
                   5796:                                     }
                   5797:                                     last if ($match);
                   5798:                                 }
                   5799:                             }
                   5800:                         }
                   5801:                     }
                   5802:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   5803:                         map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
                   5804:                     }
                   5805:                 }
                   5806:             }
                   5807:             my %lt = &proctoring_titles($provider);
                   5808:             my %fieldtitles = &proctoring_fieldtitles($provider);
                   5809:             my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
                   5810:             my %checkedavailable = (
                   5811:                                    yes => '',
                   5812:                                    no  => ' checked="checked"',
                   5813:                                  );
                   5814:             if ($available) {
                   5815:                 $checkedavailable{'yes'} = $checkedavailable{'no'};
                   5816:                 $checkedavailable{'no'} = '';
                   5817:             }
                   5818:             my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
                   5819:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5820:                          .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
                   5821:             for (my $k=0; $k<$maxnum; $k++) {
                   5822:                 my $vpos = $k+1;
                   5823:                 my $selstr;
                   5824:                 if ($k == $i) {
                   5825:                     $selstr = ' selected="selected" ';
                   5826:                 }
                   5827:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5828:             }
                   5829:             if ($version eq '') {
                   5830:                 if ($provider eq 'proctorio') {
                   5831:                     $version = '1.0';
                   5832:                 } elsif ($provider eq 'examity') {
                   5833:                     $version = '1.1';
                   5834:                 }
                   5835:             }
                   5836:             if ($lifetime eq '') {
                   5837:                 $lifetime = '300';
                   5838:             }
                   5839:             $datatable .=
                   5840:                 '</select>'.('&nbsp;'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
                   5841:                 '<span class="LC_nobreak">'.$lt{'avai'}.'&nbsp;'.
                   5842:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   5843:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
                   5844:                 '</td>'.
                   5845:                 '<td colspan="2">'.
                   5846:                 '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
                   5847:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
                   5848:                 '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
                   5849:                 ('&nbsp;'x2).
                   5850:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
                   5851:                 '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5852:                 '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
                   5853:                 ('&nbsp;'x2).
                   5854:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
                   5855:                 '<br />'.
                   5856:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
                   5857:                 '<br />'.
                   5858:                 '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
                   5859:                 ('&nbsp;'x2).
                   5860:                 '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
                   5861:                 '<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";
                   5862:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   5863:             if ($imgsrc) {
                   5864:                 $datatable .= $imgsrc.
                   5865:                               '<label><input type="checkbox" name="proctoring_image_del"'.
                   5866:                               ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
                   5867:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:');
                   5868:             }
                   5869:             $datatable .= '&nbsp;';
                   5870:             if ($switchserver) {
                   5871:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5872:             } else {
                   5873:                 $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
                   5874:             }
                   5875:             unless ($imgsrc) {
                   5876:                 $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
                   5877:             }
                   5878:             $datatable .= '</fieldset>'."\n";
                   5879:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   5880:                 if (@{$requserfields{$provider}} > 0) {
                   5881:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
                   5882:                     foreach my $field (@{$requserfields{$provider}}) {
                   5883:                         $datatable .= '<span class="LC_nobreak">'.
                   5884:                                       '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
                   5885:                                       $lt{$field}.'</label>';
                   5886:                         if ($field eq 'user') {
                   5887:                             my $seluserdom = '';
                   5888:                             my $unseluserdom = ' selected="selected"';
                   5889:                             if ($userincdom) {
                   5890:                                 $seluserdom = $unseluserdom;
                   5891:                                 $unseluserdom = '';
                   5892:                             }
                   5893:                             $datatable .= ':&nbsp;'.
                   5894:                                 '<select name="proctoring_userincdom_'.$provider.'">'.
                   5895:                                 '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
                   5896:                                 '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
                   5897:                                 '</select>&nbsp;';
                   5898:                         } else {
                   5899:                             $datatable .= '&nbsp;';
                   5900:                             if ($field eq 'roles') {
                   5901:                                 $showroles = 1; 
                   5902:                             } 
                   5903:                         }
                   5904:                         $datatable .= '</span> ';
                   5905:                     }
                   5906:                 }
                   5907:                 $datatable .= '</fieldset>'."\n";
                   5908:             }
                   5909:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   5910:                 if (@{$optuserfields{$provider}} > 0) {
                   5911:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>'; 
                   5912:                     foreach my $field (@{$optuserfields{$provider}}) {
                   5913:                         my $checked;
                   5914:                         if ($checkedfields{$field}) {
                   5915:                             $checked = ' checked="checked"';
                   5916:                         }
                   5917:                         $datatable .= '<span class="LC_nobreak">'.
                   5918:                                       '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span>&nbsp; ';
                   5919:                     }
                   5920:                     $datatable .= '</fieldset>'."\n";
                   5921:                 }
                   5922:             }
                   5923:             if (ref($defaults{$provider}) eq 'ARRAY') {
                   5924:                 if (@{$defaults{$provider}}) {
                   5925:                     my (%options,@selectboxes);
                   5926:                     if (ref($extended{$provider}) eq 'HASH') {
                   5927:                         %options = %{$extended{$provider}};
                   5928:                     }
                   5929:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
                   5930:                     my ($rem,$numinrow,$dropdowns);
                   5931:                     if ($provider eq 'proctorio') { 
                   5932:                         $datatable .= '<table>';
                   5933:                         $numinrow = 4;
                   5934:                     }
                   5935:                     my $i = 0;
                   5936:                     foreach my $field (@{$defaults{$provider}}) {
                   5937:                         my $checked;
                   5938:                         if ($inuse{$field}) {
                   5939:                             $checked = ' checked="checked"';
                   5940:                         }
                   5941:                         if ($provider eq 'examity') {
                   5942:                             if ($field eq 'display') {
                   5943:                                 $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
                   5944:                                 foreach my $option ('iframe','tab','window') {
                   5945:                                     my $checkdisp;
                   5946:                                     if ($currentdef{'target'} eq $option) {
                   5947:                                         $checkdisp = ' checked="checked"';
                   5948:                                     }
                   5949:                                     $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
                   5950:                                     $fieldtitles{$option}.'</label>'.('&nbsp;'x2);
                   5951:                                 }
                   5952:                                 $datatable .= ('&nbsp;'x4);
                   5953:                                 foreach my $dimen ('width','height') {
                   5954:                                     $datatable .= '<label>'.$fieldtitles{$dimen}.'&nbsp;'.
                   5955:                                                   '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
                   5956:                                                   'value="'.$currentdef{$dimen}.'" /></label>'.
                   5957:                                                   ('&nbsp;'x2);
                   5958:                                 }
                   5959:                                 $datatable .= '</span><br />'.
                   5960:                                               '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
                   5961:                                               '<input type="text" name="proctoring_linktext_'.$provider.'" '.
                   5962:                                               'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
                   5963:                                               '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
                   5964:                                               '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
                   5965:                                               $currentdef{'explanation'}.
                   5966:                                               '</textarea></div><div style=""></div><br />';
                   5967:                             }
                   5968:                         } else {
                   5969:                             if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   5970:                                 my ($output,$selnone);
                   5971:                                 unless ($checked) {
                   5972:                                     $selnone = ' selected="selected"';
                   5973:                                 }
                   5974:                                 $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
                   5975:                                            '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
                   5976:                                            '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>'; 
                   5977:                                 foreach my $option (@{$options{$field}}) {
                   5978:                                     my $sel; 
                   5979:                                     if ($inuse{$field} eq $option) {
                   5980:                                         $sel = ' selected="selected"';
                   5981:                                     }
                   5982:                                     $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
                   5983:                                 }
                   5984:                                 $output .= '</select></span>';
                   5985:                                 push(@selectboxes,$output);
                   5986:                             } else {
                   5987:                                 $rem = $i%($numinrow);
                   5988:                                 if ($rem == 0) {
                   5989:                                     if ($i > 0) {
                   5990:                                         $datatable .= '</tr>';
                   5991:                                     }
                   5992:                                     $datatable .= '<tr>';
                   5993:                                 }
                   5994:                                 $datatable .= '<td class="LC_left_item">'.
                   5995:                                               '<span class="LC_nobreak">'.
                   5996:                                               '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
                   5997:                                               $fieldtitles{$field}.'</label></span></td>';
                   5998:                                 $i++;
                   5999:                             }
                   6000:                         }
                   6001:                     }
                   6002:                     if ($provider eq 'proctorio') {
                   6003:                         if ($numinrow) {
                   6004:                             $rem = $i%$numinrow;
                   6005:                         }
                   6006:                         my $colsleft = $numinrow - $rem;
                   6007:                         if ($colsleft > 1) {
                   6008:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6009:                         } else {
                   6010:                             $datatable .= '<td class="LC_left_item">';
                   6011:                         }
                   6012:                         $datatable .= '&nbsp;'.
                   6013:                                       '</td></tr></table>';
                   6014:                         if (@selectboxes) {
                   6015:                             $datatable .= '<hr /><table>';
                   6016:                             $numinrow = 2;
                   6017:                             for (my $i=0; $i<@selectboxes; $i++) {
                   6018:                                 $rem = $i%($numinrow);
                   6019:                                 if ($rem == 0) {
                   6020:                                     if ($i > 0) {
                   6021:                                         $datatable .= '</tr>';
                   6022:                                     }
                   6023:                                     $datatable .= '<tr>';
                   6024:                                 }
                   6025:                                 $datatable .= '<td class="LC_left_item">'.
                   6026:                                               $selectboxes[$i].'</td>';
                   6027:                             }
                   6028:                             if ($numinrow) {
                   6029:                                 $rem = $i%$numinrow;
                   6030:                             }
                   6031:                             $colsleft = $numinrow - $rem;
                   6032:                             if ($colsleft > 1) {
                   6033:                                 $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6034:                             } else {
                   6035:                                 $datatable .= '<td class="LC_left_item">';
                   6036:                             }
                   6037:                             $datatable .= '&nbsp;'.
                   6038:                                           '</td></tr></table>';
                   6039:                         }
                   6040:                     }
                   6041:                     $datatable .= '</fieldset>';
                   6042:                 }
                   6043:                 if (ref($crsconf{$provider}) eq 'ARRAY') {
                   6044:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6045:                                   '<legend>'.&mt('Configurable in course').'</legend>';
                   6046:                     my ($rem,$numinrow);
                   6047:                     if ($provider eq 'proctorio') {
                   6048:                         $datatable .= '<table>';
                   6049:                         $numinrow = 4;
                   6050:                     }
                   6051:                     my $i = 0;
                   6052:                     foreach my $item (@{$crsconf{$provider}}) {
                   6053:                         my $name;
                   6054:                         if ($provider eq 'examity') {
                   6055:                             $name = $lt{'crs'.$item};
                   6056:                         } elsif ($provider eq 'proctorio') {
                   6057:                             $name = $fieldtitles{$item};
                   6058:                             $rem = $i%($numinrow);
                   6059:                             if ($rem == 0) {
                   6060:                                 if ($i > 0) {
                   6061:                                     $datatable .= '</tr>';
                   6062:                                 }
                   6063:                                 $datatable .= '<tr>';
                   6064:                             }
                   6065:                             $datatable .= '<td class="LC_left_item>';
                   6066:                         }
                   6067:                         my $checked;
                   6068:                         if ($crsconfig{$item}) {
                   6069:                             $checked = ' checked="checked"';
                   6070:                         }
                   6071:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   6072:                                       '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
                   6073:                                       $name.'</label></span>';
                   6074:                         if ($provider eq 'examity') {
                   6075:                             $datatable .= '&nbsp; ';
                   6076:                         }
                   6077:                         $datatable .= "\n";
                   6078:                         $i++;
                   6079:                     }
                   6080:                     if ($provider eq 'proctorio') {
                   6081:                         if ($numinrow) {
                   6082:                             $rem = $i%$numinrow;
                   6083:                         }
                   6084:                         my $colsleft = $numinrow - $rem;
                   6085:                         if ($colsleft > 1) {
                   6086:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6087:                         } else {
                   6088:                             $datatable .= '<td class="LC_left_item">';
                   6089:                         }
                   6090:                         $datatable .= '&nbsp;'.
                   6091:                                       '</td></tr></table>';
                   6092:                     }
                   6093:                     $datatable .= '</fieldset>';
                   6094:                 }
                   6095:                 if ($showroles) {
                   6096:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6097:                                   '<legend>'.&mt('Role mapping').'</legend><table><tr>';
                   6098:                     foreach my $role (@courseroles) {
                   6099:                         my ($selected,$selectnone);
                   6100:                         if (!$rolemaps{$role}) {
                   6101:                             $selectnone = ' selected="selected"';
                   6102:                         }
                   6103:                         $datatable .= '<td style="text-align: center">'.
                   6104:                                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   6105:                                       '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
                   6106:                                       '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6107:                         foreach my $ltirole (@ltiroles) {
                   6108:                             unless ($selectnone) {
                   6109:                                 if ($rolemaps{$role} eq $ltirole) {
                   6110:                                     $selected = ' selected="selected"';
                   6111:                                 } else {
                   6112:                                     $selected = '';
                   6113:                                 }
                   6114:                             }
                   6115:                             $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   6116:                         }
                   6117:                         $datatable .= '</select></td>';
                   6118:                     }
                   6119:                     $datatable .= '</tr></table></fieldset>'.
                   6120:                                   '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6121:                                   '<legend>'.&mt('Custom items sent on launch').'</legend>'.
                   6122:                                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   6123:                                   '<tr><td></td><td>lms</td>'.
                   6124:                                   '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
                   6125:                                   ' value="Loncapa" disabled="disabled"/></td></tr>';
                   6126:                     if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
                   6127:                         (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
                   6128:                         my %custom = %{$settings->{$provider}->{'custom'}};
                   6129:                         if (keys(%custom) > 0) {
                   6130:                             foreach my $key (sort(keys(%custom))) {
                   6131:                                 next if ($key eq 'lms');
                   6132:                                 $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6133:                                               '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
                   6134:                                               $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   6135:                                               '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
                   6136:                                               ' value="'.$custom{$key}.'" /></td></tr>';
                   6137:                             }
                   6138:                         }
                   6139:                     }
                   6140:                     $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6141:                                   '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
                   6142:                                   &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
                   6143:                                   '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
                   6144:                                   '</table></fieldset></td></tr>'."\n";
                   6145:                 }
                   6146:                 $datatable .= '</td></tr>';
                   6147:             }
                   6148:             $itemcount ++;
                   6149:         }
                   6150:     }
                   6151:     return $datatable;
                   6152: }
                   6153: 
                   6154: sub proctoring_data {
                   6155:     my $requserfields = {
                   6156:                       proctorio => ['user'],
                   6157:                       examity   => ['roles','user'],
                   6158:                      };
                   6159:     my $optuserfields = {
                   6160:                         proctorio => ['fullname'],
                   6161:                         examity   => ['fullname','firstname','lastname','email'],
                   6162:                      };
                   6163:     my $defaults = {
                   6164:                   proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6165:                                 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6166:                                 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6167:                                 'closetabs','onescreen','print','downloads','cache','rightclick',
                   6168:                                 'reentry','calculator','whiteboard'],
                   6169:                   examity   => ['display'],
                   6170:                 };
                   6171:     my $extended = { 
                   6172:                   proctorio => {
                   6173:                                  verifyid => ['verifyidauto','verifyidlive'],
                   6174:                                  fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
                   6175:                                  tabslinks => ['notabs','linksonly'],
                   6176:                                  reentry => ['noreentry','agentreentry'],
                   6177:                                  calculator => ['calculatorbasic','calculatorsci'],
                   6178:                                },
                   6179:                   examity => {
                   6180:                                display => {
                   6181:                                            target      => ['iframe','tab','window'],
                   6182:                                            width       => '',
                   6183:                                            height      => '',
                   6184:                                            linktext    => '',
                   6185:                                            explanation => '',
                   6186:                                           },
                   6187:                              },
                   6188:                 };
                   6189:     my $crsconf = {
                   6190:                  proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6191:                                'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6192:                                'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6193:                                'closetabs','onescreen','print','downloads','cache','rightclick',
                   6194:                                'reentry','calculator','whiteboard'],
                   6195:                  examity => ['label','title','target','linktext','explanation','append'],
                   6196:                };
                   6197:     my $courseroles = ['cc','in','ta','ep','st'];
                   6198:     my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
                   6199:     return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
                   6200: }
                   6201: 
                   6202: sub proctoring_titles {
                   6203:     my ($item) = @_;
                   6204:     my (%common_lt,%custom_lt);
                   6205:     %common_lt = &Apache::lonlocal::texthash (
                   6206:                      'avai'      => 'Available?',
                   6207:                      'base'      => 'Basic Settings',
                   6208:                      'requ'      => 'User data required to be sent on launch',
                   6209:                      'optu'      => 'User data optionally sent on launch',
                   6210:                      'udsl'      => 'User data sent on launch',
                   6211:                      'defa'      => 'Defaults for items configurable in course',
                   6212:                      'sigmethod' => 'Signature Method',
                   6213:                      'key'       => 'Key',
                   6214:                      'lifetime'  => 'Nonce lifetime (s)',
                   6215:                      'secret'    => 'Secret',
                   6216:                      'icon'      => 'Icon',
                   6217:                      'fullname'  => 'Full Name',
                   6218:                      'visible'   => 'Visible input',
                   6219:                      'username'  => 'username',
                   6220:                      'user'      => 'User',
                   6221:                  );
                   6222:     if ($item eq 'proctorio') {
                   6223:         %custom_lt = &Apache::lonlocal::texthash (
                   6224:                          'version'        => 'OAuth version',
                   6225:                          'url'            => 'API URL',
                   6226:                          'uname:dom'      => 'username-domain',
                   6227:         );
                   6228:     } elsif ($item eq 'examity') {
                   6229:         %custom_lt = &Apache::lonlocal::texthash (
                   6230:                          'version'        => 'LTI Version',
                   6231:                          'url'            => 'URL',
                   6232:                          'uname:dom'      => 'username:domain',
                   6233:                          'msgtype'        => 'Message Type',
                   6234:                          'firstname'      => 'First Name',
                   6235:                          'lastname'       => 'Last Name',
                   6236:                          'email'          => 'E-mail',
                   6237:                          'roles'          => 'Role',
                   6238:                          'crstarget'      => 'Display target',
                   6239:                          'crslabel'       => 'Course label',
                   6240:                          'crstitle'       => 'Course title', 
                   6241:                          'crslinktext'    => 'Link Text',
                   6242:                          'crsexplanation' => 'Explanation',
                   6243:                          'crsappend'      => 'Provider URL',
                   6244:         );
                   6245:     }
                   6246:     my %lt = (%common_lt,%custom_lt);
                   6247:     return %lt;
                   6248: }
                   6249: 
                   6250: sub proctoring_fieldtitles {
                   6251:     my ($item) = @_;
                   6252:     if ($item eq 'proctorio') {
                   6253:         return &Apache::lonlocal::texthash (
                   6254:                   'recordvideo' => 'Record video',
                   6255:                   'recordaudio' => 'Record audio',
                   6256:                   'recordscreen' => 'Record screen',
                   6257:                   'recordwebtraffic' => 'Record web traffic',
                   6258:                   'recordroomstart' => 'Record room scan',
                   6259:                   'verifyvideo' => 'Verify webcam',
                   6260:                   'verifyaudio' => 'Verify microphone',
                   6261:                   'verifydesktop' => 'Verify desktop recording',
                   6262:                   'verifyid' => 'Photo ID verification',
                   6263:                   'verifysignature' => 'Require signature',
                   6264:                   'fullscreen' => 'Fullscreen',
                   6265:                   'clipboard' => 'Disable copy/paste',
                   6266:                   'tabslinks' => 'New tabs/windows',
                   6267:                   'closetabs' => 'Close other tabs',
                   6268:                   'onescreen' => 'Limit to single screen',
                   6269:                   'print' => 'Disable Printing',
                   6270:                   'downloads' => 'Disable Downloads',
                   6271:                   'cache' => 'Empty cache after exam',
                   6272:                   'rightclick' => 'Disable right click',
                   6273:                   'reentry' => 'Re-entry to exam',
                   6274:                   'calculator' => 'Onscreen calculator',
                   6275:                   'whiteboard' => 'Onscreen whiteboard',
                   6276:                   'verifyidauto' => 'Automated verification',
                   6277:                   'verifyidlive' => 'Live agent verification',
                   6278:                   'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
                   6279:                   'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
                   6280:                   'fullscreensever' => 'Forced, navigation away ends exam',
                   6281:                   'notabs' => 'Disaallowed',
                   6282:                   'linksonly' => 'Allowed from links in exam',
                   6283:                   'noreentry' => 'Disallowed',
                   6284:                   'agentreentry' => 'Agent required for re-entry',
                   6285:                   'calculatorbasic' => 'Basic',
                   6286:                   'calculatorsci' => 'Scientific',
                   6287:         );
                   6288:     } elsif ($item eq 'examity') {
                   6289:         return &Apache::lonlocal::texthash (
                   6290:                 'target'         => 'Display target',   
                   6291:                 'window'         => 'Window',
                   6292:                 'tab'            => 'Tab',
                   6293:                 'iframe'         => 'iFrame',
                   6294:                 'height'         => 'Height (pixels)',
                   6295:                 'width'          => 'Width (pixels)',
                   6296:                 'linktext'       => 'Default Link Text',
                   6297:                 'explanation'    => 'Default Explanation',
                   6298:                 'append'         => 'Provider URL',
                   6299:         );
                   6300:     }
                   6301: }
                   6302: 
                   6303: sub proctoring_providernames {
                   6304:     return (
                   6305:              proctorio => 'Proctorio',
                   6306:              examity   => 'Examity',
                   6307:            );
                   6308: }
                   6309: 
1.320     raeburn  6310: sub print_lti {
                   6311:     my ($dom,$settings,$rowtotal) = @_;
                   6312:     my $itemcount = 1;
                   6313:     my $maxnum = 0;
                   6314:     my $css_class;
                   6315:     my %ordered;
                   6316:     if (ref($settings) eq 'HASH') {
                   6317:         foreach my $item (keys(%{$settings})) {
                   6318:             if (ref($settings->{$item}) eq 'HASH') {
                   6319:                 my $num = $settings->{$item}{'order'};
1.390     raeburn  6320:                 if ($num eq '') {
                   6321:                     $num = scalar(keys(%{$settings}));
                   6322:                 }
1.320     raeburn  6323:                 $ordered{$num} = $item;
                   6324:             }
                   6325:         }
                   6326:     }
                   6327:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  6328:     my $datatable;
1.320     raeburn  6329:     my %lt = &lti_names();
                   6330:     if (keys(%ordered)) {
                   6331:         my @items = sort { $a <=> $b } keys(%ordered);
                   6332:         for (my $i=0; $i<@items; $i++) {
                   6333:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6334:             my $item = $ordered{$items[$i]};
1.391     raeburn  6335:             my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
1.320     raeburn  6336:             if (ref($settings->{$item}) eq 'HASH') {
                   6337:                 $key = $settings->{$item}->{'key'};
                   6338:                 $secret = $settings->{$item}->{'secret'};
                   6339:                 $lifetime = $settings->{$item}->{'lifetime'};
                   6340:                 $consumer = $settings->{$item}->{'consumer'};
1.345     raeburn  6341:                 $requser = $settings->{$item}->{'requser'};
1.391     raeburn  6342:                 $crsinc = $settings->{$item}->{'crsinc'};
1.320     raeburn  6343:                 $current = $settings->{$item};
                   6344:             }
1.345     raeburn  6345:             my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
                   6346:             my %checkedrequser = (
                   6347:                                    yes => ' checked="checked"',
                   6348:                                    no  => '',
                   6349:                                  );
                   6350:             if (!$requser) {
                   6351:                 $checkedrequser{'no'} = $checkedrequser{'yes'};
                   6352:                 $checkedrequser{'yes'} = '';
1.352     raeburn  6353:             }
1.391     raeburn  6354:             my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
                   6355:             my %checkedcrsinc = (
                   6356:                                       yes => ' checked="checked"',
                   6357:                                       no  => '',
                   6358:                                    );
                   6359:             if (!$crsinc) {
                   6360:                 $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
                   6361:                 $checkedcrsinc{'yes'} = '';
                   6362:             }
1.320     raeburn  6363:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
                   6364:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6365:                          .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
                   6366:             for (my $k=0; $k<=$maxnum; $k++) {
                   6367:                 my $vpos = $k+1;
                   6368:                 my $selstr;
                   6369:                 if ($k == $i) {
                   6370:                     $selstr = ' selected="selected" ';
                   6371:                 }
                   6372:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6373:             }
                   6374:             $datatable .= '</select>'.('&nbsp;'x2).
                   6375:                 '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
                   6376:                 &mt('Delete?').'</label></span></td>'.
                   6377:                 '<td colspan="2">'.
                   6378:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6379:                 '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  6380:                 ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320     raeburn  6381:                 ('&nbsp;'x2).
                   6382:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                   6383:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   6384:                 ('&nbsp;'x2).
                   6385:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345     raeburn  6386:                 'value="'.$lifetime.'" size="3" /></span>'.
                   6387:                 ('&nbsp;'x2).
                   6388:                  '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6389:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6390:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  6391:                 '<br /><br />'.
1.391     raeburn  6392:                 '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6393:                 '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6394:                 '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
                   6395:                 ('&nbsp;'x4).
1.320     raeburn  6396:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   6397:                 ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
                   6398:                 ('&nbsp;'x2).
                   6399:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   6400:                 '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
                   6401:                 '<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>'.
                   6402:                 '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325     raeburn  6403:                 '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320     raeburn  6404:             $itemcount ++;
                   6405:         }
                   6406:     }
                   6407:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6408:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
                   6409:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   6410:                   '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
                   6411:                   '<select name="lti_pos_add"'.$chgstr.'>';
                   6412:     for (my $k=0; $k<$maxnum+1; $k++) {
                   6413:         my $vpos = $k+1;
                   6414:         my $selstr;
                   6415:         if ($k == $maxnum) {
                   6416:             $selstr = ' selected="selected" ';
                   6417:         }
                   6418:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6419:     }
                   6420:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  6421:                   '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320     raeburn  6422:                   '<td colspan="2">'.
                   6423:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6424:                   '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  6425:                   ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320     raeburn  6426:                   ('&nbsp;'x2).
                   6427:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   6428:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   6429:                   ('&nbsp;'x2).
1.345     raeburn  6430:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
                   6431:                   ('&nbsp;'x2).
                   6432:                   '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6433:                   '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6434:                   '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  6435:                   '<br /><br />'.
1.391     raeburn  6436:                   '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6437:                   '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6438:                   '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
                   6439:                   ('&nbsp;'x4).
1.320     raeburn  6440:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
                   6441:                   ('&nbsp;'x2).
                   6442:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
                   6443:                   '<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  6444:                   '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
1.320     raeburn  6445:                   '</td>'."\n".
                   6446:                   '</tr>'."\n";
                   6447:     $$rowtotal ++;
                   6448:     return $datatable;;
                   6449: }
                   6450: 
                   6451: sub lti_names {
                   6452:     my %lt = &Apache::lonlocal::texthash(
                   6453:                                           'version'   => 'LTI Version',
                   6454:                                           'url'       => 'URL',
                   6455:                                           'key'       => 'Key',
1.322     raeburn  6456:                                           'lifetime'  => 'Nonce lifetime (s)',
1.345     raeburn  6457:                                           'consumer'  => 'Consumer',
1.320     raeburn  6458:                                           'secret'    => 'Secret',
1.345     raeburn  6459:                                           'requser'   => "User's identity sent",
1.391     raeburn  6460:                                           'crsinc'    => "Course's identity sent",
1.320     raeburn  6461:                                           'email'     => 'Email address',
                   6462:                                           'sourcedid' => 'User ID',
                   6463:                                           'other'     => 'Other',
                   6464:                                           'passback'  => 'Can return grades to Consumer:',
                   6465:                                           'roster'    => 'Can retrieve roster from Consumer:',
1.326     raeburn  6466:                                           'topmenu'   => 'Display LON-CAPA page header',
1.345     raeburn  6467:                                           'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320     raeburn  6468:                                         );
                   6469:     return %lt;
                   6470: }
                   6471: 
                   6472: sub lti_options {
1.325     raeburn  6473:     my ($num,$current,$itemcount,%lt) = @_;
1.363     raeburn  6474:     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320     raeburn  6475:     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
                   6476:     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392     raeburn  6477:     $checked{'storecrs'}{'Y'} = ' checked="checked"';
                   6478:     $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320     raeburn  6479:     $checked{'mapcrstype'} = {};
                   6480:     $checked{'makeuser'} = {};
                   6481:     $checked{'selfenroll'} = {};
                   6482:     $checked{'crssec'} = {};
                   6483:     $checked{'crssecsrc'} = {};
1.325     raeburn  6484:     $checked{'lcauth'} = {};
1.326     raeburn  6485:     $checked{'menuitem'} = {};
1.325     raeburn  6486:     if ($num eq 'add') {
                   6487:         $checked{'lcauth'}{'lti'} = ' checked="checked"';
                   6488:     }
1.320     raeburn  6489:     my $userfieldsty = 'none';
                   6490:     my $crsfieldsty = 'none';
                   6491:     my $crssecfieldsty = 'none';
                   6492:     my $secsrcfieldsty = 'none';
1.363     raeburn  6493:     my $callbacksty = 'none';
1.337     raeburn  6494:     my $passbacksty = 'none';
1.345     raeburn  6495:     my $optionsty = 'block';
1.391     raeburn  6496:     my $crssty = 'block';
1.325     raeburn  6497:     my $lcauthparm;
                   6498:     my $lcauthparmstyle = 'display:none';
                   6499:     my $lcauthparmtext;
1.326     raeburn  6500:     my $menusty;
1.325     raeburn  6501:     my $numinrow = 4;
1.326     raeburn  6502:     my %menutitles = &ltimenu_titles();
1.320     raeburn  6503: 
                   6504:     if (ref($current) eq 'HASH') {
1.345     raeburn  6505:         if (!$current->{'requser'}) {
                   6506:             $optionsty = 'none';
1.391     raeburn  6507:             $crssty = 'none';
                   6508:         } elsif (!$current->{'crsinc'}) {
                   6509:             $crssty = 'none';
1.345     raeburn  6510:         }
1.320     raeburn  6511:         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
                   6512:             $checked{'mapuser'}{'sourcedid'} = '';
                   6513:             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
                   6514:                 $checked{'mapuser'}{'email'} = ' checked="checked"'; 
                   6515:             } else {
                   6516:                 $checked{'mapuser'}{'other'} = ' checked="checked"';
                   6517:                 $userfield = $current->{'mapuser'};
                   6518:                 $userfieldsty = 'inline-block';
                   6519:             }
                   6520:         }
                   6521:         if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
                   6522:             $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
                   6523:             if ($current->{'mapcrs'} eq 'context_id') {
                   6524:                 $checked{'mapcrs'}{'context_id'} = ' checked="checked"'; 
                   6525:             } else {
                   6526:                 $checked{'mapcrs'}{'other'} = ' checked="checked"';
                   6527:                 $cidfield = $current->{'mapcrs'};
                   6528:                 $crsfieldsty = 'inline-block';
                   6529:             }
                   6530:         }
                   6531:         if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
                   6532:             foreach my $type (@{$current->{'mapcrstype'}}) {
                   6533:                 $checked{'mapcrstype'}{$type} = ' checked="checked"';
                   6534:             }
                   6535:         }
1.392     raeburn  6536:         if (!$current->{'storecrs'}) {
                   6537:             $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
                   6538:             $checked{'storecrs'}{'Y'} = '';
                   6539:         }
1.345     raeburn  6540:         if ($current->{'makecrs'}) {
1.320     raeburn  6541:             $checked{'makecrs'}{'Y'} = '  checked="checked"';
1.326     raeburn  6542:         }
1.320     raeburn  6543:         if (ref($current->{'makeuser'}) eq 'ARRAY') {
                   6544:             foreach my $role (@{$current->{'makeuser'}}) {
                   6545:                 $checked{'makeuser'}{$role} = ' checked="checked"';
                   6546:             }
                   6547:         }
1.325     raeburn  6548:         if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
                   6549:             $checked{'lcauth'}{$1} = ' checked="checked"';
                   6550:             unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   6551:                 $lcauthparm = $current->{'lcauthparm'};
                   6552:                 $lcauthparmstyle = 'display:table-row'; 
                   6553:                 if ($current->{'lcauth'} eq 'localauth') {
                   6554:                     $lcauthparmtext = &mt('Local auth argument');
                   6555:                 } else {
                   6556:                     $lcauthparmtext = &mt('Kerberos domain');
                   6557:                 }
                   6558:             }
                   6559:         }
1.320     raeburn  6560:         if (ref($current->{'selfenroll'}) eq 'ARRAY') {
                   6561:             foreach my $role (@{$current->{'selfenroll'}}) {
                   6562:                 $checked{'selfenroll'}{$role} = ' checked="checked"';
                   6563:             }
                   6564:         }
                   6565:         if (ref($current->{'maproles'}) eq 'HASH') {
                   6566:             %rolemaps = %{$current->{'maproles'}};
                   6567:         }
                   6568:         if ($current->{'section'} ne '') {
                   6569:             $checked{'crssec'}{'Y'} = '  checked="checked"'; 
                   6570:             $crssecfieldsty = 'inline-block';
                   6571:             if ($current->{'section'} eq 'course_section_sourcedid') {
                   6572:                 $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
                   6573:             } else {
                   6574:                 $checked{'crssecsrc'}{'other'} = ' checked="checked"';
                   6575:                 $crssecsrc = $current->{'section'};
                   6576:                 $secsrcfieldsty = 'inline-block';
                   6577:             }
                   6578:         } else {
                   6579:             $checked{'crssec'}{'N'} = ' checked="checked"';
                   6580:         }
1.363     raeburn  6581:         if ($current->{'callback'} ne '') {
                   6582:             $callback = $current->{'callback'};
                   6583:             $checked{'callback'}{'Y'} = ' checked="checked"';
                   6584:             $callbacksty = 'inline-block';
                   6585:         } else {
                   6586:             $checked{'callback'}{'N'} = ' checked="checked"';
                   6587:         }
1.326     raeburn  6588:         if ($current->{'topmenu'}) {
                   6589:             $checked{'topmenu'}{'Y'} = ' checked="checked"';
                   6590:         } else {
                   6591:             $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6592:         }
                   6593:         if ($current->{'inlinemenu'}) {
                   6594:             $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
                   6595:         } else {
                   6596:             $checked{'inlinemenu'}{'N'} = ' checked="checked"';
                   6597:         }
                   6598:         if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
                   6599:             $menusty = 'inline-block';
                   6600:             if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   6601:                 foreach my $item (@{$current->{'lcmenu'}}) {
                   6602:                     if (exists($menutitles{$item})) {
                   6603:                         $checked{'menuitem'}{$item} = ' checked="checked"';
                   6604:                     }
                   6605:                 }
                   6606:             }
                   6607:         } else {
                   6608:             $menusty = 'none';
                   6609:         }
1.320     raeburn  6610:     } else {
                   6611:         $checked{'makecrs'}{'N'} = ' checked="checked"';
                   6612:         $checked{'crssec'}{'N'} = ' checked="checked"';
1.363     raeburn  6613:         $checked{'callback'}{'N'} = ' checked="checked"';
1.326     raeburn  6614:         $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6615:         $checked{'inlinemenu'}{'Y'} = ' checked="checked"'; 
                   6616:         $checked{'menuitem'}{'grades'} = ' checked="checked"';
                   6617:         $menusty = 'inline-block'; 
1.320     raeburn  6618:     }
1.325     raeburn  6619:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  6620:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   6621:                                official   => 'Official',
                   6622:                                unofficial => 'Unofficial',
                   6623:                                community  => 'Community',
                   6624:                                textbook   => 'Textbook',
                   6625:                                placement  => 'Placement Test',
1.325     raeburn  6626:                                lti        => 'LTI Provider',
1.320     raeburn  6627:     );
1.325     raeburn  6628:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6629:     my %shortauth = (
                   6630:                      internal => 'int',
                   6631:                      krb4 => 'krb4',
                   6632:                      krb5 => 'krb5',
                   6633:                      localauth  => 'loc'
                   6634:                     );
                   6635:     my %authnames = &authtype_names();
1.320     raeburn  6636:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   6637:     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
                   6638:     my @courseroles = ('cc','in','ta','ep','st');
                   6639:     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
                   6640:     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
                   6641:     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363     raeburn  6642:     my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320     raeburn  6643:     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325     raeburn  6644:     my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326     raeburn  6645:     my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391     raeburn  6646:     my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392     raeburn  6647:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').':&nbsp;'.
1.391     raeburn  6648:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
                   6649:                  $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6650:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
                   6651:                  $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
                   6652:                  '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
                   6653:                  '<span class="LC_nobreak">'.&mt('Parameter').': '.
                   6654:                  '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
                   6655:                  '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
                   6656:                  '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320     raeburn  6657:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
                   6658:     foreach my $option ('sourcedid','email','other') {
                   6659:         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
                   6660:                    $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
                   6661:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6662:     }
                   6663:     $output .= '</span></div>'.
                   6664:                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                   6665:                '<input type="text" name="lti_customuser_'.$num.'" '.
1.372     raeburn  6666:                'value="'.$userfield.'" /></div></fieldset>'.
1.391     raeburn  6667:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320     raeburn  6668:     foreach my $ltirole (@ltiroles) {
                   6669:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
                   6670:                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';     
                   6671:     }
                   6672:     $output .= '</fieldset>'.
1.391     raeburn  6673:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325     raeburn  6674:                '<table>'.
                   6675:                &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                   6676:                '</table>'.
                   6677:                '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                   6678:                '<td class="LC_left_item">';
                   6679:     foreach my $auth ('lti',@authtypes) {
                   6680:         my $authtext;
                   6681:         if ($auth eq 'lti') {
                   6682:             $authtext = &mt('None');
                   6683:         } else {
                   6684:             $authtext = $authnames{$shortauth{$auth}};
                   6685:         }
                   6686:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                   6687:                    '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                   6688:                    $authtext.'</label></span> &nbsp;';
                   6689:     }
                   6690:     $output .= '</td></tr>'.
                   6691:                '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                   6692:                '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                   6693:                '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                   6694:                '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                   6695:                '</table></fieldset>'.
1.391     raeburn  6696:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
                   6697:                &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
                   6698:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                   6699:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                   6700:                $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6701:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
                   6702:                $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
                   6703:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6704:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                   6705:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                   6706:                $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6707:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
                   6708:                $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
                   6709:      $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6710:                '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                   6711:                '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
                   6712:     foreach my $type ('fullname','coursetitle','role','logout','grades') {
                   6713:         $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                   6714:                    $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                   6715:                    ('&nbsp;'x2);
                   6716:     }
                   6717:     $output .= '</span></div></fieldset>'.
                   6718:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320     raeburn  6719:                '<div class="LC_floatleft"><span class="LC_nobreak">'.
                   6720:                &mt('Unique course identifier').':&nbsp;';
                   6721:     foreach my $option ('course_offering_sourcedid','context_id','other') {
                   6722:         $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
                   6723:                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                   6724:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6725:     }
1.334     raeburn  6726:     $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320     raeburn  6727:                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                   6728:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6729:                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
                   6730:     foreach my $type (@coursetypes) {
                   6731:         $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
                   6732:                    $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
                   6733:                    ('&nbsp;'x2);
                   6734:     }
1.392     raeburn  6735:     $output .= '</span><br /><br />'.
                   6736:                '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').':&nbsp;'.
                   6737:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
                   6738:                $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6739:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
                   6740:                $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6741:                '</fieldset>'.
1.391     raeburn  6742:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
                   6743:     foreach my $ltirole (@lticourseroles) {
                   6744:         my ($selected,$selectnone);
                   6745:         if ($rolemaps{$ltirole} eq '') {
                   6746:             $selectnone = ' selected="selected"';
                   6747:         }
                   6748:         $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
                   6749:                    '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
                   6750:                    '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6751:         foreach my $role (@courseroles) {
                   6752:             unless ($selectnone) {
                   6753:                 if ($rolemaps{$ltirole} eq $role) {
                   6754:                     $selected = ' selected="selected"';
                   6755:                 } else {
                   6756:                     $selected = '';
                   6757:                 }
                   6758:             }
                   6759:             $output .= '<option value="'.$role.'"'.$selected.'>'.
                   6760:                        &Apache::lonnet::plaintext($role,'Course').
                   6761:                        '</option>';
                   6762:         }
                   6763:         $output .= '</select></td>';
                   6764:     }
                   6765:     $output .= '</tr></table></fieldset>'.
                   6766:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320     raeburn  6767:                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                   6768:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                   6769:                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6770:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                   6771:                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6772:                '</fieldset>'.
1.391     raeburn  6773:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320     raeburn  6774:     foreach my $lticrsrole (@lticourseroles) {
                   6775:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                   6776:                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
                   6777:     }
                   6778:     $output .= '</fieldset>'.
1.391     raeburn  6779:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320     raeburn  6780:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                   6781:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                   6782:                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6783:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334     raeburn  6784:                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320     raeburn  6785:                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                   6786:                '<span class="LC_nobreak">'.&mt('From').':<label>'.
                   6787:                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
                   6788:                $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
                   6789:                &mt('Standard field').'</label>'.('&nbsp;'x2).
                   6790:                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                   6791:                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334     raeburn  6792:                '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320     raeburn  6793:                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337     raeburn  6794:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
                   6795:     my ($pb1p1chk,$pb1p0chk,$onclickpb);
                   6796:     foreach my $extra ('roster','passback') {
1.320     raeburn  6797:         my $checkedon = '';
                   6798:         my $checkedoff = ' checked="checked"';
1.337     raeburn  6799:         if ($extra eq 'passback') {
                   6800:             $pb1p1chk = ' checked="checked"';
                   6801:             $pb1p0chk = '';
                   6802:             $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"'; 
                   6803:         } else {
                   6804:             $onclickpb = ''; 
                   6805:         }
1.320     raeburn  6806:         if (ref($current) eq 'HASH') {
                   6807:             if (($current->{$extra})) {
                   6808:                 $checkedon = $checkedoff;
                   6809:                 $checkedoff = '';
1.337     raeburn  6810:                 if ($extra eq 'passback') {
                   6811:                     $passbacksty = 'inline-block';
                   6812:                 }
                   6813:                 if ($current->{'passbackformat'} eq '1.0') {
                   6814:                     $pb1p0chk =  ' checked="checked"';
                   6815:                     $pb1p1chk = '';
                   6816:                 }
1.320     raeburn  6817:             }
                   6818:         }
                   6819:         $output .= $lt{$extra}.'&nbsp;'.
1.337     raeburn  6820:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320     raeburn  6821:                    &mt('No').'</label>'.('&nbsp;'x2).
1.339     raeburn  6822:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320     raeburn  6823:                    &mt('Yes').'</label><br />';
                   6824:     }
1.337     raeburn  6825:     $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                   6826:                '<span class="LC_nobreak">'.&mt('Grade format').
                   6827:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                   6828:                &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                   6829:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363     raeburn  6830:                &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391     raeburn  6831:                '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334     raeburn  6832:     $output .= '</span></div></fieldset>';
1.320     raeburn  6833: #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
                   6834: #
                   6835: #    $output .= '</fieldset>'.
                   6836: #        '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
                   6837:     return $output;
                   6838: }
                   6839: 
1.326     raeburn  6840: sub ltimenu_titles {
                   6841:     return &Apache::lonlocal::texthash(
                   6842:                                         fullname    => 'Full name',
                   6843:                                         coursetitle => 'Course title',
                   6844:                                         role        => 'Role',
                   6845:                                         logout      => 'Logout',
                   6846:                                         grades      => 'Grades',
                   6847:     );
                   6848: }
                   6849: 
1.121     raeburn  6850: sub print_coursedefaults {
1.139     raeburn  6851:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  6852:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  6853:     my $itemcount = 1;
1.192     raeburn  6854:     my %choices =  &Apache::lonlocal::texthash (
                   6855:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  6856:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  6857:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   6858:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  6859:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   6860:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398     raeburn  6861:         inline_chem          => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314     raeburn  6862:         texengine            => 'Default method to display mathematics',
1.257     raeburn  6863:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  6864:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   6865:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192     raeburn  6866:     );
1.198     raeburn  6867:     my %staticdefaults = (
                   6868:                            anonsurvey_threshold => 10,
                   6869:                            uploadquota          => 500,
1.257     raeburn  6870:                            postsubmit           => 60,
1.276     raeburn  6871:                            mysqltables          => 172800,
1.198     raeburn  6872:                          );
1.139     raeburn  6873:     if ($position eq 'top') {
1.257     raeburn  6874:         %defaultchecked = (
                   6875:                             'canuse_pdfforms' => 'off',
                   6876:                             'uselcmath'       => 'on',
                   6877:                             'usejsme'         => 'on',
1.398     raeburn  6878:                             'inline_chem'     => 'on',
1.289     raeburn  6879:                             'canclone'        => 'none',
1.257     raeburn  6880:                           );
1.398     raeburn  6881:         @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349     raeburn  6882:         my $deftex = $Apache::lonnet::deftex;
1.314     raeburn  6883:         if (ref($settings) eq 'HASH') {
                   6884:             if ($settings->{'texengine'}) {
                   6885:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   6886:                     $deftex = $settings->{'texengine'};
                   6887:                 }
                   6888:             }
                   6889:         }
                   6890:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6891:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   6892:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   6893:                        '</span></td><td class="LC_right_item">'.
                   6894:                        '<select name="texengine">'."\n";
                   6895:         my %texoptions = (
                   6896:                             MathJax  => 'MathJax',
                   6897:                             mimetex  => &mt('Convert to Images'),
                   6898:                             tth      => &mt('TeX to HTML'),
                   6899:                          );
                   6900:         foreach my $renderer ('MathJax','mimetex','tth') {
                   6901:             my $selected = '';
                   6902:             if ($renderer eq $deftex) {
                   6903:                 $selected = ' selected="selected"';
                   6904:             }
                   6905:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   6906:         }
                   6907:         $mathdisp .= '</select></td></tr>'."\n";
                   6908:         $itemcount ++;
1.139     raeburn  6909:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  6910:                                                      \%choices,$itemcount);
1.314     raeburn  6911:         $datatable = $mathdisp.$datatable;
1.264     raeburn  6912:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6913:         $datatable .=
1.306     raeburn  6914:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  6915:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   6916:             '</span></td><td class="LC_left_item">';
                   6917:         my $currcanclone = 'none';
                   6918:         my $onclick;
                   6919:         my @cloneoptions = ('none','domain');
1.380     raeburn  6920:         my %clonetitles = &Apache::lonlocal::texthash (
1.264     raeburn  6921:                              none     => 'No additional course requesters',
                   6922:                              domain   => "Any course requester in course's domain",
                   6923:                              instcode => 'Course requests for official courses ...',
                   6924:                           );
                   6925:         my (%codedefaults,@code_order,@posscodes);
                   6926:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   6927:                                                     \@code_order) eq 'ok') {
                   6928:             if (@code_order > 0) {
                   6929:                 push(@cloneoptions,'instcode');
                   6930:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   6931:             }
                   6932:         }
                   6933:         if (ref($settings) eq 'HASH') {
                   6934:             if ($settings->{'canclone'}) {
                   6935:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   6936:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   6937:                         if (@code_order > 0) {
                   6938:                             $currcanclone = 'instcode';
                   6939:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   6940:                         }
                   6941:                     }
                   6942:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   6943:                     $currcanclone = $settings->{'canclone'};
                   6944:                 }
                   6945:             }
1.289     raeburn  6946:         }
1.264     raeburn  6947:         foreach my $option (@cloneoptions) {
                   6948:             my ($checked,$additional);
                   6949:             if ($currcanclone eq $option) {
                   6950:                 $checked = ' checked="checked"';
                   6951:             }
                   6952:             if ($option eq 'instcode') {
                   6953:                 if (@code_order) {
                   6954:                     my $show = 'none';
                   6955:                     if ($checked) {
                   6956:                         $show = 'block';
                   6957:                     }
1.317     raeburn  6958:                     $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264     raeburn  6959:                                   &mt('Institutional codes for new and cloned course have identical:').
                   6960:                                   '<br />';
                   6961:                     foreach my $item (@code_order) {
                   6962:                         my $codechk;
                   6963:                         if ($checked) {
                   6964:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   6965:                                 $codechk = ' checked="checked"';
                   6966:                             }
                   6967:                         }
                   6968:                         $additional .= '<label>'.
                   6969:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   6970:                                        $item.'</label>';
                   6971:                     }
                   6972:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   6973:                 }
                   6974:             }
                   6975:             $datatable .=
                   6976:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   6977:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   6978:                 '</label>&nbsp;'.$additional.'</span><br />';
                   6979:         }
                   6980:         $datatable .= '</td>'.
                   6981:                       '</tr>';
                   6982:         $itemcount ++;
1.139     raeburn  6983:     } else {
                   6984:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  6985:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  6986:         my $currusecredits = 0;
1.257     raeburn  6987:         my $postsubmitclient = 1;
1.271     raeburn  6988:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  6989:         if (ref($settings) eq 'HASH') {
                   6990:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  6991:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   6992:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   6993:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   6994:                 }
                   6995:             }
1.192     raeburn  6996:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  6997:                 foreach my $type (@types) {
                   6998:                     next if ($type eq 'community');
                   6999:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   7000:                     if ($defcredits{$type} ne '') {
                   7001:                         $currusecredits = 1;
                   7002:                     }
                   7003:                 }
                   7004:             }
                   7005:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   7006:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   7007:                     $postsubmitclient = 0;
                   7008:                     foreach my $type (@types) {
                   7009:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7010:                     }
                   7011:                 } else {
                   7012:                     foreach my $type (@types) {
                   7013:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   7014:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  7015:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  7016:                             } else {
                   7017:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7018:                             }
                   7019:                         } else {
                   7020:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7021:                         }
                   7022:                     }
                   7023:                 }
                   7024:             } else {
                   7025:                 foreach my $type (@types) {
                   7026:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  7027:                 }
                   7028:             }
1.276     raeburn  7029:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   7030:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   7031:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   7032:                 }
                   7033:             } else {
                   7034:                 foreach my $type (@types) {
                   7035:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   7036:                 }
                   7037:             }
1.258     raeburn  7038:         } else {
                   7039:             foreach my $type (@types) {
                   7040:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   7041:             }
1.139     raeburn  7042:         }
                   7043:         if (!$currdefresponder) {
1.198     raeburn  7044:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  7045:         } elsif ($currdefresponder < 1) {
                   7046:             $currdefresponder = 1;
                   7047:         }
1.198     raeburn  7048:         foreach my $type (@types) {
                   7049:             if ($curruploadquota{$type} eq '') {
                   7050:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   7051:             }
                   7052:         }
1.139     raeburn  7053:         $datatable .=
1.192     raeburn  7054:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7055:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  7056:                 '</span></td>'.
                   7057:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7058:                 '<input type="text" name="anonsurvey_threshold"'.
                   7059:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  7060:                 '</td></tr>'."\n";
                   7061:         $itemcount ++;
                   7062:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7063:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7064:                       $choices{'uploadquota'}.
                   7065:                       '</span></td>'.
1.306     raeburn  7066:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  7067:                       '<table><tr>';
1.198     raeburn  7068:         foreach my $type (@types) {
1.306     raeburn  7069:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  7070:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   7071:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   7072:         }
                   7073:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  7074:         $itemcount ++;
1.236     raeburn  7075:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  7076:         my $display = 'none';
1.192     raeburn  7077:         if ($currusecredits) {
                   7078:             $display = 'block';
                   7079:         }
                   7080:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  7081:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   7082:         foreach my $type (@types) {
                   7083:             next if ($type eq 'community');
1.306     raeburn  7084:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7085:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  7086:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  7087:         }
                   7088:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  7089:         %defaultchecked = ('coursecredits' => 'off');
                   7090:         @toggles = ('coursecredits');
                   7091:         my $current = {
                   7092:                         'coursecredits' => $currusecredits,
                   7093:                       };
                   7094:         (my $table,$itemcount) =
                   7095:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  7096:                                \%choices,$itemcount,$onclick,$additional,'left');
                   7097:         $datatable .= $table;
                   7098:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   7099:         my $display = 'none';
                   7100:         if ($postsubmitclient) {
                   7101:             $display = 'block';
                   7102:         }
                   7103:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  7104:                       &mt('Number of seconds submit is disabled').'<br />'.
                   7105:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   7106:                       '<table><tr>';
1.257     raeburn  7107:         foreach my $type (@types) {
1.306     raeburn  7108:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7109:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   7110:                            $deftimeout{$type}.'" size="5" /></td>';
                   7111:         }
                   7112:         $additional .= '</tr></table></div>'."\n";
                   7113:         %defaultchecked = ('postsubmit' => 'on');
                   7114:         @toggles = ('postsubmit');
1.280     raeburn  7115:         $current = {
                   7116:                        'postsubmit' => $postsubmitclient,
                   7117:                    };
1.257     raeburn  7118:         ($table,$itemcount) =
                   7119:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   7120:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  7121:         $datatable .= $table;
1.276     raeburn  7122:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7123:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7124:                       $choices{'mysqltables'}.
                   7125:                       '</span></td>'.
1.306     raeburn  7126:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  7127:                       '<table><tr>';
                   7128:         foreach my $type (@types) {
1.306     raeburn  7129:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  7130:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  7131:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  7132:         }
                   7133:         $datatable .= '</tr></table></td></tr>'."\n";
                   7134:         $itemcount ++;
                   7135: 
1.139     raeburn  7136:     }
1.192     raeburn  7137:     $$rowtotal += $itemcount;
1.121     raeburn  7138:     return $datatable;
1.118     jms      7139: }
                   7140: 
1.231     raeburn  7141: sub print_selfenrollment {
                   7142:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7143:     my ($css_class,$datatable);
                   7144:     my $itemcount = 1;
1.271     raeburn  7145:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  7146:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  7147:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   7148:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  7149:         my @rows;
                   7150:         my $key;
                   7151:         if ($position eq 'top') {
                   7152:             $key = 'admin'; 
                   7153:             if (ref($rowsref) eq 'ARRAY') {
                   7154:                 @rows = @{$rowsref};
                   7155:             }
                   7156:         } elsif ($position eq 'middle') {
                   7157:             $key = 'default';
                   7158:             @rows = ('types','registered','approval','limit');
                   7159:         }
                   7160:         foreach my $row (@rows) {
                   7161:             if (defined($titlesref->{$row})) {
                   7162:                 $itemcount ++;
                   7163:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7164:                 $datatable .= '<tr'.$css_class.'>'.
                   7165:                               '<td>'.$titlesref->{$row}.'</td>'.
                   7166:                               '<td class="LC_left_item">'.
                   7167:                               '<table><tr>';
                   7168:                 my (%current,%currentcap);
                   7169:                 if (ref($settings) eq 'HASH') {
                   7170:                     if (ref($settings->{$key}) eq 'HASH') {
                   7171:                         foreach my $type (@types) {
                   7172:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7173:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   7174:                             }
                   7175:                             if (($row eq 'limit') && ($key eq 'default')) {
                   7176:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7177:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   7178:                                 }
                   7179:                             }
                   7180:                         }
                   7181:                     }
                   7182:                 }
                   7183:                 my %roles = (
                   7184:                              '0' => &Apache::lonnet::plaintext('dc'),
                   7185:                             ); 
                   7186:             
                   7187:                 foreach my $type (@types) {
                   7188:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   7189:                         $datatable .= '<th>'.&mt($type).'</th>';
                   7190:                     }
                   7191:                 }
                   7192:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   7193:                     $datatable .= '</tr><tr>';
                   7194:                 }
                   7195:                 foreach my $type (@types) {
                   7196:                     if ($type eq 'community') {
                   7197:                         $roles{'1'} = &mt('Community personnel');
                   7198:                     } else {
                   7199:                         $roles{'1'} = &mt('Course personnel');
                   7200:                     }
                   7201:                     $datatable .= '<td style="vertical-align: top">';
                   7202:                     if ($position eq 'top') {
                   7203:                         my %checked;
                   7204:                         if ($current{$type} eq '0') {
                   7205:                             $checked{'0'} = ' checked="checked"';
                   7206:                         } else {
                   7207:                             $checked{'1'} = ' checked="checked"';
                   7208:                         }
                   7209:                         foreach my $role ('1','0') {
                   7210:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7211:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   7212:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   7213:                                           $roles{$role}.'</label></span> ';
                   7214:                         }
                   7215:                     } else {
                   7216:                         if ($row eq 'types') {
                   7217:                             my %checked;
                   7218:                             if ($current{$type} =~ /^(all|dom)$/) {
                   7219:                                 $checked{$1} = ' checked="checked"';
                   7220:                             } else {
                   7221:                                 $checked{''} = ' checked="checked"';
                   7222:                             }
                   7223:                             foreach my $val ('','dom','all') {
                   7224:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7225:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7226:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7227:                             }
                   7228:                         } elsif ($row eq 'registered') {
                   7229:                             my %checked;
                   7230:                             if ($current{$type} eq '1') {
                   7231:                                 $checked{'1'} = ' checked="checked"';
                   7232:                             } else {
                   7233:                                 $checked{'0'} = ' checked="checked"';
                   7234:                             }
                   7235:                             foreach my $val ('0','1') {
                   7236:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7237:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7238:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7239:                             }
                   7240:                         } elsif ($row eq 'approval') {
                   7241:                             my %checked;
                   7242:                             if ($current{$type} =~ /^([12])$/) {
                   7243:                                 $checked{$1} = ' checked="checked"';
                   7244:                             } else {
                   7245:                                 $checked{'0'} = ' checked="checked"';
                   7246:                             }
                   7247:                             for my $val (0..2) {
                   7248:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7249:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7250:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7251:                             }
                   7252:                         } elsif ($row eq 'limit') {
                   7253:                             my %checked;
                   7254:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   7255:                                 $checked{$1} = ' checked="checked"';
                   7256:                             } else {
                   7257:                                 $checked{'none'} = ' checked="checked"';
                   7258:                             }
                   7259:                             my $cap;
                   7260:                             if ($currentcap{$type} =~ /^\d+$/) {
                   7261:                                 $cap = $currentcap{$type};
                   7262:                             }
                   7263:                             foreach my $val ('none','allstudents','selfenrolled') {
                   7264:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7265:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7266:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7267:                             }
                   7268:                             $datatable .= '<br />'.
                   7269:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   7270:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   7271:                                           '</span>'; 
                   7272:                         }
                   7273:                     }
                   7274:                     $datatable .= '</td>';
                   7275:                 }
                   7276:                 $datatable .= '</tr>';
                   7277:             }
                   7278:             $datatable .= '</table></td></tr>';
                   7279:         }
                   7280:     } elsif ($position eq 'bottom') {
1.235     raeburn  7281:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   7282:     }
                   7283:     $$rowtotal += $itemcount;
                   7284:     return $datatable;
                   7285: }
                   7286: 
                   7287: sub print_validation_rows {
                   7288:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   7289:     my ($itemsref,$namesref,$fieldsref);
                   7290:     if ($caller eq 'selfenroll') { 
                   7291:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   7292:     } elsif ($caller eq 'requestcourses') {
                   7293:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   7294:     }
                   7295:     my %currvalidation;
                   7296:     if (ref($settings) eq 'HASH') {
                   7297:         if (ref($settings->{'validation'}) eq 'HASH') {
                   7298:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  7299:         }
1.235     raeburn  7300:     }
                   7301:     my $datatable;
                   7302:     my $itemcount = 0;
                   7303:     foreach my $item (@{$itemsref}) {
                   7304:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7305:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7306:                       $namesref->{$item}.
                   7307:                       '</span></td>'.
                   7308:                       '<td class="LC_left_item">';
                   7309:         if (($item eq 'url') || ($item eq 'button')) {
                   7310:             $datatable .= '<span class="LC_nobreak">'.
                   7311:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   7312:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   7313:         } elsif ($item eq 'fields') {
                   7314:             my @currfields;
                   7315:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   7316:                 @currfields = @{$currvalidation{$item}};
                   7317:             }
                   7318:             foreach my $field (@{$fieldsref}) {
                   7319:                 my $check = '';
                   7320:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   7321:                     $check = ' checked="checked"';
                   7322:                 }
                   7323:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7324:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   7325:                               ' value="'.$field.'"'.$check.' />'.$field.
                   7326:                               '</label></span> ';
                   7327:             }
                   7328:         } elsif ($item eq 'markup') {
1.334     raeburn  7329:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235     raeburn  7330:                            $currvalidation{$item}.
1.231     raeburn  7331:                               '</textarea>';
1.235     raeburn  7332:         }
                   7333:         $datatable .= '</td></tr>'."\n";
                   7334:         if (ref($rowtotal)) {
1.231     raeburn  7335:             $itemcount ++;
                   7336:         }
                   7337:     }
1.235     raeburn  7338:     if ($caller eq 'requestcourses') {
                   7339:         my %currhash;
1.248     raeburn  7340:         if (ref($settings) eq 'HASH') {
                   7341:             if (ref($settings->{'validation'}) eq 'HASH') {
                   7342:                 if ($settings->{'validation'}{'dc'} ne '') {
                   7343:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   7344:                 }
1.235     raeburn  7345:             }
                   7346:         }
                   7347:         my $numinrow = 2;
                   7348:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   7349:                                                        'validationdc',%currhash);
1.247     raeburn  7350:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334     raeburn  7351:         $datatable .= '<tr'.$css_class.'><td>';
1.235     raeburn  7352:         if ($numdc > 1) {
1.247     raeburn  7353:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  7354:         } else {
1.247     raeburn  7355:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  7356:         }
1.247     raeburn  7357:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  7358:         $itemcount ++;
                   7359:     }
                   7360:     if (ref($rowtotal)) {
                   7361:         $$rowtotal += $itemcount;
                   7362:     }
1.231     raeburn  7363:     return $datatable;
                   7364: }
                   7365: 
1.357     raeburn  7366: sub print_privacy {
                   7367:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7368:     my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
                   7369:     my $itemcount = 0;
                   7370:     unless ($position eq 'top') {
                   7371:         @items = ('domain','author','course','community');
                   7372:         %names = &Apache::lonlocal::texthash (
                   7373:                      domain => 'Assigned domain role(s)',
                   7374:                      author => 'Assigned co-author role(s)',
                   7375:                      course => 'Assigned course role(s)',
                   7376:                      community => 'Assigned community role',
                   7377:                  );
                   7378:         $numinrow = 4;
                   7379:         ($othertitle,$usertypes,$types) =
                   7380:             &Apache::loncommon::sorted_inst_types($dom);
                   7381:     }
                   7382:     if (($position eq 'top') || ($position eq 'middle')) {
                   7383:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   7384:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   7385:         if ($position eq 'top') {
                   7386:             my %curr;
                   7387:             my @options = ('none','user','domain','auto');
                   7388:             my %titles = &Apache::lonlocal::texthash (
                   7389:                 none   => 'Not allowed',
                   7390:                 user   => 'User authorizes',
                   7391:                 domain => 'DC authorizes',
                   7392:                 auto   => 'Unrestricted',
                   7393:                 instdom => 'Other domain shares institution/provider',
                   7394:                 extdom => 'Other domain has different institution/provider',
                   7395:             );
                   7396:             my %names = &Apache::lonlocal::texthash (
                   7397:                 domain => 'Domain role',
                   7398:                 author => 'Co-author role',
                   7399:                 course => 'Course role',
                   7400:                 community => 'Community role',
                   7401:             );
                   7402:             my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7403:             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7404:             foreach my $domtype ('instdom','extdom') {
                   7405:                 my (%checked,$skip);
                   7406:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7407:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                   7408:                               '<td class="LC_left_item">';
                   7409:                 if ($domtype eq 'instdom') {
                   7410:                     unless (@instdoms > 1) {
                   7411:                         $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                   7412:                         $skip = 1;
                   7413:                     }
                   7414:                 } elsif ($domtype eq 'extdom') {
                   7415:                     if (keys(%by_location) == 0) {
                   7416:                         $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                   7417:                         $skip = 1;
                   7418:                     }
                   7419:                 }
                   7420:                 unless ($skip) {
                   7421:                     foreach my $roletype ('domain','author','course','community') {
                   7422:                         $checked{'auto'} = ' checked="checked"';
                   7423:                         if (ref($settings) eq 'HASH') {
                   7424:                             if (ref($settings->{approval}) eq 'HASH') {
                   7425:                                 if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                   7426:                                     if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                   7427:                                         $checked{$1} = ' checked="checked"';
                   7428:                                         $checked{'auto'} = '';
                   7429:                                     }
                   7430:                                 }
                   7431:                             }
                   7432:                         }
                   7433:                         $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                   7434:                         foreach my $option (@options) {
                   7435:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7436:                                           '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                   7437:                                           'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   7438:                                           '</label></span>&nbsp; ';
                   7439:                         }
                   7440:                         $datatable .= '</fieldset>';
                   7441:                     }
                   7442:                 }
                   7443:                 $datatable .= '</td></tr>';
                   7444:                 $itemcount ++;
                   7445:             }
                   7446:         } elsif ($position eq 'middle') {
                   7447:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   7448:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7449:                     foreach my $item (@{$types}) {
                   7450:                         $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                   7451:                                                                $numinrow,$itemcount,'','','','','',
                   7452:                                                                '',$usertypes->{$item});
                   7453:                         $itemcount ++;
                   7454:                     }
                   7455:                 }
                   7456:                 $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                   7457:                                                        $numinrow,$itemcount,'','','','','',
                   7458:                                                        '',$othertitle);
                   7459:                 $itemcount ++;
                   7460:             } else {
1.360     raeburn  7461:                 my (@insttypes,%insttitles);
                   7462:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7463:                     @insttypes = @{$types};
                   7464:                     %insttitles = %{$usertypes};
                   7465:                 }
                   7466:                 foreach my $item (@insttypes,'default') {
                   7467:                     my $title;
                   7468:                     if ($item eq 'default') {
                   7469:                         $title = $othertitle;
                   7470:                     } else {
                   7471:                         $title = $insttitles{$item};
                   7472:                     }
                   7473:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7474:                     $datatable .= '<tr'.$css_class.'>'.
                   7475:                                   '<td class="LC_left_item">'.$title.'</td>'.
                   7476:                                   '<td class="LC_left_item">'.
                   7477:                                   &mt('Nothing to set here, as there are no other domains').
                   7478:                                   '</td></tr>';
                   7479:                     $itemcount ++;
                   7480:                 }
1.357     raeburn  7481:             }
                   7482:         }
                   7483:     } else {
                   7484:         my $prefix;
                   7485:         if ($position eq 'lower') {
                   7486:             $prefix = 'priv';
                   7487:         } else {
                   7488:             $prefix = 'unpriv';
                   7489:         }
                   7490:         foreach my $item (@items) {
                   7491:             $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                   7492:                                                    $numinrow,$itemcount,'','','','','',
                   7493:                                                    '',$names{$item});
                   7494:             $itemcount ++;
                   7495:         }
                   7496:     }
                   7497:     if (ref($rowtotal)) {
                   7498:         $$rowtotal += $itemcount;
                   7499:     }
                   7500:     return $datatable;
                   7501: }
                   7502: 
1.354     raeburn  7503: sub print_passwords {
                   7504:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   7505:     my ($datatable,$css_class);
                   7506:     my $itemcount = 0;
                   7507:     my %titles = &Apache::lonlocal::texthash (
                   7508:         captcha        => '"Forgot Password" CAPTCHA validation',
                   7509:         link           => 'Reset link expiration (hours)',
                   7510:         case           => 'Case-sensitive usernames/e-mail',
                   7511:         prelink        => 'Information required (form 1)',
                   7512:         postlink       => 'Information required (form 2)',
                   7513:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   7514:         customtext     => 'Domain specific text (HTML)',
                   7515:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   7516:         intauth_check  => 'Check bcrypt cost if authenticated',
                   7517:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   7518:         permanent      => 'Permanent e-mail address',
                   7519:         critical       => 'Critical notification address',
                   7520:         notify         => 'Notification address',
                   7521:         min            => 'Minimum password length',
                   7522:         max            => 'Maximum password length',
                   7523:         chars          => 'Required characters',
                   7524:         expire         => 'Password expiration (days)',
1.356     raeburn  7525:         numsaved       => 'Number of previous passwords to save and disallow reuse',
1.354     raeburn  7526:     );
                   7527:     if ($position eq 'top') {
                   7528:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7529:         my $shownlinklife = 2;
                   7530:         my $prelink = 'both';
                   7531:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   7532:         if (ref($settings) eq 'HASH') {
                   7533:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   7534:                 $shownlinklife = $settings->{resetlink};
                   7535:             }
                   7536:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   7537:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   7538:             }
                   7539:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   7540:                 $prelink = $settings->{resetprelink};
                   7541:             }
                   7542:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   7543:                 %postlink = %{$settings->{resetpostlink}};
                   7544:             }
                   7545:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   7546:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   7547:             }
                   7548:             if ($settings->{resetremove}) {
                   7549:                 $nostdtext = 1;
                   7550:             }
                   7551:             if ($settings->{resetcustom}) {
                   7552:                 $customurl = $settings->{resetcustom};
                   7553:             }
                   7554:         } else {
                   7555:             if (ref($types) eq 'ARRAY') {
                   7556:                 foreach my $item (@{$types}) {
                   7557:                     $casesens{$item} = 1;
                   7558:                     $postlink{$item} = ['username','email'];
                   7559:                 }
                   7560:             }
                   7561:             $casesens{'default'} = 1;
                   7562:             $postlink{'default'} = ['username','email'];
                   7563:             $prelink = 'both';
                   7564:             %emailsrc = (
                   7565:                           permanent => 1,
                   7566:                           critical  => 1,
                   7567:                           notify    => 1,
                   7568:             );
                   7569:         }
                   7570:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   7571:         $itemcount ++;
                   7572:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7573:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   7574:                       '<td class="LC_left_item">'.
                   7575:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   7576:                       'name="passwords_link" size="3" /></td></tr>';
                   7577:         $itemcount ++;
                   7578:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7579:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   7580:                       '<td class="LC_left_item">';
                   7581:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7582:             foreach my $item (@{$types}) {
                   7583:                 my $checkedcase;
                   7584:                 if ($casesens{$item}) {
                   7585:                     $checkedcase = ' checked="checked"';
                   7586:                 }
                   7587:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7588:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   7589:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369     raeburn  7590:                               '</span>&nbsp;&nbsp; ';
1.354     raeburn  7591:             }
                   7592:         }
                   7593:         my $checkedcase;
                   7594:         if ($casesens{'default'}) {
                   7595:             $checkedcase = ' checked="checked"';
                   7596:         }
                   7597:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   7598:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   7599:                       $othertitle.'</label></span></td>';
                   7600:         $itemcount ++;
                   7601:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7602:         my %checkedpre = (
                   7603:                              both => ' checked="checked"',
                   7604:                              either => '',
                   7605:                          );
                   7606:         if ($prelink eq 'either') {
                   7607:             $checkedpre{either} = ' checked="checked"';
                   7608:             $checkedpre{both} = '';
                   7609:         }
                   7610:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   7611:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   7612:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   7613:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   7614:                       '<span class="LC_nobreak"><label>'.
                   7615:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   7616:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   7617:         $itemcount ++;
                   7618:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7619:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   7620:                       '<td class="LC_left_item">';
                   7621:         my %postlinked;
                   7622:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7623:             foreach my $item (@{$types}) {
                   7624:                 undef(%postlinked);
                   7625:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   7626:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   7627:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   7628:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   7629:                 }
                   7630:                 foreach my $field ('email','username') {
                   7631:                     my $checked;
                   7632:                     if ($postlinked{$field}) {
                   7633:                         $checked = ' checked="checked"';
                   7634:                     }
                   7635:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   7636:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   7637:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   7638:                                   '<span>&nbsp;&nbsp; ';
                   7639:                 }
                   7640:                 $datatable .= '</fieldset>';
                   7641:             }
                   7642:         }
                   7643:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   7644:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   7645:         }
                   7646:         $datatable .= '<fieldset style="display: inline-block;">'.
                   7647:                       '<legend>'.$othertitle.'</legend>';
                   7648:         foreach my $field ('email','username') {
                   7649:             my $checked;
                   7650:             if ($postlinked{$field}) {
                   7651:                 $checked = ' checked="checked"';
                   7652:             }
                   7653:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7654:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   7655:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   7656:                           '<span>&nbsp;&nbsp; ';
                   7657:         }
                   7658:         $datatable .= '</fieldset></td></tr>';
                   7659:         $itemcount ++;
                   7660:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7661:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   7662:                       '<td class="LC_left_item">';
                   7663:         foreach my $type ('permanent','critical','notify') {
                   7664:             my $checkedemail;
                   7665:             if ($emailsrc{$type}) {
                   7666:                 $checkedemail = ' checked="checked"';
                   7667:             }
                   7668:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7669:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   7670:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   7671:                           '<span>&nbsp;&nbsp; ';
                   7672:         }
                   7673:         $datatable .= '</td></tr>';
                   7674:         $itemcount ++;
                   7675:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7676:         my $switchserver = &check_switchserver($dom,$confname);
                   7677:         my ($showstd,$noshowstd);
                   7678:         if ($nostdtext) {
                   7679:             $noshowstd = ' checked="checked"';
                   7680:         } else {
                   7681:             $showstd = ' checked="checked"';
                   7682:         }
                   7683:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   7684:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   7685:                       &mt('Retain standard text:').
                   7686:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   7687:                       &mt('Yes').'</label>'.'&nbsp;'.
                   7688:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   7689:                       &mt('No').'</label></span><br />'.
                   7690:                       '<span class="LC_fontsize_small">'.
                   7691:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   7692:                       &mt('Include custom text:');
                   7693:         if ($customurl) {
1.369     raeburn  7694:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354     raeburn  7695:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   7696:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   7697:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   7698:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   7699:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   7700:         }
                   7701:         if ($switchserver) {
                   7702:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   7703:         } else {
                   7704:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   7705:                          '<input type="file" name="passwords_customfile" /></span>';
                   7706:         }
                   7707:         $datatable .= '</td></tr>';
                   7708:     } elsif ($position eq 'middle') {
                   7709:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   7710:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   7711:         my %defaults;
                   7712:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   7713:             %defaults = %{$domconf{'defaults'}};
                   7714:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   7715:                 $defaults{'intauth_cost'} = 10;
                   7716:             }
                   7717:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   7718:                 $defaults{'intauth_check'} = 0;
                   7719:             }
                   7720:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   7721:                 $defaults{'intauth_switch'} = 0;
                   7722:             }
                   7723:         } else {
                   7724:             %defaults = (
                   7725:                           'intauth_cost'   => 10,
                   7726:                           'intauth_check'  => 0,
                   7727:                           'intauth_switch' => 0,
                   7728:                         );
                   7729:         }
                   7730:         foreach my $item (@items) {
                   7731:             if ($itemcount%2) {
                   7732:                 $css_class = '';
                   7733:             } else {
                   7734:                 $css_class = ' class="LC_odd_row" ';
                   7735:             }
                   7736:             $datatable .= '<tr'.$css_class.'>'.
                   7737:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   7738:                           '</span></td><td class="LC_left_item" colspan="3">';
                   7739:             if ($item eq 'intauth_switch') {
                   7740:                 my @options = (0,1,2);
                   7741:                 my %optiondesc = &Apache::lonlocal::texthash (
                   7742:                                    0 => 'No',
                   7743:                                    1 => 'Yes',
                   7744:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   7745:                                  );
                   7746:                 $datatable .= '<table width="100%">';
                   7747:                 foreach my $option (@options) {
                   7748:                     my $checked = ' ';
                   7749:                     if ($defaults{$item} eq $option) {
                   7750:                         $checked = ' checked="checked"';
                   7751:                     }
                   7752:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   7753:                                   '<label><input type="radio" name="'.$item.
                   7754:                                   '" value="'.$option.'"'.$checked.' />'.
                   7755:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   7756:                 }
                   7757:                 $datatable .= '</table>';
                   7758:             } elsif ($item eq 'intauth_check') {
                   7759:                 my @options = (0,1,2);
                   7760:                 my %optiondesc = &Apache::lonlocal::texthash (
                   7761:                                    0 => 'No',
                   7762:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   7763:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   7764:                                  );
                   7765:                 $datatable .= '<table width="100%">';
                   7766:                 foreach my $option (@options) {
                   7767:                     my $checked = ' ';
                   7768:                     my $onclick;
                   7769:                     if ($defaults{$item} eq $option) {
                   7770:                         $checked = ' checked="checked"';
                   7771:                     }
                   7772:                     if ($option == 2) {
                   7773:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   7774:                     }
                   7775:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   7776:                                   '<label><input type="radio" name="'.$item.
                   7777:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   7778:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   7779:                 }
                   7780:                 $datatable .= '</table>';
                   7781:             } else {
                   7782:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   7783:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   7784:             }
                   7785:             $datatable .= '</td></tr>';
                   7786:             $itemcount ++;
                   7787:         }
                   7788:     } elsif ($position eq 'lower') {
1.356     raeburn  7789:         my ($min,$max,%chars,$expire,$numsaved);
1.365     raeburn  7790:         $min = $Apache::lonnet::passwdmin;
1.354     raeburn  7791:         if (ref($settings) eq 'HASH') {
                   7792:             if ($settings->{min}) {
                   7793:                 $min = $settings->{min};
                   7794:             }
                   7795:             if ($settings->{max}) {
                   7796:                 $max = $settings->{max};
                   7797:             }
                   7798:             if (ref($settings->{chars}) eq 'ARRAY') {
                   7799:                 map { $chars{$_} = 1; } (@{$settings->{chars}});
                   7800:             }
                   7801:             if ($settings->{expire}) {
                   7802:                 $expire = $settings->{expire};
                   7803:             }
1.358     raeburn  7804:             if ($settings->{numsaved}) {
                   7805:                 $numsaved = $settings->{numsaved};
1.356     raeburn  7806:             }
1.354     raeburn  7807:         }
                   7808:         my %rulenames = &Apache::lonlocal::texthash(
                   7809:                                                      uc => 'At least one upper case letter',
                   7810:                                                      lc => 'At least one lower case letter',
                   7811:                                                      num => 'At least one number',
                   7812:                                                      spec => 'At least one non-alphanumeric',
                   7813:                                                    );
                   7814:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7815:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   7816:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7817:                       '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
                   7818:                       'onblur="javascript:warnIntPass(this);" />'.
                   7819:                       '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354     raeburn  7820:                       '</span></td></tr>';
                   7821:         $itemcount ++;
                   7822:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7823:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   7824:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7825:                       '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
                   7826:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  7827:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   7828:                       '</span></td></tr>';
                   7829:         $itemcount ++;
                   7830:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7831:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   7832:                       '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   7833:                       '</span></td>';
                   7834:         my $numinrow = 2;
                   7835:         my @possrules = ('uc','lc','num','spec');
                   7836:         $datatable .= '<td class="LC_left_item"><table>';
                   7837:         for (my $i=0; $i<@possrules; $i++) {
                   7838:             my ($rem,$checked);
                   7839:             if ($chars{$possrules[$i]}) {
                   7840:                 $checked = ' checked="checked"';
                   7841:             }
                   7842:             $rem = $i%($numinrow);
                   7843:             if ($rem == 0) {
                   7844:                 if ($i > 0) {
                   7845:                     $datatable .= '</tr>';
                   7846:                 }
                   7847:                 $datatable .= '<tr>';
                   7848:             }
                   7849:             $datatable .= '<td><span class="LC_nobreak"><label>'.
                   7850:                           '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   7851:                           $rulenames{$possrules[$i]}.'</label></span></td>';
                   7852:         }
                   7853:         my $rem = @possrules%($numinrow);
                   7854:         my $colsleft = $numinrow - $rem;
                   7855:         if ($colsleft > 1 ) {
                   7856:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7857:                           '&nbsp;</td>';
                   7858:         } elsif ($colsleft == 1) {
                   7859:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   7860:         }
                   7861:         $datatable .='</table></td></tr>';
                   7862:         $itemcount ++;
                   7863:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7864:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                   7865:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7866:                       '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
                   7867:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  7868:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                   7869:                       '</span></td></tr>';
1.356     raeburn  7870:         $itemcount ++;
                   7871:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7872:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   7873:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367     raeburn  7874:                       '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
                   7875:                       'onblur="javascript:warnIntPass(this);" />'. 
1.356     raeburn  7876:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   7877:                       '</span></td></tr>';
1.354     raeburn  7878:     } else {
1.359     raeburn  7879:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7880:         my %ownerchg = (
                   7881:                           by  => {},
                   7882:                           for => {},
                   7883:                        );
                   7884:         my %ownertitles = &Apache::lonlocal::texthash (
                   7885:                             by  => 'Course owner status(es) allowed',
                   7886:                             for => 'Student status(es) allowed',
                   7887:                           );
1.354     raeburn  7888:         if (ref($settings) eq 'HASH') {
1.359     raeburn  7889:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   7890:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   7891:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   7892:                 }
                   7893:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   7894:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   7895:                 }
1.354     raeburn  7896:             }
                   7897:         }
                   7898:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7899:         $datatable .= '<tr '.$css_class.'>'.
                   7900:                       '<td>'.
                   7901:                       &mt('Requirements').'<ul>'.
1.359     raeburn  7902:                       '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354     raeburn  7903:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   7904:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359     raeburn  7905:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354     raeburn  7906:                       '</ul>'.
                   7907:                       '</td>'.
1.359     raeburn  7908:                       '<td class="LC_left_item">';
                   7909:         foreach my $item ('by','for') {
                   7910:             $datatable .= '<fieldset style="display: inline-block;">'.
                   7911:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   7912:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7913:                 foreach my $type (@{$types}) {
                   7914:                     my $checked;
                   7915:                     if ($ownerchg{$item}{$type}) {
                   7916:                         $checked = ' checked="checked"';
                   7917:                     }
                   7918:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   7919:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   7920:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369     raeburn  7921:                                   '</span>&nbsp;&nbsp; ';
1.359     raeburn  7922:                 }
                   7923:             }
                   7924:             my $checked;
                   7925:             if ($ownerchg{$item}{'default'}) {
                   7926:                 $checked = ' checked="checked"';
                   7927:             }
                   7928:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   7929:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   7930:                           $othertitle.'</label></span></fieldset>';
                   7931:         }
                   7932:         $datatable .= '</td></tr>';
1.354     raeburn  7933:     }
                   7934:     return $datatable;
                   7935: }
                   7936: 
1.373     raeburn  7937: sub print_wafproxy {
                   7938:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7939:     my $css_class;
                   7940:     my $itemcount = 0;
                   7941:     my $datatable;
                   7942:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  7943:     my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374     raeburn  7944:     my %lt = &wafproxy_titles();
1.373     raeburn  7945:     foreach my $server (sort(keys(%servers))) {
                   7946:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381     raeburn  7947:         next if ($serverhome eq '');
1.373     raeburn  7948:         my $serverdom;
                   7949:         if ($serverhome ne $server) {
                   7950:             $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381     raeburn  7951:             if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
                   7952:                 $othercontrol{$server} = $serverdom;
                   7953:             }
1.373     raeburn  7954:         } else {
                   7955:             $serverdom = &Apache::lonnet::host_domain($server);
1.381     raeburn  7956:             next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373     raeburn  7957:             if ($serverdom ne $dom) {
                   7958:                 $othercontrol{$server} = $serverdom;
                   7959:             } else {
                   7960:                 $setdom = 1;
                   7961:                 if (ref($settings) eq 'HASH') {
                   7962:                     if (ref($settings->{'alias'}) eq 'HASH') {
                   7963:                         $aliases{$dom} = $settings->{'alias'};
1.381     raeburn  7964:                         if ($aliases{$dom} ne '') {
                   7965:                             $showdom = 1;
                   7966:                         }
1.373     raeburn  7967:                     }
1.388     raeburn  7968:                     if (ref($settings->{'saml'}) eq 'HASH') {
                   7969:                         $saml{$dom} = $settings->{'saml'};
                   7970:                     }
1.373     raeburn  7971:                 }
                   7972:             }
                   7973:         }
                   7974:     }
1.381     raeburn  7975:     if ($setdom) {
                   7976:         %{$values{$dom}} = ();
                   7977:         if (ref($settings) eq 'HASH') {
                   7978:             foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   7979:                 $values{$dom}{$item} = $settings->{$item};
                   7980:             }
                   7981:         }
                   7982:     }
1.373     raeburn  7983:     if (keys(%othercontrol)) {
                   7984:         %otherdoms = reverse(%othercontrol);
                   7985:         foreach my $domain (keys(%otherdoms)) {
                   7986:             %{$values{$domain}} = ();
                   7987:             my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383     raeburn  7988:             if (ref($config{'wafproxy'}) eq 'HASH') {
                   7989:                 $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388     raeburn  7990:                 if (exists($config{'wafproxy'}{'saml'})) { 
                   7991:                     $saml{$domain} = $config{'wafproxy'}{'saml'};
                   7992:                 }
1.383     raeburn  7993:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   7994:                     $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373     raeburn  7995:                 }
                   7996:             }
                   7997:         }
                   7998:     }
                   7999:     if ($position eq 'top') {
                   8000:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381     raeburn  8001:         my %aliasinfo;
1.373     raeburn  8002:         foreach my $server (sort(keys(%servers))) {
1.381     raeburn  8003:             $itemcount ++;
                   8004:             my $dom_in_effect;
                   8005:             my $aliasrows = '<tr>'.
1.383     raeburn  8006:                             '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8007:                             &mt('Hostname').':&nbsp;'.
                   8008:                             '<i>'.&Apache::lonnet::hostname($server).'</i></td><td>&nbsp;</td>';
1.373     raeburn  8009:             if ($othercontrol{$server}) {
1.381     raeburn  8010:                 $dom_in_effect = $othercontrol{$server};
1.388     raeburn  8011:                 my ($current,$forsaml);
1.383     raeburn  8012:                 if (ref($aliases{$dom_in_effect}) eq 'HASH') {
                   8013:                     $current = $aliases{$dom_in_effect}{$server};
1.373     raeburn  8014:                 }
1.388     raeburn  8015:                 if (ref($saml{$dom_in_effect}) eq 'HASH') {
                   8016:                     if ($saml{$dom_in_effect}{$server}) {
                   8017:                         $forsaml = 1;
                   8018:                     }
                   8019:                 }
1.383     raeburn  8020:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8021:                               &mt('Alias').':&nbsp';
1.373     raeburn  8022:                 if ($current) {
1.381     raeburn  8023:                     $aliasrows .= $current;
1.388     raeburn  8024:                     if ($forsaml) {
1.396     raeburn  8025:                          $aliasrows .= '&nbsp;('.&mt('also for SSO Auth').')';
1.388     raeburn  8026:                     }
1.373     raeburn  8027:                 } else {
1.383     raeburn  8028:                     $aliasrows .= &mt('None');
1.373     raeburn  8029:                 }
1.383     raeburn  8030:                 $aliasrows .= '&nbsp;<span class="LC_small">('.
                   8031:                               &mt('controlled by domain: [_1]',
                   8032:                                   '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373     raeburn  8033:             } else {
1.381     raeburn  8034:                 $dom_in_effect = $dom;
1.388     raeburn  8035:                 my ($current,$samlon,$samloff);
                   8036:                 $samloff = ' checked="checked"';
1.373     raeburn  8037:                 if (ref($aliases{$dom}) eq 'HASH') {
                   8038:                     if ($aliases{$dom}{$server}) {
                   8039:                         $current = $aliases{$dom}{$server};
                   8040:                     }
                   8041:                 }
1.388     raeburn  8042:                 if (ref($saml{$dom}) eq 'HASH') {
                   8043:                     if ($saml{$dom}{$server}) {
                   8044:                         $samlon = $samloff;
                   8045:                         undef($samloff);
                   8046:                     }
                   8047:                 }
1.383     raeburn  8048:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   8049:                               &mt('Alias').':&nbsp;'.
1.381     raeburn  8050:                               '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388     raeburn  8051:                               'value="'.$current.'" size="30" />'.
                   8052:                               ('&nbsp;'x2).'<span class="LC_nobreak">'.
1.396     raeburn  8053:                               &mt('Alias used for SSO Auth').':&nbsp;<label>'.
1.388     raeburn  8054:                               '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
                   8055:                               &mt('No').'</label>&nbsp;<label>'. 
                   8056:                               '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
                   8057:                               &mt('Yes').'</label></span>'.
                   8058:                               '</td>'; 
1.381     raeburn  8059:             }
                   8060:             $aliasrows .= '</tr>';
                   8061:             $aliasinfo{$dom_in_effect} .= $aliasrows;
                   8062:         }
                   8063:         if ($aliasinfo{$dom}) {
                   8064:             my ($onclick,$wafon,$wafoff,$showtable);
                   8065:             $onclick = ' onclick="javascript:toggleWAF();"';
                   8066:             $wafoff = ' checked="checked"';
                   8067:             $showtable = ' style="display:none";';
                   8068:             if ($showdom) {
                   8069:                 $wafon = $wafoff;
                   8070:                 $wafoff = '';
                   8071:                 $showtable = ' style="display:inline;"';
                   8072:             }
                   8073:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8074:             $datatable = '<tr'.$css_class.'>'.
                   8075:                          '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
                   8076:                          '<span class="LC_nobreak">'.&mt('WAF in use?').'&nbsp;<label>'.
                   8077:                          '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
                   8078:                          &mt('Yes').'</label>'.('&nbsp;'x2).'<label>'.
                   8079:                          '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
                   8080:                          &mt('No').'</label></span></td>'.
                   8081:                          '<td class="LC_left_item">'.
                   8082:                          '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
                   8083:                          '</table></td></tr>';
                   8084:             $itemcount++;
                   8085:         }
1.383     raeburn  8086:         if (keys(%otherdoms)) {
                   8087:             foreach my $key (sort(keys(%otherdoms))) {
1.381     raeburn  8088:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383     raeburn  8089:                 $datatable .= '<tr'.$css_class.'>'.
                   8090:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
                   8091:                               '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
                   8092:                               '</table></td></tr>';
1.381     raeburn  8093:                 $itemcount++;
1.373     raeburn  8094:             }
                   8095:         }
                   8096:     } else {
1.383     raeburn  8097:         my %ip_methods = &remoteip_methods();
1.373     raeburn  8098:         if ($setdom) {
                   8099:             $itemcount ++;
                   8100:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381     raeburn  8101:             my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382     raeburn  8102:                 $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381     raeburn  8103:             $wafstyle = ' style="display:none;"';
                   8104:             $nowafstyle = ' style="display:table-row;"';
                   8105:             $currwafdisplay = ' style="display: none"';
                   8106:             $wafrangestyle = ' style="display: none"';
                   8107:             $curr_remotip = 'n';
1.382     raeburn  8108:             $ssltossl = ' checked="checked"';
1.381     raeburn  8109:             if ($showdom) {
                   8110:                 $wafstyle = ' style="display:table-row;"';
                   8111:                 $nowafstyle =  ' style="display:none;"';
                   8112:                 if (keys(%{$values{$dom}})) {
                   8113:                     if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
                   8114:                         $curr_remotip = $values{$dom}{remoteip};
                   8115:                     }
                   8116:                     if ($curr_remotip eq 'h') {
                   8117:                         $currwafdisplay = ' style="display:table-row"';
                   8118:                         $wafrangestyle = ' style="display:inline-block;"';
                   8119:                     }
1.382     raeburn  8120:                     if ($values{$dom}{'sslopt'}) {
                   8121:                         $alltossl = ' checked="checked"';
                   8122:                         $ssltossl = '';
                   8123:                     }
1.381     raeburn  8124:                 }
                   8125:                 if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
                   8126:                     $vpndircheck = ' checked="checked"';
                   8127:                     $currwafvpn = ' style="display:table-row;"';
                   8128:                     $wafrangestyle = ' style="display:inline-block;"';
                   8129:                 } else {
                   8130:                     $vpnaliascheck = ' checked="checked"';
                   8131:                     $currwafvpn = ' style="display:none;"';
                   8132:                 }
                   8133:             }
                   8134:             $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                   8135:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
                   8136:                           '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
                   8137:                           '</tr>'.
                   8138:                           '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374     raeburn  8139:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381     raeburn  8140:                           '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393     raeburn  8141:                           &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   8142:                           &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381     raeburn  8143:                           '<td class="LC_left_item"><table>'.
                   8144:                           '<tr>'.
                   8145:                           '<td valign="top">'.$lt{'remoteip'}.':&nbsp;'.
                   8146:                           '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
                   8147:             foreach my $option ('m','h','n') {
                   8148:                 my $sel;
                   8149:                 if ($option eq $curr_remotip) {
                   8150:                    $sel = ' selected="selected"';
                   8151:                 }
                   8152:                 $datatable .= '<option value="'.$option.'"'.$sel.'>'.
                   8153:                               $ip_methods{$option}.'</option>';
                   8154:             }
                   8155:             $datatable .= '</select></td></tr>'."\n".
                   8156:                           '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
                   8157:                           $lt{'ipheader'}.':&nbsp;'.
                   8158:                           '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
                   8159:                           'name="wafproxy_ipheader" />'.
                   8160:                           '</td></tr>'."\n".
                   8161:                           '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382     raeburn  8162:                           $lt{'trusted'}.':<br />'.
1.381     raeburn  8163:                           '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
                   8164:                           $values{$dom}{'trusted'}.'</textarea>'.
                   8165:                           '</td></tr>'."\n".
                   8166:                           '<tr><td><hr /></td></tr>'."\n".
                   8167:                           '<tr>'.
                   8168:                           '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
                   8169:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
                   8170:                           $lt{'vpndirect'}.'</label>'.('&nbsp;'x2).
                   8171:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
                   8172:                           $lt{'vpnaliased'}.'</label></span></td></tr>';
                   8173:             foreach my $item ('vpnint','vpnext') {
                   8174:                 $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382     raeburn  8175:                               '<td valign="top">'.$lt{$item}.':<br />'.
1.381     raeburn  8176:                               '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
                   8177:                               $values{$dom}{$item}.'</textarea>'.
                   8178:                               '</td></tr>'."\n";
1.373     raeburn  8179:             }
1.382     raeburn  8180:             $datatable .= '<tr><td><hr /></td></tr>'."\n".
                   8181:                           '<tr>'.
                   8182:                           '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
                   8183:                           '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
                   8184:                           $lt{'alltossl'}.'</label>'.('&nbsp;'x2).
                   8185:                           '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
                   8186:                           $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
                   8187:                           '</table></td></tr>';
1.373     raeburn  8188:         }
                   8189:         if (keys(%otherdoms)) {
                   8190:             foreach my $domain (sort(keys(%otherdoms))) {
                   8191:                 $itemcount ++;
                   8192:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8193:                 $datatable .= '<tr'.$css_class.'>'.
1.383     raeburn  8194:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374     raeburn  8195:                               '<td class="LC_left_item"><table>';
1.382     raeburn  8196:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  8197:                     my $showval = &mt('None');
1.382     raeburn  8198:                     if ($item eq 'ssl') {
                   8199:                         $showval = $lt{'ssltossl'};
                   8200:                     }
1.373     raeburn  8201:                     if ($values{$domain}{$item}) {
1.381     raeburn  8202:                         $showval = $values{$domain}{$item};
1.382     raeburn  8203:                         if ($item eq 'ssl') {
                   8204:                             $showval = $lt{'alltossl'};
1.383     raeburn  8205:                         } elsif ($item eq 'remoteip') {
                   8206:                             $showval = $ip_methods{$values{$domain}{$item}};
1.382     raeburn  8207:                         }
1.373     raeburn  8208:                     }
                   8209:                     $datatable .= '<tr>'.
                   8210:                                   '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';
                   8211:                 }
1.381     raeburn  8212:                 $datatable .= '</table></td></tr>';
1.373     raeburn  8213:             }
                   8214:         }
                   8215:     }
                   8216:     $$rowtotal += $itemcount;
                   8217:     return $datatable;
                   8218: }
                   8219: 
                   8220: sub wafproxy_titles {
                   8221:     return &Apache::lonlocal::texthash(
1.381     raeburn  8222:                remoteip   => "Method for determining user's IP",
                   8223:                ipheader   => 'Request header containing remote IP',
                   8224:                trusted    => 'Trusted IP range(s)',
                   8225:                vpnaccess  => 'Access from institutional VPN',
                   8226:                vpndirect  => 'via regular hostname (no WAF)',
                   8227:                vpnaliased => 'via aliased hostname (WAF)',
                   8228:                vpnint     => 'Internal IP Range(s) for VPN sessions',
                   8229:                vpnext     => 'IP Range(s) for backend WAF connections',
1.382     raeburn  8230:                sslopt     => 'Forwarding http/https',
1.381     raeburn  8231:                alltossl   => 'WAF forwards both http and https requests to https',
                   8232:                ssltossl   => 'WAF forwards http requests to http and https to https',
                   8233:            );
                   8234: }
                   8235: 
                   8236: sub remoteip_methods {
                   8237:     return &Apache::lonlocal::texthash(
                   8238:               m => 'Use Apache mod_remoteip',
                   8239:               h => 'Use headers parsed by LON-CAPA',
                   8240:               n => 'Not in use',
1.373     raeburn  8241:            );
                   8242: }
                   8243: 
1.137     raeburn  8244: sub print_usersessions {
                   8245:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  8246:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  8247:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8248:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  8249: 
                   8250:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  8251:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  8252:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  8253:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  8254:     if ($position eq 'top') {
1.152     raeburn  8255:         if (keys(%serverhomes) > 1) {
1.145     raeburn  8256:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.371     raeburn  8257:             my ($curroffloadnow,$curroffloadoth);
1.261     raeburn  8258:             if (ref($settings) eq 'HASH') {
                   8259:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   8260:                     $curroffloadnow = $settings->{'offloadnow'};
                   8261:                 }
1.371     raeburn  8262:                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   8263:                     $curroffloadoth = $settings->{'offloadoth'};
                   8264:                 }
1.261     raeburn  8265:             }
1.371     raeburn  8266:             my $other_insts = scalar(keys(%by_location));
                   8267:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   8268:                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  8269:         } else {
1.140     raeburn  8270:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  8271:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   8272:                           '</td></tr>';
1.140     raeburn  8273:         }
1.137     raeburn  8274:     } else {
1.279     raeburn  8275:         my %titles = &usersession_titles();
                   8276:         my ($prefix,@types);
                   8277:         if ($position eq 'bottom') {
                   8278:             $prefix = 'remote';
                   8279:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  8280:         } else {
1.279     raeburn  8281:             $prefix = 'hosted';
                   8282:             @types = ('excludedomain','includedomain');
                   8283:         }
                   8284:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8285:     }
                   8286:     $$rowtotal += $itemcount;
                   8287:     return $datatable;
                   8288: }
                   8289: 
                   8290: sub rules_by_location {
                   8291:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   8292:     my ($datatable,$itemcount,$css_class);
                   8293:     if (keys(%{$by_location}) == 0) {
                   8294:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8295:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   8296:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   8297:                      '</td></tr>';
                   8298:         $itemcount = 1;
                   8299:     } else {
                   8300:         $itemcount = 0;
                   8301:         my $numinrow = 5;
                   8302:         my (%current,%checkedon,%checkedoff);
                   8303:         my @locations = sort(keys(%{$by_location}));
                   8304:         foreach my $type (@{$types}) {
                   8305:             $checkedon{$type} = '';
                   8306:             $checkedoff{$type} = ' checked="checked"';
                   8307:         }
                   8308:         if (ref($settings) eq 'HASH') {
                   8309:             if (ref($settings->{$prefix}) eq 'HASH') {
                   8310:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   8311:                     $current{$key} = $settings->{$prefix}{$key};
                   8312:                     if ($key eq 'version') {
                   8313:                         if ($current{$key} ne '') {
1.145     raeburn  8314:                             $checkedon{$key} = ' checked="checked"';
                   8315:                             $checkedoff{$key} = '';
                   8316:                         }
1.279     raeburn  8317:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   8318:                         $checkedon{$key} = ' checked="checked"';
                   8319:                         $checkedoff{$key} = '';
1.137     raeburn  8320:                     }
                   8321:                 }
                   8322:             }
1.279     raeburn  8323:         }
                   8324:         foreach my $type (@{$types}) {
                   8325:             next if ($type ne 'version' && !@locations);
                   8326:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8327:             $datatable .= '<tr'.$css_class.'>
                   8328:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   8329:                            <span class="LC_nobreak">&nbsp;
                   8330:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   8331:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   8332:             if ($type eq 'version') {
                   8333:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   8334:                 my $selector = '<select name="'.$prefix.'_version">';
                   8335:                 foreach my $version (@lcversions) {
                   8336:                     my $selected = '';
                   8337:                     if ($current{'version'} eq $version) {
                   8338:                         $selected = ' selected="selected"';
1.145     raeburn  8339:                     }
1.279     raeburn  8340:                     $selector .= ' <option value="'.$version.'"'.
                   8341:                                  $selected.'>'.$version.'</option>';
                   8342:                 }
                   8343:                 $selector .= '</select> ';
                   8344:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   8345:             } else {
                   8346:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   8347:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   8348:                              ' />'.('&nbsp;'x2).
                   8349:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   8350:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   8351:                              "\n".
                   8352:                              '</div><div><table>';
                   8353:                 my $rem;
                   8354:                 for (my $i=0; $i<@locations; $i++) {
                   8355:                     my ($showloc,$value,$checkedtype);
                   8356:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   8357:                         my $ip = $by_location->{$locations[$i]}->[0];
                   8358:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8359:                             $value = join(':',@{$by_ip->{$ip}});
                   8360:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   8361:                             if (ref($current{$type}) eq 'ARRAY') {
                   8362:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   8363:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   8364:                                         $checkedtype = ' checked="checked"';
                   8365:                                         last;
1.145     raeburn  8366:                                     }
1.138     raeburn  8367:                                 }
                   8368:                             }
                   8369:                         }
1.137     raeburn  8370:                     }
1.279     raeburn  8371:                     $rem = $i%($numinrow);
                   8372:                     if ($rem == 0) {
                   8373:                         if ($i > 0) {
                   8374:                             $datatable .= '</tr>';
                   8375:                         }
                   8376:                         $datatable .= '<tr>';
                   8377:                     }
                   8378:                     $datatable .= '<td class="LC_left_item">'.
                   8379:                                   '<span class="LC_nobreak"><label>'.
                   8380:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   8381:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   8382:                                   '</label></span></td>';
                   8383:                 }
                   8384:                 $rem = @locations%($numinrow);
                   8385:                 my $colsleft = $numinrow - $rem;
                   8386:                 if ($colsleft > 1 ) {
                   8387:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8388:                                   '&nbsp;</td>';
                   8389:                 } elsif ($colsleft == 1) {
                   8390:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  8391:                 }
1.279     raeburn  8392:                 $datatable .= '</tr></table>';
1.137     raeburn  8393:             }
1.279     raeburn  8394:             $datatable .= '</td></tr>';
                   8395:             $itemcount ++;
1.137     raeburn  8396:         }
                   8397:     }
1.279     raeburn  8398:     return ($datatable,$itemcount);
1.137     raeburn  8399: }
                   8400: 
1.275     raeburn  8401: sub print_ssl {
                   8402:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8403:     my ($css_class,$datatable);
                   8404:     my $itemcount = 1;
                   8405:     if ($position eq 'top') {
1.281     raeburn  8406:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8407:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8408:         my $same_institution;
                   8409:         if ($intdom ne '') {
                   8410:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   8411:             if (ref($internet_names) eq 'ARRAY') {
                   8412:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   8413:                     $same_institution = 1;
                   8414:                 }
                   8415:             }
                   8416:         }
1.275     raeburn  8417:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  8418:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   8419:         if ($same_institution) {
                   8420:             my %domservers = &Apache::lonnet::get_servers($dom);
                   8421:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   8422:         } else {
                   8423:             $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.");
                   8424:         }
                   8425:         $datatable .= '</td></tr>';
1.275     raeburn  8426:         $itemcount ++;
                   8427:     } else {
                   8428:         my %titles = &ssl_titles();
                   8429:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   8430:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8431:         my @alldoms = &Apache::lonnet::all_domains();
                   8432:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   8433:         my @domservers = &Apache::lonnet::get_servers($dom);
                   8434:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8435:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  8436:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   8437:             my $legacy;
                   8438:             unless (ref($settings) eq 'HASH') {
                   8439:                 my $name;
                   8440:                 if ($position eq 'connto') {
                   8441:                     $name = 'loncAllowInsecure';
                   8442:                 } else {
                   8443:                     $name = 'londAllowInsecure';
                   8444:                 }
                   8445:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   8446:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8447:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   8448:                     my %what = (
                   8449:                                    $name => 1,
                   8450:                                );
                   8451:                     my ($result,$returnhash) =
                   8452:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   8453:                     if ($result eq 'ok') {
                   8454:                         if (ref($returnhash) eq 'HASH') {
                   8455:                             $legacy = $returnhash->{$name};
                   8456:                         }
                   8457:                     }
                   8458:                 } else {
                   8459:                     $legacy = $Apache::lonnet::perlvar{$name};
                   8460:                 }
                   8461:             }
1.275     raeburn  8462:             foreach my $type ('dom','intdom','other') {
                   8463:                 my %checked;
                   8464:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8465:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   8466:                               '<td class="LC_right_item">';
                   8467:                 my $skip; 
                   8468:                 if ($type eq 'dom') {
                   8469:                     unless (keys(%servers) > 1) {
                   8470:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   8471:                         $skip = 1;
                   8472:                     }
                   8473:                 }
                   8474:                 if ($type eq 'intdom') {
                   8475:                     unless (@instdoms > 1) {
                   8476:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   8477:                         $skip = 1;
                   8478:                     } 
                   8479:                 } elsif ($type eq 'other') {
                   8480:                     if (keys(%by_location) == 0) {
                   8481:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   8482:                         $skip = 1;
                   8483:                     }
                   8484:                 }
                   8485:                 unless ($skip) {
                   8486:                     $checked{'yes'} = ' checked="checked"'; 
                   8487:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  8488:                         if (ref($settings->{$position}) eq 'HASH') {
                   8489:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  8490:                                 $checked{$1} = $checked{'yes'};
                   8491:                                 delete($checked{'yes'}); 
                   8492:                             }
                   8493:                         }
1.293     raeburn  8494:                     } else {
                   8495:                         if ($legacy == 0) {
                   8496:                             $checked{'req'} = $checked{'yes'};
                   8497:                             delete($checked{'yes'});    
                   8498:                         }
1.275     raeburn  8499:                     }
                   8500:                     foreach my $option ('no','yes','req') {
                   8501:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  8502:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  8503:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   8504:                                       '</label></span>'.('&nbsp;'x2);
                   8505:                     }
                   8506:                 }
                   8507:                 $datatable .= '</td></tr>';
                   8508:                 $itemcount ++; 
                   8509:             }
                   8510:         } else {
                   8511:             my $prefix = 'replication';
                   8512:             my @types = ('certreq','nocertreq');
1.279     raeburn  8513:             if (keys(%by_location) == 0) {
                   8514:                 $datatable .= '<tr'.$css_class.'><td>'.
                   8515:                               &mt('Nothing to set here, as there are no other institutions').
                   8516:                               '</td></tr>';
                   8517:                 $itemcount ++;
1.275     raeburn  8518:             } else {
1.279     raeburn  8519:                 ($datatable,$itemcount) = 
                   8520:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  8521:             }
                   8522:         }
                   8523:     }
                   8524:     $$rowtotal += $itemcount;
                   8525:     return $datatable;
                   8526: }
                   8527: 
                   8528: sub ssl_titles {
                   8529:     return &Apache::lonlocal::texthash (
                   8530:                dom           => 'LON-CAPA servers/VMs from same domain',
                   8531:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   8532:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  8533:                connto        => 'Connections to other servers',
                   8534:                connfrom      => 'Connections from other servers',
1.275     raeburn  8535:                replication   => 'Replicating content to other institutions',
                   8536:                certreq       => 'Client certificate required, but specific domains exempt',
                   8537:                nocertreq     => 'No client certificate required, except for specific domains',
                   8538:                no            => 'SSL not used',
                   8539:                yes           => 'SSL Optional (used if available)',
                   8540:                req           => 'SSL Required',
                   8541:     );
1.279     raeburn  8542: }
                   8543: 
                   8544: sub print_trust {
                   8545:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   8546:     my ($css_class,$datatable,%checked,%choices);
                   8547:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8548:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8549:     my $itemcount = 1;
                   8550:     my %titles = &trust_titles();
                   8551:     my @types = ('exc','inc');
                   8552:     if ($prefix eq 'top') {
                   8553:         $prefix = 'content';
                   8554:     } elsif ($prefix eq 'bottom') {
                   8555:         $prefix = 'msg';
                   8556:     }
                   8557:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8558:     $$rowtotal += $itemcount;
                   8559:     return $datatable;
                   8560: }
                   8561: 
                   8562: sub trust_titles {
                   8563:     return &Apache::lonlocal::texthash(
                   8564:                content  => "Access to this domain's content by others",
                   8565:                shared   => "Access to other domain's content by this domain",
                   8566:                enroll   => "Enrollment in this domain's courses by others", 
                   8567:                othcoau  => "Co-author roles in this domain for others",
                   8568:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   8569:                domroles => "Domain roles in this domain assignable to others",
                   8570:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   8571:                reqcrs   => "Requests for creation of courses in this domain by others",
                   8572:                msg      => "Users in other domains can send messages to this domain",
                   8573:                exc      => "Allow all, but exclude specific domains",
                   8574:                inc      => "Deny all, but include specific domains",
                   8575:            );
1.275     raeburn  8576: } 
                   8577: 
1.138     raeburn  8578: sub build_location_hashes {
1.275     raeburn  8579:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  8580:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  8581:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  8582:     my %iphost = &Apache::lonnet::get_iphost();
                   8583:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   8584:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   8585:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   8586:         foreach my $id (@{$iphost{$primary_ip}}) {
                   8587:             my $intdom = &Apache::lonnet::internet_dom($id);
                   8588:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   8589:                 push(@{$intdoms},$intdom);
                   8590:             }
                   8591:         }
                   8592:     }
                   8593:     foreach my $ip (keys(%iphost)) {
                   8594:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   8595:             foreach my $id (@{$iphost{$ip}}) {
                   8596:                 my $location = &Apache::lonnet::internet_dom($id);
                   8597:                 if ($location) {
1.275     raeburn  8598:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   8599:                         my $dom = &Apache::lonnet::host_domain($id);
                   8600:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   8601:                             push(@{$instdoms},$dom);
                   8602:                         }
                   8603:                         next;
                   8604:                     }
1.138     raeburn  8605:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8606:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   8607:                             push(@{$by_ip->{$ip}},$location);
                   8608:                         }
                   8609:                     } else {
                   8610:                         $by_ip->{$ip} = [$location];
                   8611:                     }
                   8612:                 }
                   8613:             }
                   8614:         }
                   8615:     }
                   8616:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   8617:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8618:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   8619:             my $first = $by_ip->{$ip}->[0];
                   8620:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   8621:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   8622:                     push(@{$by_location->{$first}},$ip);
                   8623:                 }
                   8624:             } else {
                   8625:                 $by_location->{$first} = [$ip];
                   8626:             }
                   8627:         }
                   8628:     }
                   8629:     return;
                   8630: }
                   8631: 
1.145     raeburn  8632: sub current_offloads_to {
                   8633:     my ($dom,$settings,$servers) = @_;
                   8634:     my (%spareid,%otherdomconfigs);
1.152     raeburn  8635:     if (ref($servers) eq 'HASH') {
1.145     raeburn  8636:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   8637:             my $gotspares;
1.152     raeburn  8638:             if (ref($settings) eq 'HASH') {
                   8639:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   8640:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   8641:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   8642:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   8643:                         $gotspares = 1;
                   8644:                     }
1.145     raeburn  8645:                 }
                   8646:             }
                   8647:             unless ($gotspares) {
                   8648:                 my $gotspares;
                   8649:                 my $serverhomeID =
                   8650:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   8651:                 my $serverhomedom =
                   8652:                     &Apache::lonnet::host_domain($serverhomeID);
                   8653:                 if ($serverhomedom ne $dom) {
                   8654:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   8655:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   8656:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   8657:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   8658:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   8659:                                 $gotspares = 1;
                   8660:                             }
                   8661:                         }
                   8662:                     } else {
                   8663:                         $otherdomconfigs{$serverhomedom} =
                   8664:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   8665:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   8666:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   8667:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   8668:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   8669:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   8670:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   8671:                                         $gotspares = 1;
                   8672:                                     }
                   8673:                                 }
                   8674:                             }
                   8675:                         }
                   8676:                     }
                   8677:                 }
                   8678:             }
                   8679:             unless ($gotspares) {
                   8680:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   8681:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   8682:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   8683:                } else {
                   8684:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   8685:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   8686:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   8687:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   8688:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   8689:                     } else {
1.150     raeburn  8690:                         my %what = (
                   8691:                              spareid => 1,
                   8692:                         );
                   8693:                         my ($result,$returnhash) = 
                   8694:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   8695:                         if ($result eq 'ok') { 
                   8696:                             if (ref($returnhash) eq 'HASH') {
                   8697:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   8698:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   8699:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   8700:                                 }
                   8701:                             }
1.145     raeburn  8702:                         }
                   8703:                     }
                   8704:                 }
                   8705:             }
                   8706:         }
                   8707:     }
                   8708:     return %spareid;
                   8709: }
                   8710: 
                   8711: sub spares_row {
1.371     raeburn  8712:     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   8713:         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  8714:     my $css_class;
                   8715:     my $numinrow = 4;
                   8716:     my $itemcount = 1;
                   8717:     my $datatable;
1.152     raeburn  8718:     my %typetitles = &sparestype_titles();
                   8719:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  8720:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  8721:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   8722:             my ($othercontrol,$serverdom);
                   8723:             if ($serverhome ne $server) {
                   8724:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   8725:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   8726:             } else {
                   8727:                 $serverdom = &Apache::lonnet::host_domain($server);
                   8728:                 if ($serverdom ne $dom) {
                   8729:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   8730:                 }
                   8731:             }
                   8732:             next unless (ref($spareid->{$server}) eq 'HASH');
1.371     raeburn  8733:             my ($checkednow,$checkedoth);
1.261     raeburn  8734:             if (ref($curroffloadnow) eq 'HASH') {
                   8735:                 if ($curroffloadnow->{$server}) {
                   8736:                     $checkednow = ' checked="checked"';
                   8737:                 }
                   8738:             }
1.371     raeburn  8739:             if (ref($curroffloadoth) eq 'HASH') {
                   8740:                 if ($curroffloadoth->{$server}) {
                   8741:                     $checkedoth = ' checked="checked"';
                   8742:                 }
                   8743:             }
1.145     raeburn  8744:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8745:             $datatable .= '<tr'.$css_class.'>
                   8746:                            <td rowspan="2">
1.183     bisitz   8747:                             <span class="LC_nobreak">'.
                   8748:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  8749:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  8750:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  8751:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371     raeburn  8752:                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.183     bisitz   8753:                           "\n";
1.371     raeburn  8754:             if ($other_insts) {
                   8755:                 $datatable .= '<br />'.
                   8756:                               '<span class="LC_nobreak">'."\n".
                   8757:                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   8758:                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   8759:                           "\n";
                   8760:             }
1.145     raeburn  8761:             my (%current,%canselect);
1.152     raeburn  8762:             my @choices = 
                   8763:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   8764:             foreach my $type ('primary','default') {
                   8765:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  8766:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   8767:                         my @spares = @{$spareid->{$server}{$type}};
                   8768:                         if (@spares > 0) {
1.152     raeburn  8769:                             if ($othercontrol) {
                   8770:                                 $current{$type} = join(', ',@spares);
                   8771:                             } else {
                   8772:                                 $current{$type} .= '<table>';
                   8773:                                 my $numspares = scalar(@spares);
                   8774:                                 for (my $i=0;  $i<@spares; $i++) {
                   8775:                                     my $rem = $i%($numinrow);
                   8776:                                     if ($rem == 0) {
                   8777:                                         if ($i > 0) {
                   8778:                                             $current{$type} .= '</tr>';
                   8779:                                         }
                   8780:                                         $current{$type} .= '<tr>';
1.145     raeburn  8781:                                     }
1.152     raeburn  8782:                                     $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;'.
                   8783:                                                        $spareid->{$server}{$type}[$i].
                   8784:                                                        '</label></td>'."\n";
                   8785:                                 }
                   8786:                                 my $rem = @spares%($numinrow);
                   8787:                                 my $colsleft = $numinrow - $rem;
                   8788:                                 if ($colsleft > 1 ) {
                   8789:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   8790:                                                        '" class="LC_left_item">'.
                   8791:                                                        '&nbsp;</td>';
                   8792:                                 } elsif ($colsleft == 1) {
                   8793:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  8794:                                 }
1.152     raeburn  8795:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  8796:                             }
1.145     raeburn  8797:                         }
                   8798:                     }
                   8799:                     if ($current{$type} eq '') {
                   8800:                         $current{$type} = &mt('None specified');
                   8801:                     }
1.152     raeburn  8802:                     if ($othercontrol) {
                   8803:                         if ($type eq 'primary') {
                   8804:                             $canselect{$type} = $othercontrol;
                   8805:                         }
                   8806:                     } else {
                   8807:                         $canselect{$type} = 
                   8808:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   8809:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   8810:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   8811:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   8812:                         if (@choices > 0) {
                   8813:                             foreach my $lonhost (@choices) {
                   8814:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   8815:                             }
                   8816:                         }
                   8817:                         $canselect{$type} .= '</select>'."\n";
                   8818:                     }
                   8819:                 } else {
                   8820:                     $current{$type} = &mt('Could not be determined');
                   8821:                     if ($type eq 'primary') {
                   8822:                         $canselect{$type} =  $othercontrol;
                   8823:                     }
1.145     raeburn  8824:                 }
1.152     raeburn  8825:                 if ($type eq 'default') {
                   8826:                     $datatable .= '<tr'.$css_class.'>';
                   8827:                 }
                   8828:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   8829:                               '<td>'.$current{$type}.'</td>'."\n".
                   8830:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  8831:             }
                   8832:             $itemcount ++;
                   8833:         }
                   8834:     }
                   8835:     $$rowtotal += $itemcount;
                   8836:     return $datatable;
                   8837: }
                   8838: 
1.152     raeburn  8839: sub possible_newspares {
                   8840:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   8841:     my $serverhostname = &Apache::lonnet::hostname($server);
                   8842:     my %excluded;
                   8843:     if ($serverhostname ne '') {
                   8844:         %excluded = (
                   8845:                        $serverhostname => 1,
                   8846:                     );
                   8847:     }
                   8848:     if (ref($currspares) eq 'HASH') {
                   8849:         foreach my $type (keys(%{$currspares})) {
                   8850:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   8851:                 if (@{$currspares->{$type}} > 0) {
                   8852:                     foreach my $curr (@{$currspares->{$type}}) {
                   8853:                         my $hostname = &Apache::lonnet::hostname($curr);
                   8854:                         $excluded{$hostname} = 1;
                   8855:                     }
                   8856:                 }
                   8857:             }
                   8858:         }
                   8859:     }
                   8860:     my @choices;
                   8861:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   8862:         if (keys(%{$serverhomes}) > 1) {
                   8863:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   8864:                 unless ($excluded{$name}) {
                   8865:                     if (exists($altids->{$serverhomes->{$name}})) {
                   8866:                         push(@choices,$altids->{$serverhomes->{$name}});
                   8867:                     } else {
                   8868:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  8869:                     }
                   8870:                 }
                   8871:             }
                   8872:         }
                   8873:     }
1.152     raeburn  8874:     return sort(@choices);
1.145     raeburn  8875: }
                   8876: 
1.150     raeburn  8877: sub print_loadbalancing {
                   8878:     my ($dom,$settings,$rowtotal) = @_;
                   8879:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8880:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8881:     my $numinrow = 1;
                   8882:     my $datatable;
                   8883:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342     raeburn  8884:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  8885:     if (ref($settings) eq 'HASH') {
                   8886:         %existing = %{$settings};
                   8887:     }
                   8888:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   8889:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  8890:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  8891:     } else {
                   8892:         return;
                   8893:     }
                   8894:     my ($othertitle,$usertypes,$types) =
                   8895:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  8896:     my $rownum = 8;
1.150     raeburn  8897:     if (ref($types) eq 'ARRAY') {
                   8898:         $rownum += scalar(@{$types});
                   8899:     }
1.171     raeburn  8900:     my @css_class = ('LC_odd_row','LC_even_row');
                   8901:     my $balnum = 0;
                   8902:     my $islast;
                   8903:     my (@toshow,$disabledtext);
                   8904:     if (keys(%currbalancer) > 0) {
                   8905:         @toshow = sort(keys(%currbalancer));
                   8906:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   8907:             push(@toshow,'');
                   8908:         }
                   8909:     } else {
                   8910:         @toshow = ('');
                   8911:         $disabledtext = &mt('No existing load balancer');
                   8912:     }
                   8913:     foreach my $lonhost (@toshow) {
                   8914:         if ($balnum == scalar(@toshow)-1) {
                   8915:             $islast = 1;
                   8916:         } else {
                   8917:             $islast = 0;
                   8918:         }
                   8919:         my $cssidx = $balnum%2;
                   8920:         my $targets_div_style = 'display: none';
                   8921:         my $disabled_div_style = 'display: block';
                   8922:         my $homedom_div_style = 'display: none';
                   8923:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  8924:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  8925:                       '<p>';
                   8926:         if ($lonhost eq '') {
1.210     raeburn  8927:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  8928:             if (keys(%currbalancer) > 0) {
                   8929:                 $datatable .= &mt('Add balancer:');
                   8930:             } else {
                   8931:                 $datatable .= &mt('Enable balancer:');
                   8932:             }
                   8933:             $datatable .= '&nbsp;'.
                   8934:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   8935:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   8936:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   8937:                           '<option value="" selected="selected">'.&mt('None').
                   8938:                           '</option>'."\n";
                   8939:             foreach my $server (sort(keys(%servers))) {
                   8940:                 next if ($currbalancer{$server});
                   8941:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   8942:             }
1.210     raeburn  8943:             $datatable .=
1.171     raeburn  8944:                 '</select>'."\n".
                   8945:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   8946:         } else {
                   8947:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   8948:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   8949:                            &mt('Stop balancing').'</label>'.
                   8950:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   8951:             $targets_div_style = 'display: block';
                   8952:             $disabled_div_style = 'display: none';
                   8953:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   8954:                 $homedom_div_style = 'display: block';
                   8955:             }
                   8956:         }
1.306     raeburn  8957:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  8958:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   8959:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   8960:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   8961:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   8962:         my @sparestypes = ('primary','default');
                   8963:         my %typetitles = &sparestype_titles();
1.284     raeburn  8964:         my %hostherechecked = (
                   8965:                                   no => ' checked="checked"',
                   8966:                               );
1.342     raeburn  8967:         my %balcookiechecked = (
                   8968:                                   no => ' checked="checked"', 
                   8969:                                );
1.171     raeburn  8970:         foreach my $sparetype (@sparestypes) {
                   8971:             my $targettable;
                   8972:             for (my $i=0; $i<$numspares; $i++) {
                   8973:                 my $checked;
                   8974:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   8975:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   8976:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   8977:                             $checked = ' checked="checked"';
                   8978:                         }
                   8979:                     }
                   8980:                 }
                   8981:                 my ($chkboxval,$disabled);
                   8982:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   8983:                     $chkboxval = $spares[$i];
                   8984:                 }
                   8985:                 if (exists($currbalancer{$spares[$i]})) {
                   8986:                     $disabled = ' disabled="disabled"';
                   8987:                 }
1.210     raeburn  8988:                 $targettable .=
1.253     raeburn  8989:                     '<td><span class="LC_nobreak"><label>'.
                   8990:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  8991:                     $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  8992:                     '</span></label></span></td>';
1.171     raeburn  8993:                 my $rem = $i%($numinrow);
                   8994:                 if ($rem == 0) {
                   8995:                     if (($i > 0) && ($i < $numspares-1)) {
                   8996:                         $targettable .= '</tr>';
                   8997:                     }
                   8998:                     if ($i < $numspares-1) {
                   8999:                         $targettable .= '<tr>';
1.150     raeburn  9000:                     }
                   9001:                 }
                   9002:             }
1.171     raeburn  9003:             if ($targettable ne '') {
                   9004:                 my $rem = $numspares%($numinrow);
                   9005:                 my $colsleft = $numinrow - $rem;
                   9006:                 if ($colsleft > 1 ) {
                   9007:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9008:                                     '&nbsp;</td>';
                   9009:                 } elsif ($colsleft == 1) {
                   9010:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   9011:                 }
                   9012:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   9013:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   9014:             }
1.284     raeburn  9015:             $hostherechecked{$sparetype} = '';
                   9016:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   9017:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   9018:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   9019:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   9020:                         $hostherechecked{'no'} = '';
                   9021:                     }
                   9022:                 }
                   9023:             }
                   9024:         }
1.342     raeburn  9025:         if ($currcookies{$lonhost}) {
                   9026:             %balcookiechecked = (
                   9027:                                     yes => ' checked="checked"',
                   9028:                                 );
                   9029:         }
1.284     raeburn  9030:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   9031:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   9032:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   9033:         foreach my $sparetype (@sparestypes) {
                   9034:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   9035:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   9036:                           '</i></label><br />';
1.171     raeburn  9037:         }
1.342     raeburn  9038:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   9039:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   9040:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   9041:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   9042:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   9043:                       '</div></td></tr>'.
1.171     raeburn  9044:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   9045:                                            $othertitle,$usertypes,$types,\%servers,
                   9046:                                            \%currbalancer,$lonhost,
                   9047:                                            $targets_div_style,$homedom_div_style,
                   9048:                                            $css_class[$cssidx],$balnum,$islast);
                   9049:         $$rowtotal += $rownum;
                   9050:         $balnum ++;
                   9051:     }
                   9052:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   9053:     return $datatable;
                   9054: }
                   9055: 
                   9056: sub get_loadbalancers_config {
1.342     raeburn  9057:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171     raeburn  9058:     return unless ((ref($servers) eq 'HASH') &&
                   9059:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342     raeburn  9060:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   9061:                    (ref($currcookies) eq 'HASH'));
1.171     raeburn  9062:     if (keys(%{$existing}) > 0) {
                   9063:         my $oldlonhost;
                   9064:         foreach my $key (sort(keys(%{$existing}))) {
                   9065:             if ($key eq 'lonhost') {
                   9066:                 $oldlonhost = $existing->{'lonhost'};
                   9067:                 $currbalancer->{$oldlonhost} = 1;
                   9068:             } elsif ($key eq 'targets') {
                   9069:                 if ($oldlonhost) {
                   9070:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   9071:                 }
                   9072:             } elsif ($key eq 'rules') {
                   9073:                 if ($oldlonhost) {
                   9074:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   9075:                 }
                   9076:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   9077:                 $currbalancer->{$key} = 1;
                   9078:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   9079:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.342     raeburn  9080:                 if ($existing->{$key}{'cookie'}) {
                   9081:                     $currcookies->{$key} = 1;
                   9082:                 }
1.150     raeburn  9083:             }
                   9084:         }
1.171     raeburn  9085:     } else {
                   9086:         my ($balancerref,$targetsref) =
                   9087:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   9088:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   9089:             foreach my $server (sort(keys(%{$balancerref}))) {
                   9090:                 $currbalancer->{$server} = 1;
                   9091:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  9092:             }
                   9093:         }
                   9094:     }
1.171     raeburn  9095:     return;
1.150     raeburn  9096: }
                   9097: 
                   9098: sub loadbalancing_rules {
                   9099:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  9100:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   9101:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  9102:     my $output;
1.171     raeburn  9103:     my $num = 0;
1.210     raeburn  9104:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  9105:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   9106:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   9107:         foreach my $type (@{$alltypes}) {
1.171     raeburn  9108:             $num ++;
1.150     raeburn  9109:             my $current;
                   9110:             if (ref($currrules) eq 'HASH') {
                   9111:                 $current = $currrules->{$type};
                   9112:             }
1.253     raeburn  9113:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  9114:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  9115:                     $current = '';
                   9116:                 }
                   9117:             }
                   9118:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  9119:                                              $servers,$currbalancer,$lonhost,$dom,
                   9120:                                              $targets_div_style,$homedom_div_style,
                   9121:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  9122:         }
                   9123:     }
                   9124:     return $output;
                   9125: }
                   9126: 
                   9127: sub loadbalancing_titles {
                   9128:     my ($dom,$intdom,$usertypes,$types) = @_;
                   9129:     my %othertypes = (
                   9130:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   9131:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   9132:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   9133:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  9134:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   9135:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  9136:                      );
1.209     raeburn  9137:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  9138:     my @available;
1.150     raeburn  9139:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  9140:         @available = @{$types};
1.150     raeburn  9141:     }
1.302     raeburn  9142:     unless (grep(/^default$/,@available)) {
                   9143:         push(@available,'default');
                   9144:     }
                   9145:     unshift(@alltypes,@available);
1.150     raeburn  9146:     my %titles;
                   9147:     foreach my $type (@alltypes) {
                   9148:         if ($type =~ /^_LC_/) {
                   9149:             $titles{$type} = $othertypes{$type};
                   9150:         } elsif ($type eq 'default') {
                   9151:             $titles{$type} = &mt('All users from [_1]',$dom);
                   9152:             if (ref($types) eq 'ARRAY') {
                   9153:                 if (@{$types} > 0) {
                   9154:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   9155:                 }
                   9156:             }
                   9157:         } elsif (ref($usertypes) eq 'HASH') {
                   9158:             $titles{$type} = $usertypes->{$type};
                   9159:         }
                   9160:     }
                   9161:     return (\@alltypes,\%othertypes,\%titles);
                   9162: }
                   9163: 
                   9164: sub loadbalance_rule_row {
1.171     raeburn  9165:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   9166:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  9167:     my @rulenames;
1.150     raeburn  9168:     my %ruletitles = &offloadtype_text();
1.209     raeburn  9169:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  9170:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  9171:     } else {
1.209     raeburn  9172:         @rulenames = ('default','homeserver');
                   9173:         if ($type eq '_LC_external') {
                   9174:             push(@rulenames,'externalbalancer');
                   9175:         } else {
                   9176:             push(@rulenames,'specific');
                   9177:         }
                   9178:         push(@rulenames,'none');
1.150     raeburn  9179:     }
                   9180:     my $style = $targets_div_style;
1.253     raeburn  9181:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  9182:         $style = $homedom_div_style;
                   9183:     }
1.171     raeburn  9184:     my $space;
                   9185:     if ($islast && $num == 1) {
1.317     raeburn  9186:         $space = '<div style="display:inline-block;">&nbsp;</div>';
1.171     raeburn  9187:     }
1.210     raeburn  9188:     my $output =
1.306     raeburn  9189:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  9190:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   9191:         '<td valaign="top">'.$space.
                   9192:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  9193:     for (my $i=0; $i<@rulenames; $i++) {
                   9194:         my $rule = $rulenames[$i];
                   9195:         my ($checked,$extra);
                   9196:         if ($rulenames[$i] eq 'default') {
                   9197:             $rule = '';
                   9198:         }
                   9199:         if ($rulenames[$i] eq 'specific') {
                   9200:             if (ref($servers) eq 'HASH') {
                   9201:                 my $default;
                   9202:                 if (($current ne '') && (exists($servers->{$current}))) {
                   9203:                     $checked = ' checked="checked"';
                   9204:                 }
                   9205:                 unless ($checked) {
                   9206:                     $default = ' selected="selected"';
                   9207:                 }
1.210     raeburn  9208:                 $extra =
1.171     raeburn  9209:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9210:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9211:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   9212:                     '<option value=""'.$default.'></option>'."\n";
                   9213:                 foreach my $server (sort(keys(%{$servers}))) {
                   9214:                     if (ref($currbalancer) eq 'HASH') {
                   9215:                         next if (exists($currbalancer->{$server}));
                   9216:                     }
1.150     raeburn  9217:                     my $selected;
1.171     raeburn  9218:                     if ($server eq $current) {
1.150     raeburn  9219:                         $selected = ' selected="selected"';
                   9220:                     }
1.171     raeburn  9221:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  9222:                 }
                   9223:                 $extra .= '</select>';
                   9224:             }
                   9225:         } elsif ($rule eq $current) {
                   9226:             $checked = ' checked="checked"';
                   9227:         }
                   9228:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  9229:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   9230:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   9231:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  9232:                    ')"'.$checked.' />&nbsp;';
                   9233:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   9234:             $output .= $ruletitles{'particular'};
                   9235:         } else {
                   9236:             $output .= $ruletitles{$rulenames[$i]};
                   9237:         }
                   9238:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  9239:     }
                   9240:     $output .= '</div></td></tr>'."\n";
                   9241:     return $output;
                   9242: }
                   9243: 
                   9244: sub offloadtype_text {
                   9245:     my %ruletitles = &Apache::lonlocal::texthash (
                   9246:            'default'          => 'Offloads to default destinations',
                   9247:            'homeserver'       => "Offloads to user's home server",
                   9248:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   9249:            'specific'         => 'Offloads to specific server',
1.161     raeburn  9250:            'none'             => 'No offload',
1.209     raeburn  9251:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   9252:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  9253:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  9254:     );
                   9255:     return %ruletitles;
                   9256: }
                   9257: 
                   9258: sub sparestype_titles {
                   9259:     my %typestitles = &Apache::lonlocal::texthash (
                   9260:                           'primary' => 'primary',
                   9261:                           'default' => 'default',
                   9262:                       );
                   9263:     return %typestitles;
                   9264: }
                   9265: 
1.28      raeburn  9266: sub contact_titles {
                   9267:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  9268:                    'supportemail'    => 'Support E-mail address',
                   9269:                    'adminemail'      => 'Default Server Admin E-mail address',
                   9270:                    'errormail'       => 'Error reports to be e-mailed to',
                   9271:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  9272:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   9273:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  9274:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   9275:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   9276:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  9277:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350     raeburn  9278:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.378     raeburn  9279:                    'errorthreshold'  => 'Error count threshold for status e-mail to admin(s)',
                   9280:                    'errorsysmail'    => 'Error count threshold for e-mail to developer group',
1.340     raeburn  9281:                    'errorweights'    => 'Weights used to compute error count',
                   9282:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  9283:                  );
                   9284:     my %short_titles = &Apache::lonlocal::texthash (
                   9285:                            adminemail   => 'Admin E-mail address',
                   9286:                            supportemail => 'Support E-mail',
                   9287:                        );   
                   9288:     return (\%titles,\%short_titles);
                   9289: }
                   9290: 
1.286     raeburn  9291: sub helpform_fields {
                   9292:     my %titles =  &Apache::lonlocal::texthash (
                   9293:                        'username'   => 'Name',
                   9294:                        'user'       => 'Username/domain',
                   9295:                        'phone'      => 'Phone',
                   9296:                        'cc'         => 'Cc e-mail',
                   9297:                        'course'     => 'Course Details',
                   9298:                        'section'    => 'Sections',
1.289     raeburn  9299:                        'screenshot' => 'File upload',
1.286     raeburn  9300:     );
                   9301:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   9302:     my %possoptions = (
                   9303:                         username     => ['yes','no','req'],
1.289     raeburn  9304:                         phone        => ['yes','no','req'],
1.286     raeburn  9305:                         user         => ['yes','no'],
1.289     raeburn  9306:                         cc           => ['yes','no'],
1.286     raeburn  9307:                         course       => ['yes','no'],
                   9308:                         section      => ['yes','no'],
                   9309:                         screenshot   => ['yes','no'],
                   9310:                       );
                   9311:     my %fieldoptions = &Apache::lonlocal::texthash (
                   9312:                          'yes'  => 'Optional',
                   9313:                          'req'  => 'Required',
                   9314:                          'no'   => "Not shown",
                   9315:     );
                   9316:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   9317: }
                   9318: 
1.72      raeburn  9319: sub tool_titles {
                   9320:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  9321:                      aboutme    => 'Personal web page',
1.86      raeburn  9322:                      blog       => 'Blog',
1.162     raeburn  9323:                      webdav     => 'WebDAV',
1.86      raeburn  9324:                      portfolio  => 'Portfolio',
1.88      bisitz   9325:                      official   => 'Official courses (with institutional codes)',
                   9326:                      unofficial => 'Unofficial courses',
1.98      raeburn  9327:                      community  => 'Communities',
1.216     raeburn  9328:                      textbook   => 'Textbook courses',
1.271     raeburn  9329:                      placement  => 'Placement tests',
1.86      raeburn  9330:                  );
1.72      raeburn  9331:     return %titles;
                   9332: }
                   9333: 
1.101     raeburn  9334: sub courserequest_titles {
                   9335:     my %titles = &Apache::lonlocal::texthash (
                   9336:                                    official   => 'Official',
                   9337:                                    unofficial => 'Unofficial',
                   9338:                                    community  => 'Communities',
1.216     raeburn  9339:                                    textbook   => 'Textbook',
1.271     raeburn  9340:                                    placement  => 'Placement tests',
1.325     raeburn  9341:                                    lti        => 'LTI Provider',
1.101     raeburn  9342:                                    norequest  => 'Not allowed',
1.325     raeburn  9343:                                    approval   => 'Approval by DC',
1.101     raeburn  9344:                                    validate   => 'With validation',
                   9345:                                    autolimit  => 'Numerical limit',
1.103     raeburn  9346:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  9347:                  );
                   9348:     return %titles;
                   9349: }
                   9350: 
1.163     raeburn  9351: sub authorrequest_titles {
                   9352:     my %titles = &Apache::lonlocal::texthash (
                   9353:                                    norequest  => 'Not allowed',
                   9354:                                    approval   => 'Approval by Dom. Coord.',
                   9355:                                    automatic  => 'Automatic approval',
                   9356:                  );
                   9357:     return %titles;
1.210     raeburn  9358: }
1.163     raeburn  9359: 
1.101     raeburn  9360: sub courserequest_conditions {
                   9361:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  9362:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   9363:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  9364:                  );
                   9365:     return %conditions;
                   9366: }
                   9367: 
                   9368: 
1.27      raeburn  9369: sub print_usercreation {
1.30      raeburn  9370:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  9371:     my $numinrow = 4;
1.28      raeburn  9372:     my $datatable;
                   9373:     if ($position eq 'top') {
1.30      raeburn  9374:         $$rowtotal ++;
1.34      raeburn  9375:         my $rowcount = 0;
1.32      raeburn  9376:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  9377:         if (ref($rules) eq 'HASH') {
                   9378:             if (keys(%{$rules}) > 0) {
1.32      raeburn  9379:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   9380:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  9381:                 $$rowtotal ++;
1.32      raeburn  9382:                 $rowcount ++;
                   9383:             }
                   9384:         }
                   9385:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   9386:         if (ref($idrules) eq 'HASH') {
                   9387:             if (keys(%{$idrules}) > 0) {
                   9388:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   9389:                                                 $idruleorder,$numinrow,$rowcount);
                   9390:                 $$rowtotal ++;
                   9391:                 $rowcount ++;
1.28      raeburn  9392:             }
                   9393:         }
1.39      raeburn  9394:         if ($rowcount == 0) {
                   9395:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   9396:             $$rowtotal ++;
                   9397:             $rowcount ++;
                   9398:         }
1.34      raeburn  9399:     } elsif ($position eq 'middle') {
1.224     raeburn  9400:         my @creators = ('author','course','requestcrs');
1.37      raeburn  9401:         my ($rules,$ruleorder) =
                   9402:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  9403:         my %lt = &usercreation_types();
                   9404:         my %checked;
                   9405:         if (ref($settings) eq 'HASH') {
                   9406:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9407:                 foreach my $item (@creators) {
                   9408:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   9409:                 }
                   9410:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   9411:                 foreach my $item (@creators) {
                   9412:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   9413:                         $checked{$item} = 'none';
                   9414:                     }
                   9415:                 }
                   9416:             }
                   9417:         }
                   9418:         my $rownum = 0;
                   9419:         foreach my $item (@creators) {
                   9420:             $rownum ++;
1.224     raeburn  9421:             if ($checked{$item} eq '') {
                   9422:                 $checked{$item} = 'any';
1.34      raeburn  9423:             }
                   9424:             my $css_class;
                   9425:             if ($rownum%2) {
                   9426:                 $css_class = '';
                   9427:             } else {
                   9428:                 $css_class = ' class="LC_odd_row" ';
                   9429:             }
                   9430:             $datatable .= '<tr'.$css_class.'>'.
                   9431:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  9432:                          '</span></td><td style="text-align: right">';
1.224     raeburn  9433:             my @options = ('any');
                   9434:             if (ref($rules) eq 'HASH') {
                   9435:                 if (keys(%{$rules}) > 0) {
                   9436:                     push(@options,('official','unofficial'));
1.37      raeburn  9437:                 }
                   9438:             }
1.224     raeburn  9439:             push(@options,'none');
1.37      raeburn  9440:             foreach my $option (@options) {
1.50      raeburn  9441:                 my $type = 'radio';
1.34      raeburn  9442:                 my $check = ' ';
1.224     raeburn  9443:                 if ($checked{$item} eq $option) {
                   9444:                     $check = ' checked="checked" ';
1.34      raeburn  9445:                 } 
                   9446:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  9447:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  9448:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   9449:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   9450:             }
                   9451:             $datatable .= '</td></tr>';
                   9452:         }
1.28      raeburn  9453:     } else {
                   9454:         my @contexts = ('author','course','domain');
1.325     raeburn  9455:         my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  9456:         my %checked;
                   9457:         if (ref($settings) eq 'HASH') {
                   9458:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   9459:                 foreach my $item (@contexts) {
                   9460:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   9461:                         foreach my $auth (@authtypes) {
                   9462:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   9463:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   9464:                             }
                   9465:                         }
                   9466:                     }
                   9467:                 }
1.27      raeburn  9468:             }
1.35      raeburn  9469:         } else {
                   9470:             foreach my $item (@contexts) {
1.36      raeburn  9471:                 foreach my $auth (@authtypes) {
1.35      raeburn  9472:                     $checked{$item}{$auth} = ' checked="checked" ';
                   9473:                 }
                   9474:             }
1.27      raeburn  9475:         }
1.28      raeburn  9476:         my %title = &context_names();
                   9477:         my %authname = &authtype_names();
                   9478:         my $rownum = 0;
                   9479:         my $css_class; 
                   9480:         foreach my $item (@contexts) {
                   9481:             if ($rownum%2) {
                   9482:                 $css_class = '';
                   9483:             } else {
                   9484:                 $css_class = ' class="LC_odd_row" ';
                   9485:             }
1.30      raeburn  9486:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  9487:                             '<td>'.$title{$item}.
                   9488:                             '</td><td class="LC_left_item">'.
                   9489:                             '<span class="LC_nobreak">';
                   9490:             foreach my $auth (@authtypes) {
                   9491:                 $datatable .= '<label>'. 
                   9492:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   9493:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   9494:                               $authname{$auth}.'</label>&nbsp;';
                   9495:             }
                   9496:             $datatable .= '</span></td></tr>';
                   9497:             $rownum ++;
1.27      raeburn  9498:         }
1.30      raeburn  9499:         $$rowtotal += $rownum;
1.27      raeburn  9500:     }
                   9501:     return $datatable;
                   9502: }
                   9503: 
1.224     raeburn  9504: sub print_selfcreation {
                   9505:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  9506:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   9507:         $emaildomain,$datatable);
1.224     raeburn  9508:     if (ref($settings) eq 'HASH') {
                   9509:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9510:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  9511:             if (ref($createsettings) eq 'HASH') {
                   9512:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   9513:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   9514:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   9515:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   9516:                         @selfcreate = ('email','login','sso');
                   9517:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   9518:                         @selfcreate = ($createsettings->{'selfcreate'});
                   9519:                     }
                   9520:                 }
                   9521:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   9522:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  9523:                 }
1.305     raeburn  9524:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   9525:                     $emailoptions = $createsettings->{'emailoptions'};
                   9526:                 }
1.303     raeburn  9527:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   9528:                     $emailverified = $createsettings->{'emailverified'};
                   9529:                 }
                   9530:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   9531:                     $emaildomain = $createsettings->{'emaildomain'};
                   9532:                 }
1.224     raeburn  9533:             }
                   9534:         }
                   9535:     }
                   9536:     my %radiohash;
                   9537:     my $numinrow = 4;
                   9538:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  9539:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  9540:     if ($position eq 'top') {
                   9541:         my %choices = &Apache::lonlocal::texthash (
                   9542:                                                       cancreate_login      => 'Institutional Login',
                   9543:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   9544:                                                   );
                   9545:         my @toggles = sort(keys(%choices));
                   9546:         my %defaultchecked = (
                   9547:                                'cancreate_login' => 'off',
                   9548:                                'cancreate_sso'   => 'off',
                   9549:                              );
1.228     raeburn  9550:         my ($onclick,$itemcount);
1.224     raeburn  9551:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   9552:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  9553:         $$rowtotal += $itemcount;
                   9554:         
1.224     raeburn  9555:         if (ref($usertypes) eq 'HASH') {
                   9556:             if (keys(%{$usertypes}) > 0) {
                   9557:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   9558:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  9559:                                              'statustocreate',$rowtotal);
1.224     raeburn  9560:                 $$rowtotal ++;
                   9561:             }
                   9562:         }
1.240     raeburn  9563:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   9564:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9565:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   9566:         my $rem;
                   9567:         my $numperrow = 2;
                   9568:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   9569:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  9570:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  9571:                      '<td class="LC_left_item">'."\n".
1.334     raeburn  9572:                      '<table>'."\n";
1.240     raeburn  9573:         for (my $i=0; $i<@fields; $i++) {
                   9574:             $rem = $i%($numperrow);
                   9575:             if ($rem == 0) {
                   9576:                 if ($i > 0) {
                   9577:                     $datatable .= '</tr>';
                   9578:                 }
                   9579:                 $datatable .= '<tr>';
                   9580:             }
                   9581:             my $currval;
1.248     raeburn  9582:             if (ref($createsettings) eq 'HASH') {
                   9583:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   9584:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   9585:                 }
1.240     raeburn  9586:             }
                   9587:             $datatable .= '<td class="LC_left_item">'.
                   9588:                           '<span class="LC_nobreak">'.
                   9589:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   9590:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   9591:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   9592:         }
                   9593:         my $colsleft = $numperrow - $rem;
                   9594:         if ($colsleft > 1 ) {
                   9595:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9596:                          '&nbsp;</td>';
                   9597:         } elsif ($colsleft == 1) {
                   9598:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   9599:         }
                   9600:         $datatable .= '</tr></table></td></tr>';
                   9601:         $$rowtotal ++;
1.224     raeburn  9602:     } elsif ($position eq 'middle') {
                   9603:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  9604:         my @posstypes;
1.224     raeburn  9605:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  9606:             @posstypes = @{$types};
                   9607:         }
                   9608:         unless (grep(/^default$/,@posstypes)) {
                   9609:             push(@posstypes,'default');
                   9610:         }
                   9611:         my %usertypeshash;
                   9612:         if (ref($usertypes) eq 'HASH') {
                   9613:             %usertypeshash = %{$usertypes};
                   9614:         }
                   9615:         $usertypeshash{'default'} = $othertitle;
                   9616:         foreach my $status (@posstypes) {
                   9617:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   9618:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   9619:             $$rowtotal ++;
1.224     raeburn  9620:         }
                   9621:     } else {
1.236     raeburn  9622:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  9623:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  9624:                                                   );
                   9625:         my @toggles = sort(keys(%choices));
                   9626:         my %defaultchecked = (
                   9627:                                'cancreate_email' => 'off',
                   9628:                              );
1.305     raeburn  9629:         my $customclass = 'LC_selfcreate_email';
                   9630:         my $classprefix = 'LC_canmodify_emailusername_';
                   9631:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  9632:         my $display = 'none';
1.305     raeburn  9633:         my $rowstyle = 'display:none';
1.236     raeburn  9634:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   9635:             $display = 'block';
1.305     raeburn  9636:             $rowstyle = 'display:table-row';
1.236     raeburn  9637:         }
1.305     raeburn  9638:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   9639:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   9640:                                                      \%choices,$$rowtotal,$onclick);
                   9641:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   9642:                                          $rowstyle);
                   9643:         $$rowtotal ++;
                   9644:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   9645:                                       $rowstyle);
                   9646:         $$rowtotal ++;
                   9647:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  9648:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  9649:         my ($emailrules,$emailruleorder) =
                   9650:             &Apache::lonnet::inst_userrules($dom,'email');
                   9651:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9652:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9653:         if (ref($types) eq 'ARRAY') {
                   9654:             @posstypes = @{$types};
                   9655:         }
                   9656:         if (@posstypes) {
                   9657:             unless (grep(/^default$/,@posstypes)) {
                   9658:                 push(@posstypes,'default');
1.302     raeburn  9659:             }
                   9660:             if (ref($usertypes) eq 'HASH') {
                   9661:                 %usertypeshash = %{$usertypes};
                   9662:             }
1.305     raeburn  9663:             my $currassign;
                   9664:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   9665:                 $currassign = {
                   9666:                                   selfassign => $domdefaults{'inststatusguest'},
                   9667:                               };
                   9668:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   9669:             } else {
                   9670:                 $currassign = { selfassign => [] };
                   9671:             }
                   9672:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   9673:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   9674:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   9675:                                          $numinrow,$othertitle,'selfassign',
                   9676:                                          $rowtotal,$onclicktypes,$customclass,
                   9677:                                          $rowstyle);
                   9678:             $$rowtotal ++;
1.302     raeburn  9679:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  9680:             foreach my $status (@posstypes) {
                   9681:                 my $css_class;
                   9682:                 if ($$rowtotal%2) {
                   9683:                     $css_class = 'LC_odd_row ';
                   9684:                 }
                   9685:                 $css_class .= $customclass;
                   9686:                 my $rowid = $optionsprefix.$status;
                   9687:                 my $hidden = 1;
                   9688:                 my $currstyle = 'display:none';
                   9689:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   9690:                     $currstyle = $rowstyle;
                   9691:                     $hidden = 0; 
                   9692:                 }
                   9693:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   9694:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   9695:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   9696:                 unless ($hidden) {
                   9697:                     $$rowtotal ++;
                   9698:                 }
1.224     raeburn  9699:             }
1.302     raeburn  9700:         } else {
1.305     raeburn  9701:             my $css_class;
                   9702:             if ($$rowtotal%2) {
                   9703:                 $css_class = 'LC_odd_row ';
                   9704:             }
                   9705:             $css_class .= $customclass;
1.302     raeburn  9706:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  9707:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   9708:                                          $emailrules,$emailruleorder,$settings,'default','',
                   9709:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   9710:             $$rowtotal ++;
1.224     raeburn  9711:         }
                   9712:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  9713:         $numinrow = 1;
1.305     raeburn  9714:         if (@posstypes) {
                   9715:             foreach my $status (@posstypes) {
                   9716:                 my $rowid = $classprefix.$status;
                   9717:                 my $datarowstyle = 'display:none';
                   9718:                 if (grep(/^\Q$status\E$/,@ordered)) { 
                   9719:                     $datarowstyle = $rowstyle; 
                   9720:                 }
                   9721:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   9722:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   9723:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   9724:                 unless ($datarowstyle eq 'display:none') {
                   9725:                     $$rowtotal ++;
                   9726:                 }
1.224     raeburn  9727:             }
1.305     raeburn  9728:         } else {
                   9729:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   9730:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   9731:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  9732:         }
                   9733:     }
                   9734:     return $datatable;
                   9735: }
                   9736: 
1.305     raeburn  9737: sub selfcreate_javascript {
                   9738:     return <<"ENDSCRIPT";
                   9739: 
                   9740: <script type="text/javascript">
                   9741: // <![CDATA[
                   9742: 
                   9743: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   9744:     var x = document.getElementsByClassName(target);
                   9745:     var insttypes = 0;
                   9746:     var insttypeRegExp = new RegExp(prefix);
                   9747:     if ((x.length != undefined) && (x.length > 0)) {
                   9748:         if (form.elements[radio].length != undefined) {
                   9749:             for (var i=0; i<form.elements[radio].length; i++) {
                   9750:                 if (form.elements[radio][i].checked) {
                   9751:                     if (form.elements[radio][i].value == 1) {
                   9752:                         for (var j=0; j<x.length; j++) {
                   9753:                             if (x[j].id == 'undefined') {
                   9754:                                 x[j].style.display = 'table-row';
                   9755:                             } else if (insttypeRegExp.test(x[j].id)) {
                   9756:                                 insttypes ++;
                   9757:                             } else {
                   9758:                                 x[j].style.display = 'table-row';
                   9759:                             }
                   9760:                         }
                   9761:                     } else {
                   9762:                         for (var j=0; j<x.length; j++) {
                   9763:                             x[j].style.display = 'none';
                   9764:                         }
1.236     raeburn  9765:                     }
1.305     raeburn  9766:                     break;
                   9767:                 }
                   9768:             }
                   9769:             if (insttypes > 0) {
                   9770:                 toggleDataRow(form,checkbox,target,altprefix);
                   9771:                 toggleDataRow(form,checkbox,target,prefix,1);
                   9772:             }
                   9773:         }
                   9774:     }
                   9775:     return;
                   9776: }
                   9777: 
                   9778: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   9779:     if (form.elements[checkbox].length != undefined) {
                   9780:         var count = 0;
                   9781:         if (docount) {
                   9782:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   9783:                 if (form.elements[checkbox][i].checked) {
                   9784:                     count ++;
1.236     raeburn  9785:                 }
1.305     raeburn  9786:             }
                   9787:         }
                   9788:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   9789:             var type = form.elements[checkbox][i].value;
                   9790:             if (document.getElementById(prefix+type)) {
                   9791:                 if (form.elements[checkbox][i].checked) {
                   9792:                     document.getElementById(prefix+type).style.display = 'table-row';
                   9793:                     if (count % 2 == 1) {
                   9794:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   9795:                     } else {
                   9796:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  9797:                     }
1.305     raeburn  9798:                     count ++;
1.236     raeburn  9799:                 } else {
1.305     raeburn  9800:                     document.getElementById(prefix+type).style.display = 'none';
                   9801:                 }
                   9802:             }
                   9803:         }
                   9804:     }
                   9805:     return;
                   9806: }
                   9807: 
                   9808: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   9809:     var caller = radio+'_'+status;
                   9810:     if (form.elements[caller].length != undefined) {
                   9811:         for (var i=0; i<form.elements[caller].length; i++) {
                   9812:             if (form.elements[caller][i].checked) {
                   9813:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   9814:                     var curr = form.elements[caller][i].value;
                   9815:                     if (prefix) {
                   9816:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   9817:                     }
                   9818:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   9819:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   9820:                     if (curr == 'custom') {
                   9821:                         if (prefix) { 
                   9822:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   9823:                         }
                   9824:                     } else if (curr == 'inst') {
                   9825:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   9826:                     } else if (curr == 'noninst') {
                   9827:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  9828:                     }
1.305     raeburn  9829:                     break;
1.236     raeburn  9830:                 }
                   9831:             }
                   9832:         }
                   9833:     }
                   9834: }
                   9835: 
1.305     raeburn  9836: // ]]>
                   9837: </script>
                   9838: 
                   9839: ENDSCRIPT
                   9840: }
                   9841: 
                   9842: sub noninst_users {
                   9843:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   9844:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                   9845:     my $class = 'LC_left_item';
                   9846:     if ($css_class) {
                   9847:         $css_class = ' class="'.$css_class.'"'; 
                   9848:     }
                   9849:     if ($rowid) {
                   9850:         $rowid = ' id="'.$rowid.'"';
                   9851:     }
                   9852:     if ($rowstyle) {
                   9853:         $rowstyle = ' style="'.$rowstyle.'"';
                   9854:     }
                   9855:     my ($output,$description);
                   9856:     if ($type eq 'default') {
                   9857:         $description = &mt('Requests for: [_1]',$typetitle);
                   9858:     } else {
                   9859:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   9860:     }
                   9861:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   9862:               "<td>$description</td>\n".           
                   9863:               '<td class="'.$class.'" colspan="2">'.
                   9864:               '<table><tr>';
                   9865:     my %headers = &Apache::lonlocal::texthash( 
                   9866:               approve  => 'Processing',
                   9867:               email    => 'E-mail',
                   9868:               username => 'Username',
                   9869:     );
                   9870:     foreach my $item ('approve','email','username') {
                   9871:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  9872:     }
1.305     raeburn  9873:     $output .= '</tr><tr>';
                   9874:     foreach my $item ('approve','email','username') {
1.306     raeburn  9875:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  9876:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   9877:         if ($item eq 'approve') {
                   9878:             %choices = &Apache::lonlocal::texthash (
                   9879:                                                      automatic => 'Automatically approved',
                   9880:                                                      approval  => 'Queued for approval',
                   9881:                                                    );
                   9882:             @options = ('automatic','approval');
                   9883:             $hashref = $processing;
                   9884:             $defoption = 'automatic';
                   9885:             $name = 'cancreate_emailprocess_'.$type;
                   9886:         } elsif ($item eq 'email') {
                   9887:             %choices = &Apache::lonlocal::texthash (
                   9888:                                                      any     => 'Any e-mail',
                   9889:                                                      inst    => 'Institutional only',
                   9890:                                                      noninst => 'Non-institutional only',
                   9891:                                                      custom  => 'Custom restrictions',
                   9892:                                                    );
                   9893:             @options = ('any','inst','noninst');
                   9894:             my $showcustom;
                   9895:             if (ref($emailrules) eq 'HASH') {
                   9896:                 if (keys(%{$emailrules}) > 0) {
                   9897:                     push(@options,'custom');
                   9898:                     $showcustom = 'cancreate_emailrule';
                   9899:                     if (ref($settings) eq 'HASH') {
                   9900:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   9901:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   9902:                                 if (exists($emailrules->{$rule})) {
                   9903:                                     $hascustom ++;
                   9904:                                 }
                   9905:                             }
                   9906:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   9907:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   9908:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   9909:                                     if (exists($emailrules->{$rule})) {
                   9910:                                         $hascustom ++;
                   9911:                                     }
                   9912:                                 }
                   9913:                             }
                   9914:                         }
                   9915:                     }
                   9916:                 }
                   9917:             }
                   9918:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   9919:                                                      "'cancreate_emaildomain','$type'".');"';
                   9920:             $hashref = $emailoptions;
                   9921:             $defoption = 'any';
                   9922:             $name = 'cancreate_emailoptions_'.$type;
                   9923:         } elsif ($item eq 'username') {
                   9924:             %choices = &Apache::lonlocal::texthash (
                   9925:                                                      all    => 'Same as e-mail',
                   9926:                                                      first  => 'Omit @domain',
                   9927:                                                      free   => 'Free to choose',
                   9928:                                                    );
                   9929:             @options = ('all','first','free');
                   9930:             $hashref = $emailverified;
                   9931:             $defoption = 'all';
                   9932:             $name = 'cancreate_usernameoptions_'.$type;
                   9933:         }
                   9934:         foreach my $option (@options) {
                   9935:             my $checked;
                   9936:             if (ref($hashref) eq 'HASH') {
                   9937:                 if ($type eq '') {
                   9938:                     if (!exists($hashref->{'default'})) {
                   9939:                         if ($option eq $defoption) {
                   9940:                             $checked = ' checked="checked"';
                   9941:                         }
                   9942:                     } else {
                   9943:                         if ($hashref->{'default'} eq $option) {
                   9944:                             $checked = ' checked="checked"';
                   9945:                         }
1.303     raeburn  9946:                     }
                   9947:                 } else {
1.305     raeburn  9948:                     if (!exists($hashref->{$type})) {
                   9949:                         if ($option eq $defoption) {
                   9950:                             $checked = ' checked="checked"';
                   9951:                         }
                   9952:                     } else {
                   9953:                         if ($hashref->{$type} eq $option) {
                   9954:                             $checked = ' checked="checked"';
                   9955:                         }
1.303     raeburn  9956:                     }
                   9957:                 }
1.305     raeburn  9958:             } elsif (($item eq 'email') && ($hascustom)) {
                   9959:                 if ($option eq 'custom') {
                   9960:                     $checked = ' checked="checked"';
                   9961:                 }
                   9962:             } elsif ($option eq $defoption) {
                   9963:                 $checked = ' checked="checked"';
                   9964:             }
                   9965:             $output .= '<span class="LC_nobreak"><label>'.
                   9966:                        '<input type="radio" name="'.$name.'"'.
                   9967:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   9968:                        $choices{$option}.'</label></span><br />';
                   9969:             if ($item eq 'email') {
                   9970:                 if ($option eq 'custom') {
                   9971:                     my $id = 'cancreate_emailrule_'.$type;
                   9972:                     my $display = 'none';
                   9973:                     if ($checked) {
                   9974:                         $display = 'inline';
1.303     raeburn  9975:                     }
1.305     raeburn  9976:                     my $numinrow = 2;
                   9977:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   9978:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   9979:                                &user_formats_row('email',$settings,$emailrules,
                   9980:                                                  $emailruleorder,$numinrow,'',$type);
                   9981:                               '</table></fieldset>';
                   9982:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   9983:                     my %text = &Apache::lonlocal::texthash (
                   9984:                                                              inst    => 'must end:',
                   9985:                                                              noninst => 'cannot end:',
                   9986:                                                            );
                   9987:                     my $value;
                   9988:                     if (ref($emaildomain) eq 'HASH') {
                   9989:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   9990:                             $value = $emaildomain->{$type}->{$option}; 
1.303     raeburn  9991:                         }
                   9992:                     }
1.305     raeburn  9993:                     if ($value eq '') {
                   9994:                         $value = '@'.$intdom;
                   9995:                     }
                   9996:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   9997:                     my $display = 'none';
                   9998:                     if ($checked) {
                   9999:                         $display = 'inline';
                   10000:                     }
                   10001:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   10002:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   10003:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   10004:                                '</div>';
1.303     raeburn  10005:                 }
                   10006:             }
                   10007:         }
1.305     raeburn  10008:         $output .= '</td>'."\n";
1.303     raeburn  10009:     }
1.305     raeburn  10010:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  10011:     return $output;
                   10012: }
                   10013: 
1.165     raeburn  10014: sub captcha_choice {
1.305     raeburn  10015:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  10016:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   10017:         $vertext,$currver);
1.165     raeburn  10018:     my %lt = &captcha_phrases();
                   10019:     $keyentry = 'hidden';
1.354     raeburn  10020:     my $colspan=2;
1.165     raeburn  10021:     if ($context eq 'cancreate') {
1.224     raeburn  10022:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  10023:     } elsif ($context eq 'login') {
                   10024:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.354     raeburn  10025:     } elsif ($context eq 'passwords') {
                   10026:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   10027:         $colspan=1;
1.165     raeburn  10028:     }
                   10029:     if (ref($settings) eq 'HASH') {
                   10030:         if ($settings->{'captcha'}) {
                   10031:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   10032:         } else {
                   10033:             $checked{'original'} = ' checked="checked"';
                   10034:         }
                   10035:         if ($settings->{'captcha'} eq 'recaptcha') {
                   10036:             $pubtext = $lt{'pub'};
                   10037:             $privtext = $lt{'priv'};
                   10038:             $keyentry = 'text';
1.269     raeburn  10039:             $vertext = $lt{'ver'};
                   10040:             $currver = $settings->{'recaptchaversion'};
                   10041:             if ($currver ne '2') {
                   10042:                 $currver = 1;
                   10043:             }
1.165     raeburn  10044:         }
                   10045:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   10046:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   10047:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   10048:         }
                   10049:     } else {
                   10050:         $checked{'original'} = ' checked="checked"';
                   10051:     }
1.305     raeburn  10052:     my $css_class;
                   10053:     if ($itemcount%2) {
                   10054:         $css_class = 'LC_odd_row';
                   10055:     }
                   10056:     if ($customcss) {
                   10057:         $css_class .= " $customcss";
                   10058:     }
                   10059:     $css_class =~ s/^\s+//;
                   10060:     if ($css_class) {
                   10061:         $css_class = ' class="'.$css_class.'"';
                   10062:     }
                   10063:     if ($rowstyle) {
                   10064:         $css_class .= ' style="'.$rowstyle.'"';
                   10065:     }
1.169     raeburn  10066:     my $output = '<tr'.$css_class.'>'.
1.354     raeburn  10067:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165     raeburn  10068:                  '<table><tr><td>'."\n";
                   10069:     foreach my $option ('original','recaptcha','notused') {
                   10070:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   10071:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   10072:                    $lt{$option}.'</label></span>';
                   10073:         unless ($option eq 'notused') {
                   10074:             $output .= ('&nbsp;'x2)."\n";
                   10075:         }
                   10076:     }
                   10077: #
                   10078: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   10079: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  10080: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  10081: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  10082: #
1.165     raeburn  10083:     $output .= '</td></tr>'."\n".
1.305     raeburn  10084:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  10085:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   10086:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   10087:                $currpub.'" size="40" /></span><br />'."\n".
                   10088:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   10089:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  10090:                $currpriv.'" size="40" /></span><br />'.
                   10091:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   10092:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   10093:                $currver.'" size="3" /></span><br />'.
                   10094:                '</td></tr></table>'."\n".
1.165     raeburn  10095:                '</td></tr>';
                   10096:     return $output;
                   10097: }
                   10098: 
1.32      raeburn  10099: sub user_formats_row {
1.305     raeburn  10100:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  10101:     my $output;
                   10102:     my %text = (
                   10103:                    'username' => 'new usernames',
                   10104:                    'id'       => 'IDs',
                   10105:                );
1.305     raeburn  10106:     unless ($type eq 'email') {
                   10107:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   10108:         $output = '<tr '.$css_class.'>'.
                   10109:                   '<td><span class="LC_nobreak">'.
                   10110:                   &mt("Format rules to check for $text{$type}: ").
                   10111:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  10112:     }
1.27      raeburn  10113:     my $rem;
                   10114:     if (ref($ruleorder) eq 'ARRAY') {
                   10115:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   10116:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   10117:                 my $rem = $i%($numinrow);
                   10118:                 if ($rem == 0) {
                   10119:                     if ($i > 0) {
                   10120:                         $output .= '</tr>';
                   10121:                     }
                   10122:                     $output .= '<tr>';
                   10123:                 }
                   10124:                 my $check = ' ';
1.39      raeburn  10125:                 if (ref($settings) eq 'HASH') {
                   10126:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   10127:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   10128:                             $check = ' checked="checked" ';
                   10129:                         }
1.305     raeburn  10130:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   10131:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   10132:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   10133:                                 $check = ' checked="checked" ';
                   10134:                             }
                   10135:                         }
1.27      raeburn  10136:                     }
                   10137:                 }
1.305     raeburn  10138:                 my $name = $type.'_rule';
                   10139:                 if ($type eq 'email') {
                   10140:                     $name .= '_'.$status;
                   10141:                 }
1.27      raeburn  10142:                 $output .= '<td class="LC_left_item">'.
                   10143:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  10144:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  10145:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   10146:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   10147:             }
                   10148:         }
                   10149:         $rem = @{$ruleorder}%($numinrow);
                   10150:     }
1.305     raeburn  10151:     my $colsleft;
                   10152:     if ($rem) {
                   10153:         $colsleft = $numinrow - $rem;
                   10154:     }
1.27      raeburn  10155:     if ($colsleft > 1 ) {
                   10156:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   10157:                    '&nbsp;</td>';
                   10158:     } elsif ($colsleft == 1) {
                   10159:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   10160:     }
1.305     raeburn  10161:     $output .= '</tr></table>';
                   10162:     unless ($type eq 'email') {
                   10163:         $output .= '</td></tr>';
                   10164:     }
1.27      raeburn  10165:     return $output;
                   10166: }
                   10167: 
1.34      raeburn  10168: sub usercreation_types {
                   10169:     my %lt = &Apache::lonlocal::texthash (
                   10170:                     author     => 'When adding a co-author',
                   10171:                     course     => 'When adding a user to a course',
1.100     raeburn  10172:                     requestcrs => 'When requesting a course',
1.34      raeburn  10173:                     any        => 'Any',
                   10174:                     official   => 'Institutional only ',
                   10175:                     unofficial => 'Non-institutional only',
                   10176:                     none       => 'None',
                   10177:     );
                   10178:     return %lt;
1.48      raeburn  10179: }
1.34      raeburn  10180: 
1.224     raeburn  10181: sub selfcreation_types {
                   10182:     my %lt = &Apache::lonlocal::texthash (
                   10183:                     selfcreate => 'User creates own account',
                   10184:                     any        => 'Any',
                   10185:                     official   => 'Institutional only ',
                   10186:                     unofficial => 'Non-institutional only',
                   10187:                     email      => 'E-mail address',
                   10188:                     login      => 'Institutional Login',
                   10189:                     sso        => 'SSO',
                   10190:              );
                   10191: }
                   10192: 
1.28      raeburn  10193: sub authtype_names {
                   10194:     my %lt = &Apache::lonlocal::texthash(
                   10195:                       int    => 'Internal',
                   10196:                       krb4   => 'Kerberos 4',
                   10197:                       krb5   => 'Kerberos 5',
                   10198:                       loc    => 'Local',
1.325     raeburn  10199:                       lti    => 'LTI',
1.28      raeburn  10200:                   );
                   10201:     return %lt;
                   10202: }
                   10203: 
                   10204: sub context_names {
                   10205:     my %context_title = &Apache::lonlocal::texthash(
                   10206:        author => 'Creating users when an Author',
                   10207:        course => 'Creating users when in a course',
                   10208:        domain => 'Creating users when a Domain Coordinator',
                   10209:     );
                   10210:     return %context_title;
                   10211: }
                   10212: 
1.33      raeburn  10213: sub print_usermodification {
                   10214:     my ($position,$dom,$settings,$rowtotal) = @_;
                   10215:     my $numinrow = 4;
                   10216:     my ($context,$datatable,$rowcount);
                   10217:     if ($position eq 'top') {
                   10218:         $rowcount = 0;
                   10219:         $context = 'author'; 
                   10220:         foreach my $role ('ca','aa') {
                   10221:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10222:                                                    $numinrow,$rowcount);
                   10223:             $$rowtotal ++;
                   10224:             $rowcount ++;
                   10225:         }
1.230     raeburn  10226:     } elsif ($position eq 'bottom') {
1.33      raeburn  10227:         $context = 'course';
                   10228:         $rowcount = 0;
                   10229:         foreach my $role ('st','ep','ta','in','cr') {
                   10230:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10231:                                                    $numinrow,$rowcount);
                   10232:             $$rowtotal ++;
                   10233:             $rowcount ++;
                   10234:         }
                   10235:     }
                   10236:     return $datatable;
                   10237: }
                   10238: 
1.43      raeburn  10239: sub print_defaults {
1.236     raeburn  10240:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  10241:     my $rownum = 0;
1.294     raeburn  10242:     my ($datatable,$css_class,$titles);
                   10243:     unless ($position eq 'bottom') {
                   10244:         $titles = &defaults_titles($dom);
                   10245:     }
1.236     raeburn  10246:     if ($position eq 'top') {
                   10247:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   10248:                      'datelocale_def','portal_def');
                   10249:         my %defaults;
                   10250:         if (ref($settings) eq 'HASH') {
                   10251:             %defaults = %{$settings};
1.43      raeburn  10252:         } else {
1.236     raeburn  10253:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10254:             foreach my $item (@items) {
                   10255:                 $defaults{$item} = $domdefaults{$item};
                   10256:             }
1.43      raeburn  10257:         }
1.236     raeburn  10258:         foreach my $item (@items) {
                   10259:             if ($rownum%2) {
                   10260:                 $css_class = '';
                   10261:             } else {
                   10262:                 $css_class = ' class="LC_odd_row" ';
                   10263:             }
                   10264:             $datatable .= '<tr'.$css_class.'>'.
                   10265:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   10266:                           '</span></td><td class="LC_right_item" colspan="3">';
                   10267:             if ($item eq 'auth_def') {
1.325     raeburn  10268:                 my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236     raeburn  10269:                 my %shortauth = (
                   10270:                                  internal => 'int',
                   10271:                                  krb4 => 'krb4',
                   10272:                                  krb5 => 'krb5',
1.325     raeburn  10273:                                  localauth  => 'loc',
                   10274:                                  lti => 'lti',
1.236     raeburn  10275:                                 );
                   10276:                 my %authnames = &authtype_names();
                   10277:                 foreach my $auth (@authtypes) {
                   10278:                     my $checked = ' ';
                   10279:                     if ($defaults{$item} eq $auth) {
                   10280:                         $checked = ' checked="checked" ';
                   10281:                     }
                   10282:                     $datatable .= '<label><input type="radio" name="'.$item.
                   10283:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   10284:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   10285:                 }
                   10286:             } elsif ($item eq 'timezone_def') {
                   10287:                 my $includeempty = 1;
                   10288:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   10289:             } elsif ($item eq 'datelocale_def') {
                   10290:                 my $includeempty = 1;
                   10291:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   10292:             } elsif ($item eq 'lang_def') {
1.263     raeburn  10293:                 my $includeempty = 1;
                   10294:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  10295:             } else {
                   10296:                 my $size;
                   10297:                 if ($item eq 'portal_def') {
                   10298:                     $size = ' size="25"';
                   10299:                 }
                   10300:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   10301:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  10302:             }
1.236     raeburn  10303:             $datatable .= '</td></tr>';
                   10304:             $rownum ++;
                   10305:         }
1.354     raeburn  10306:     } else {
1.294     raeburn  10307:         my %defaults;
                   10308:         if (ref($settings) eq 'HASH') {
1.354     raeburn  10309:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   10310:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   10311:                 for (my $i=0; $i<$maxnum; $i++) {
                   10312:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10313:                     my $item = $settings->{'inststatusorder'}->[$i];
                   10314:                     my $title = $settings->{'inststatustypes'}->{$item};
                   10315:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   10316:                     $datatable .= '<tr'.$css_class.'>'.
                   10317:                                   '<td><span class="LC_nobreak">'.
                   10318:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   10319:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10320:                         my $vpos = $k+1;
                   10321:                         my $selstr;
                   10322:                         if ($k == $i) {
                   10323:                             $selstr = ' selected="selected" ';
                   10324:                         }
                   10325:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10326:                     }
                   10327:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   10328:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   10329:                                   &mt('delete').'</span></td>'.
1.380     raeburn  10330:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354     raeburn  10331:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   10332:                                   '</span></td></tr>';
                   10333:                 }
                   10334:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10335:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   10336:                 $datatable .= '<tr '.$css_class.'>'.
                   10337:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   10338:                 for (my $k=0; $k<=$maxnum; $k++) {
                   10339:                     my $vpos = $k+1;
                   10340:                     my $selstr;
                   10341:                     if ($k == $maxnum) {
                   10342:                         $selstr = ' selected="selected" ';
                   10343:                     }
                   10344:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10345:                 }
                   10346:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                   10347:                               '<input type="text" size="10" name="addinststatus" value="" />'.
                   10348:                               '&nbsp;'.&mt('(new)').
                   10349:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380     raeburn  10350:                               &mt('Name displayed').':'.
1.354     raeburn  10351:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   10352:                               '</tr>'."\n";
                   10353:                 $rownum ++;
1.294     raeburn  10354:             }
1.354     raeburn  10355:         }
                   10356:     }
                   10357:     $$rowtotal += $rownum;
1.43      raeburn  10358:     return $datatable;
                   10359: }
                   10360: 
1.168     raeburn  10361: sub get_languages_hash {
                   10362:     my %langchoices;
                   10363:     foreach my $id (&Apache::loncommon::languageids()) {
                   10364:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   10365:         if ($code ne '') {
                   10366:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   10367:         }
                   10368:     }
                   10369:     return %langchoices;
                   10370: }
                   10371: 
1.43      raeburn  10372: sub defaults_titles {
1.141     raeburn  10373:     my ($dom) = @_;
1.43      raeburn  10374:     my %titles = &Apache::lonlocal::texthash (
                   10375:                    'auth_def'      => 'Default authentication type',
                   10376:                    'auth_arg_def'  => 'Default authentication argument',
                   10377:                    'lang_def'      => 'Default language',
1.54      raeburn  10378:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  10379:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  10380:                    'portal_def'     => 'Portal/Default URL',
1.294     raeburn  10381:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   10382:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   10383:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  10384:                  );
1.141     raeburn  10385:     if ($dom) {
                   10386:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   10387:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   10388:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   10389:         $protocol = 'http' if ($protocol ne 'https');
                   10390:         if ($uint_dom) {
                   10391:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   10392:                                          $uint_dom);
                   10393:         }
                   10394:     }
1.43      raeburn  10395:     return (\%titles);
                   10396: }
                   10397: 
1.346     raeburn  10398: sub print_scantron {
                   10399:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   10400:     if ($position eq 'top') {
                   10401:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   10402:     } else {
                   10403:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   10404:     }
                   10405: }
                   10406: 
                   10407: sub scantron_javascript {
                   10408:     return <<"ENDSCRIPT";
                   10409: 
                   10410: <script type="text/javascript">
                   10411: // <![CDATA[
                   10412: 
                   10413: function toggleScantron(form) {
1.347     raeburn  10414:     var csvfieldset = new Array();
1.346     raeburn  10415:     if (document.getElementById('scantroncsv_cols')) {
1.347     raeburn  10416:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   10417:     }
                   10418:     if (document.getElementById('scantroncsv_options')) {
                   10419:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   10420:     }
                   10421:     if (csvfieldset.length) {
1.346     raeburn  10422:         if (document.getElementById('scantronconfcsv')) {
1.347     raeburn  10423:             var scantroncsv = document.getElementById('scantronconfcsv');
1.346     raeburn  10424:             if (scantroncsv.checked) {
1.347     raeburn  10425:                 for (var i=0; i<csvfieldset.length; i++) {
                   10426:                     csvfieldset[i].style.display = 'block';
                   10427:                 }
1.346     raeburn  10428:             } else {
1.347     raeburn  10429:                 for (var i=0; i<csvfieldset.length; i++) {
                   10430:                     csvfieldset[i].style.display = 'none';
                   10431:                 }
1.346     raeburn  10432:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   10433:                 if (csvselects.length) {
                   10434:                     for (var j=0; j<csvselects.length; j++) {
                   10435:                         csvselects[j].selectedIndex = 0;
                   10436:                     }
                   10437:                 }
                   10438:             }
                   10439:         }
                   10440:     }
                   10441:     return;
                   10442: }
                   10443: // ]]>
                   10444: </script>
                   10445: 
                   10446: ENDSCRIPT
                   10447: 
                   10448: }
                   10449: 
1.46      raeburn  10450: sub print_scantronformat {
                   10451:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   10452:     my $itemcount = 1;
1.60      raeburn  10453:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   10454:         %confhash);
1.46      raeburn  10455:     my $switchserver = &check_switchserver($dom,$confname);
                   10456:     my %lt = &Apache::lonlocal::texthash (
1.95      www      10457:                 default => 'Default bubblesheet format file error',
                   10458:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  10459:              );
                   10460:     my %scantronfiles = (
                   10461:         default => 'default.tab',
                   10462:         custom => 'custom.tab',
                   10463:     );
                   10464:     foreach my $key (keys(%scantronfiles)) {
                   10465:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   10466:                               .$scantronfiles{$key};
                   10467:     }
                   10468:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   10469:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   10470:         if (!$switchserver) {
                   10471:             my $servadm = $r->dir_config('lonAdmEMail');
                   10472:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   10473:             if ($configuserok eq 'ok') {
                   10474:                 if ($author_ok eq 'ok') {
                   10475:                     my %legacyfile = (
1.346     raeburn  10476:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   10477:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  10478:                     );
                   10479:                     my %md5chk;
                   10480:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  10481:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   10482:                         chomp($md5chk{$type});
1.46      raeburn  10483:                     }
                   10484:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   10485:                         foreach my $type (keys(%legacyfile)) {
1.346     raeburn  10486:                             ($scantronurls{$type},my $error) =
1.46      raeburn  10487:                                 &legacy_scantronformat($r,$dom,$confname,
                   10488:                                                  $type,$legacyfile{$type},
                   10489:                                                  $scantronurls{$type},
                   10490:                                                  $scantronfiles{$type});
1.60      raeburn  10491:                             if ($error ne '') {
                   10492:                                 $error{$type} = $error;
                   10493:                             }
                   10494:                         }
                   10495:                         if (keys(%error) == 0) {
                   10496:                             $is_custom = 1;
1.346     raeburn  10497:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  10498:                                 $scantronurls{'custom'};
1.346     raeburn  10499:                             my $putresult =
1.60      raeburn  10500:                                 &Apache::lonnet::put_dom('configuration',
                   10501:                                                          \%confhash,$dom);
                   10502:                             if ($putresult ne 'ok') {
1.346     raeburn  10503:                                 $error{'custom'} =
1.60      raeburn  10504:                                     '<span class="LC_error">'.
                   10505:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10506:                             }
1.46      raeburn  10507:                         }
                   10508:                     } else {
1.60      raeburn  10509:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  10510:                             &legacy_scantronformat($r,$dom,$confname,
                   10511:                                           'default',$legacyfile{'default'},
                   10512:                                           $scantronurls{'default'},
                   10513:                                           $scantronfiles{'default'});
1.60      raeburn  10514:                         if ($error eq '') {
                   10515:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   10516:                             my $putresult =
                   10517:                                 &Apache::lonnet::put_dom('configuration',
                   10518:                                                          \%confhash,$dom);
                   10519:                             if ($putresult ne 'ok') {
                   10520:                                 $error{'default'} =
                   10521:                                     '<span class="LC_error">'.
                   10522:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10523:                             }
                   10524:                         } else {
                   10525:                             $error{'default'} = $error;
                   10526:                         }
1.46      raeburn  10527:                     }
                   10528:                 }
                   10529:             }
                   10530:         } else {
1.95      www      10531:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  10532:         }
                   10533:     }
                   10534:     if (ref($settings) eq 'HASH') {
                   10535:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   10536:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   10537:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   10538:                 $scantronurl = '';
                   10539:             } else {
                   10540:                 $scantronurl = $settings->{'scantronformat'};
                   10541:             }
                   10542:             $is_custom = 1;
                   10543:         } else {
                   10544:             $scantronurl = $scantronurls{'default'};
                   10545:         }
                   10546:     } else {
1.60      raeburn  10547:         if ($is_custom) {
                   10548:             $scantronurl = $scantronurls{'custom'};
                   10549:         } else {
                   10550:             $scantronurl = $scantronurls{'default'};
                   10551:         }
1.46      raeburn  10552:     }
                   10553:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10554:     $datatable .= '<tr'.$css_class.'>';
                   10555:     if (!$is_custom) {
1.65      raeburn  10556:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   10557:                       '<span class="LC_nobreak">';
1.46      raeburn  10558:         if ($scantronurl) {
1.199     raeburn  10559:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   10560:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  10561:         } else {
                   10562:             $datatable = &mt('File unavailable for display');
                   10563:         }
1.65      raeburn  10564:         $datatable .= '</span></td>';
1.60      raeburn  10565:         if (keys(%error) == 0) { 
1.306     raeburn  10566:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  10567:             if (!$switchserver) {
                   10568:                 $datatable .= &mt('Upload:').'<br />';
                   10569:             }
                   10570:         } else {
                   10571:             my $errorstr;
                   10572:             foreach my $key (sort(keys(%error))) {
                   10573:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   10574:             }
                   10575:             $datatable .= '<td>'.$errorstr;
                   10576:         }
1.46      raeburn  10577:     } else {
                   10578:         if (keys(%error) > 0) {
                   10579:             my $errorstr;
                   10580:             foreach my $key (sort(keys(%error))) {
                   10581:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   10582:             } 
1.60      raeburn  10583:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  10584:         } elsif ($scantronurl) {
1.199     raeburn  10585:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   10586:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  10587:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  10588:                           $link.
                   10589:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   10590:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  10591:                           '<td><span class="LC_nobreak">&nbsp;'.
                   10592:                           &mt('Replace:').'</span><br />';
1.46      raeburn  10593:         }
                   10594:     }
                   10595:     if (keys(%error) == 0) {
                   10596:         if ($switchserver) {
                   10597:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   10598:         } else {
1.65      raeburn  10599:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   10600:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  10601:         }
                   10602:     }
                   10603:     $datatable .= '</td></tr>';
                   10604:     $$rowtotal ++;
                   10605:     return $datatable;
                   10606: }
                   10607: 
                   10608: sub legacy_scantronformat {
                   10609:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   10610:     my ($url,$error);
                   10611:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   10612:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   10613:         (my $result,$url) =
                   10614:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   10615:                          '','',$newfile);
                   10616:         if ($result ne 'ok') {
1.130     raeburn  10617:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  10618:         }
                   10619:     }
                   10620:     return ($url,$error);
                   10621: }
1.43      raeburn  10622: 
1.346     raeburn  10623: sub print_scantronconfig {
                   10624:     my ($dom,$settings,$rowtotal) = @_;
                   10625:     my $itemcount = 2;
                   10626:     my $is_checked = ' checked="checked"';
1.347     raeburn  10627:     my %optionson = (
                   10628:                      hdr => ' checked="checked"',
                   10629:                      pad => ' checked="checked"',
                   10630:                      rem => ' checked="checked"',
                   10631:                     );
                   10632:     my %optionsoff = (
                   10633:                       hdr => '',
                   10634:                       pad => '',
                   10635:                       rem => '',
                   10636:                      );
1.346     raeburn  10637:     my $currcsvsty = 'none';
1.347     raeburn  10638:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346     raeburn  10639:     my @fields = &scantroncsv_fields();
                   10640:     my %titles = &scantronconfig_titles();
                   10641:     if (ref($settings) eq 'HASH') {
                   10642:         if (ref($settings->{config}) eq 'HASH') {
                   10643:             if ($settings->{config}->{dat}) {
                   10644:                 $checked{'dat'} = $is_checked;
                   10645:             }
                   10646:             if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347     raeburn  10647:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   10648:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   10649:                     if (keys(%csvfields) > 0) {
                   10650:                         $checked{'csv'} = $is_checked;
                   10651:                         $currcsvsty = 'block';
                   10652:                     }
                   10653:                 }
                   10654:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   10655:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   10656:                     foreach my $option (keys(%optionson)) {
                   10657:                         unless ($csvoptions{$option}) {
                   10658:                             $optionsoff{$option} = $optionson{$option};
                   10659:                             $optionson{$option} = '';
                   10660:                         }
                   10661:                     }
1.346     raeburn  10662:                 }
                   10663:             }
                   10664:         } else {
                   10665:             $checked{'dat'} = $is_checked;
                   10666:         }
                   10667:     } else {
                   10668:         $checked{'dat'} = $is_checked;
                   10669:     }
                   10670:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   10671:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   10672:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   10673:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   10674:     foreach my $item ('dat','csv') {
                   10675:         my $id;
                   10676:         if ($item eq 'csv') {
                   10677:             $id = 'id="scantronconfcsv" ';
1.347     raeburn  10678:         }
1.346     raeburn  10679:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   10680:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   10681:         if ($item eq 'csv') {
                   10682:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   10683:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   10684:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   10685:             foreach my $col (@fields) {
                   10686:                 my $selnone;
                   10687:                 if ($csvfields{$col} eq '') {
                   10688:                     $selnone = ' selected="selected"';
                   10689:                 }
                   10690:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   10691:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   10692:                               '<option value=""'.$selnone.'></option>';
                   10693:                 for (my $i=0; $i<20; $i++) {
                   10694:                     my $shown = $i+1;
                   10695:                     my $sel;
                   10696:                     unless ($selnone) {
                   10697:                         if (exists($csvfields{$col})) {
                   10698:                             if ($csvfields{$col} == $i) {
                   10699:                                 $sel = ' selected="selected"';
                   10700:                             }
                   10701:                         }
                   10702:                     }
                   10703:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   10704:                 }
                   10705:                 $datatable .= '</select></td></tr>';
                   10706:            }
1.347     raeburn  10707:            $datatable .= '</table></fieldset>'.
                   10708:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   10709:                          '<legend>'.&mt('CSV Options').'</legend>';
                   10710:            foreach my $option ('hdr','pad','rem') {
                   10711:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   10712:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   10713:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   10714:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   10715:            }
                   10716:            $datatable .= '</fieldset>';
1.346     raeburn  10717:            $itemcount ++;
                   10718:         }
                   10719:     }
                   10720:     $datatable .= '</td></tr>';
                   10721:     $$rowtotal ++;
                   10722:     return $datatable;
                   10723: }
                   10724: 
                   10725: sub scantronconfig_titles {
                   10726:     return &Apache::lonlocal::texthash(
                   10727:                                           dat => 'Standard format (.dat)',
                   10728:                                           csv => 'Comma separated values (.csv)',
1.347     raeburn  10729:                                           hdr => 'Remove first line in file (contains column titles)',
                   10730:                                           pad => 'Prepend 0s to PaperID',
1.348     raeburn  10731:                                           rem => 'Remove leading spaces (except Question Response columns)',
1.346     raeburn  10732:                                           CODE => 'CODE',
                   10733:                                           ID   => 'Student ID',
                   10734:                                           PaperID => 'Paper ID',
                   10735:                                           FirstName => 'First Name',
                   10736:                                           LastName => 'Last Name',
                   10737:                                           FirstQuestion => 'First Question Response',
                   10738:                                           Section => 'Section',
                   10739:     );
                   10740: }
                   10741: 
                   10742: sub scantroncsv_fields {
                   10743:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   10744: }
                   10745: 
1.49      raeburn  10746: sub print_coursecategories {
1.57      raeburn  10747:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   10748:     my $datatable;
                   10749:     if ($position eq 'top') {
1.238     raeburn  10750:         my (%checked);
                   10751:         my @catitems = ('unauth','auth');
                   10752:         my @cattypes = ('std','domonly','codesrch','none');
                   10753:         $checked{'unauth'} = 'std';
                   10754:         $checked{'auth'} = 'std';
                   10755:         if (ref($settings) eq 'HASH') {
                   10756:             foreach my $type (@cattypes) {
                   10757:                 if ($type eq $settings->{'unauth'}) {
                   10758:                     $checked{'unauth'} = $type;
                   10759:                 }
                   10760:                 if ($type eq $settings->{'auth'}) {
                   10761:                     $checked{'auth'} = $type;
                   10762:                 }
                   10763:             }
                   10764:         }
                   10765:         my %lt = &Apache::lonlocal::texthash (
                   10766:                                                unauth   => 'Catalog type for unauthenticated users',
                   10767:                                                auth     => 'Catalog type for authenticated users',
                   10768:                                                none     => 'No catalog',
                   10769:                                                std      => 'Standard catalog',
                   10770:                                                domonly  => 'Domain-only catalog',
                   10771:                                                codesrch => "Code search form",
                   10772:                                              );
                   10773:        my $itemcount = 0;
                   10774:        foreach my $item (@catitems) {
                   10775:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   10776:            $datatable .= '<tr '.$css_class.'>'.
                   10777:                          '<td>'.$lt{$item}.'</td>'.
                   10778:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   10779:            foreach my $type (@cattypes) {
                   10780:                my $ischecked;
                   10781:                if ($checked{$item} eq $type) {
                   10782:                    $ischecked=' checked="checked"';
                   10783:                }
                   10784:                $datatable .= '<label>'.
                   10785:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   10786:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   10787:            }
1.327     raeburn  10788:            $datatable .= '</span></td></tr>';
1.238     raeburn  10789:            $itemcount ++;
                   10790:         }
                   10791:         $$rowtotal += $itemcount;
                   10792:     } elsif ($position eq 'middle') {
1.57      raeburn  10793:         my $toggle_cats_crs = ' ';
                   10794:         my $toggle_cats_dom = ' checked="checked" ';
                   10795:         my $can_cat_crs = ' ';
                   10796:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  10797:         my $toggle_catscomm_comm = ' ';
                   10798:         my $toggle_catscomm_dom = ' checked="checked" ';
                   10799:         my $can_catcomm_comm = ' ';
                   10800:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  10801:         my $toggle_catsplace_place = ' ';
                   10802:         my $toggle_catsplace_dom = ' checked="checked" ';
                   10803:         my $can_catplace_place = ' ';
                   10804:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  10805: 
1.57      raeburn  10806:         if (ref($settings) eq 'HASH') {
                   10807:             if ($settings->{'togglecats'} eq 'crs') {
                   10808:                 $toggle_cats_crs = $toggle_cats_dom;
                   10809:                 $toggle_cats_dom = ' ';
                   10810:             }
                   10811:             if ($settings->{'categorize'} eq 'crs') {
                   10812:                 $can_cat_crs = $can_cat_dom;
                   10813:                 $can_cat_dom = ' ';
                   10814:             }
1.120     raeburn  10815:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   10816:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   10817:                 $toggle_catscomm_dom = ' ';
                   10818:             }
                   10819:             if ($settings->{'categorizecomm'} eq 'comm') {
                   10820:                 $can_catcomm_comm = $can_catcomm_dom;
                   10821:                 $can_catcomm_dom = ' ';
                   10822:             }
1.272     raeburn  10823:             if ($settings->{'togglecatsplace'} eq 'place') {
                   10824:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   10825:                 $toggle_catsplace_dom = ' ';
                   10826:             }
                   10827:             if ($settings->{'categorizeplace'} eq 'place') {
                   10828:                 $can_catplace_place = $can_catplace_dom;
                   10829:                 $can_catplace_dom = ' ';
                   10830:             }
1.57      raeburn  10831:         }
                   10832:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  10833:                      togglecats      => 'Show/Hide a course in catalog',
                   10834:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   10835:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   10836:                      categorize      => 'Assign a category to a course',
                   10837:                      categorizecomm  => 'Assign a category to a community',
                   10838:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  10839:                     );
                   10840:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  10841:                      dom   => 'Set in Domain',
                   10842:                      crs   => 'Set in Course',
                   10843:                      comm  => 'Set in Community',
                   10844:                      place => 'Set in Placement Test',
1.57      raeburn  10845:                     );
                   10846:         $datatable = '<tr class="LC_odd_row">'.
                   10847:                   '<td>'.$title{'togglecats'}.'</td>'.
                   10848:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10849:                   '<input type="radio" name="togglecats"'.
                   10850:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10851:                   '<label><input type="radio" name="togglecats"'.
                   10852:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   10853:                   '</tr><tr>'.
                   10854:                   '<td>'.$title{'categorize'}.'</td>'.
                   10855:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10856:                   '<label><input type="radio" name="categorize"'.
                   10857:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10858:                   '<label><input type="radio" name="categorize"'.
                   10859:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  10860:                   '</tr><tr class="LC_odd_row">'.
                   10861:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   10862:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10863:                   '<input type="radio" name="togglecatscomm"'.
                   10864:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10865:                   '<label><input type="radio" name="togglecatscomm"'.
                   10866:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   10867:                   '</tr><tr>'.
                   10868:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   10869:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10870:                   '<label><input type="radio" name="categorizecomm"'.
                   10871:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10872:                   '<label><input type="radio" name="categorizecomm"'.
                   10873:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327     raeburn  10874:                   '</tr><tr class="LC_odd_row">'.
1.272     raeburn  10875:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   10876:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10877:                   '<input type="radio" name="togglecatsplace"'.
                   10878:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10879:                   '<label><input type="radio" name="togglecatscomm"'.
                   10880:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   10881:                   '</tr><tr>'.
                   10882:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   10883:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10884:                   '<label><input type="radio" name="categorizeplace"'.
                   10885:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10886:                   '<label><input type="radio" name="categorizeplace"'.
                   10887:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  10888:                   '</tr>';
1.272     raeburn  10889:         $$rowtotal += 6;
1.57      raeburn  10890:     } else {
                   10891:         my $css_class;
                   10892:         my $itemcount = 1;
                   10893:         my $cathash; 
                   10894:         if (ref($settings) eq 'HASH') {
                   10895:             $cathash = $settings->{'cats'};
                   10896:         }
                   10897:         if (ref($cathash) eq 'HASH') {
                   10898:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   10899:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   10900:                                                    \%allitems,\%idx,\@jsarray);
                   10901:             my $maxdepth = scalar(@cats);
                   10902:             my $colattrib = '';
                   10903:             if ($maxdepth > 2) {
                   10904:                 $colattrib = ' colspan="2" ';
                   10905:             }
                   10906:             my @path;
                   10907:             if (@cats > 0) {
                   10908:                 if (ref($cats[0]) eq 'ARRAY') {
                   10909:                     my $numtop = @{$cats[0]};
                   10910:                     my $maxnum = $numtop;
1.120     raeburn  10911:                     my %default_names = (
                   10912:                           instcode    => &mt('Official courses'),
                   10913:                           communities => &mt('Communities'),
1.272     raeburn  10914:                           placement   => &mt('Placement Tests'),
1.120     raeburn  10915:                     );
                   10916: 
                   10917:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   10918:                         ($cathash->{'instcode::0'} eq '') ||
                   10919:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  10920:                         ($cathash->{'communities::0'} eq '') ||
                   10921:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   10922:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  10923:                         $maxnum ++;
                   10924:                     }
                   10925:                     my $lastidx;
                   10926:                     for (my $i=0; $i<$numtop; $i++) {
                   10927:                         my $parent = $cats[0][$i];
                   10928:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10929:                         my $item = &escape($parent).'::0';
                   10930:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   10931:                         $lastidx = $idx{$item};
                   10932:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   10933:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   10934:                         for (my $k=0; $k<=$maxnum; $k++) {
                   10935:                             my $vpos = $k+1;
                   10936:                             my $selstr;
                   10937:                             if ($k == $i) {
                   10938:                                 $selstr = ' selected="selected" ';
                   10939:                             }
                   10940:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10941:                         }
1.214     raeburn  10942:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  10943:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  10944:                             $datatable .=  '<span class="LC_nobreak">'
                   10945:                                            .$default_names{$parent}.'</span>';
                   10946:                             if ($parent eq 'instcode') {
                   10947:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   10948:                                               .&mt('with institutional codes')
                   10949:                                               .')</span></td><td'.$colattrib.'>';
                   10950:                             } else {
                   10951:                                 $datatable .= '<table><tr><td>';
                   10952:                             }
                   10953:                             $datatable .= '<span class="LC_nobreak">'
                   10954:                                           .'<label><input type="radio" name="'
                   10955:                                           .$parent.'" value="1" checked="checked" />'
                   10956:                                           .&mt('Display').'</label>';
                   10957:                             if ($parent eq 'instcode') {
                   10958:                                 $datatable .= '&nbsp;';
                   10959:                             } else {
                   10960:                                 $datatable .= '</span></td></tr><tr><td>'
                   10961:                                               .'<span class="LC_nobreak">';
                   10962:                             }
                   10963:                             $datatable .= '<label><input type="radio" name="'
                   10964:                                           .$parent.'" value="0" />'
                   10965:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  10966:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  10967:                                 $datatable .= '</td></tr></table>';
                   10968:                             }
                   10969:                             $datatable .= '</td>';
1.57      raeburn  10970:                         } else {
                   10971:                             $datatable .= $parent
1.214     raeburn  10972:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   10973:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  10974:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   10975:                         }
                   10976:                         my $depth = 1;
                   10977:                         push(@path,$parent);
                   10978:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   10979:                         pop(@path);
                   10980:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   10981:                         $itemcount ++;
                   10982:                     }
1.48      raeburn  10983:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  10984:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   10985:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  10986:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10987:                         my $vpos = $k+1;
                   10988:                         my $selstr;
1.57      raeburn  10989:                         if ($k == $numtop) {
1.48      raeburn  10990:                             $selstr = ' selected="selected" ';
                   10991:                         }
                   10992:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10993:                     }
1.59      bisitz   10994:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  10995:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   10996:                                   .'</tr>'."\n";
1.48      raeburn  10997:                     $itemcount ++;
1.272     raeburn  10998:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  10999:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   11000:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11001:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   11002:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   11003:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   11004:                             for (my $k=0; $k<=$maxnum; $k++) {
                   11005:                                 my $vpos = $k+1;
                   11006:                                 my $selstr;
                   11007:                                 if ($k == $maxnum) {
                   11008:                                     $selstr = ' selected="selected" ';
                   11009:                                 }
                   11010:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  11011:                             }
1.120     raeburn  11012:                             $datatable .= '</select></span></td>'.
                   11013:                                           '<td><span class="LC_nobreak">'.
                   11014:                                           $default_names{$default}.'</span>';
                   11015:                             if ($default eq 'instcode') {
                   11016:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   11017:                                               .&mt('with institutional codes').')</span>';
                   11018:                             }
                   11019:                             $datatable .= '</td>'
                   11020:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   11021:                                           .&mt('Display').'</label>&nbsp;'
                   11022:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   11023:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  11024:                         }
                   11025:                     }
                   11026:                 }
1.57      raeburn  11027:             } else {
                   11028:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  11029:             }
                   11030:         } else {
1.327     raeburn  11031:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  11032:                           .&initialize_categories($itemcount);
1.48      raeburn  11033:         }
1.57      raeburn  11034:         $$rowtotal += $itemcount;
1.48      raeburn  11035:     }
                   11036:     return $datatable;
                   11037: }
                   11038: 
1.69      raeburn  11039: sub print_serverstatuses {
                   11040:     my ($dom,$settings,$rowtotal) = @_;
                   11041:     my $datatable;
                   11042:     my @pages = &serverstatus_pages();
                   11043:     my (%namedaccess,%machineaccess);
                   11044:     foreach my $type (@pages) {
                   11045:         $namedaccess{$type} = '';
                   11046:         $machineaccess{$type}= '';
                   11047:     }
                   11048:     if (ref($settings) eq 'HASH') {
                   11049:         foreach my $type (@pages) {
                   11050:             if (exists($settings->{$type})) {
                   11051:                 if (ref($settings->{$type}) eq 'HASH') {
                   11052:                     foreach my $key (keys(%{$settings->{$type}})) {
                   11053:                         if ($key eq 'namedusers') {
                   11054:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   11055:                         } elsif ($key eq 'machines') {
                   11056:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   11057:                         }
                   11058:                     }
                   11059:                 }
                   11060:             }
                   11061:         }
                   11062:     }
1.81      raeburn  11063:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  11064:     my $rownum = 0;
                   11065:     my $css_class;
                   11066:     foreach my $type (@pages) {
                   11067:         $rownum ++;
                   11068:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   11069:         $datatable .= '<tr'.$css_class.'>'.
                   11070:                       '<td><span class="LC_nobreak">'.
                   11071:                       $titles->{$type}.'</span></td>'.
                   11072:                       '<td class="LC_left_item">'.
                   11073:                       '<input type="text" name="'.$type.'_namedusers" '.
                   11074:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   11075:                       '<td class="LC_right_item">'.
                   11076:                       '<span class="LC_nobreak">'.
                   11077:                       '<input type="text" name="'.$type.'_machines" '.
                   11078:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.334     raeburn  11079:                       '</span></td></tr>'."\n";
1.69      raeburn  11080:     }
                   11081:     $$rowtotal += $rownum;
                   11082:     return $datatable;
                   11083: }
                   11084: 
                   11085: sub serverstatus_pages {
                   11086:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  11087:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   11088:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   11089:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  11090: }
                   11091: 
1.236     raeburn  11092: sub defaults_javascript {
                   11093:     my ($settings) = @_;
1.354     raeburn  11094:     return unless (ref($settings) eq 'HASH');
1.236     raeburn  11095:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   11096:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   11097:         if ($maxnum eq '') {
                   11098:             $maxnum = 0;
                   11099:         }
                   11100:         $maxnum ++;
1.249     raeburn  11101:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  11102:         return <<"ENDSCRIPT";
                   11103: <script type="text/javascript">
                   11104: // <![CDATA[
                   11105: function reorderTypes(form,caller) {
                   11106:     var changedVal;
                   11107: $jstext 
                   11108:     var newpos = 'addinststatus_pos';
                   11109:     var current = new Array;
                   11110:     var maxh = $maxnum;
                   11111:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11112:     var oldVal;
                   11113:     if (caller == newpos) {
                   11114:         changedVal = newitemVal;
                   11115:     } else {
                   11116:         var curritem = 'inststatus_pos_'+caller;
                   11117:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   11118:         current[newitemVal] = newpos;
                   11119:     }
                   11120:     for (var i=0; i<inststatuses.length; i++) {
                   11121:         if (inststatuses[i] != caller) {
                   11122:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   11123:             if (form.elements[elementName]) {
                   11124:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11125:                 current[currVal] = elementName;
                   11126:             }
                   11127:         }
                   11128:     }
                   11129:     for (var j=0; j<maxh; j++) {
                   11130:         if (current[j] == undefined) {
                   11131:             oldVal = j;
                   11132:         }
                   11133:     }
                   11134:     if (oldVal < changedVal) {
                   11135:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11136:            var elementName = current[k];
                   11137:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11138:         }
                   11139:     } else {
                   11140:         for (var k=changedVal; k<oldVal; k++) {
                   11141:             var elementName = current[k];
                   11142:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11143:         }
                   11144:     }
                   11145:     return;
                   11146: }
                   11147: 
                   11148: // ]]>
                   11149: </script>
                   11150: 
                   11151: ENDSCRIPT
                   11152:     }
1.354     raeburn  11153:     return;
                   11154: }
                   11155: 
                   11156: sub passwords_javascript {
1.365     raeburn  11157:     my %intalert = &Apache::lonlocal::texthash (
                   11158:         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.',
                   11159:         authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   11160:         passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   11161:         passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   11162:         passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   11163:         passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   11164:     );
                   11165:     &js_escape(\%intalert);
                   11166:     my $defmin = $Apache::lonnet::passwdmin;
1.354     raeburn  11167:     my $intauthjs = <<"ENDSCRIPT";
                   11168: 
                   11169: function warnIntAuth(field) {
                   11170:     if (field.name == 'intauth_check') {
                   11171:         if (field.value == '2') {
1.365     raeburn  11172:             alert('$intalert{authcheck}');
1.354     raeburn  11173:         }
                   11174:     }
                   11175:     if (field.name == 'intauth_cost') {
                   11176:         field.value.replace(/\s/g,'');
                   11177:         if (field.value != '') {
                   11178:             var regexdigit=/^\\d+\$/;
                   11179:             if (!regexdigit.test(field.value)) {
1.365     raeburn  11180:                 alert('$intalert{authcost}');
                   11181:             }
                   11182:         }
                   11183:     }
                   11184:     return;
                   11185: }
                   11186: 
                   11187: function warnIntPass(field) {
                   11188:     field.value.replace(/^\s+/,'');
                   11189:     field.value.replace(/\s+\$/,'');
                   11190:     var regexdigit=/^\\d+\$/;
                   11191:     if (field.name == 'passwords_min') {
                   11192:         if (field.value == '') {
                   11193:             alert('$intalert{passmin}');
                   11194:             field.value = '$defmin';
                   11195:         } else {
                   11196:             if (!regexdigit.test(field.value)) {
                   11197:                 alert('$intalert{passmin}');
                   11198:                 field.value = '$defmin';
                   11199:             }
1.366     raeburn  11200:             var minval = parseInt(field.value,10);
1.365     raeburn  11201:             if (minval < $defmin) {
                   11202:                 alert('$intalert{passmin}');
                   11203:                 field.value = '$defmin';
                   11204:             }
                   11205:         }
                   11206:     } else {
                   11207:         if (field.value == '0') {
                   11208:             field.value = '';
                   11209:         }
                   11210:         if (field.value != '') {
                   11211:             if (field.name == 'passwords_expire') {
                   11212:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/; 
                   11213:                 if (!regexpposnum.test(field.value)) {
                   11214:                     alert('$intalert{passexp}');
                   11215:                     field.value = '';
                   11216:                 } else {
                   11217:                     var expval = parseFloat(field.value);
                   11218:                     if (expval == 0) {
                   11219:                         alert('$intalert{passexp}');
                   11220:                         field.value = '';
                   11221:                     }
                   11222:                 }
                   11223:             } else {
                   11224:                 if (!regexdigit.test(field.value)) {
                   11225:                     if (field.name == 'passwords_max') {
                   11226:                         alert('$intalert{passmax}');
                   11227:                     } else {
                   11228:                         if (field.name == 'passwords_numsaved') {
                   11229:                             alert('$intalert{passnum}');
                   11230:                         }
                   11231:                     }
1.370     raeburn  11232:                     field.value = '';
1.365     raeburn  11233:                 }
1.354     raeburn  11234:             }
                   11235:         }
                   11236:     }
                   11237:     return;
                   11238: }
                   11239: 
                   11240: ENDSCRIPT
                   11241:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  11242: }
                   11243: 
1.49      raeburn  11244: sub coursecategories_javascript {
                   11245:     my ($settings) = @_;
1.57      raeburn  11246:     my ($output,$jstext,$cathash);
1.49      raeburn  11247:     if (ref($settings) eq 'HASH') {
1.57      raeburn  11248:         $cathash = $settings->{'cats'};
                   11249:     }
                   11250:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  11251:         my (@cats,@jsarray,%idx);
1.57      raeburn  11252:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  11253:         if (@jsarray > 0) {
                   11254:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   11255:             for (my $i=0; $i<@jsarray; $i++) {
                   11256:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   11257:                     my $catstr = join('","',@{$jsarray[$i]});
                   11258:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   11259:                 }
                   11260:             }
                   11261:         }
                   11262:     } else {
                   11263:         $jstext  = '    var categories = Array(1);'."\n".
                   11264:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   11265:     }
1.237     bisitz   11266:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   11267:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  11268:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  11269:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   11270:     &js_escape(\$instcode_reserved);
                   11271:     &js_escape(\$communities_reserved);
1.272     raeburn  11272:     &js_escape(\$placement_reserved);
1.265     damieng  11273:     &js_escape(\$choose_again);
1.49      raeburn  11274:     $output = <<"ENDSCRIPT";
                   11275: <script type="text/javascript">
1.109     raeburn  11276: // <![CDATA[
1.49      raeburn  11277: function reorderCats(form,parent,item,idx) {
                   11278:     var changedVal;
                   11279: $jstext
                   11280:     var newpos = 'addcategory_pos';
                   11281:     if (parent == '') {
                   11282:         var has_instcode = 0;
                   11283:         var maxtop = categories[idx].length;
                   11284:         for (var j=0; j<maxtop; j++) {
                   11285:             if (categories[idx][j] == 'instcode::0') {
                   11286:                 has_instcode == 1;
                   11287:             }
                   11288:         }
                   11289:         if (has_instcode == 0) {
                   11290:             categories[idx][maxtop] = 'instcode_pos';
                   11291:         }
                   11292:     } else {
                   11293:         newpos += '_'+parent;
                   11294:     }
                   11295:     var maxh = 1 + categories[idx].length;
                   11296:     var current = new Array;
                   11297:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11298:     if (item == newpos) {
                   11299:         changedVal = newitemVal;
                   11300:     } else {
                   11301:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   11302:         current[newitemVal] = newpos;
                   11303:     }
                   11304:     for (var i=0; i<categories[idx].length; i++) {
                   11305:         var elementName = categories[idx][i];
                   11306:         if (elementName != item) {
                   11307:             if (form.elements[elementName]) {
                   11308:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11309:                 current[currVal] = elementName;
                   11310:             }
                   11311:         }
                   11312:     }
                   11313:     var oldVal;
                   11314:     for (var j=0; j<maxh; j++) {
                   11315:         if (current[j] == undefined) {
                   11316:             oldVal = j;
                   11317:         }
                   11318:     }
                   11319:     if (oldVal < changedVal) {
                   11320:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11321:            var elementName = current[k];
                   11322:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11323:         }
                   11324:     } else {
                   11325:         for (var k=changedVal; k<oldVal; k++) {
                   11326:             var elementName = current[k];
                   11327:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11328:         }
                   11329:     }
                   11330:     return;
                   11331: }
1.120     raeburn  11332: 
                   11333: function categoryCheck(form) {
                   11334:     if (form.elements['addcategory_name'].value == 'instcode') {
                   11335:         alert('$instcode_reserved\\n$choose_again');
                   11336:         return false;
                   11337:     }
                   11338:     if (form.elements['addcategory_name'].value == 'communities') {
                   11339:         alert('$communities_reserved\\n$choose_again');
                   11340:         return false;
                   11341:     }
1.272     raeburn  11342:     if (form.elements['addcategory_name'].value == 'placement') {
                   11343:         alert('$placement_reserved\\n$choose_again');
                   11344:         return false;
                   11345:     }
1.120     raeburn  11346:     return true;
                   11347: }
                   11348: 
1.109     raeburn  11349: // ]]>
1.49      raeburn  11350: </script>
                   11351: 
                   11352: ENDSCRIPT
                   11353:     return $output;
                   11354: }
                   11355: 
1.48      raeburn  11356: sub initialize_categories {
                   11357:     my ($itemcount) = @_;
1.120     raeburn  11358:     my ($datatable,$css_class,$chgstr);
1.380     raeburn  11359:     my %default_names = &Apache::lonlocal::texthash (
1.120     raeburn  11360:                       instcode    => 'Official courses (with institutional codes)',
                   11361:                       communities => 'Communities',
1.272     raeburn  11362:                       placement   => 'Placement Tests',
1.120     raeburn  11363:                         );
1.328     raeburn  11364:     my %selnum = (
                   11365:                    instcode    => '0',
                   11366:                    communities => '1',
                   11367:                    placement   => '2',
                   11368:                  );
                   11369:     my %selected;
1.272     raeburn  11370:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  11371:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327     raeburn  11372:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328     raeburn  11373:         map { $selected{$selnum{$_}} = '' } keys(%selnum);
                   11374:         $selected{$selnum{$default}} = ' selected="selected"';
1.120     raeburn  11375:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328     raeburn  11376:                      .'<select name="'.$default.'_pos"'.$chgstr.'>'
                   11377:                      .'<option value="0"'.$selected{'0'}.'>1</option>'
                   11378:                      .'<option value="1"'.$selected{'1'}.'>2</option>'
                   11379:                      .'<option value="2"'.$selected{'2'}.'>3</option>'
                   11380:                      .'<option value="3">4</option></select>&nbsp;'
1.120     raeburn  11381:                      .$default_names{$default}
                   11382:                      .'</span></td><td><span class="LC_nobreak">'
                   11383:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   11384:                      .&mt('Display').'</label>&nbsp;<label>'
                   11385:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  11386:                  .'</label></span></td></tr>';
1.120     raeburn  11387:         $itemcount ++;
                   11388:     }
1.48      raeburn  11389:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  11390:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  11391:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  11392:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   11393:                   .'<option value="0">1</option>'
                   11394:                   .'<option value="1">2</option>'
1.328     raeburn  11395:                   .'<option value="2">3</option>'
                   11396:                   .'<option value="3" selected="selected">4</option></select>&nbsp;'
1.327     raeburn  11397:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                   11398:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   11399:                   .'</td></tr>';
1.48      raeburn  11400:     return $datatable;
                   11401: }
                   11402: 
                   11403: sub build_category_rows {
1.49      raeburn  11404:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   11405:     my ($text,$name,$item,$chgstr);
1.48      raeburn  11406:     if (ref($cats) eq 'ARRAY') {
                   11407:         my $maxdepth = scalar(@{$cats});
                   11408:         if (ref($cats->[$depth]) eq 'HASH') {
                   11409:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   11410:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   11411:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  11412:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  11413:                 my ($idxnum,$parent_name,$parent_item);
                   11414:                 my $higher = $depth - 1;
                   11415:                 if ($higher == 0) {
                   11416:                     $parent_name = &escape($parent).'::'.$higher;
                   11417:                 } else {
                   11418:                     if (ref($path) eq 'ARRAY') {
                   11419:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11420:                     }
                   11421:                 }
                   11422:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  11423:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  11424:                     if ($j < $numchildren) {
1.48      raeburn  11425:                         $name = $cats->[$depth]{$parent}[$j];
                   11426:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  11427:                         $idxnum = $idx->{$item};
                   11428:                     } else {
                   11429:                         $name = $parent_name;
                   11430:                         $item = $parent_item;
1.48      raeburn  11431:                     }
1.49      raeburn  11432:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   11433:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  11434:                     for (my $i=0; $i<=$numchildren; $i++) {
                   11435:                         my $vpos = $i+1;
                   11436:                         my $selstr;
                   11437:                         if ($j == $i) {
                   11438:                             $selstr = ' selected="selected" ';
                   11439:                         }
                   11440:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   11441:                     }
                   11442:                     $text .= '</select>&nbsp;';
                   11443:                     if ($j < $numchildren) {
                   11444:                         my $deeper = $depth+1;
                   11445:                         $text .= $name.'&nbsp;'
                   11446:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   11447:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   11448:                         if(ref($path) eq 'ARRAY') {
                   11449:                             push(@{$path},$name);
1.49      raeburn  11450:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  11451:                             pop(@{$path});
                   11452:                         }
                   11453:                     } else {
1.330     raeburn  11454:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  11455:                         if ($j == $numchildren) {
                   11456:                             $text .= $name;
                   11457:                         } else {
                   11458:                             $text .= $item;
                   11459:                         }
                   11460:                         $text .= '" value="" />';
                   11461:                     }
                   11462:                     $text .= '</td></tr>';
                   11463:                 }
                   11464:                 $text .= '</table></td>';
                   11465:             } else {
                   11466:                 my $higher = $depth-1;
                   11467:                 if ($higher == 0) {
                   11468:                     $name = &escape($parent).'::'.$higher;
                   11469:                 } else {
                   11470:                     if (ref($path) eq 'ARRAY') {
                   11471:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11472:                     }
                   11473:                 }
                   11474:                 my $colspan;
                   11475:                 if ($parent ne 'instcode') {
                   11476:                     $colspan = $maxdepth - $depth - 1;
1.330     raeburn  11477:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  11478:                 }
                   11479:             }
                   11480:         }
                   11481:     }
                   11482:     return $text;
                   11483: }
                   11484: 
1.33      raeburn  11485: sub modifiable_userdata_row {
1.305     raeburn  11486:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357     raeburn  11487:         $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228     raeburn  11488:     my ($role,$rolename,$statustype);
                   11489:     $role = $item;
1.224     raeburn  11490:     if ($context eq 'cancreate') {
1.305     raeburn  11491:         if ($item =~ /^(emailusername)_(.+)$/) {
                   11492:             $role = $1;
                   11493:             $statustype = $2;
1.228     raeburn  11494:             if (ref($usertypes) eq 'HASH') {
                   11495:                 if ($usertypes->{$statustype}) {
                   11496:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   11497:                 } else {
                   11498:                     $rolename = &mt('Data provided by user');
                   11499:                 }
                   11500:             }
1.224     raeburn  11501:         }
                   11502:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  11503:         if (ref($usertypes) eq 'HASH') {
                   11504:             $rolename = $usertypes->{$role};
                   11505:         } else {
                   11506:             $rolename = $role;
                   11507:         }
1.325     raeburn  11508:     } elsif ($context eq 'lti') {
                   11509:         $rolename = &mt('Institutional data used (if available)');
1.357     raeburn  11510:     } elsif ($context eq 'privacy') {
                   11511:         $rolename = $itemdesc;
1.33      raeburn  11512:     } else {
1.63      raeburn  11513:         if ($role eq 'cr') {
                   11514:             $rolename = &mt('Custom role');
                   11515:         } else {
                   11516:             $rolename = &Apache::lonnet::plaintext($role);
                   11517:         }
1.33      raeburn  11518:     }
1.224     raeburn  11519:     my (@fields,%fieldtitles);
                   11520:     if (ref($fieldsref) eq 'ARRAY') {
                   11521:         @fields = @{$fieldsref};
                   11522:     } else {
                   11523:         @fields = ('lastname','firstname','middlename','generation',
                   11524:                    'permanentemail','id');
                   11525:     }
                   11526:     if ((ref($titlesref) eq 'HASH')) {
                   11527:         %fieldtitles = %{$titlesref};
                   11528:     } else {
                   11529:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   11530:     }
1.33      raeburn  11531:     my $output;
1.305     raeburn  11532:     my $css_class;
                   11533:     if ($rowcount%2) {
                   11534:         $css_class = 'LC_odd_row';
                   11535:     }
                   11536:     if ($customcss) {
                   11537:         $css_class .= " $customcss";
                   11538:     }
                   11539:     $css_class =~ s/^\s+//;
                   11540:     if ($css_class) {
                   11541:         $css_class = ' class="'.$css_class.'"';
                   11542:     }
                   11543:     if ($rowstyle) {
                   11544:         $css_class .= ' style="'.$rowstyle.'"';
                   11545:     }
                   11546:     if ($rowid) {
                   11547:         $rowid = ' id="'.$rowid.'"';
                   11548:     }
                   11549:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  11550:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   11551:               '<td class="LC_left_item" colspan="2"><table>';
                   11552:     my $rem;
                   11553:     my %checks;
1.325     raeburn  11554:     my %current;
1.33      raeburn  11555:     if (ref($settings) eq 'HASH') {
1.325     raeburn  11556:         my $hashref;
                   11557:         if ($context eq 'lti') {
                   11558:             if (ref($settings) eq 'HASH') {
                   11559:                 $hashref = $settings->{'instdata'};
                   11560:             }
1.357     raeburn  11561:         } elsif ($context eq 'privacy') {
                   11562:             my ($key,$inner) = split(/_/,$role);
                   11563:             if (ref($settings) eq 'HASH') {
                   11564:                 if (ref($settings->{$key}) eq 'HASH') {
                   11565:                     $hashref = $settings->{$key}->{$inner};
                   11566:                 }
                   11567:             }
1.325     raeburn  11568:         } elsif (ref($settings->{$context}) eq 'HASH') {
1.33      raeburn  11569:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325     raeburn  11570:                 $hashref = $settings->{'lti_instdata'};
                   11571:             }
                   11572:             if ($role eq 'emailusername') {
                   11573:                 if ($statustype) {
                   11574:                     if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   11575:                         $hashref = $settings->{$context}->{$role}->{$statustype};
1.228     raeburn  11576:                     }
1.325     raeburn  11577:                 }
                   11578:             }
                   11579:         }
                   11580:         if (ref($hashref) eq 'HASH') { 
                   11581:             foreach my $field (@fields) {
                   11582:                 if ($hashref->{$field}) {
                   11583:                     if ($role eq 'emailusername') {
                   11584:                         $checks{$field} = $hashref->{$field};
                   11585:                     } else {
                   11586:                         $checks{$field} = ' checked="checked" ';
1.33      raeburn  11587:                     }
                   11588:                 }
                   11589:             }
                   11590:         }
                   11591:     }
1.305     raeburn  11592:  
                   11593:     my $total = scalar(@fields);
                   11594:     for (my $i=0; $i<$total; $i++) {
                   11595:         $rem = $i%($numinrow);
1.33      raeburn  11596:         if ($rem == 0) {
                   11597:             if ($i > 0) {
                   11598:                 $output .= '</tr>';
                   11599:             }
                   11600:             $output .= '<tr>';
                   11601:         }
                   11602:         my $check = ' ';
1.228     raeburn  11603:         unless ($role eq 'emailusername') {
                   11604:             if (exists($checks{$fields[$i]})) {
1.354     raeburn  11605:                 $check = $checks{$fields[$i]};
1.357     raeburn  11606:             } elsif ($context eq 'privacy') {
                   11607:                 if ($role =~ /^priv_(domain|course)$/) {
                   11608:                     if (ref($settings) ne 'HASH') {
                   11609:                         $check = ' checked="checked" ';
                   11610:                     }
                   11611:                 } elsif ($role =~ /^priv_(author|community)$/) {
                   11612:                     if (ref($settings) ne 'HASH') {
                   11613:                         unless ($fields[$i] eq 'id') {
                   11614:                             $check = ' checked="checked" ';
                   11615:                         }
                   11616:                     }
                   11617:                 } elsif ($role =~ /^(unpriv|othdom)_/) {
                   11618:                     if (ref($settings) ne 'HASH') {
                   11619:                         if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                   11620:                             $check = ' checked="checked" ';
                   11621:                         }
                   11622:                     }
                   11623:                 }
1.325     raeburn  11624:             } elsif ($context ne 'lti') {
1.228     raeburn  11625:                 if ($role eq 'st') {
                   11626:                     if (ref($settings) ne 'HASH') {
                   11627:                         $check = ' checked="checked" '; 
                   11628:                     }
1.33      raeburn  11629:                 }
                   11630:             }
                   11631:         }
                   11632:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  11633:                    '<span class="LC_nobreak">';
1.325     raeburn  11634:         my $prefix = 'canmodify';
1.228     raeburn  11635:         if ($role eq 'emailusername') {
                   11636:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   11637:                 $checks{$fields[$i]} = 'omit';
                   11638:             }
                   11639:             foreach my $option ('required','optional','omit') {
                   11640:                 my $checked='';
                   11641:                 if ($checks{$fields[$i]} eq $option) {
                   11642:                     $checked='checked="checked" ';
                   11643:                 }
                   11644:                 $output .= '<label>'.
1.325     raeburn  11645:                            '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228     raeburn  11646:                            &mt($option).'</label>'.('&nbsp;' x2);
                   11647:             }
                   11648:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   11649:         } else {
1.325     raeburn  11650:             if ($context eq 'lti') {
                   11651:                 $prefix = 'lti';
1.357     raeburn  11652:             } elsif ($context eq 'privacy') {
                   11653:                 $prefix = 'privacy';
1.325     raeburn  11654:             }
1.228     raeburn  11655:             $output .= '<label>'.
1.325     raeburn  11656:                        '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228     raeburn  11657:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   11658:                        '</label>';
                   11659:         }
                   11660:         $output .= '</span></td>';
1.33      raeburn  11661:     }
1.305     raeburn  11662:     $rem = $total%$numinrow;
                   11663:     my $colsleft;
                   11664:     if ($rem) {
                   11665:         $colsleft = $numinrow - $rem;
                   11666:     }
                   11667:     if ($colsleft > 1) {
1.33      raeburn  11668:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   11669:                    '&nbsp;</td>';
                   11670:     } elsif ($colsleft == 1) {
                   11671:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   11672:     }
                   11673:     $output .= '</tr></table></td></tr>';
                   11674:     return $output;
                   11675: }
1.28      raeburn  11676: 
1.93      raeburn  11677: sub insttypes_row {
1.305     raeburn  11678:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   11679:         $customcss,$rowstyle) = @_;
1.93      raeburn  11680:     my %lt = &Apache::lonlocal::texthash (
                   11681:                       cansearch => 'Users allowed to search',
                   11682:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  11683:                       lockablenames => 'User preference to lock name',
1.305     raeburn  11684:                       selfassign    => 'Self-reportable affiliations',
1.315     raeburn  11685:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  11686:              );
                   11687:     my $showdom;
                   11688:     if ($context eq 'cansearch') {
                   11689:         $showdom = ' ('.$dom.')';
                   11690:     }
1.165     raeburn  11691:     my $class = 'LC_left_item';
                   11692:     if ($context eq 'statustocreate') {
                   11693:         $class = 'LC_right_item';
                   11694:     }
1.305     raeburn  11695:     my $css_class;
                   11696:     if ($$rowtotal%2) {
                   11697:         $css_class = 'LC_odd_row';
                   11698:     }
                   11699:     if ($customcss) {
                   11700:         $css_class .= ' '.$customcss;
                   11701:     }
                   11702:     $css_class =~ s/^\s+//;
                   11703:     if ($css_class) {
                   11704:         $css_class = ' class="'.$css_class.'"';
                   11705:     }
                   11706:     if ($rowstyle) {
                   11707:         $css_class .= ' style="'.$rowstyle.'"';
                   11708:     }
                   11709:     if ($onclick) {
                   11710:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  11711:     }
                   11712:     my $output = '<tr'.$css_class.'>'.
                   11713:                  '<td>'.$lt{$context}.$showdom.
                   11714:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  11715:     my $rem;
                   11716:     if (ref($types) eq 'ARRAY') {
                   11717:         for (my $i=0; $i<@{$types}; $i++) {
                   11718:             if (defined($usertypes->{$types->[$i]})) {
                   11719:                 my $rem = $i%($numinrow);
                   11720:                 if ($rem == 0) {
                   11721:                     if ($i > 0) {
                   11722:                         $output .= '</tr>';
                   11723:                     }
                   11724:                     $output .= '<tr>';
1.23      raeburn  11725:                 }
1.26      raeburn  11726:                 my $check = ' ';
1.99      raeburn  11727:                 if (ref($settings) eq 'HASH') {
                   11728:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   11729:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   11730:                             $check = ' checked="checked" ';
                   11731:                         }
1.315     raeburn  11732:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   11733:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   11734:                             $check = ' checked="checked" ';
                   11735:                         }
1.99      raeburn  11736:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  11737:                         $check = ' checked="checked" ';
                   11738:                     }
1.23      raeburn  11739:                 }
1.26      raeburn  11740:                 $output .= '<td class="LC_left_item">'.
                   11741:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  11742:                            '<input type="checkbox" name="'.$context.'" '.
1.305     raeburn  11743:                            'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26      raeburn  11744:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  11745:             }
                   11746:         }
1.26      raeburn  11747:         $rem = @{$types}%($numinrow);
1.23      raeburn  11748:     }
                   11749:     my $colsleft = $numinrow - $rem;
1.315     raeburn  11750:     if ($context eq 'overrides') {
                   11751:         if ($colsleft > 1) {
                   11752:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   11753:         } else {
                   11754:             $output .= '<td class="LC_left_item">';
                   11755:         }
                   11756:         $output .= '&nbsp;';  
1.23      raeburn  11757:     } else {
1.334     raeburn  11758:         if ($rem == 0) {
1.315     raeburn  11759:             $output .= '<tr>';
                   11760:         }
                   11761:         if ($colsleft > 1) {
                   11762:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   11763:         } else {
                   11764:             $output .= '<td class="LC_left_item">';
                   11765:         }
                   11766:         my $defcheck = ' ';
                   11767:         if (ref($settings) eq 'HASH') {  
                   11768:             if (ref($settings->{$context}) eq 'ARRAY') {
                   11769:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   11770:                     $defcheck = ' checked="checked" ';
                   11771:                 }
                   11772:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  11773:                 $defcheck = ' checked="checked" ';
                   11774:             }
1.26      raeburn  11775:         }
1.315     raeburn  11776:         $output .= '<span class="LC_nobreak"><label>'.
                   11777:                    '<input type="checkbox" name="'.$context.'" '.
                   11778:                    'value="default"'.$defcheck.$onclick.' />'.
                   11779:                    $othertitle.'</label></span>';
1.23      raeburn  11780:     }
1.315     raeburn  11781:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  11782:     return $output;
1.23      raeburn  11783: }
                   11784: 
                   11785: sub sorted_searchtitles {
                   11786:     my %searchtitles = &Apache::lonlocal::texthash(
                   11787:                          'uname' => 'username',
                   11788:                          'lastname' => 'last name',
                   11789:                          'lastfirst' => 'last name, first name',
                   11790:                      );
                   11791:     my @titleorder = ('uname','lastname','lastfirst');
                   11792:     return (\%searchtitles,\@titleorder);
                   11793: }
                   11794: 
1.25      raeburn  11795: sub sorted_searchtypes {
                   11796:     my %srchtypes_desc = (
                   11797:                            exact    => 'is exact match',
                   11798:                            contains => 'contains ..',
                   11799:                            begins   => 'begins with ..',
                   11800:                          );
                   11801:     my @srchtypeorder = ('exact','begins','contains');
                   11802:     return (\%srchtypes_desc,\@srchtypeorder);
                   11803: }
                   11804: 
1.3       raeburn  11805: sub usertype_update_row {
                   11806:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   11807:     my $datatable;
                   11808:     my $numinrow = 4;
                   11809:     foreach my $type (@{$types}) {
                   11810:         if (defined($usertypes->{$type})) {
                   11811:             $$rownums ++;
                   11812:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   11813:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   11814:                           '</td><td class="LC_left_item"><table>';
                   11815:             for (my $i=0; $i<@{$fields}; $i++) {
                   11816:                 my $rem = $i%($numinrow);
                   11817:                 if ($rem == 0) {
                   11818:                     if ($i > 0) {
                   11819:                         $datatable .= '</tr>';
                   11820:                     }
                   11821:                     $datatable .= '<tr>';
                   11822:                 }
                   11823:                 my $check = ' ';
1.39      raeburn  11824:                 if (ref($settings) eq 'HASH') {
                   11825:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   11826:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   11827:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   11828:                                 $check = ' checked="checked" ';
                   11829:                             }
1.3       raeburn  11830:                         }
                   11831:                     }
                   11832:                 }
                   11833: 
                   11834:                 if ($i == @{$fields}-1) {
                   11835:                     my $colsleft = $numinrow - $rem;
                   11836:                     if ($colsleft > 1) {
                   11837:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   11838:                     } else {
                   11839:                         $datatable .= '<td>';
                   11840:                     }
                   11841:                 } else {
                   11842:                     $datatable .= '<td>';
                   11843:                 }
1.8       raeburn  11844:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   11845:                               '<input type="checkbox" name="updateable_'.$type.
                   11846:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   11847:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  11848:             }
                   11849:             $datatable .= '</tr></table></td></tr>';
                   11850:         }
                   11851:     }
                   11852:     return $datatable;
1.1       raeburn  11853: }
                   11854: 
                   11855: sub modify_login {
1.205     raeburn  11856:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  11857:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386     raeburn  11858:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
                   11859:         %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168     raeburn  11860:     %title = ( coursecatalog => 'Display course catalog',
                   11861:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  11862:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  11863:                newuser => 'Link for visitors to create a user account',
1.386     raeburn  11864:                loginheader => 'Log-in box header',
                   11865:                saml => 'Dual SSO and non-SSO login');
1.168     raeburn  11866:     @offon = ('off','on');
1.112     raeburn  11867:     if (ref($domconfig{login}) eq 'HASH') {
                   11868:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   11869:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   11870:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   11871:             }
                   11872:         }
1.386     raeburn  11873:         if (ref($domconfig{login}{'saml'}) eq 'HASH') {
                   11874:             foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
                   11875:                 if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
                   11876:                     $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
                   11877:                     $saml{$lonhost} = 1;
                   11878:                     $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
                   11879:                     $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
                   11880:                     $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                   11881:                     $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                   11882:                     $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
                   11883:                     $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                   11884:                 }
                   11885:             }
                   11886:         }
1.112     raeburn  11887:     }
1.9       raeburn  11888:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   11889:                                            \%domconfig,\%loginhash);
1.188     raeburn  11890:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  11891:     foreach my $item (@toggles) {
                   11892:         $loginhash{login}{$item} = $env{'form.'.$item};
                   11893:     }
1.41      raeburn  11894:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  11895:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   11896:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   11897:                                          \%loginhash);
                   11898:     }
1.110     raeburn  11899: 
1.149     raeburn  11900:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  11901:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  11902:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  11903:     if (keys(%servers) > 1) {
                   11904:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  11905:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   11906:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   11907:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   11908:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   11909:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   11910:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11911:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   11912:                         $changes{'loginvia'}{$lonhost} = 1;
                   11913:                     } else {
                   11914:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   11915:                         $changes{'loginvia'}{$lonhost} = 1;
                   11916:                     }
                   11917:                 } else {
                   11918:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11919:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   11920:                         $changes{'loginvia'}{$lonhost} = 1;
                   11921:                     }
                   11922:                 }
                   11923:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   11924:                     foreach my $item (@loginvia_attribs) {
                   11925:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   11926:                     }
                   11927:                 } else {
                   11928:                     foreach my $item (@loginvia_attribs) {
                   11929:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   11930:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   11931:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   11932:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   11933:                                 $new = '/';
                   11934:                             }
                   11935:                         }
                   11936:                         if (($item eq 'custompath') && 
                   11937:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   11938:                             $new = '';
                   11939:                         }
                   11940:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   11941:                             $changes{'loginvia'}{$lonhost} = 1;
                   11942:                         }
                   11943:                         if ($item eq 'exempt') {
1.256     raeburn  11944:                             $new = &check_exempt_addresses($new);
1.128     raeburn  11945:                         }
                   11946:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   11947:                     }
                   11948:                 }
1.112     raeburn  11949:             } else {
1.128     raeburn  11950:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11951:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  11952:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  11953:                     foreach my $item (@loginvia_attribs) {
                   11954:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   11955:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   11956:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   11957:                                 $new = '/';
                   11958:                             }
                   11959:                         }
                   11960:                         if (($item eq 'custompath') && 
                   11961:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   11962:                             $new = '';
                   11963:                         }
                   11964:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   11965:                     }
1.110     raeburn  11966:                 }
                   11967:             }
                   11968:         }
                   11969:     }
1.119     raeburn  11970: 
1.168     raeburn  11971:     my $servadm = $r->dir_config('lonAdmEMail');
                   11972:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   11973:     if (ref($domconfig{'login'}) eq 'HASH') {
                   11974:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   11975:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   11976:                 if ($lang eq 'nolang') {
                   11977:                     push(@currlangs,$lang);
                   11978:                 } elsif (defined($langchoices{$lang})) {
                   11979:                     push(@currlangs,$lang);
                   11980:                 } else {
                   11981:                     next;
                   11982:                 }
                   11983:             }
                   11984:         }
                   11985:     }
                   11986:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   11987:     if (@currlangs > 0) {
                   11988:         foreach my $lang (@currlangs) {
                   11989:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   11990:                 $changes{'helpurl'}{$lang} = 1;
                   11991:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   11992:                 $changes{'helpurl'}{$lang} = 1;
                   11993:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   11994:                 push(@newlangs,$lang);
                   11995:             } else {
                   11996:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   11997:             }
                   11998:         }
                   11999:     }
                   12000:     unless (grep(/^nolang$/,@currlangs)) {
                   12001:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   12002:             $changes{'helpurl'}{'nolang'} = 1;
                   12003:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   12004:             push(@newlangs,'nolang');
                   12005:         }
                   12006:     }
                   12007:     if ($env{'form.loginhelpurl_add_lang'}) {
                   12008:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   12009:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   12010:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   12011:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   12012:         }
                   12013:     }
                   12014:     if ((@newlangs > 0) || ($addedfile)) {
                   12015:         my $error;
                   12016:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12017:         if ($configuserok eq 'ok') {
                   12018:             if ($switchserver) {
                   12019:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   12020:             } elsif ($author_ok eq 'ok') {
                   12021:                 my @allnew = @newlangs;
                   12022:                 if ($addedfile ne '') {
                   12023:                     push(@allnew,$addedfile);
                   12024:                 }
                   12025:                 foreach my $lang (@allnew) {
                   12026:                     my $formelem = 'loginhelpurl_'.$lang;
                   12027:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   12028:                         $formelem = 'loginhelpurl_add_file';
                   12029:                     }
                   12030:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12031:                                                                "help/$lang",'','',$newfile{$lang});
                   12032:                     if ($result eq 'ok') {
                   12033:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   12034:                         $changes{'helpurl'}{$lang} = 1;
                   12035:                     } else {
                   12036:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   12037:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  12038:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  12039:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   12040:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   12041:                         }
                   12042:                     }
                   12043:                 }
                   12044:             } else {
                   12045:                 $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);
                   12046:             }
                   12047:         } else {
                   12048:             $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);
                   12049:         }
                   12050:         if ($error) {
                   12051:             &Apache::lonnet::logthis($error);
                   12052:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12053:         }
                   12054:     }
1.256     raeburn  12055: 
                   12056:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   12057:     if (ref($domconfig{'login'}) eq 'HASH') {
                   12058:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   12059:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   12060:                 if ($domservers{$lonhost}) {
                   12061:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12062:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  12063:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  12064:                     }
                   12065:                 }
                   12066:             }
                   12067:         }
                   12068:     }
                   12069:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   12070:     foreach my $lonhost (sort(keys(%domservers))) {
                   12071:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12072:             $changes{'headtag'}{$lonhost} = 1;
                   12073:         } else {
                   12074:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   12075:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   12076:             }
                   12077:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   12078:                 push(@newhosts,$lonhost);
                   12079:             } elsif ($currheadtagurls{$lonhost}) {
                   12080:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   12081:                 if ($currexempt{$lonhost}) {
1.289     raeburn  12082:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  12083:                         $changes{'headtag'}{$lonhost} = 1;
                   12084:                     }
                   12085:                 } elsif ($possexempt{$lonhost}) {
                   12086:                     $changes{'headtag'}{$lonhost} = 1;
                   12087:                 }
                   12088:                 if ($possexempt{$lonhost}) {
                   12089:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12090:                 }
                   12091:             }
                   12092:         }
                   12093:     }
                   12094:     if (@newhosts) {
                   12095:         my $error;
                   12096:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12097:         if ($configuserok eq 'ok') {
                   12098:             if ($switchserver) {
                   12099:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   12100:             } elsif ($author_ok eq 'ok') {
                   12101:                 foreach my $lonhost (@newhosts) {
                   12102:                     my $formelem = 'loginheadtag_'.$lonhost;
                   12103:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12104:                                                                           "login/headtag/$lonhost",'','',
                   12105:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   12106:                     if ($result eq 'ok') {
                   12107:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   12108:                         $changes{'headtag'}{$lonhost} = 1;
                   12109:                         if ($possexempt{$lonhost}) {
                   12110:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12111:                         }
                   12112:                     } else {
                   12113:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   12114:                                            $newheadtagurls{$lonhost},$result);
                   12115:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12116:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   12117:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   12118:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   12119:                         }
                   12120:                     }
                   12121:                 }
                   12122:             } else {
                   12123:                 $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);
                   12124:             }
                   12125:         } else {
                   12126:             $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);
                   12127:         }
                   12128:         if ($error) {
                   12129:             &Apache::lonnet::logthis($error);
                   12130:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12131:         }
                   12132:     }
1.386     raeburn  12133:     my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
                   12134:     my @newsamlimgs;
                   12135:     foreach my $lonhost (keys(%domservers)) {
                   12136:         if ($env{'form.saml_'.$lonhost}) {
                   12137:             if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                   12138:                 push(@newsamlimgs,$lonhost);
                   12139:             }
                   12140:             foreach my $item ('text','alt','url','title','notsso') {
                   12141:                 $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
                   12142:             }
                   12143:             if ($saml{$lonhost}) {
                   12144:                 if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
                   12145: #FIXME Need to obsolete published image
                   12146:                     delete($currsaml{$lonhost}{'img'});
                   12147:                     $changes{'saml'}{$lonhost} = 1;
                   12148:                 }
                   12149:                 if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
                   12150:                     $changes{'saml'}{$lonhost} = 1;
                   12151:                 }
                   12152:                 if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
                   12153:                     $changes{'saml'}{$lonhost} = 1;
                   12154:                 }
                   12155:                 if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
                   12156:                     $changes{'saml'}{$lonhost} = 1;
                   12157:                 }
                   12158:                 if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
                   12159:                     $changes{'saml'}{$lonhost} = 1;
                   12160:                 }
                   12161:                 if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
                   12162:                     $changes{'saml'}{$lonhost} = 1;
                   12163:                 }
                   12164:             } else {
                   12165:                 $changes{'saml'}{$lonhost} = 1;
                   12166:             }
                   12167:             foreach my $item ('text','alt','url','title','notsso') {
                   12168:                 $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
                   12169:             }
                   12170:         } else {
1.389     raeburn  12171:             if ($saml{$lonhost}) {  
                   12172:                 $changes{'saml'}{$lonhost} = 1;
                   12173:                 delete($currsaml{$lonhost});
                   12174:             }
1.386     raeburn  12175:         }
                   12176:     }
                   12177:     foreach my $posshost (keys(%currsaml)) {
                   12178:         unless (exists($domservers{$posshost})) { 
                   12179:             delete($currsaml{$posshost}); 
                   12180:         }
                   12181:     }
                   12182:     %{$loginhash{'login'}{'saml'}} = %currsaml;
                   12183:     if (@newsamlimgs) {
                   12184:         my $error;
                   12185:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12186:         if ($configuserok eq 'ok') {
                   12187:             if ($switchserver) {
                   12188:                 $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
                   12189:             } elsif ($author_ok eq 'ok') {
                   12190:                 foreach my $lonhost (@newsamlimgs) {
                   12191:                     my $formelem = 'saml_img_'.$lonhost;
                   12192:                     my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12193:                                                         "login/saml/$lonhost",'','',
                   12194:                                                         $env{'form.saml_img_'.$lonhost.'.filename'});
                   12195:                     if ($result eq 'ok') {
                   12196:                         $currsaml{$lonhost}{'img'} = $imgurl;
                   12197:                         $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
                   12198:                         $changes{'saml'}{$lonhost} = 1;
                   12199:                     } else {
                   12200:                         my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
                   12201:                                            $lonhost,$result);
                   12202:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12203:                     }
                   12204:                 }
                   12205:             } else {
                   12206:                 $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);
                   12207:             }
                   12208:         } else {
                   12209:             $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);
                   12210:         }
                   12211:         if ($error) {
                   12212:             &Apache::lonnet::logthis($error);
                   12213:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12214:         }
                   12215:     }
1.169     raeburn  12216:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  12217: 
                   12218:     my $defaulthelpfile = '/adm/loginproblems.html';
                   12219:     my $defaulttext = &mt('Default in use');
                   12220: 
1.1       raeburn  12221:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   12222:                                              $dom);
                   12223:     if ($putresult eq 'ok') {
1.188     raeburn  12224:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  12225:         my %defaultchecked = (
                   12226:                     'coursecatalog' => 'on',
1.188     raeburn  12227:                     'helpdesk'      => 'on',
1.42      raeburn  12228:                     'adminmail'     => 'off',
1.43      raeburn  12229:                     'newuser'       => 'off',
1.42      raeburn  12230:         );
1.55      raeburn  12231:         if (ref($domconfig{'login'}) eq 'HASH') {
                   12232:             foreach my $item (@toggles) {
                   12233:                 if ($defaultchecked{$item} eq 'on') { 
                   12234:                     if (($domconfig{'login'}{$item} eq '0') &&
                   12235:                         ($env{'form.'.$item} eq '1')) {
                   12236:                         $changes{$item} = 1;
                   12237:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12238:                               $domconfig{'login'}{$item} eq '1') &&
                   12239:                              ($env{'form.'.$item} eq '0')) {
                   12240:                         $changes{$item} = 1;
                   12241:                     }
                   12242:                 } elsif ($defaultchecked{$item} eq 'off') {
                   12243:                     if (($domconfig{'login'}{$item} eq '1') &&
                   12244:                         ($env{'form.'.$item} eq '0')) {
                   12245:                         $changes{$item} = 1;
                   12246:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12247:                               $domconfig{'login'}{$item} eq '0') &&
                   12248:                              ($env{'form.'.$item} eq '1')) {
                   12249:                         $changes{$item} = 1;
                   12250:                     }
1.42      raeburn  12251:                 }
                   12252:             }
1.41      raeburn  12253:         }
1.6       raeburn  12254:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  12255:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386     raeburn  12256:             if (exists($changes{'saml'})) {
                   12257:                 my $hostid_in_use;
                   12258:                 my @hosts = &Apache::lonnet::current_machine_ids();
                   12259:                 if (@hosts > 1) {
                   12260:                     foreach my $hostid (@hosts) {
                   12261:                         if (&Apache::lonnet::host_domain($hostid) eq $dom) {
                   12262:                             $hostid_in_use = $hostid;
                   12263:                             last;
                   12264:                         }
                   12265:                     }
                   12266:                 } else {
                   12267:                     $hostid_in_use = $r->dir_config('lonHostID');
                   12268:                 }
                   12269:                 if (($hostid_in_use) &&
                   12270:                     (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387     raeburn  12271:                     &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386     raeburn  12272:                 }
                   12273:                 if (ref($lastactref) eq 'HASH') {
                   12274:                     if (ref($changes{'saml'}) eq 'HASH') {
                   12275:                         my %updates;
                   12276:                         map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
                   12277:                         $lastactref->{'samllanding'} = \%updates;
                   12278:                     }
                   12279:                 }
                   12280:             }
1.212     raeburn  12281:             if (ref($lastactref) eq 'HASH') {
                   12282:                 $lastactref->{'domainconfig'} = 1;
                   12283:             }
1.1       raeburn  12284:             $resulttext = &mt('Changes made:').'<ul>';
                   12285:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   12286:                 if ($item eq 'loginvia') {
1.112     raeburn  12287:                     if (ref($changes{$item}) eq 'HASH') {
                   12288:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   12289:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  12290:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   12291:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   12292:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   12293:                                     $protocol = 'http' if ($protocol ne 'https');
                   12294:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   12295: 
                   12296:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   12297:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   12298:                                     } else {
                   12299:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   12300:                                     }
                   12301:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   12302:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   12303:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   12304:                                     }
                   12305:                                     $resulttext .= '</li>';
                   12306:                                 } else {
                   12307:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   12308:                                 }
1.112     raeburn  12309:                             } else {
1.128     raeburn  12310:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  12311:                             }
                   12312:                         }
1.128     raeburn  12313:                         $resulttext .= '</ul></li>';
1.112     raeburn  12314:                     }
1.168     raeburn  12315:                 } elsif ($item eq 'helpurl') {
                   12316:                     if (ref($changes{$item}) eq 'HASH') {
                   12317:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   12318:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   12319:                                 my ($chg,$link);
                   12320:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   12321:                                 if ($lang eq 'nolang') {
                   12322:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   12323:                                 } else {
                   12324:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   12325:                                 }
                   12326:                                 $resulttext .= '<li>'.$chg.'</li>';
                   12327:                             } else {
                   12328:                                 my $chg;
                   12329:                                 if ($lang eq 'nolang') {
                   12330:                                     $chg = &mt('custom log-in help file for no preferred language');
                   12331:                                 } else {
                   12332:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   12333:                                 }
                   12334:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   12335:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   12336:                                                       '?inhibitmenu=yes',$chg,600,500).
                   12337:                                                '</li>';
                   12338:                             }
                   12339:                         }
                   12340:                     }
1.256     raeburn  12341:                 } elsif ($item eq 'headtag') {
                   12342:                     if (ref($changes{$item}) eq 'HASH') {
                   12343:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12344:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12345:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   12346:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12347:                                 $resulttext .= '<li><a href="'.
                   12348:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   12349:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   12350:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   12351:                                 if ($possexempt{$lonhost}) {
                   12352:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   12353:                                 } else {
                   12354:                                     $resulttext .= &mt('included for any client IP');
                   12355:                                 }
                   12356:                                 $resulttext .= '</li>';
                   12357:                             }
                   12358:                         }
                   12359:                     }
1.386     raeburn  12360:                 } elsif ($item eq 'saml') {
                   12361:                     if (ref($changes{$item}) eq 'HASH') {
                   12362:                         my %notlt = (
                   12363:                                        text   => 'Text for log-in by SSO',
                   12364:                                        img    => 'SSO button image',
                   12365:                                        alt    => 'Alt text for button image',
                   12366:                                        url    => 'SSO URL',
                   12367:                                        title  => 'Tooltip for SSO link',
                   12368:                                        notsso => 'Text for non-SSO log-in',
                   12369:                                     );
                   12370:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12371:                             if (ref($currsaml{$lonhost}) eq 'HASH') {
                   12372:                                 $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
                   12373:                                                '<ul>';
                   12374:                                 foreach my $key ('text','img','alt','url','title','notsso') {
                   12375:                                     if ($currsaml{$lonhost}{$key} eq '') {
                   12376:                                         $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
                   12377:                                     } else {
                   12378:                                         my $value = "'$currsaml{$lonhost}{$key}'";
                   12379:                                         if ($key eq 'img') {
                   12380:                                             $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
                   12381:                                         }
                   12382:                                         $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                   12383:                                                                   $value).'</li>';
                   12384:                                     }
                   12385:                                 }
                   12386:                                 $resulttext .= '</ul></li>';
                   12387:                             } else {
                   12388:                                 $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
                   12389:                             }
                   12390:                         }
                   12391:                     }
1.169     raeburn  12392:                 } elsif ($item eq 'captcha') {
                   12393:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  12394:                         my $chgtxt;
1.169     raeburn  12395:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   12396:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   12397:                         } else {
                   12398:                             my %captchas = &captcha_phrases();
                   12399:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   12400:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   12401:                             } else {
                   12402:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   12403:                             }
                   12404:                         }
                   12405:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12406:                     }
                   12407:                 } elsif ($item eq 'recaptchakeys') {
                   12408:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12409:                         my ($privkey,$pubkey);
                   12410:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   12411:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   12412:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   12413:                         }
                   12414:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   12415:                         if (!$pubkey) {
                   12416:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   12417:                         } else {
                   12418:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   12419:                         }
                   12420:                         if (!$privkey) {
                   12421:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   12422:                         } else {
1.251     raeburn  12423:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  12424:                         }
                   12425:                         $chgtxt .= '</ul>';
                   12426:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12427:                     }
1.269     raeburn  12428:                 } elsif ($item eq 'recaptchaversion') {
                   12429:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12430:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  12431:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  12432:                                            '</li>';
                   12433:                         }
                   12434:                     }
1.41      raeburn  12435:                 } else {
                   12436:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   12437:                 }
1.1       raeburn  12438:             }
1.6       raeburn  12439:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  12440:         } else {
                   12441:             $resulttext = &mt('No changes made to log-in page settings');
                   12442:         }
                   12443:     } else {
1.11      albertel 12444:         $resulttext = '<span class="LC_error">'.
                   12445: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  12446:     }
1.6       raeburn  12447:     if ($errors) {
1.9       raeburn  12448:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  12449:                        $errors.'</ul>';
                   12450:     }
                   12451:     return $resulttext;
                   12452: }
                   12453: 
1.256     raeburn  12454: sub check_exempt_addresses {
                   12455:     my ($iplist) = @_;
                   12456:     $iplist =~ s/^\s+//;
                   12457:     $iplist =~ s/\s+$//;
                   12458:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   12459:     my (@okips,$new);
                   12460:     foreach my $ip (@poss_ips) {
                   12461:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   12462:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   12463:                 push(@okips,$ip);
                   12464:             }
                   12465:         }
                   12466:     }
                   12467:     if (@okips > 0) {
                   12468:         $new = join(',',@okips);
                   12469:     } else {
                   12470:         $new = '';
                   12471:     }
                   12472:     return $new;
                   12473: }
                   12474: 
1.6       raeburn  12475: sub color_font_choices {
                   12476:     my %choices =
                   12477:         &Apache::lonlocal::texthash (
                   12478:             img => "Header",
                   12479:             bgs => "Background colors",
                   12480:             links => "Link colors",
1.55      raeburn  12481:             images => "Images",
1.6       raeburn  12482:             font => "Font color",
1.201     raeburn  12483:             fontmenu => "Font menu",
1.76      raeburn  12484:             pgbg => "Page",
1.6       raeburn  12485:             tabbg => "Header",
                   12486:             sidebg => "Border",
                   12487:             link => "Link",
                   12488:             alink => "Active link",
                   12489:             vlink => "Visited link",
                   12490:         );
                   12491:     return %choices;
                   12492: }
                   12493: 
1.394     raeburn  12494: sub modify_ipaccess {
                   12495:     my ($dom,$lastactref,%domconfig) = @_;
                   12496:     my (@allpos,%changes,%confhash,$errors,$resulttext);
                   12497:     my (@items,%deletions,%itemids,@warnings);
                   12498:     my ($typeorder,$types) = &commblocktype_text();
                   12499:     if ($env{'form.ipaccess_add'}) {
                   12500:         my $name = $env{'form.ipaccess_name_add'};
                   12501:         my ($newid,$error) = &get_ipaccess_id($dom,$name);
                   12502:         if ($newid) {
                   12503:             $itemids{'add'} = $newid;
                   12504:             push(@items,'add');
                   12505:             $changes{$newid} = 1;
                   12506:         } else {
                   12507:             $error = &mt('Failed to acquire unique ID for new IP access control item');
                   12508:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12509:         }
                   12510:     }
                   12511:     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   12512:         my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
                   12513:         if (@todelete) {
                   12514:             map { $deletions{$_} = 1; } @todelete;
                   12515:         }
                   12516:         my $maxnum = $env{'form.ipaccess_maxnum'};
                   12517:         for (my $i=0; $i<$maxnum; $i++) {
                   12518:             my $itemid = $env{'form.ipaccess_id_'.$i};
                   12519:             $itemid =~ s/\D+//g;
                   12520:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12521:                 if ($deletions{$itemid}) {
                   12522:                     $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
                   12523:                 } else {
                   12524:                     push(@items,$i);
                   12525:                     $itemids{$i} = $itemid;
                   12526:                 }
                   12527:             }
                   12528:         }
                   12529:     }
                   12530:     foreach my $idx (@items) {
                   12531:         my $itemid = $itemids{$idx};
                   12532:         next unless ($itemid);
                   12533:         my %current;
                   12534:         unless ($idx eq 'add') {
                   12535:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12536:                 %current = %{$domconfig{'ipaccess'}{$itemid}};
                   12537:             }
                   12538:         }
                   12539:         my $position = $env{'form.ipaccess_pos_'.$itemid};
                   12540:         $position =~ s/\D+//g;
                   12541:         if ($position ne '') {
                   12542:             $allpos[$position] = $itemid;
                   12543:         }
                   12544:         my $name = $env{'form.ipaccess_name_'.$idx};
                   12545:         $name =~ s/^\s+|\s+$//g;
                   12546:         $confhash{$itemid}{'name'} = $name;
                   12547:         my $possrange = $env{'form.ipaccess_range_'.$idx};
                   12548:         $possrange =~ s/^\s+|\s+$//g;
                   12549:         unless ($possrange eq '') {
                   12550:             $possrange =~ s/[\r\n]+/\s/g;
                   12551:             $possrange =~ s/\s*-\s*/-/g;
                   12552:             $possrange =~ s/\s+/,/g;
                   12553:             $possrange =~ s/,+/,/g;
                   12554:             if ($possrange ne '') {
                   12555:                 my (@ok,$count);
                   12556:                 $count = 0; 
                   12557:                 foreach my $poss (split(/\,/,$possrange)) {
                   12558:                     $count ++;
                   12559:                     $poss = &validate_ip_pattern($poss);
                   12560:                     if ($poss ne '') {
                   12561:                         push(@ok,$poss);
                   12562:                     }
                   12563:                 }
                   12564:                 my $diff = $count - scalar(@ok);
                   12565:                 if ($diff) {
                   12566:                     $errors .= '<li><span class="LC_error">'.
                   12567:                                &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
                   12568:                                    $diff,$name).
                   12569:                                '</span></li>';
                   12570:                 }
                   12571:                 if (@ok) {
                   12572:                     my @cidr_list;
                   12573:                     foreach my $item (@ok) {
                   12574:                         @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   12575:                     }
                   12576:                     $confhash{$itemid}{'ip'} = join(',',@cidr_list);
                   12577:                 }
                   12578:             }
                   12579:         }
                   12580:         foreach my $field ('name','ip') {
                   12581:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   12582:                 if ($current{$field} ne $confhash{$itemid}{$field}) {
                   12583:                     $changes{$itemid} = 1;
                   12584:                     last;
                   12585:                 }
                   12586:             }
                   12587:         }
                   12588:         $confhash{$itemid}{'commblocks'} = {};
                   12589:          
                   12590:         my %commblocks;
                   12591:         map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);  
                   12592:         foreach my $type (@{$typeorder}) {
                   12593:             if ($commblocks{$type}) {
                   12594:                 $confhash{$itemid}{'commblocks'}{$type} = 'on';
                   12595:             }
                   12596:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   12597:                 if (ref($current{'commblocks'}) eq 'HASH') {
                   12598:                     if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
                   12599:                         $changes{$itemid} = 1;
                   12600:                     }
                   12601:                 } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
                   12602:                     $changes{$itemid} = 1;
                   12603:                 }
                   12604:             }
                   12605:         }
                   12606:         $confhash{$itemid}{'courses'} = {};
                   12607:         my %crsdeletions;
                   12608:         my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
                   12609:         if (@delcrs) {
                   12610:             map { $crsdeletions{$_} = 1; } @delcrs;
                   12611:         }
                   12612:         if (ref($current{'courses'}) eq 'HASH') {
                   12613:             foreach my $cid (sort(keys(%{$current{'courses'}}))) {
                   12614:                 if ($crsdeletions{$cid}) {
                   12615:                     $changes{$itemid} = 1;
                   12616:                 } else {
                   12617:                     $confhash{$itemid}{'courses'}{$cid} = 1;
                   12618:                 }
                   12619:             }
                   12620:         }
                   12621:         $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
                   12622:         $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
                   12623:         if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) && 
                   12624:             ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
                   12625:             if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
                   12626:                                             $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
                   12627:                 $errors .= '<li><span class="LC_error">'.
                   12628:                            &mt('Invalid courseID [_1] omitted from list of allowed courses',
                   12629:                                $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
                   12630:                            '</span></li>';
                   12631:             } else {
                   12632:                 $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
                   12633:                 $changes{$itemid} = 1;
                   12634:             }
                   12635:         }
                   12636:     }
                   12637:     if (@allpos > 0) {
                   12638:         my $idx = 0;
                   12639:         foreach my $itemid (@allpos) {
                   12640:             if ($itemid ne '') {
                   12641:                 $confhash{$itemid}{'order'} = $idx;
                   12642:                 unless ($changes{$itemid}) {
                   12643:                     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   12644:                         if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12645:                             if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
                   12646:                                 $changes{$itemid} = 1;
                   12647:                             }
                   12648:                         }
                   12649:                     }
                   12650:                 }
                   12651:                 $idx ++;
                   12652:             }
                   12653:         }
                   12654:     }
                   12655:     if (keys(%changes)) {
                   12656:         my %defaultshash = (
                   12657:                               ipaccess => \%confhash,
                   12658:                            );
                   12659:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12660:                                                  $dom);
                   12661:         if ($putresult eq 'ok') {
                   12662:             my $cachetime = 1800;
                   12663:             &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
                   12664:             if (ref($lastactref) eq 'HASH') {
                   12665:                 $lastactref->{'ipaccess'} = 1;
                   12666:             }
                   12667:             $resulttext = &mt('Changes made:').'<ul>';
                   12668:             my %bynum;
                   12669:             foreach my $itemid (sort(keys(%changes))) {
                   12670:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   12671:                     my $position = $confhash{$itemid}{'order'};
                   12672:                     if ($position =~ /^\d+$/) {
                   12673:                         $bynum{$position} = $itemid;
                   12674:                     }
                   12675:                 }
                   12676:             }
                   12677:             if (keys(%deletions)) {
                   12678:                 foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
                   12679:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12680:                 }
                   12681:             }
                   12682:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12683:                 my $itemid = $bynum{$pos};
                   12684:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   12685:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
                   12686:                     my $position = $pos + 1;
                   12687:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   12688:                     if ($confhash{$itemid}{'ip'} eq '') {
                   12689:                         $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
                   12690:                     } else {
                   12691:                         $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
                   12692:                     }
                   12693:                     if (keys(%{$confhash{$itemid}{'commblocks'}})) {
                   12694:                         $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
                   12695:                                                   join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
                   12696:                                        '</li>';
                   12697:                     } else {
                   12698:                         $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
                   12699:                     }
                   12700:                     if (keys(%{$confhash{$itemid}{'courses'}})) {
                   12701:                         my @courses;
                   12702:                         foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
                   12703:                             my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1}); 
                   12704:                             push(@courses,$courseinfo{'description'}.' ('.$cid.')');
                   12705:                         }
                   12706:                         $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
                   12707:                                              join('</li><li>',@courses).'</li></ul>';
                   12708:                     } else {
                   12709:                         $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
                   12710:                     }
1.395     raeburn  12711:                     $resulttext .= '</ul></li>';
1.394     raeburn  12712:                 }
                   12713:             }
1.395     raeburn  12714:             $resulttext .= '</ul>';
1.394     raeburn  12715:         } else {
                   12716:             $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   12717:         }
                   12718:     } else {
                   12719:         $resulttext = &mt('No changes made');
                   12720:     }
                   12721:     if ($errors) {
                   12722:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   12723:                        $errors.'</ul></p>';
                   12724:     }
                   12725:     return $resulttext;
                   12726: }
                   12727: 
                   12728: sub get_ipaccess_id {
                   12729:     my ($domain,$location) = @_;
                   12730:     # get lock on ipaccess db
                   12731:     my $lockhash = {
                   12732:                       lock => $env{'user.name'}.
                   12733:                               ':'.$env{'user.domain'},
                   12734:                    };
                   12735:     my $tries = 0;
                   12736:     my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   12737:     my ($id,$error);
                   12738: 
                   12739:     while (($gotlock ne 'ok') && ($tries<10)) {
                   12740:         $tries ++;
                   12741:         sleep (0.1);
                   12742:         $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   12743:     }
                   12744:     if ($gotlock eq 'ok') {
                   12745:         my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
                   12746:         if ($currids{'lock'}) {
                   12747:             delete($currids{'lock'});
                   12748:             if (keys(%currids)) {
                   12749:                 my @curr = sort { $a <=> $b } keys(%currids);
                   12750:                 if ($curr[-1] =~ /^\d+$/) {
                   12751:                     $id = 1 + $curr[-1];
                   12752:                 }
                   12753:             } else {
                   12754:                 $id = 1;
                   12755:             }
                   12756:             if ($id) {
                   12757:                 unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
                   12758:                     $error = 'nostore';
                   12759:                 }
                   12760:             } else {
                   12761:                 $error = 'nonumber';
                   12762:             }
                   12763:         }
                   12764:         my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
                   12765:     } else {
                   12766:         $error = 'nolock';
                   12767:     }
                   12768:     return ($id,$error);
                   12769: }
                   12770: 
1.6       raeburn  12771: sub modify_rolecolors {
1.205     raeburn  12772:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  12773:     my ($resulttext,%rolehash);
                   12774:     $rolehash{'rolecolors'} = {};
1.55      raeburn  12775:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   12776:         if ($domconfig{'rolecolors'} eq '') {
                   12777:             $domconfig{'rolecolors'} = {};
                   12778:         }
                   12779:     }
1.9       raeburn  12780:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  12781:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   12782:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   12783:                                              $dom);
                   12784:     if ($putresult eq 'ok') {
                   12785:         if (keys(%changes) > 0) {
1.41      raeburn  12786:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  12787:             if (ref($lastactref) eq 'HASH') {
                   12788:                 $lastactref->{'domainconfig'} = 1;
                   12789:             }
1.6       raeburn  12790:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   12791:                                              $rolehash{'rolecolors'});
                   12792:         } else {
                   12793:             $resulttext = &mt('No changes made to default color schemes');
                   12794:         }
                   12795:     } else {
1.11      albertel 12796:         $resulttext = '<span class="LC_error">'.
                   12797: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  12798:     }
                   12799:     if ($errors) {
                   12800:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   12801:                        $errors.'</ul>';
                   12802:     }
                   12803:     return $resulttext;
                   12804: }
                   12805: 
                   12806: sub modify_colors {
1.9       raeburn  12807:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  12808:     my (%changes,%choices);
1.51      raeburn  12809:     my @bgs;
1.6       raeburn  12810:     my @links = ('link','alink','vlink');
1.41      raeburn  12811:     my @logintext;
1.6       raeburn  12812:     my @images;
                   12813:     my $servadm = $r->dir_config('lonAdmEMail');
                   12814:     my $errors;
1.200     raeburn  12815:     my %defaults;
1.6       raeburn  12816:     foreach my $role (@{$roles}) {
                   12817:         if ($role eq 'login') {
1.12      raeburn  12818:             %choices = &login_choices();
1.41      raeburn  12819:             @logintext = ('textcol','bgcol');
1.12      raeburn  12820:         } else {
                   12821:             %choices = &color_font_choices();
                   12822:         }
                   12823:         if ($role eq 'login') {
1.41      raeburn  12824:             @images = ('img','logo','domlogo','login');
1.51      raeburn  12825:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  12826:         } else {
                   12827:             @images = ('img');
1.200     raeburn  12828:             @bgs = ('pgbg','tabbg','sidebg');
                   12829:         }
                   12830:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   12831:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   12832:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   12833:         }
                   12834:         if ($role eq 'login') {
                   12835:             foreach my $item (@logintext) {
1.234     raeburn  12836:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12837:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12838:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12839:                 }
                   12840:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  12841:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12842:                 }
                   12843:             }
                   12844:         } else {
1.234     raeburn  12845:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   12846:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   12847:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   12848:             }
                   12849:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  12850:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   12851:             }
1.6       raeburn  12852:         }
1.200     raeburn  12853:         foreach my $item (@bgs) {
1.234     raeburn  12854:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12855:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12856:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12857:             }
                   12858:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  12859:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12860:             }
                   12861:         }
                   12862:         foreach my $item (@links) {
1.234     raeburn  12863:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12864:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12865:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12866:             }
                   12867:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  12868:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12869:             }
1.6       raeburn  12870:         }
1.46      raeburn  12871:         my ($configuserok,$author_ok,$switchserver) = 
                   12872:             &config_check($dom,$confname,$servadm);
1.9       raeburn  12873:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  12874:         if (ref($domconfig->{$role}) ne 'HASH') {
                   12875:             $domconfig->{$role} = {};
                   12876:         }
1.8       raeburn  12877:         foreach my $img (@images) {
1.402   ! raeburn  12878:             if ($role eq 'login') {
        !          12879:                 if (($img eq 'img') || ($img eq 'logo')) {  
        !          12880:                     if (defined($env{'form.login_showlogo_'.$img})) {
        !          12881:                         $confhash->{$role}{'showlogo'}{$img} = 1;
        !          12882:                     } else { 
        !          12883:                         $confhash->{$role}{'showlogo'}{$img} = 0;
        !          12884:                     }
        !          12885:                 }
        !          12886:                 if ($env{'form.login_alt_'.$img} ne '') {
        !          12887:                     $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70      raeburn  12888:                 }
1.402   ! raeburn  12889:             }
1.18      albertel 12890: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   12891: 		 && !defined($domconfig->{$role}{$img})
                   12892: 		 && !$env{'form.'.$role.'_del_'.$img}
                   12893: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   12894: 		# import the old configured image from the .tab setting
                   12895: 		# if they haven't provided a new one 
                   12896: 		$domconfig->{$role}{$img} = 
                   12897: 		    $env{'form.'.$role.'_import_'.$img};
                   12898: 	    }
1.6       raeburn  12899:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  12900:                 my $error;
1.6       raeburn  12901:                 if ($configuserok eq 'ok') {
1.9       raeburn  12902:                     if ($switchserver) {
1.12      raeburn  12903:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  12904:                     } else {
                   12905:                         if ($author_ok eq 'ok') {
                   12906:                             my ($result,$logourl) = 
                   12907:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   12908:                                            $dom,$confname,$img,$width,$height);
                   12909:                             if ($result eq 'ok') {
                   12910:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  12911:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  12912:                             } else {
1.12      raeburn  12913:                                 $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  12914:                             }
                   12915:                         } else {
1.46      raeburn  12916:                             $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  12917:                         }
                   12918:                     }
                   12919:                 } else {
1.46      raeburn  12920:                     $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  12921:                 }
                   12922:                 if ($error) {
1.8       raeburn  12923:                     &Apache::lonnet::logthis($error);
1.11      albertel 12924:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  12925:                 }
                   12926:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  12927:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   12928:                     my $error;
                   12929:                     if ($configuserok eq 'ok') {
                   12930: # is confname an author?
                   12931:                         if ($switchserver eq '') {
                   12932:                             if ($author_ok eq 'ok') {
                   12933:                                 my ($result,$logourl) = 
                   12934:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   12935:                                             $dom,$confname,$img,$width,$height);
                   12936:                                 if ($result eq 'ok') {
                   12937:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 12938: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  12939:                                 }
                   12940:                             }
                   12941:                         }
                   12942:                     }
1.6       raeburn  12943:                 }
                   12944:             }
                   12945:         }
                   12946:         if (ref($domconfig) eq 'HASH') {
                   12947:             if (ref($domconfig->{$role}) eq 'HASH') {
                   12948:                 foreach my $img (@images) {
                   12949:                     if ($domconfig->{$role}{$img} ne '') {
                   12950:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   12951:                             $confhash->{$role}{$img} = '';
1.12      raeburn  12952:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  12953:                         } else {
1.9       raeburn  12954:                             if ($confhash->{$role}{$img} eq '') {
                   12955:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   12956:                             }
1.6       raeburn  12957:                         }
                   12958:                     } else {
                   12959:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   12960:                             $confhash->{$role}{$img} = '';
1.12      raeburn  12961:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  12962:                         } 
                   12963:                     }
1.402   ! raeburn  12964:                     if ($role eq 'login') {
        !          12965:                         if (($img eq 'logo') || ($img eq 'img')) {
        !          12966:                             if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
        !          12967:                                 if ($confhash->{$role}{'showlogo'}{$img} ne 
        !          12968:                                     $domconfig->{$role}{'showlogo'}{$img}) {
        !          12969:                                     $changes{$role}{'showlogo'}{$img} = 1; 
        !          12970:                                 }
        !          12971:                             } else {
        !          12972:                                 if ($confhash->{$role}{'showlogo'}{$img} == 0) {
        !          12973:                                     $changes{$role}{'showlogo'}{$img} = 1;
        !          12974:                                 }
1.70      raeburn  12975:                             }
1.402   ! raeburn  12976:                         }
        !          12977:                         if ($img ne 'login') {
        !          12978:                             if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
        !          12979:                                 if ($confhash->{$role}{'alttext'}{$img} ne
        !          12980:                                     $domconfig->{$role}{'alttext'}{$img}) {
        !          12981:                                     $changes{$role}{'alttext'}{$img} = 1;
        !          12982:                                 }
        !          12983:                             } else {
        !          12984:                                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
        !          12985:                                     $changes{$role}{'alttext'}{$img} = 1;
        !          12986:                                 }
1.70      raeburn  12987:                             }
                   12988:                         }
                   12989:                     }
                   12990:                 }
1.6       raeburn  12991:                 if ($domconfig->{$role}{'font'} ne '') {
                   12992:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   12993:                         $changes{$role}{'font'} = 1;
                   12994:                     }
                   12995:                 } else {
                   12996:                     if ($confhash->{$role}{'font'}) {
                   12997:                         $changes{$role}{'font'} = 1;
                   12998:                     }
                   12999:                 }
1.107     raeburn  13000:                 if ($role ne 'login') {
                   13001:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   13002:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   13003:                             $changes{$role}{'fontmenu'} = 1;
                   13004:                         }
                   13005:                     } else {
                   13006:                         if ($confhash->{$role}{'fontmenu'}) {
                   13007:                             $changes{$role}{'fontmenu'} = 1;
                   13008:                         }
1.97      tempelho 13009:                     }
                   13010:                 }
1.6       raeburn  13011:                 foreach my $item (@bgs) {
                   13012:                     if ($domconfig->{$role}{$item} ne '') {
                   13013:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13014:                             $changes{$role}{'bgs'}{$item} = 1;
                   13015:                         } 
                   13016:                     } else {
                   13017:                         if ($confhash->{$role}{$item}) {
                   13018:                             $changes{$role}{'bgs'}{$item} = 1;
                   13019:                         }
                   13020:                     }
                   13021:                 }
                   13022:                 foreach my $item (@links) {
                   13023:                     if ($domconfig->{$role}{$item} ne '') {
                   13024:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13025:                             $changes{$role}{'links'}{$item} = 1;
                   13026:                         }
                   13027:                     } else {
                   13028:                         if ($confhash->{$role}{$item}) {
                   13029:                             $changes{$role}{'links'}{$item} = 1;
                   13030:                         }
                   13031:                     }
                   13032:                 }
1.41      raeburn  13033:                 foreach my $item (@logintext) {
                   13034:                     if ($domconfig->{$role}{$item} ne '') {
                   13035:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   13036:                             $changes{$role}{'logintext'}{$item} = 1;
                   13037:                         }
                   13038:                     } else {
                   13039:                         if ($confhash->{$role}{$item}) {
                   13040:                             $changes{$role}{'logintext'}{$item} = 1;
                   13041:                         }
                   13042:                     }
                   13043:                 }
1.6       raeburn  13044:             } else {
                   13045:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13046:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  13047:             }
                   13048:         } else {
                   13049:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  13050:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  13051:         }
                   13052:     }
                   13053:     return ($errors,%changes);
                   13054: }
                   13055: 
1.46      raeburn  13056: sub config_check {
                   13057:     my ($dom,$confname,$servadm) = @_;
                   13058:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   13059:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   13060:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   13061:                                                    $confname,$servadm);
                   13062:     if ($configuserok eq 'ok') {
                   13063:         $switchserver = &check_switchserver($dom,$confname);
                   13064:         if ($switchserver eq '') {
                   13065:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   13066:         }
                   13067:     }
                   13068:     return ($configuserok,$author_ok,$switchserver);
                   13069: }
                   13070: 
1.6       raeburn  13071: sub default_change_checker {
1.41      raeburn  13072:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  13073:     foreach my $item (@{$links}) {
                   13074:         if ($confhash->{$role}{$item}) {
                   13075:             $changes->{$role}{'links'}{$item} = 1;
                   13076:         }
                   13077:     }
                   13078:     foreach my $item (@{$bgs}) {
                   13079:         if ($confhash->{$role}{$item}) {
                   13080:             $changes->{$role}{'bgs'}{$item} = 1;
                   13081:         }
                   13082:     }
1.41      raeburn  13083:     foreach my $item (@{$logintext}) {
                   13084:         if ($confhash->{$role}{$item}) {
                   13085:             $changes->{$role}{'logintext'}{$item} = 1;
                   13086:         }
                   13087:     }
1.6       raeburn  13088:     foreach my $img (@{$images}) {
                   13089:         if ($env{'form.'.$role.'_del_'.$img}) {
                   13090:             $confhash->{$role}{$img} = '';
1.12      raeburn  13091:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  13092:         }
1.70      raeburn  13093:         if ($role eq 'login') {
                   13094:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   13095:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   13096:             }
1.402   ! raeburn  13097:             if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
        !          13098:                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
        !          13099:                     $changes->{$role}{'alttext'}{$img} = 1;
        !          13100:                 }
        !          13101:             }
1.70      raeburn  13102:         }
1.6       raeburn  13103:     }
                   13104:     if ($confhash->{$role}{'font'}) {
                   13105:         $changes->{$role}{'font'} = 1;
                   13106:     }
1.48      raeburn  13107: }
1.6       raeburn  13108: 
                   13109: sub display_colorchgs {
                   13110:     my ($dom,$changes,$roles,$confhash) = @_;
                   13111:     my (%choices,$resulttext);
                   13112:     if (!grep(/^login$/,@{$roles})) {
                   13113:         $resulttext = &mt('Changes made:').'<br />';
                   13114:     }
                   13115:     foreach my $role (@{$roles}) {
                   13116:         if ($role eq 'login') {
                   13117:             %choices = &login_choices();
                   13118:         } else {
                   13119:             %choices = &color_font_choices();
                   13120:         }
                   13121:         if (ref($changes->{$role}) eq 'HASH') {
                   13122:             if ($role ne 'login') {
                   13123:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   13124:             }
                   13125:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   13126:                 if ($role ne 'login') {
                   13127:                     $resulttext .= '<ul>';
                   13128:                 }
                   13129:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   13130:                     if ($role ne 'login') {
                   13131:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   13132:                     }
                   13133:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  13134:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   13135:                             if ($confhash->{$role}{$key}{$item}) {
                   13136:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   13137:                             } else {
                   13138:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   13139:                             }
1.402   ! raeburn  13140:                         } elsif (($role eq 'login') && ($key eq 'alttext')) {
        !          13141:                             if ($confhash->{$role}{$key}{$item} ne '') {
        !          13142:                                 $resulttext .= '<li>'.&mt("$choices{$key for $choices{$item} set to [_1].",
        !          13143:                                                $confhash->{$role}{$key}{$item}).'</li>';
        !          13144:                             } else {
        !          13145:                                 $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
        !          13146:                             }
1.70      raeburn  13147:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  13148:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   13149:                         } else {
1.12      raeburn  13150:                             my $newitem = $confhash->{$role}{$item};
                   13151:                             if ($key eq 'images') {
1.306     raeburn  13152:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  13153:                             }
                   13154:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  13155:                         }
                   13156:                     }
                   13157:                     if ($role ne 'login') {
                   13158:                         $resulttext .= '</ul></li>';
                   13159:                     }
                   13160:                 } else {
                   13161:                     if ($confhash->{$role}{$key} eq '') {
                   13162:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   13163:                     } else {
                   13164:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   13165:                     }
                   13166:                 }
                   13167:                 if ($role ne 'login') {
                   13168:                     $resulttext .= '</ul>';
                   13169:                 }
                   13170:             }
                   13171:         }
                   13172:     }
1.3       raeburn  13173:     return $resulttext;
1.1       raeburn  13174: }
                   13175: 
1.9       raeburn  13176: sub thumb_dimensions {
                   13177:     return ('200','50');
                   13178: }
                   13179: 
1.16      raeburn  13180: sub check_dimensions {
                   13181:     my ($inputfile) = @_;
                   13182:     my ($fullwidth,$fullheight);
                   13183:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   13184:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   13185:             my $imageinfo = <PIPE>;
                   13186:             if (!close(PIPE)) {
                   13187:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   13188:             }
                   13189:             chomp($imageinfo);
                   13190:             my ($fullsize) = 
1.21      raeburn  13191:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  13192:             if ($fullsize) {
                   13193:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   13194:             }
                   13195:         }
                   13196:     }
                   13197:     return ($fullwidth,$fullheight);
                   13198: }
                   13199: 
1.9       raeburn  13200: sub check_configuser {
                   13201:     my ($uhome,$dom,$confname,$servadm) = @_;
                   13202:     my ($configuserok,%currroles);
                   13203:     if ($uhome eq 'no_host') {
                   13204:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.361     raeburn  13205:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  13206:         $configuserok = 
                   13207:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   13208:                              $configpass,'','','','','',undef,$servadm);
                   13209:     } else {
                   13210:         $configuserok = 'ok';
                   13211:         %currroles = 
                   13212:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   13213:     }
                   13214:     return ($configuserok,%currroles);
                   13215: }
                   13216: 
                   13217: sub check_authorstatus {
                   13218:     my ($dom,$confname,%currroles) = @_;
                   13219:     my $author_ok;
1.40      raeburn  13220:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  13221:         my $start = time;
                   13222:         my $end = 0;
                   13223:         $author_ok = 
                   13224:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  13225:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  13226:     } else {
                   13227:         $author_ok = 'ok';
                   13228:     }
                   13229:     return $author_ok;
                   13230: }
                   13231: 
                   13232: sub publishlogo {
1.46      raeburn  13233:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  13234:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  13235:     if ($action eq 'upload') {
                   13236:         $fname=$env{'form.'.$formname.'.filename'};
                   13237:         chop($env{'form.'.$formname});
                   13238:     } else {
                   13239:         ($fname) = ($formname =~ /([^\/]+)$/);
                   13240:     }
1.46      raeburn  13241:     if ($savefileas ne '') {
                   13242:         $fname = $savefileas;
                   13243:     }
1.9       raeburn  13244:     $fname=&Apache::lonnet::clean_filename($fname);
                   13245: # See if there is anything left
                   13246:     unless ($fname) { return ('error: no uploaded file'); }
                   13247:     $fname="$subdir/$fname";
1.210     raeburn  13248:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  13249:     my $filepath="$docroot/priv";
                   13250:     my $relpath = "$dom/$confname";
1.9       raeburn  13251:     my ($fnamepath,$file,$fetchthumb);
                   13252:     $file=$fname;
                   13253:     if ($fname=~m|/|) {
                   13254:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   13255:     }
1.164     raeburn  13256:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  13257:     my $count;
1.164     raeburn  13258:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  13259:         $filepath.="/$parts[$count]";
                   13260:         if ((-e $filepath)!=1) {
                   13261:             mkdir($filepath,02770);
                   13262:         }
                   13263:     }
                   13264:     # Check for bad extension and disallow upload
                   13265:     if ($file=~/\.(\w+)$/ &&
                   13266:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   13267:         $output = 
1.207     bisitz   13268:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  13269:     } elsif ($file=~/\.(\w+)$/ &&
                   13270:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   13271:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   13272:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   13273:         $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  13274:     } elsif (-d "$filepath/$file") {
1.195     bisitz   13275:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  13276:     } else {
                   13277:         my $source = $filepath.'/'.$file;
                   13278:         my $logfile;
1.316     raeburn  13279:         if (!open($logfile,">>",$source.'.log')) {
1.196     raeburn  13280:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  13281:         }
                   13282:         print $logfile
                   13283: "\n================= Publish ".localtime()." ================\n".
                   13284: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   13285: # Save the file
1.316     raeburn  13286:         if (!open(FH,">",$source)) {
1.9       raeburn  13287:             &Apache::lonnet::logthis('Failed to create '.$source);
                   13288:             return (&mt('Failed to create file'));
                   13289:         }
                   13290:         if ($action eq 'upload') {
                   13291:             if (!print FH ($env{'form.'.$formname})) {
                   13292:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   13293:                 return (&mt('Failed to write file'));
                   13294:             }
                   13295:         } else {
                   13296:             my $original = &Apache::lonnet::filelocation('',$formname);
                   13297:             if(!copy($original,$source)) {
                   13298:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   13299:                 return (&mt('Failed to write file'));
                   13300:             }
                   13301:         }
                   13302:         close(FH);
                   13303:         chmod(0660, $source); # Permissions to rw-rw---.
                   13304: 
                   13305:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   13306:         my $copyfile=$targetdir.'/'.$file;
                   13307: 
                   13308:         my @parts=split(/\//,$targetdir);
                   13309:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   13310:         for (my $count=5;$count<=$#parts;$count++) {
                   13311:             $path.="/$parts[$count]";
                   13312:             if (!-e $path) {
                   13313:                 print $logfile "\nCreating directory ".$path;
                   13314:                 mkdir($path,02770);
                   13315:             }
                   13316:         }
                   13317:         my $versionresult;
                   13318:         if (-e $copyfile) {
                   13319:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   13320:         } else {
                   13321:             $versionresult = 'ok';
                   13322:         }
                   13323:         if ($versionresult eq 'ok') {
                   13324:             if (copy($source,$copyfile)) {
                   13325:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   13326:                 $output = 'ok';
                   13327:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  13328:                 push(@{$modified_urls},[$copyfile,$source]);
                   13329:                 my $metaoutput = 
                   13330:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   13331:                 unless ($registered_cleanup) {
                   13332:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13333:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13334:                     $registered_cleanup=1;
                   13335:                 }
1.9       raeburn  13336:             } else {
                   13337:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   13338:                 $output = &mt('Failed to copy file to RES space').", $!";
                   13339:             }
                   13340:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   13341:                 my $inputfile = $filepath.'/'.$file;
                   13342:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  13343:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   13344:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   13345:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   13346:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316     raeburn  13347:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   13348:                         system({$args[0]} @args);
1.16      raeburn  13349:                         chmod(0660, $filepath.'/tn-'.$file);
                   13350:                         if (-e $outfile) {
                   13351:                             my $copyfile=$targetdir.'/tn-'.$file;
                   13352:                             if (copy($outfile,$copyfile)) {
                   13353:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  13354:                                 my $thumb_metaoutput = 
                   13355:                                     &write_metadata($dom,$confname,$formname,
                   13356:                                                     $targetdir,'tn-'.$file,$logfile);
                   13357:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   13358:                                 unless ($registered_cleanup) {
                   13359:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13360:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13361:                                     $registered_cleanup=1;
                   13362:                                 }
1.267     raeburn  13363:                                 $madethumb = 1;
1.16      raeburn  13364:                             } else {
                   13365:                                 print $logfile "\nUnable to write ".$copyfile.
                   13366:                                                ':'.$!."\n";
                   13367:                             }
                   13368:                         }
1.9       raeburn  13369:                     }
                   13370:                 }
                   13371:             }
                   13372:         } else {
                   13373:             $output = $versionresult;
                   13374:         }
                   13375:     }
1.267     raeburn  13376:     return ($output,$logourl,$madethumb);
1.9       raeburn  13377: }
                   13378: 
                   13379: sub logo_versioning {
                   13380:     my ($targetdir,$file,$logfile) = @_;
                   13381:     my $target = $targetdir.'/'.$file;
                   13382:     my ($maxversion,$fn,$extn,$output);
                   13383:     $maxversion = 0;
                   13384:     if ($file =~ /^(.+)\.(\w+)$/) {
                   13385:         $fn=$1;
                   13386:         $extn=$2;
                   13387:     }
                   13388:     opendir(DIR,$targetdir);
                   13389:     while (my $filename=readdir(DIR)) {
                   13390:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   13391:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   13392:         }
                   13393:     }
                   13394:     $maxversion++;
                   13395:     print $logfile "\nCreating old version ".$maxversion."\n";
                   13396:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   13397:     if (copy($target,$copyfile)) {
                   13398:         print $logfile "Copied old target to ".$copyfile."\n";
                   13399:         $copyfile=$copyfile.'.meta';
                   13400:         if (copy($target.'.meta',$copyfile)) {
                   13401:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   13402:             $output = 'ok';
                   13403:         } else {
                   13404:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   13405:             $output = &mt('Failed to copy old meta').", $!, ";
                   13406:         }
                   13407:     } else {
                   13408:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   13409:         $output = &mt('Failed to copy old target').", $!, ";
                   13410:     }
                   13411:     return $output;
                   13412: }
                   13413: 
                   13414: sub write_metadata {
                   13415:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   13416:     my (%metadatafields,%metadatakeys,$output);
                   13417:     $metadatafields{'title'}=$formname;
                   13418:     $metadatafields{'creationdate'}=time;
                   13419:     $metadatafields{'lastrevisiondate'}=time;
                   13420:     $metadatafields{'copyright'}='public';
                   13421:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   13422:                                          $env{'user.domain'};
                   13423:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   13424:     $metadatafields{'domain'}=$dom;
                   13425:     {
                   13426:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   13427:         my $mfh;
1.316     raeburn  13428:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  13429:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  13430:                 unless ($_=~/\./) {
                   13431:                     my $unikey=$_;
                   13432:                     $unikey=~/^([A-Za-z]+)/;
                   13433:                     my $tag=$1;
                   13434:                     $tag=~tr/A-Z/a-z/;
                   13435:                     print $mfh "\n\<$tag";
                   13436:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   13437:                         my $value=$metadatafields{$unikey.'.'.$_};
                   13438:                         $value=~s/\"/\'\'/g;
                   13439:                         print $mfh ' '.$_.'="'.$value.'"';
                   13440:                     }
                   13441:                     print $mfh '>'.
                   13442:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   13443:                             .'</'.$tag.'>';
                   13444:                 }
                   13445:             }
                   13446:             $output = 'ok';
                   13447:             print $logfile "\nWrote metadata";
                   13448:             close($mfh);
                   13449:         } else {
                   13450:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  13451:             $output = &mt('Could not write metadata');
                   13452:         }
                   13453:     }
1.155     raeburn  13454:     return $output;
                   13455: }
                   13456: 
                   13457: sub notifysubscribed {
                   13458:     foreach my $targetsource (@{$modified_urls}){
                   13459:         next unless (ref($targetsource) eq 'ARRAY');
                   13460:         my ($target,$source)=@{$targetsource};
                   13461:         if ($source ne '') {
1.316     raeburn  13462:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  13463:                 print $logfh "\nCleanup phase: Notifications\n";
                   13464:                 my @subscribed=&subscribed_hosts($target);
                   13465:                 foreach my $subhost (@subscribed) {
                   13466:                     print $logfh "\nNotifying host ".$subhost.':';
                   13467:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   13468:                     print $logfh $reply;
                   13469:                 }
                   13470:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   13471:                 foreach my $subhost (@subscribedmeta) {
                   13472:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   13473:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   13474:                                                         $subhost);
                   13475:                     print $logfh $reply;
                   13476:                 }
                   13477:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  13478:                 close($logfh);
1.155     raeburn  13479:             }
                   13480:         }
                   13481:     }
                   13482:     return OK;
                   13483: }
                   13484: 
                   13485: sub subscribed_hosts {
                   13486:     my ($target) = @_;
                   13487:     my @subscribed;
1.316     raeburn  13488:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  13489:         while (my $subline=<$fh>) {
                   13490:             if ($subline =~ /^($match_lonid):/) {
                   13491:                 my $host = $1;
                   13492:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   13493:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   13494:                         push(@subscribed,$host);
                   13495:                     }
                   13496:                 }
                   13497:             }
                   13498:         }
                   13499:     }
                   13500:     return @subscribed;
1.9       raeburn  13501: }
                   13502: 
                   13503: sub check_switchserver {
                   13504:     my ($dom,$confname) = @_;
                   13505:     my ($allowed,$switchserver);
                   13506:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   13507:     if ($home eq 'no_host') {
                   13508:         $home = &Apache::lonnet::domain($dom,'primary');
                   13509:     }
                   13510:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 13511:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   13512:     if (!$allowed) {
1.180     raeburn  13513: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  13514:     }
                   13515:     return $switchserver;
                   13516: }
                   13517: 
1.1       raeburn  13518: sub modify_quotas {
1.216     raeburn  13519:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  13520:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  13521:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  13522:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   13523:         $validationfieldsref);
1.86      raeburn  13524:     if ($action eq 'quotas') {
                   13525:         $context = 'tools'; 
1.163     raeburn  13526:     } else {
1.86      raeburn  13527:         $context = $action;
                   13528:     }
                   13529:     if ($context eq 'requestcourses') {
1.325     raeburn  13530:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  13531:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  13532:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   13533:         %titles = &courserequest_titles();
                   13534:         $toolregexp = join('|',@usertools);
                   13535:         %conditions = &courserequest_conditions();
1.216     raeburn  13536:         $confname = $dom.'-domainconfig';
                   13537:         my $servadm = $r->dir_config('lonAdmEMail');
                   13538:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  13539:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   13540:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  13541:     } elsif ($context eq 'requestauthor') {
                   13542:         @usertools = ('author');
                   13543:         %titles = &authorrequest_titles();
1.86      raeburn  13544:     } else {
1.162     raeburn  13545:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  13546:         %titles = &tool_titles();
1.86      raeburn  13547:     }
1.212     raeburn  13548:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  13549:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  13550:     foreach my $key (keys(%env)) {
1.101     raeburn  13551:         if ($context eq 'requestcourses') {
                   13552:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   13553:                 my $item = $1;
                   13554:                 my $type = $2;
                   13555:                 if ($type =~ /^limit_(.+)/) {
                   13556:                     $limithash{$item}{$1} = $env{$key};
                   13557:                 } else {
                   13558:                     $confhash{$item}{$type} = $env{$key};
                   13559:                 }
                   13560:             }
1.163     raeburn  13561:         } elsif ($context eq 'requestauthor') {
                   13562:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   13563:                 $confhash{$1} = $env{$key};
                   13564:             }
1.101     raeburn  13565:         } else {
1.86      raeburn  13566:             if ($key =~ /^form\.quota_(.+)$/) {
                   13567:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  13568:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   13569:                 $confhash{'authorquota'}{$1} = $env{$key};
                   13570:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  13571:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   13572:             }
1.72      raeburn  13573:         }
                   13574:     }
1.163     raeburn  13575:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  13576:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  13577:         @approvalnotify = sort(@approvalnotify);
                   13578:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325     raeburn  13579:         my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218     raeburn  13580:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   13581:         foreach my $type (@hasuniquecode) {
                   13582:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   13583:                 $confhash{'uniquecode'}{$type} = 1;
                   13584:             }
1.216     raeburn  13585:         }
1.242     raeburn  13586:         my (%newbook,%allpos);
1.216     raeburn  13587:         if ($context eq 'requestcourses') {
1.242     raeburn  13588:             foreach my $type ('textbooks','templates') {
                   13589:                 @{$allpos{$type}} = (); 
                   13590:                 my $invalid;
                   13591:                 if ($type eq 'textbooks') {
                   13592:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   13593:                 } else {
                   13594:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   13595:                 }
                   13596:                 if ($env{'form.'.$type.'_addbook'}) {
                   13597:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   13598:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   13599:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   13600:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   13601:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   13602:                         } else {
                   13603:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   13604:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   13605:                             $position =~ s/\D+//g;
                   13606:                             if ($position ne '') {
                   13607:                                 $allpos{$type}[$position] = $newbook{$type};
                   13608:                             }
1.216     raeburn  13609:                         }
1.242     raeburn  13610:                     } else {
                   13611:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  13612:                     }
                   13613:                 }
1.242     raeburn  13614:             } 
1.216     raeburn  13615:         }
1.102     raeburn  13616:         if (ref($domconfig{$action}) eq 'HASH') {
                   13617:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   13618:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   13619:                     $changes{'notify'}{'approval'} = 1;
                   13620:                 }
                   13621:             } else {
1.144     raeburn  13622:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  13623:                     $changes{'notify'}{'approval'} = 1;
                   13624:                 }
                   13625:             }
1.218     raeburn  13626:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   13627:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   13628:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   13629:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   13630:                             $changes{'uniquecode'} = 1;
                   13631:                         }
                   13632:                     }
                   13633:                     unless ($changes{'uniquecode'}) {
                   13634:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   13635:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   13636:                                 $changes{'uniquecode'} = 1;
                   13637:                             }
                   13638:                         }
                   13639:                     }
                   13640:                } else {
                   13641:                    $changes{'uniquecode'} = 1;
                   13642:                }
                   13643:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   13644:                 $changes{'uniquecode'} = 1;
1.216     raeburn  13645:             }
                   13646:             if ($context eq 'requestcourses') {
1.242     raeburn  13647:                 foreach my $type ('textbooks','templates') {
                   13648:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   13649:                         my %deletions;
                   13650:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   13651:                         if (@todelete) {
                   13652:                             map { $deletions{$_} = 1; } @todelete;
                   13653:                         }
                   13654:                         my %imgdeletions;
                   13655:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   13656:                         if (@todeleteimages) {
                   13657:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   13658:                         }
                   13659:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   13660:                         for (my $i=0; $i<=$maxnum; $i++) {
                   13661:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   13662:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   13663:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   13664:                                 if ($deletions{$key}) {
                   13665:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   13666:                                         #FIXME need to obsolete item in RES space
                   13667:                                     }
                   13668:                                     next;
                   13669:                                 } else {
                   13670:                                     my $newpos = $env{'form.'.$itemid};
                   13671:                                     $newpos =~ s/\D+//g;
1.243     raeburn  13672:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  13673:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  13674:                                                  ($type eq 'templates'));
1.242     raeburn  13675:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   13676:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   13677:                                             $changes{$type}{$key} = 1;
                   13678:                                         }
                   13679:                                     }
                   13680:                                     $allpos{$type}[$newpos] = $key;
                   13681:                                 }
                   13682:                                 if ($imgdeletions{$key}) {
                   13683:                                     $changes{$type}{$key} = 1;
1.216     raeburn  13684:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  13685:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   13686:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  13687:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   13688:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   13689:                                     } else {
                   13690:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   13691:                                                                                       $cdom,$cnum,$type,$configuserok,
                   13692:                                                                                       $switchserver,$author_ok);
                   13693:                                         if ($imgurl) {
                   13694:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   13695:                                             $changes{$type}{$key} = 1; 
                   13696:                                         }
                   13697:                                         if ($error) {
                   13698:                                             &Apache::lonnet::logthis($error);
                   13699:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13700:                                         }
                   13701:                                     }
1.242     raeburn  13702:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   13703:                                     $confhash{$type}{$key}{'image'} = 
                   13704:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  13705:                                 }
                   13706:                             }
                   13707:                         }
                   13708:                     }
                   13709:                 }
                   13710:             }
1.102     raeburn  13711:         } else {
1.144     raeburn  13712:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  13713:                 $changes{'notify'}{'approval'} = 1;
                   13714:             }
1.218     raeburn  13715:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  13716:                 $changes{'uniquecode'} = 1;
                   13717:             }
                   13718:         }
                   13719:         if ($context eq 'requestcourses') {
1.242     raeburn  13720:             foreach my $type ('textbooks','templates') {
                   13721:                 if ($newbook{$type}) {
                   13722:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  13723:                     foreach my $item ('subject','title','publisher','author') {
                   13724:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   13725:                                  ($type eq 'template'));
1.242     raeburn  13726:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   13727:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   13728:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   13729:                         }
                   13730:                     }
                   13731:                     if ($type eq 'textbooks') {
                   13732:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   13733:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  13734:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   13735:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   13736:                             } else {
                   13737:                                 my ($imageurl,$error) =
                   13738:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   13739:                                                             $configuserok,$switchserver,$author_ok);
                   13740:                                 if ($imageurl) {
                   13741:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   13742:                                 }
                   13743:                                 if ($error) {
                   13744:                                     &Apache::lonnet::logthis($error);
                   13745:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13746:                                 }
1.242     raeburn  13747:                             }
                   13748:                         }
1.216     raeburn  13749:                     }
                   13750:                 }
1.242     raeburn  13751:                 if (@{$allpos{$type}} > 0) {
                   13752:                     my $idx = 0;
                   13753:                     foreach my $item (@{$allpos{$type}}) {
                   13754:                         if ($item ne '') {
                   13755:                             $confhash{$type}{$item}{'order'} = $idx;
                   13756:                             if (ref($domconfig{$action}) eq 'HASH') {
                   13757:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   13758:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   13759:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   13760:                                             $changes{$type}{$item} = 1;
                   13761:                                         }
1.216     raeburn  13762:                                     }
                   13763:                                 }
                   13764:                             }
1.242     raeburn  13765:                             $idx ++;
1.216     raeburn  13766:                         }
                   13767:                     }
                   13768:                 }
                   13769:             }
1.235     raeburn  13770:             if (ref($validationitemsref) eq 'ARRAY') {
                   13771:                 foreach my $item (@{$validationitemsref}) {
                   13772:                     if ($item eq 'fields') {
                   13773:                         my @changed;
                   13774:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   13775:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   13776:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   13777:                         }
1.266     raeburn  13778:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13779:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13780:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   13781:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   13782:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   13783:                                 } else {
                   13784:                                     @changed = @{$confhash{'validation'}{$item}};
                   13785:                                 }
1.235     raeburn  13786:                             } else {
                   13787:                                 @changed = @{$confhash{'validation'}{$item}};
                   13788:                             }
                   13789:                         } else {
                   13790:                             @changed = @{$confhash{'validation'}{$item}};
                   13791:                         }
                   13792:                         if (@changed) {
                   13793:                             if ($confhash{'validation'}{$item}) {
                   13794:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   13795:                             } else {
                   13796:                                 $changes{'validation'}{$item} = &mt('None');
                   13797:                             }
                   13798:                         }
                   13799:                     } else {
                   13800:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   13801:                         if ($item eq 'markup') {
                   13802:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   13803:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   13804:                             }
                   13805:                         }
1.266     raeburn  13806:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13807:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13808:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   13809:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13810:                                 }
                   13811:                             } else {
                   13812:                                 if ($confhash{'validation'}{$item} ne '') {
                   13813:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13814:                                 }
1.235     raeburn  13815:                             }
                   13816:                         } else {
                   13817:                             if ($confhash{'validation'}{$item} ne '') {
                   13818:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13819:                             }
                   13820:                         }
                   13821:                     }
                   13822:                 }
                   13823:             }
                   13824:             if ($env{'form.validationdc'}) {
                   13825:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  13826:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  13827:                 if (exists($domcoords{$newval})) {
                   13828:                     $confhash{'validation'}{'dc'} = $newval;
                   13829:                 }
                   13830:             }
                   13831:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  13832:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13833:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13834:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13835:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13836:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   13837:                                     $changes{'validation'}{'dc'} = &mt('None');
                   13838:                                 } else {
                   13839:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   13840:                                 }
1.235     raeburn  13841:                             }
1.266     raeburn  13842:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13843:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  13844:                         }
                   13845:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13846:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   13847:                     }
                   13848:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13849:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  13850:                 }
1.266     raeburn  13851:             } else {
                   13852:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13853:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13854:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13855:                             $changes{'validation'}{'dc'} = &mt('None');
                   13856:                         }
                   13857:                     }
1.235     raeburn  13858:                 }
                   13859:             }
1.102     raeburn  13860:         }
                   13861:     } else {
1.86      raeburn  13862:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  13863:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  13864:     }
1.72      raeburn  13865:     foreach my $item (@usertools) {
                   13866:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  13867:             my $unset; 
1.101     raeburn  13868:             if ($context eq 'requestcourses') {
1.104     raeburn  13869:                 $unset = '0';
                   13870:                 if ($type eq '_LC_adv') {
                   13871:                     $unset = '';
                   13872:                 }
1.101     raeburn  13873:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   13874:                     $confhash{$item}{$type} .= '=';
                   13875:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   13876:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   13877:                     }
                   13878:                 }
1.163     raeburn  13879:             } elsif ($context eq 'requestauthor') {
                   13880:                 $unset = '0';
                   13881:                 if ($type eq '_LC_adv') {
                   13882:                     $unset = '';
                   13883:                 }
1.72      raeburn  13884:             } else {
1.101     raeburn  13885:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   13886:                     $confhash{$item}{$type} = 1;
                   13887:                 } else {
                   13888:                     $confhash{$item}{$type} = 0;
                   13889:                 }
1.72      raeburn  13890:             }
1.86      raeburn  13891:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  13892:                 if ($action eq 'requestauthor') {
                   13893:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   13894:                         $changes{$type} = 1;
                   13895:                     }
                   13896:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  13897:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   13898:                         $changes{$item}{$type} = 1;
                   13899:                     }
                   13900:                 } else {
                   13901:                     if ($context eq 'requestcourses') {
1.104     raeburn  13902:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  13903:                             $changes{$item}{$type} = 1;
                   13904:                         }
                   13905:                     } else {
                   13906:                         if (!$confhash{$item}{$type}) {
                   13907:                             $changes{$item}{$type} = 1;
                   13908:                         }
                   13909:                     }
                   13910:                 }
                   13911:             } else {
                   13912:                 if ($context eq 'requestcourses') {
1.104     raeburn  13913:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  13914:                         $changes{$item}{$type} = 1;
                   13915:                     }
1.163     raeburn  13916:                 } elsif ($context eq 'requestauthor') {
                   13917:                     if ($confhash{$type} ne $unset) {
                   13918:                         $changes{$type} = 1;
                   13919:                     }
1.72      raeburn  13920:                 } else {
                   13921:                     if (!$confhash{$item}{$type}) {
                   13922:                         $changes{$item}{$type} = 1;
                   13923:                     }
                   13924:                 }
                   13925:             }
1.1       raeburn  13926:         }
                   13927:     }
1.163     raeburn  13928:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  13929:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13930:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   13931:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   13932:                     if (exists($confhash{'defaultquota'}{$key})) {
                   13933:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   13934:                             $changes{'defaultquota'}{$key} = 1;
                   13935:                         }
                   13936:                     } else {
                   13937:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  13938:                     }
                   13939:                 }
1.86      raeburn  13940:             } else {
                   13941:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   13942:                     if (exists($confhash{'defaultquota'}{$key})) {
                   13943:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   13944:                             $changes{'defaultquota'}{$key} = 1;
                   13945:                         }
                   13946:                     } else {
                   13947:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  13948:                     }
1.1       raeburn  13949:                 }
                   13950:             }
1.197     raeburn  13951:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   13952:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   13953:                     if (exists($confhash{'authorquota'}{$key})) {
                   13954:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   13955:                             $changes{'authorquota'}{$key} = 1;
                   13956:                         }
                   13957:                     } else {
                   13958:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   13959:                     }
                   13960:                 }
                   13961:             }
1.1       raeburn  13962:         }
1.86      raeburn  13963:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   13964:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   13965:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13966:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   13967:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   13968:                             $changes{'defaultquota'}{$key} = 1;
                   13969:                         }
                   13970:                     } else {
                   13971:                         if (!exists($domconfig{'quotas'}{$key})) {
                   13972:                             $changes{'defaultquota'}{$key} = 1;
                   13973:                         }
1.72      raeburn  13974:                     }
                   13975:                 } else {
1.86      raeburn  13976:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  13977:                 }
1.1       raeburn  13978:             }
                   13979:         }
1.197     raeburn  13980:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   13981:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   13982:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13983:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   13984:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   13985:                             $changes{'authorquota'}{$key} = 1;
                   13986:                         }
                   13987:                     } else {
                   13988:                         $changes{'authorquota'}{$key} = 1;
                   13989:                     }
                   13990:                 } else {
                   13991:                     $changes{'authorquota'}{$key} = 1;
                   13992:                 }
                   13993:             }
                   13994:         }
1.1       raeburn  13995:     }
1.72      raeburn  13996: 
1.163     raeburn  13997:     if ($context eq 'requestauthor') {
                   13998:         $domdefaults{'requestauthor'} = \%confhash;
                   13999:     } else {
                   14000:         foreach my $key (keys(%confhash)) {
1.242     raeburn  14001:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  14002:                 $domdefaults{$key} = $confhash{$key};
                   14003:             }
1.163     raeburn  14004:         }
1.72      raeburn  14005:     }
1.163     raeburn  14006: 
1.1       raeburn  14007:     my %quotahash = (
1.86      raeburn  14008:                       $action => { %confhash }
1.1       raeburn  14009:                     );
                   14010:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   14011:                                              $dom);
                   14012:     if ($putresult eq 'ok') {
                   14013:         if (keys(%changes) > 0) {
1.72      raeburn  14014:             my $cachetime = 24*60*60;
                   14015:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  14016:             if (ref($lastactref) eq 'HASH') {
                   14017:                 $lastactref->{'domdefaults'} = 1;
                   14018:             }
1.1       raeburn  14019:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  14020:             unless (($context eq 'requestcourses') ||
1.163     raeburn  14021:                     ($context eq 'requestauthor')) {
1.86      raeburn  14022:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   14023:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   14024:                     foreach my $type (@{$types},'default') {
                   14025:                         if (defined($changes{'defaultquota'}{$type})) {
                   14026:                             my $typetitle = $usertypes->{$type};
                   14027:                             if ($type eq 'default') {
                   14028:                                 $typetitle = $othertitle;
                   14029:                             }
1.213     raeburn  14030:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  14031:                         }
                   14032:                     }
1.86      raeburn  14033:                     $resulttext .= '</ul></li>';
1.72      raeburn  14034:                 }
1.197     raeburn  14035:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   14036:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  14037:                     foreach my $type (@{$types},'default') {
                   14038:                         if (defined($changes{'authorquota'}{$type})) {
                   14039:                             my $typetitle = $usertypes->{$type};
                   14040:                             if ($type eq 'default') {
                   14041:                                 $typetitle = $othertitle;
                   14042:                             }
1.213     raeburn  14043:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  14044:                         }
                   14045:                     }
                   14046:                     $resulttext .= '</ul></li>';
                   14047:                 }
1.72      raeburn  14048:             }
1.80      raeburn  14049:             my %newenv;
1.72      raeburn  14050:             foreach my $item (@usertools) {
1.163     raeburn  14051:                 my (%haschgs,%inconf);
                   14052:                 if ($context eq 'requestauthor') {
                   14053:                     %haschgs = %changes;
1.210     raeburn  14054:                     %inconf = %confhash;
1.163     raeburn  14055:                 } else {
                   14056:                     if (ref($changes{$item}) eq 'HASH') {
                   14057:                         %haschgs = %{$changes{$item}};
                   14058:                     }
                   14059:                     if (ref($confhash{$item}) eq 'HASH') {
                   14060:                         %inconf = %{$confhash{$item}};
                   14061:                     }
                   14062:                 }
                   14063:                 if (keys(%haschgs) > 0) {
1.80      raeburn  14064:                     my $newacc = 
                   14065:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   14066:                                                           $env{'user.domain'},
1.86      raeburn  14067:                                                           $item,'reload',$context);
1.210     raeburn  14068:                     if (($context eq 'requestcourses') ||
1.163     raeburn  14069:                         ($context eq 'requestauthor')) {
1.108     raeburn  14070:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   14071:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  14072:                         }
                   14073:                     } else {
                   14074:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   14075:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   14076:                         }
1.80      raeburn  14077:                     }
1.163     raeburn  14078:                     unless ($context eq 'requestauthor') {
                   14079:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   14080:                     }
1.72      raeburn  14081:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  14082:                         if ($haschgs{$type}) {
1.72      raeburn  14083:                             my $typetitle = $usertypes->{$type};
                   14084:                             if ($type eq 'default') {
                   14085:                                 $typetitle = $othertitle;
                   14086:                             } elsif ($type eq '_LC_adv') {
                   14087:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   14088:                             }
1.163     raeburn  14089:                             if ($inconf{$type}) {
1.101     raeburn  14090:                                 if ($context eq 'requestcourses') {
                   14091:                                     my $cond;
1.163     raeburn  14092:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  14093:                                         if ($1 eq '') {
                   14094:                                             $cond = &mt('(Automatic processing of any request).');
                   14095:                                         } else {
                   14096:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   14097:                                         }
                   14098:                                     } else { 
1.163     raeburn  14099:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  14100:                                     }
                   14101:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  14102:                                 } elsif ($context eq 'requestauthor') {
                   14103:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   14104:                                                              $titles{$inconf{$type}},$typetitle);
                   14105: 
1.101     raeburn  14106:                                 } else {
                   14107:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   14108:                                 }
1.72      raeburn  14109:                             } else {
1.104     raeburn  14110:                                 if ($type eq '_LC_adv') {
1.163     raeburn  14111:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  14112:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14113:                                     } else { 
                   14114:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   14115:                                     }
                   14116:                                 } else {
                   14117:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   14118:                                 }
1.72      raeburn  14119:                             }
                   14120:                         }
1.26      raeburn  14121:                     }
1.163     raeburn  14122:                     unless ($context eq 'requestauthor') {
                   14123:                         $resulttext .= '</ul></li>';
                   14124:                     }
1.26      raeburn  14125:                 }
1.1       raeburn  14126:             }
1.163     raeburn  14127:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  14128:                 if (ref($changes{'notify'}) eq 'HASH') {
                   14129:                     if ($changes{'notify'}{'approval'}) {
                   14130:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   14131:                             if ($confhash{'notify'}{'approval'}) {
                   14132:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   14133:                             } else {
1.163     raeburn  14134:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  14135:                             }
                   14136:                         }
                   14137:                     }
                   14138:                 }
                   14139:             }
1.216     raeburn  14140:             if ($action eq 'requestcourses') {
                   14141:                 my @offon = ('off','on');
                   14142:                 if ($changes{'uniquecode'}) {
1.218     raeburn  14143:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14144:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   14145:                         $resulttext .= '<li>'.
                   14146:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   14147:                                        '</li>';
                   14148:                     } else {
                   14149:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   14150:                                        '</li>';
                   14151:                     }
1.216     raeburn  14152:                 }
1.242     raeburn  14153:                 foreach my $type ('textbooks','templates') {
                   14154:                     if (ref($changes{$type}) eq 'HASH') {
                   14155:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   14156:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   14157:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   14158:                             my $coursetitle = $coursehash{'description'};
                   14159:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   14160:                             $resulttext .= '<li>';
1.243     raeburn  14161:                             foreach my $item ('subject','title','publisher','author') {
                   14162:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   14163:                                          ($type eq 'templates'));
1.242     raeburn  14164:                                 my $name = $item.':';
                   14165:                                 $name =~ s/^(\w)/\U$1/;
                   14166:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   14167:                             }
                   14168:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   14169:                             if ($type eq 'textbooks') {
                   14170:                                 if ($confhash{$type}{$key}{'image'}) {
                   14171:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   14172:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   14173:                                                    ' alt="Textbook cover" />').'<br />';
                   14174:                                 }
                   14175:                             }
                   14176:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  14177:                         }
1.242     raeburn  14178:                         $resulttext .= '</ul></li>';
1.216     raeburn  14179:                     }
                   14180:                 }
1.235     raeburn  14181:                 if (ref($changes{'validation'}) eq 'HASH') {
                   14182:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   14183:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   14184:                         foreach my $item (@{$validationitemsref}) {
                   14185:                             if (exists($changes{'validation'}{$item})) {
                   14186:                                 if ($item eq 'markup') {
                   14187:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14188:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   14189:                                 } else {
                   14190:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14191:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   14192:                                 }
                   14193:                             }
                   14194:                         }
                   14195:                         if (exists($changes{'validation'}{'dc'})) {
                   14196:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   14197:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   14198:                         }
                   14199:                     }
                   14200:                 }
1.216     raeburn  14201:             }
1.1       raeburn  14202:             $resulttext .= '</ul>';
1.80      raeburn  14203:             if (keys(%newenv)) {
                   14204:                 &Apache::lonnet::appenv(\%newenv);
                   14205:             }
1.1       raeburn  14206:         } else {
1.86      raeburn  14207:             if ($context eq 'requestcourses') {
                   14208:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  14209:             } elsif ($context eq 'requestauthor') {
                   14210:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  14211:             } else {
1.90      weissno  14212:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  14213:             }
1.1       raeburn  14214:         }
                   14215:     } else {
1.11      albertel 14216:         $resulttext = '<span class="LC_error">'.
                   14217: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  14218:     }
1.216     raeburn  14219:     if ($errors) {
                   14220:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   14221:                        '<ul>'.$errors.'</ul></p>';
                   14222:     }
1.3       raeburn  14223:     return $resulttext;
1.1       raeburn  14224: }
                   14225: 
1.216     raeburn  14226: sub process_textbook_image {
1.242     raeburn  14227:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  14228:     my $filename = $env{'form.'.$caller.'.filename'};
                   14229:     my ($error,$url);
                   14230:     my ($width,$height) = (50,50);
                   14231:     if ($configuserok eq 'ok') {
                   14232:         if ($switchserver) {
                   14233:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   14234:                          $switchserver);
                   14235:         } elsif ($author_ok eq 'ok') {
                   14236:             my ($result,$imageurl) =
                   14237:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.312     raeburn  14238:                              "$type/$cdom/$cnum/cover",$width,$height);
1.216     raeburn  14239:             if ($result eq 'ok') {
                   14240:                 $url = $imageurl;
                   14241:             } else {
                   14242:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14243:             }
                   14244:         } else {
                   14245:             $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);
                   14246:         }
                   14247:     } else {
                   14248:         $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);
                   14249:     }
                   14250:     return ($url,$error);
                   14251: }
                   14252: 
1.267     raeburn  14253: sub modify_ltitools {
                   14254:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   14255:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297     raeburn  14256:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267     raeburn  14257:     my $confname = $dom.'-domainconfig';
                   14258:     my $servadm = $r->dir_config('lonAdmEMail');
                   14259:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   14260:     my (%posslti,%possfield);
                   14261:     my @courseroles = ('cc','in','ta','ep','st');
                   14262:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   14263:     map { $posslti{$_} = 1; } @ltiroles;
                   14264:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   14265:     map { $possfield{$_} = 1; } @allfields;
                   14266:     my %lt = &ltitools_names(); 
                   14267:     if ($env{'form.ltitools_add'}) {
                   14268:         my $title = $env{'form.ltitools_add_title'};
                   14269:         $title =~ s/(`)/'/g;
                   14270:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   14271:         if ($newid) {
                   14272:             my $position = $env{'form.ltitools_add_pos'};
                   14273:             $position =~ s/\D+//g;
                   14274:             if ($position ne '') {
                   14275:                 $allpos[$position] = $newid;
                   14276:             }
                   14277:             $changes{$newid} = 1;
1.322     raeburn  14278:             foreach my $item ('title','url','key','secret','lifetime') {
1.267     raeburn  14279:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322     raeburn  14280:                 if ($item eq 'lifetime') {
                   14281:                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   14282:                 }
1.267     raeburn  14283:                 if ($env{'form.ltitools_add_'.$item}) {
1.297     raeburn  14284:                     if (($item eq 'key') || ($item eq 'secret')) {
                   14285:                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14286:                     } else {
                   14287:                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14288:                     }
1.267     raeburn  14289:                 }
                   14290:             }
                   14291:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   14292:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   14293:             }
                   14294:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   14295:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   14296:             }
1.323     raeburn  14297:             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   14298:                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   14299:             } else {
                   14300:                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   14301:             }
1.296     raeburn  14302:             foreach my $item ('width','height','linktext','explanation') {
1.267     raeburn  14303:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   14304:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296     raeburn  14305:                 if (($item eq 'width') || ($item eq 'height')) {
                   14306:                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   14307:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   14308:                     }
                   14309:                 } else {
                   14310:                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   14311:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item}; 
                   14312:                     }
1.267     raeburn  14313:                 }
                   14314:             }
                   14315:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   14316:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298     raeburn  14317:             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   14318:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267     raeburn  14319:             } else {
                   14320:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   14321:             }
                   14322:             foreach my $item ('passback','roster') {
1.319     raeburn  14323:                 if ($env{'form.ltitools_'.$item.'_add'}) {
1.267     raeburn  14324:                     $confhash{$newid}{$item} = 1;
1.319     raeburn  14325:                     if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
                   14326:                         my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
                   14327:                         $lifetime =~ s/^\s+|\s+$//g;
                   14328:                         if ($lifetime =~ /^\d+\.?\d*$/) {
                   14329:                             $confhash{$newid}{$item.'valid'} = $lifetime;
                   14330:                         }
                   14331:                     }
1.267     raeburn  14332:                 }
                   14333:             }
                   14334:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   14335:                 my ($imageurl,$error) =
1.307     raeburn  14336:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267     raeburn  14337:                                             $configuserok,$switchserver,$author_ok);
                   14338:                 if ($imageurl) {
                   14339:                     $confhash{$newid}{'image'} = $imageurl;
                   14340:                 }
                   14341:                 if ($error) {
                   14342:                     &Apache::lonnet::logthis($error);
                   14343:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14344:                 }
                   14345:             }
                   14346:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   14347:             foreach my $field (@fields) {
                   14348:                 if ($possfield{$field}) {
                   14349:                     if ($field eq 'roles') {
                   14350:                         foreach my $role (@courseroles) {
                   14351:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   14352:                             if (($choice ne '') && ($posslti{$choice})) {
                   14353:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   14354:                                 if ($role eq 'cc') {
                   14355:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   14356:                                 }
                   14357:                             }
                   14358:                         }
                   14359:                     } else {
                   14360:                         $confhash{$newid}{'fields'}{$field} = 1;
                   14361:                     }
                   14362:                 }
                   14363:             }
1.324     raeburn  14364:             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   14365:                 if ($confhash{$newid}{'fields'}{'user'}) {
                   14366:                     if ($env{'form.ltitools_userincdom_add'}) {
                   14367:                         $confhash{$newid}{'incdom'} = 1;
                   14368:                     }
                   14369:                 }
                   14370:             }
1.273     raeburn  14371:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   14372:             foreach my $item (@courseconfig) {
                   14373:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   14374:             }
1.267     raeburn  14375:             if ($env{'form.ltitools_add_custom'}) {
                   14376:                 my $name = $env{'form.ltitools_add_custom_name'};
                   14377:                 my $value = $env{'form.ltitools_add_custom_value'};
                   14378:                 $value =~ s/(`)/'/g;
                   14379:                 $name =~ s/(`)/'/g;
                   14380:                 $confhash{$newid}{'custom'}{$name} = $value;
                   14381:             }
                   14382:         } else {
                   14383:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   14384:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14385:         }
                   14386:     }
                   14387:     if (ref($domconfig{$action}) eq 'HASH') {
                   14388:         my %deletions;
                   14389:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   14390:         if (@todelete) {
                   14391:             map { $deletions{$_} = 1; } @todelete;
                   14392:         }
                   14393:         my %customadds;
                   14394:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   14395:         if (@newcustom) {
                   14396:             map { $customadds{$_} = 1; } @newcustom;
                   14397:         } 
                   14398:         my %imgdeletions;
                   14399:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   14400:         if (@todeleteimages) {
                   14401:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14402:         }
                   14403:         my $maxnum = $env{'form.ltitools_maxnum'};
                   14404:         for (my $i=0; $i<=$maxnum; $i++) {
                   14405:             my $itemid = $env{'form.ltitools_id_'.$i};
1.308     raeburn  14406:             $itemid =~ s/\D+//g;
1.267     raeburn  14407:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   14408:                 if ($deletions{$itemid}) {
                   14409:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   14410:                         #FIXME need to obsolete item in RES space
                   14411:                     }
                   14412:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   14413:                     next;
                   14414:                 } else {
                   14415:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   14416:                     $newpos =~ s/\D+//g;
1.322     raeburn  14417:                     foreach my $item ('title','url','lifetime') {
1.267     raeburn  14418:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14419:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   14420:                             $changes{$itemid} = 1;
                   14421:                         }
                   14422:                     }
1.297     raeburn  14423:                     foreach my $item ('key','secret') {
                   14424:                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14425:                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   14426:                             $changes{$itemid} = 1;
                   14427:                         }
                   14428:                     }
1.267     raeburn  14429:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   14430:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   14431:                     }
                   14432:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   14433:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   14434:                     }
1.323     raeburn  14435:                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   14436:                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   14437:                     } else {
                   14438:                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1'; 
                   14439:                     }
                   14440:                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   14441:                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   14442:                             $changes{$itemid} = 1;
                   14443:                         }
                   14444:                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   14445:                         $changes{$itemid} = 1;
                   14446:                     }
1.267     raeburn  14447:                     foreach my $size ('width','height') {
                   14448:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   14449:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   14450:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   14451:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   14452:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14453:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   14454:                                     $changes{$itemid} = 1;
                   14455:                                 }
                   14456:                             } else {
                   14457:                                 $changes{$itemid} = 1;
                   14458:                             }
1.296     raeburn  14459:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14460:                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   14461:                                 $changes{$itemid} = 1;
                   14462:                             }
                   14463:                         }
                   14464:                     }
                   14465:                     foreach my $item ('linktext','explanation') {
                   14466:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   14467:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   14468:                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   14469:                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14470:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14471:                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   14472:                                     $changes{$itemid} = 1;
                   14473:                                 }
                   14474:                             } else {
                   14475:                                 $changes{$itemid} = 1;
                   14476:                             }
                   14477:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14478:                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   14479:                                 $changes{$itemid} = 1;
                   14480:                             }
1.267     raeburn  14481:                         }
                   14482:                     }
                   14483:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   14484:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298     raeburn  14485:                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   14486:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267     raeburn  14487:                     } else {
                   14488:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   14489:                     }
                   14490:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14491:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   14492:                             $changes{$itemid} = 1;
                   14493:                         }
                   14494:                     } else {
                   14495:                         $changes{$itemid} = 1;
                   14496:                     }
                   14497:                     foreach my $extra ('passback','roster') {
                   14498:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   14499:                             $confhash{$itemid}{$extra} = 1;
1.319     raeburn  14500:                             if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338     raeburn  14501:                                 my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319     raeburn  14502:                                 $lifetime =~ s/^\s+|\s+$//g;
                   14503:                                 if ($lifetime =~ /^\d+\.?\d*$/) {
                   14504:                                     $confhash{$itemid}{$extra.'valid'} = $lifetime;
                   14505:                                 }
                   14506:                             }
1.267     raeburn  14507:                         }
                   14508:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   14509:                             $changes{$itemid} = 1;
                   14510:                         }
1.319     raeburn  14511:                         if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
                   14512:                             $changes{$itemid} = 1;
                   14513:                         }
1.267     raeburn  14514:                     }
1.273     raeburn  14515:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318     raeburn  14516:                     foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  14517:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   14518:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   14519:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   14520:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   14521:                                     $changes{$itemid} = 1;
                   14522:                                 }
                   14523:                             } else {
                   14524:                                 $changes{$itemid} = 1;
                   14525:                             }
                   14526:                         }
                   14527:                     }
1.267     raeburn  14528:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   14529:                     foreach my $field (@fields) {
                   14530:                         if ($possfield{$field}) {
                   14531:                             if ($field eq 'roles') {
                   14532:                                 foreach my $role (@courseroles) {
                   14533:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   14534:                                     if (($choice ne '') && ($posslti{$choice})) {
                   14535:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   14536:                                         if ($role eq 'cc') {
                   14537:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   14538:                                         }
                   14539:                                     }
                   14540:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   14541:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   14542:                                             $changes{$itemid} = 1;
                   14543:                                         }
                   14544:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   14545:                                         $changes{$itemid} = 1;
                   14546:                                     }
                   14547:                                 }
                   14548:                             } else {
                   14549:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   14550:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   14551:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   14552:                                         $changes{$itemid} = 1;
                   14553:                                     }
                   14554:                                 } else {
                   14555:                                     $changes{$itemid} = 1;
                   14556:                                 }
                   14557:                             }
                   14558:                         }
                   14559:                     }
1.324     raeburn  14560:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   14561:                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   14562:                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   14563:                                 $confhash{$itemid}{'incdom'} = 1;
                   14564:                             }
                   14565:                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   14566:                                 $changes{$itemid} = 1;
                   14567:                             }
                   14568:                         }
                   14569:                     }
1.267     raeburn  14570:                     $allpos[$newpos] = $itemid;
                   14571:                 }
                   14572:                 if ($imgdeletions{$itemid}) {
                   14573:                     $changes{$itemid} = 1;
                   14574:                     #FIXME need to obsolete item in RES space
                   14575:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   14576:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   14577:                                                                  $itemid,$configuserok,$switchserver,
                   14578:                                                                  $author_ok);
                   14579:                     if ($imgurl) {
                   14580:                         $confhash{$itemid}{'image'} = $imgurl;
                   14581:                         $changes{$itemid} = 1;
                   14582:                     }
                   14583:                     if ($error) {
                   14584:                         &Apache::lonnet::logthis($error);
                   14585:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14586:                     }
                   14587:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   14588:                     $confhash{$itemid}{'image'} =
                   14589:                        $domconfig{$action}{$itemid}{'image'};
                   14590:                 }
                   14591:                 if ($customadds{$i}) {
                   14592:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   14593:                     $name =~ s/(`)/'/g;
                   14594:                     $name =~ s/^\s+//;
                   14595:                     $name =~ s/\s+$//;
                   14596:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   14597:                     $value =~ s/(`)/'/g;
                   14598:                     $value =~ s/^\s+//;
                   14599:                     $value =~ s/\s+$//;
                   14600:                     if ($name ne '') {
                   14601:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   14602:                         $changes{$itemid} = 1;
                   14603:                     }
                   14604:                 }
                   14605:                 my %customdels;
                   14606:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   14607:                 if (@customdeletions) {
                   14608:                     $changes{$itemid} = 1;
                   14609:                 }
                   14610:                 map { $customdels{$_} = 1; } @customdeletions;
                   14611:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   14612:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   14613:                         unless ($customdels{$key}) {
                   14614:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   14615:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   14616:                             }
                   14617:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   14618:                                 $changes{$itemid} = 1;
                   14619:                             }
                   14620:                         }
                   14621:                     }
                   14622:                 }
                   14623:                 unless ($changes{$itemid}) {
                   14624:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   14625:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   14626:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   14627:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   14628:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   14629:                                         $changes{$itemid} = 1;
                   14630:                                         last;
                   14631:                                     }
                   14632:                                 }
                   14633:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   14634:                                 $changes{$itemid} = 1;
                   14635:                             }
                   14636:                         }
                   14637:                         last if ($changes{$itemid});
                   14638:                     }
                   14639:                 }
                   14640:             }
                   14641:         }
                   14642:     }
                   14643:     if (@allpos > 0) {
                   14644:         my $idx = 0;
                   14645:         foreach my $itemid (@allpos) {
                   14646:             if ($itemid ne '') {
                   14647:                 $confhash{$itemid}{'order'} = $idx;
                   14648:                 if (ref($domconfig{$action}) eq 'HASH') {
                   14649:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   14650:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   14651:                             $changes{$itemid} = 1;
                   14652:                         }
                   14653:                     }
                   14654:                 }
                   14655:                 $idx ++;
                   14656:             }
                   14657:         }
                   14658:     }
                   14659:     my %ltitoolshash = (
                   14660:                           $action => { %confhash }
                   14661:                        );
                   14662:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   14663:                                              $dom);
                   14664:     if ($putresult eq 'ok') {
1.297     raeburn  14665:         my %ltienchash = (
                   14666:                              $action => { %encconfig }
                   14667:                          );
1.384     raeburn  14668:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267     raeburn  14669:         if (keys(%changes) > 0) {
                   14670:             my $cachetime = 24*60*60;
1.297     raeburn  14671:             my %ltiall = %confhash;
                   14672:             foreach my $id (keys(%ltiall)) {
                   14673:                 if (ref($encconfig{$id}) eq 'HASH') {
                   14674:                     foreach my $item ('key','secret') {
                   14675:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   14676:                     }
                   14677:                 }
                   14678:             }
                   14679:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267     raeburn  14680:             if (ref($lastactref) eq 'HASH') {
                   14681:                 $lastactref->{'ltitools'} = 1;
                   14682:             }
                   14683:             $resulttext = &mt('Changes made:').'<ul>';
                   14684:             my %bynum;
                   14685:             foreach my $itemid (sort(keys(%changes))) {
                   14686:                 my $position = $confhash{$itemid}{'order'};
                   14687:                 $bynum{$position} = $itemid;
                   14688:             }
                   14689:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   14690:                 my $itemid = $bynum{$pos}; 
                   14691:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   14692:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   14693:                 } else {
                   14694:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   14695:                     if ($confhash{$itemid}{'image'}) {
                   14696:                         $resulttext .= '&nbsp;'.
                   14697:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   14698:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   14699:                     }
                   14700:                     $resulttext .= '</li><ul>';
                   14701:                     my $position = $pos + 1;
                   14702:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323     raeburn  14703:                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267     raeburn  14704:                         if ($confhash{$itemid}{$item} ne '') {
                   14705:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   14706:                         }
                   14707:                     }
1.297     raeburn  14708:                     if ($encconfig{$itemid}{'key'} ne '') {
                   14709:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   14710:                     }
                   14711:                     if ($encconfig{$itemid}{'secret'} ne '') {
1.267     raeburn  14712:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
1.297     raeburn  14713:                         my $num = length($encconfig{$itemid}{'secret'});
1.267     raeburn  14714:                         $resulttext .= ('*'x$num).'</li>';
                   14715:                     }
1.273     raeburn  14716:                     $resulttext .= '<li>'.&mt('Configurable in course:');
1.318     raeburn  14717:                     my @possconfig = ('label','title','target','linktext','explanation','append');
1.273     raeburn  14718:                     my $numconfig = 0; 
                   14719:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   14720:                         foreach my $item (@possconfig) {
                   14721:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   14722:                                 $numconfig ++;
1.296     raeburn  14723:                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273     raeburn  14724:                             }
                   14725:                         }
                   14726:                     }
                   14727:                     if (!$numconfig) {
1.372     raeburn  14728:                         $resulttext .= '&nbsp;'.&mt('None');
1.273     raeburn  14729:                     }
                   14730:                     $resulttext .= '</li>';
1.267     raeburn  14731:                     foreach my $item ('passback','roster') {
                   14732:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   14733:                         if ($confhash{$itemid}{$item}) {
                   14734:                             $resulttext .= &mt('Yes');
1.319     raeburn  14735:                             if ($confhash{$itemid}{$item.'valid'}) {
                   14736:                                 if ($item eq 'passback') {
                   14737:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
                   14738:                                                            $confhash{$itemid}{$item.'valid'});
                   14739:                                 } else {
                   14740:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
                   14741:                                                            $confhash{$itemid}{$item.'valid'});
                   14742:                                 }
                   14743:                             }
1.267     raeburn  14744:                         } else {
                   14745:                             $resulttext .= &mt('No');
                   14746:                         }
                   14747:                         $resulttext .= '</li>';
                   14748:                     }
                   14749:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   14750:                         my $displaylist;
                   14751:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   14752:                             $displaylist = &mt('Display target').':&nbsp;'.
                   14753:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   14754:                         }
                   14755:                         foreach my $size ('width','height') { 
                   14756:                             if ($confhash{$itemid}{'display'}{$size}) {
                   14757:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   14758:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   14759:                             }
                   14760:                         }
                   14761:                         if ($displaylist) {
                   14762:                             $displaylist =~ s/,$//;
                   14763:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   14764:                         }
1.296     raeburn  14765:                         foreach my $item ('linktext','explanation') {
                   14766:                             if ($confhash{$itemid}{'display'}{$item}) {
                   14767:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   14768:                             }
                   14769:                         }
                   14770:                     }
1.267     raeburn  14771:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   14772:                         my $fieldlist;
                   14773:                         foreach my $field (@allfields) {
                   14774:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   14775:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   14776:                             }
                   14777:                         }
                   14778:                         if ($fieldlist) {
                   14779:                             $fieldlist =~ s/,$//;
1.324     raeburn  14780:                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   14781:                                 if ($confhash{$itemid}{'incdom'}) {
                   14782:                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   14783:                                 } else {
                   14784:                                     $fieldlist .= ' ('.&mt('username').')';
                   14785:                                 }
                   14786:                             }
1.267     raeburn  14787:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   14788:                         }
                   14789:                     }
                   14790:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   14791:                         my $rolemaps;
                   14792:                         foreach my $role (@courseroles) {
                   14793:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   14794:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   14795:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   14796:                             }
                   14797:                         }
                   14798:                         if ($rolemaps) {
                   14799:                             $rolemaps =~ s/,$//; 
                   14800:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   14801:                         }
                   14802:                     }
                   14803:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   14804:                         my $customlist;
                   14805:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   14806:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   14807:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   14808:                             } 
                   14809:                         }
                   14810:                         if ($customlist) {
1.317     raeburn  14811:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267     raeburn  14812:                         }
                   14813:                     } 
                   14814:                     $resulttext .= '</ul></li>';
                   14815:                 }
                   14816:             }
                   14817:             $resulttext .= '</ul>';
                   14818:         } else {
                   14819:             $resulttext = &mt('No changes made.');
                   14820:         }
                   14821:     } else {
                   14822:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   14823:     }
                   14824:     if ($errors) {
                   14825:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   14826:                        $errors.'</ul>';
                   14827:     }
                   14828:     return $resulttext;
                   14829: }
                   14830: 
                   14831: sub process_ltitools_image {
                   14832:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   14833:     my $filename = $env{'form.'.$caller.'.filename'};
                   14834:     my ($error,$url);
                   14835:     my ($width,$height) = (21,21);
                   14836:     if ($configuserok eq 'ok') {
                   14837:         if ($switchserver) {
                   14838:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   14839:                          $switchserver);
                   14840:         } elsif ($author_ok eq 'ok') {
                   14841:             my ($result,$imageurl,$madethumb) =
                   14842:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   14843:                              "ltitools/$itemid/icon",$width,$height);
                   14844:             if ($result eq 'ok') {
                   14845:                 if ($madethumb) {
                   14846:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   14847:                     my $imagethumb = "$path/tn-".$imagefile;
                   14848:                     $url = $imagethumb;
                   14849:                 } else {
                   14850:                     $url = $imageurl;
                   14851:                 }
                   14852:             } else {
                   14853:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14854:             }
                   14855:         } else {
                   14856:             $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);
                   14857:         }
                   14858:     } else {
                   14859:         $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);
                   14860:     }
                   14861:     return ($url,$error);
                   14862: }
                   14863: 
                   14864: sub get_ltitools_id {
                   14865:     my ($cdom,$title) = @_;
                   14866:     # get lock on ltitools db
                   14867:     my $lockhash = {
                   14868:                       lock => $env{'user.name'}.
                   14869:                               ':'.$env{'user.domain'},
                   14870:                    };
                   14871:     my $tries = 0;
                   14872:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   14873:     my ($id,$error);
                   14874:  
                   14875:     while (($gotlock ne 'ok') && ($tries<10)) {
                   14876:         $tries ++;
                   14877:         sleep (0.1);
                   14878:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   14879:     }
                   14880:     if ($gotlock eq 'ok') {
                   14881:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   14882:         if ($currids{'lock'}) {
                   14883:             delete($currids{'lock'});
                   14884:             if (keys(%currids)) {
                   14885:                 my @curr = sort { $a <=> $b } keys(%currids);
                   14886:                 if ($curr[-1] =~ /^\d+$/) {
                   14887:                     $id = 1 + $curr[-1];
                   14888:                 }
                   14889:             } else {
                   14890:                 $id = 1;
                   14891:             }
                   14892:             if ($id) {
                   14893:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   14894:                     $error = 'nostore';
                   14895:                 }
                   14896:             } else {
                   14897:                 $error = 'nonumber';
                   14898:             }
                   14899:         }
                   14900:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   14901:     } else {
                   14902:         $error = 'nolock';
                   14903:     }
                   14904:     return ($id,$error);
                   14905: }
                   14906: 
1.372     raeburn  14907: sub modify_proctoring {
                   14908:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   14909:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14910:     my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
                   14911:     my $confname = $dom.'-domainconfig';
                   14912:     my $servadm = $r->dir_config('lonAdmEMail');
                   14913:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   14914:     my %providernames = &proctoring_providernames();
                   14915:     my $maxnum = scalar(keys(%providernames));
                   14916: 
                   14917:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   14918:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   14919:     if (ref($requref) eq 'HASH') {
                   14920:         %requserfields = %{$requref};
                   14921:     }
                   14922:     if (ref($opturef) eq 'HASH') {
                   14923:         %optuserfields = %{$opturef};
                   14924:     }
                   14925:     if (ref($defref) eq 'HASH') {
                   14926:         %defaults = %{$defref};
                   14927:     }
                   14928:     if (ref($extref) eq 'HASH') {
                   14929:         %extended = %{$extref};
                   14930:     }
                   14931:     if (ref($crsref) eq 'HASH') {
                   14932:         %crsconf = %{$crsref};
                   14933:     }
                   14934:     if (ref($rolesref) eq 'ARRAY') {
                   14935:         @courseroles = @{$rolesref};
                   14936:     }
                   14937:     if (ref($ltiref) eq 'ARRAY') {
                   14938:         @ltiroles = @{$ltiref};
                   14939:     }
                   14940: 
                   14941:     if (ref($domconfig{$action}) eq 'HASH') {
                   14942:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
                   14943:         if (@todeleteimages) {
                   14944:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14945:         }
                   14946:     }
                   14947:     my %customadds;
                   14948:     my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
                   14949:     if (@newcustom) {
                   14950:         map { $customadds{$_} = 1; } @newcustom;
                   14951:     }
                   14952:     foreach my $provider (sort(keys(%providernames))) {
                   14953:         $confhash{$provider} = {};
                   14954:         my $pos = $env{'form.proctoring_pos_'.$provider};
                   14955:         $pos =~ s/\D+//g;
                   14956:         $allpos[$pos] = $provider;
                   14957:         my (%current,%currentenc);
                   14958:         my $showroles = 0;
                   14959:         if (ref($domconfig{$action}) eq 'HASH') {
                   14960:             if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   14961:                 %current = %{$domconfig{$action}{$provider}};
                   14962:                 foreach my $item ('key','secret') { 
                   14963:                     $currentenc{$item} = $current{$item};
                   14964:                     delete($current{$item});
                   14965:                 }
                   14966:             }
                   14967:         }
                   14968:         if ($env{'form.proctoring_available_'.$provider}) {
                   14969:             $confhash{$provider}{'available'} = 1;
                   14970:             unless ($current{'available'}) {
                   14971:                 $changes{$provider} = 1;
                   14972:             }
                   14973:         } else {
                   14974:             %{$confhash{$provider}} = %current;
                   14975:             %{$encconfhash{$provider}} = %currentenc;
                   14976:             $confhash{$provider}{'available'} = 0;
                   14977:             if ($current{'available'}) {
                   14978:                 $changes{$provider} = 1;
                   14979:             }
                   14980:         }
                   14981:         if ($confhash{$provider}{'available'}) {
                   14982:             foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
                   14983:                 my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
                   14984:                 if ($field eq 'lifetime') {
                   14985:                     if ($possval =~ /^\d+$/) {
                   14986:                         $confhash{$provider}{$field} = $possval;
                   14987:                     }
                   14988:                 } elsif ($field eq 'version') {
                   14989:                     if ($possval =~ /^\d+\.\d+$/) {
                   14990:                         $confhash{$provider}{$field} = $possval;
                   14991:                     }
                   14992:                 } elsif ($field eq 'sigmethod') {
                   14993:                     if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
                   14994:                         $confhash{$provider}{$field} = $possval;
                   14995:                     }
                   14996:                 } elsif ($field eq 'url') {
                   14997:                     $confhash{$provider}{$field} = $possval;
                   14998:                 } elsif (($field eq 'key') || ($field eq 'secret')) {
                   14999:                     $encconfhash{$provider}{$field} = $possval;
                   15000:                     unless ($currentenc{$field} eq $possval) {
                   15001:                         $changes{$provider} = 1;
                   15002:                     }
                   15003:                 }
                   15004:                 unless (($field eq 'key') || ($field eq 'secret')) {
                   15005:                     unless ($current{$field} eq $confhash{$provider}{$field}) {
                   15006:                         $changes{$provider} = 1;
                   15007:                     }
                   15008:                 }
                   15009:             }
                   15010:             if ($imgdeletions{$provider}) {
                   15011:                 $changes{$provider} = 1;
                   15012:             } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
                   15013:                 my ($imageurl,$error) =
                   15014:                     &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
                   15015:                                               $configuserok,$switchserver,$author_ok);
                   15016:                 if ($imageurl) {
                   15017:                     $confhash{$provider}{'image'} = $imageurl;
                   15018:                     $changes{$provider} = 1; 
                   15019:                 }
                   15020:                 if ($error) {
                   15021:                     &Apache::lonnet::logthis($error);
                   15022:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15023:                 }
                   15024:             } elsif (exists($current{'image'})) {
                   15025:                 $confhash{$provider}{'image'} = $current{'image'};
                   15026:             }
                   15027:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15028:                 if (@{$requserfields{$provider}} > 0) {
                   15029:                     if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15030:                         if ($env{'form.proctoring_userincdom_'.$provider}) {
                   15031:                             $confhash{$provider}{'incdom'} = 1;
                   15032:                         }
                   15033:                         unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
                   15034:                             $changes{$provider} = 1;
                   15035:                         }
                   15036:                     }
                   15037:                     if (grep(/^roles$/,@{$requserfields{$provider}})) {
                   15038:                         $showroles = 1;
                   15039:                     }
                   15040:                 }
                   15041:             }
                   15042:             $confhash{$provider}{'fields'} = [];
                   15043:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   15044:                 if (@{$optuserfields{$provider}} > 0) {
                   15045:                     my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
                   15046:                     foreach my $field (@{$optuserfields{$provider}}) {
                   15047:                         if (grep(/^\Q$field\E$/,@optfields)) {
                   15048:                             push(@{$confhash{$provider}{'fields'}},$field);
                   15049:                         }
                   15050:                     }
                   15051:                 }
                   15052:                 if (ref($current{'fields'}) eq 'ARRAY') {
                   15053:                     unless ($changes{$provider}) {
                   15054:                         my @new = sort(@{$confhash{$provider}{'fields'}});
                   15055:                         my @old = sort(@{$current{'fields'}}); 
                   15056:                         my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15057:                         if (@diffs) {
                   15058:                             $changes{$provider} = 1;
                   15059:                         }
                   15060:                     }
                   15061:                 } elsif (@{$confhash{$provider}{'fields'}}) {
                   15062:                     $changes{$provider} = 1;
                   15063:                 }
                   15064:             }
                   15065:             if (ref($defaults{$provider}) eq 'ARRAY') {  
                   15066:                 if (@{$defaults{$provider}} > 0) {
                   15067:                     my %options;
                   15068:                     if (ref($extended{$provider}) eq 'HASH') {
                   15069:                         %options = %{$extended{$provider}};
                   15070:                     }
                   15071:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
                   15072:                     foreach my $field (@{$defaults{$provider}}) {
                   15073:                         if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   15074:                             my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
                   15075:                             if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
                   15076:                                 push(@{$confhash{$provider}{'defaults'}},$poss); 
                   15077:                             }
                   15078:                         } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
                   15079:                             foreach my $inner (keys(%{$options{$field}})) {
                   15080:                                 if (ref($options{$field}{$inner}) eq 'ARRAY') {
                   15081:                                     my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15082:                                     if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
                   15083:                                         $confhash{$provider}{'defaults'}{$inner} = $poss;
                   15084:                                     }
                   15085:                                 } else {
                   15086:                                     $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
                   15087:                                 }
                   15088:                             }
                   15089:                         } else {
                   15090:                             if (grep(/^\Q$field\E$/,@checked)) {
                   15091:                                 push(@{$confhash{$provider}{'defaults'}},$field);
                   15092:                             }
                   15093:                         }
                   15094:                     }
                   15095:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15096:                         if (ref($current{'defaults'}) eq 'ARRAY') {
                   15097:                             unless ($changes{$provider}) {
                   15098:                                 my @new = sort(@{$confhash{$provider}{'defaults'}});
                   15099:                                 my @old = sort(@{$current{'defaults'}});
                   15100:                                 my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15101:                                 if (@diffs) {
                   15102:                                     $changes{$provider} = 1; 
                   15103:                                 }
                   15104:                             }
                   15105:                         } elsif (ref($current{'defaults'}) eq 'ARRAY') {
                   15106:                             if (@{$current{'defaults'}}) {
                   15107:                                 $changes{$provider} = 1;
                   15108:                             }
                   15109:                         }
                   15110:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15111:                         if (ref($current{'defaults'}) eq 'HASH') {
                   15112:                             unless ($changes{$provider}) {
                   15113:                                 foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
                   15114:                                     unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
                   15115:                                         $changes{$provider} = 1;
                   15116:                                         last;
                   15117:                                     }
                   15118:                                 }
                   15119:                             }
                   15120:                             unless ($changes{$provider}) {
                   15121:                                 foreach my $key (keys(%{$current{'defaults'}})) {
                   15122:                                     unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
                   15123:                                         $changes{$provider} = 1;
                   15124:                                         last;
                   15125:                                     }
                   15126:                                 }
                   15127:                             }
                   15128:                         } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
                   15129:                             $changes{$provider} = 1;
                   15130:                         }
                   15131:                     }
                   15132:                 }
                   15133:             }
                   15134:             if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15135:                 if (@{$crsconf{$provider}} > 0) {
                   15136:                     $confhash{$provider}{'crsconf'} = [];
                   15137:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
                   15138:                     foreach my $crsfield (@{$crsconf{$provider}}) {
                   15139:                         if (grep(/^\Q$crsfield\E$/,@checked)) {
                   15140:                             push(@{$confhash{$provider}{'crsconf'}},$crsfield);
                   15141:                         }
                   15142:                     }
                   15143:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   15144:                         unless ($changes{$provider}) {  
                   15145:                             my @new = sort(@{$confhash{$provider}{'crsconf'}});
                   15146:                             my @old = sort(@{$current{'crsconf'}});
                   15147:                             my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15148:                             if (@diffs) {
                   15149:                                 $changes{$provider} = 1;
                   15150:                             }
                   15151:                         }
                   15152:                     } elsif (@{$confhash{$provider}{'crsconf'}}) {
                   15153:                         $changes{$provider} = 1;
                   15154:                     }
                   15155:                 }
                   15156:             }
                   15157:             if ($showroles) {
                   15158:                 $confhash{$provider}{'roles'} = {};
                   15159:                 foreach my $role (@courseroles) {
                   15160:                     my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
                   15161:                     if (grep(/^\Q$poss\E$/,@ltiroles)) {
                   15162:                         $confhash{$provider}{'roles'}{$role} = $poss;
                   15163:                     }
                   15164:                 }
                   15165:                 unless ($changes{$provider}) {
                   15166:                     if (ref($current{'roles'}) eq 'HASH') {
                   15167:                         foreach my $role (keys(%{$current{'roles'}})) {
                   15168:                             unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
                   15169:                                 $changes{$provider} = 1;
                   15170:                                 last
                   15171:                             }
                   15172:                         }
                   15173:                         unless ($changes{$provider}) {
                   15174:                             foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
                   15175:                                 unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
                   15176:                                     $changes{$provider} = 1;
                   15177:                                     last;
                   15178:                                 }
                   15179:                             }
                   15180:                         }
                   15181:                     } elsif (keys(%{$confhash{$provider}{'roles'}})) {
                   15182:                         $changes{$provider} = 1;
                   15183:                     }
                   15184:                 }
                   15185:             }
                   15186:             if (ref($current{'custom'}) eq 'HASH') {
                   15187:                 my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
                   15188:                 foreach my $key (keys(%{$current{'custom'}})) {
                   15189:                     if (grep(/^\Q$key\E$/,@customdels)) {
                   15190:                         $changes{$provider} = 1;
                   15191:                     } else {
                   15192:                         $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
                   15193:                         if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
                   15194:                             $changes{$provider} = 1;
                   15195:                         }
                   15196:                     }
                   15197:                 }
                   15198:             }
                   15199:             if ($customadds{$provider}) {
                   15200:                 my $name = $env{'form.proctoring_custom_name_'.$provider};
                   15201:                 $name =~ s/(`)/'/g;
                   15202:                 $name =~ s/^\s+//;
                   15203:                 $name =~ s/\s+$//;
                   15204:                 my $value = $env{'form.proctoring_custom_value_'.$provider};
                   15205:                 $value =~ s/(`)/'/g;
                   15206:                 $value =~ s/^\s+//;
                   15207:                 $value =~ s/\s+$//;
                   15208:                 if ($name ne '') {
                   15209:                     $confhash{$provider}{'custom'}{$name} = $value;
                   15210:                     $changes{$provider} = 1;
                   15211:                 }
                   15212:             }
                   15213:         }
                   15214:     }
                   15215:     if (@allpos > 0) {
                   15216:         my $idx = 0;
                   15217:         foreach my $provider (@allpos) {
                   15218:             if ($provider ne '') {
                   15219:                 $confhash{$provider}{'order'} = $idx;
                   15220:                 unless ($changes{$provider}) {
                   15221:                     if (ref($domconfig{$action}) eq 'HASH') {
                   15222:                         if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   15223:                             if ($domconfig{$action}{$provider}{'order'} ne $idx) {
                   15224:                                 $changes{$provider} = 1;
                   15225:                             }
                   15226:                         }
                   15227:                     }
                   15228:                 }
                   15229:                 $idx ++;
                   15230:             }
                   15231:         }
                   15232:     }
                   15233:     my %proc_hash = (
                   15234:                           $action => { %confhash }
                   15235:                        );
                   15236:     my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
                   15237:                                              $dom);
                   15238:     if ($putresult eq 'ok') {
                   15239:         my %proc_enchash = (
                   15240:                              $action => { %encconfhash }
                   15241:                          );
1.384     raeburn  15242:         &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372     raeburn  15243:         if (keys(%changes) > 0) {
                   15244:             my $cachetime = 24*60*60;
                   15245:             my %procall = %confhash;
                   15246:             foreach my $provider (keys(%procall)) {
                   15247:                 if (ref($encconfhash{$provider}) eq 'HASH') {
                   15248:                     foreach my $key ('key','secret') {
                   15249:                         $procall{$provider}{$key} = $encconfhash{$provider}{$key};
                   15250:                     }
                   15251:                 }
                   15252:             }
                   15253:             &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
                   15254:             if (ref($lastactref) eq 'HASH') {
                   15255:                 $lastactref->{'proctoring'} = 1;
                   15256:             }
                   15257:             $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
                   15258:             my %bynum;
                   15259:             foreach my $provider (sort(keys(%changes))) {
                   15260:                 my $position = $confhash{$provider}{'order'};
                   15261:                 $bynum{$position} = $provider;
                   15262:             }
                   15263:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15264:                 my $provider = $bynum{$pos};
                   15265:                 my %lt = &proctoring_titles($provider);
                   15266:                 my %fieldtitles = &proctoring_fieldtitles($provider);
                   15267:                 if (!$confhash{$provider}{'available'}) {
                   15268:                     $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
                   15269:                 } else {
                   15270:                     $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
                   15271:                     if ($confhash{$provider}{'image'}) {
                   15272:                         $resulttext .= '&nbsp;'.
                   15273:                                        '<img src="'.$confhash{$provider}{'image'}.'"'.
                   15274:                                        ' alt="'.&mt('Proctoring icon').'" />';
                   15275:                     }
                   15276:                     $resulttext .= '<ul>';
                   15277:                     my $position = $pos + 1;
                   15278:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15279:                     foreach my $key ('version','sigmethod','url','lifetime') {
                   15280:                         if ($confhash{$provider}{$key} ne '') {
                   15281:                             $resulttext .= '<li>'.$lt{$key}.':&nbsp;'.$confhash{$provider}{$key}.'</li>';
                   15282:                         }
                   15283:                     }
                   15284:                     if ($encconfhash{$provider}{'key'} ne '') {
                   15285:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfhash{$provider}{'key'}.'</li>';
                   15286:                     }
                   15287:                     if ($encconfhash{$provider}{'secret'} ne '') {
                   15288:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15289:                         my $num = length($encconfhash{$provider}{'secret'});
                   15290:                         $resulttext .= ('*'x$num).'</li>';
                   15291:                     }
                   15292:                     my (@fields,$showroles);
                   15293:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15294:                         push(@fields,@{$requserfields{$provider}});
                   15295:                     }
                   15296:                     if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
                   15297:                         push(@fields,@{$confhash{$provider}{'fields'}});
                   15298:                     } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
                   15299:                         push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
                   15300:                     }
                   15301:                     if (@fields) {
                   15302:                         if (grep(/^roles$/,@fields)) {
                   15303:                             $showroles = 1;
                   15304:                         }
                   15305:                         $resulttext .= '<li>'.$lt{'udsl'}.':&nbsp;"'.
                   15306:                                        join('", "', map { $lt{$_}; } @fields).'"</li>';
                   15307:                     }
                   15308:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15309:                         if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15310:                             if ($confhash{$provider}{'incdom'}) {
                   15311:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
                   15312:                             } else { 
                   15313:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
                   15314:                             }
                   15315:                         }
                   15316:                     }
                   15317:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15318:                         if (@{$confhash{$provider}{'defaults'}} > 0) {
                   15319:                             $resulttext .= '<li>'.$lt{'defa'};
                   15320:                             foreach my $field (@{$confhash{$provider}{'defaults'}}) {
                   15321:                                 $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15322:                             }
                   15323:                             $resulttext =~ s/,$//;
                   15324:                             $resulttext .= '</li>';
                   15325:                         }
                   15326:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15327:                         if (keys(%{$confhash{$provider}{'defaults'}})) {
                   15328:                             $resulttext .= '<li>'.$lt{'defa'}.':&nbsp;<ul>';
                   15329:                             foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
                   15330:                                 if ($confhash{$provider}{'defaults'}{$key} ne '') {
                   15331:                                     $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
                   15332:                                 }
                   15333:                             }
                   15334:                             $resulttext .= '</ul></li>';
                   15335:                         }
                   15336:                     }
                   15337:                     if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15338:                         if (@{$crsconf{$provider}} > 0) {
                   15339:                             $resulttext .= '<li>'.&mt('Configurable in course:');
                   15340:                             my $numconfig = 0;
                   15341:                             if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
                   15342:                                 if (@{$confhash{$provider}{'crsconf'}} > 0) {
                   15343:                                     foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
                   15344:                                         $numconfig ++;
                   15345:                                         if ($provider eq 'examity') {
                   15346:                                             $resulttext .= ' "'.$lt{'crs'.$field}.'",';
                   15347:                                         } else {
                   15348:                                             $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15349:                                         }
                   15350:                                     }
                   15351:                                     $resulttext =~ s/,$//;
                   15352:                                 }
                   15353:                             }
                   15354:                             if (!$numconfig) {
                   15355:                                 $resulttext .= '&nbsp;'.&mt('None');
                   15356:                             }
                   15357:                             $resulttext .= '</li>';
                   15358:                         }
                   15359:                     }
                   15360:                     if ($showroles) {
                   15361:                         if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
                   15362:                             my $rolemaps;
                   15363:                             foreach my $role (@courseroles) {
                   15364:                                 if ($confhash{$provider}{'roles'}{$role}) {
                   15365:                                     $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   15366:                                                  $confhash{$provider}{'roles'}{$role}.',';
                   15367:                                 }
                   15368:                             }
                   15369:                             if ($rolemaps) {
                   15370:                                 $rolemaps =~ s/,$//;
                   15371:                                 $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15372:                             }
                   15373:                         }
                   15374:                     }
                   15375:                     if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
                   15376:                         my $customlist;
                   15377:                         if (keys(%{$confhash{$provider}{'custom'}})) {
                   15378:                             foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
                   15379:                                 $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
                   15380:                             }
                   15381:                             $customlist =~ s/,$//;
                   15382:                         }
                   15383:                         if ($customlist) {
                   15384:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
                   15385:                         }
                   15386:                     } 
                   15387:                     $resulttext .= '</ul></li>';
                   15388:                 }
                   15389:             }
                   15390:             $resulttext .= '</ul>';
                   15391:         } else {
                   15392:             $resulttext = &mt('No changes made.');
                   15393:         }
                   15394:     } else {
                   15395:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15396:     }
                   15397:     if ($errors) {
                   15398:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15399:                        $errors.'</ul>';
                   15400:     }
                   15401:     return $resulttext;
                   15402: }
                   15403: 
                   15404: sub process_proctoring_image {
                   15405:     my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
                   15406:     my $filename = $env{'form.'.$caller.'.filename'};
                   15407:     my ($error,$url);
                   15408:     my ($width,$height) = (21,21);
                   15409:     if ($configuserok eq 'ok') {
                   15410:         if ($switchserver) {
                   15411:             $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
                   15412:                          $switchserver);
                   15413:         } elsif ($author_ok eq 'ok') {
                   15414:             my ($result,$imageurl,$madethumb) =
                   15415:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   15416:                              "proctoring/$provider/icon",$width,$height);
                   15417:             if ($result eq 'ok') {
                   15418:                 if ($madethumb) {
                   15419:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   15420:                     my $imagethumb = "$path/tn-".$imagefile;
                   15421:                     $url = $imagethumb;
                   15422:                 } else {
                   15423:                     $url = $imageurl;
                   15424:                 }
                   15425:             } else {
                   15426:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   15427:             }
                   15428:         } else {
                   15429:             $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);
                   15430:         }
                   15431:     } else {
                   15432:         $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);
                   15433:     }
                   15434:     return ($url,$error);
                   15435: }
                   15436: 
1.320     raeburn  15437: sub modify_lti {
                   15438:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   15439:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15440:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   15441:     my (%posslti,%posslticrs,%posscrstype);
                   15442:     my @courseroles = ('cc','in','ta','ep','st');
                   15443:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   15444:     my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392     raeburn  15445:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  15446:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   15447:                                official   => 'Official',
                   15448:                                unofficial => 'Unofficial',
                   15449:                                community  => 'Community',
                   15450:                                textbook   => 'Textbook',
                   15451:                                placement  => 'Placement Test',
1.392     raeburn  15452:                                lti        => 'LTI Provider',
1.320     raeburn  15453:     );
1.325     raeburn  15454:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320     raeburn  15455:     my %lt = &lti_names();
                   15456:     map { $posslti{$_} = 1; } @ltiroles;
                   15457:     map { $posslticrs{$_} = 1; } @lticourseroles;
                   15458:     map { $posscrstype{$_} = 1; } @coursetypes;
1.325     raeburn  15459: 
1.326     raeburn  15460:     my %menutitles = &ltimenu_titles();
                   15461: 
1.320     raeburn  15462:     my (@items,%deletions,%itemids);
                   15463:     if ($env{'form.lti_add'}) {
                   15464:         my $consumer = $env{'form.lti_consumer_add'};
                   15465:         $consumer =~ s/(`)/'/g;
                   15466:         ($newid,my $error) = &get_lti_id($dom,$consumer);
                   15467:         if ($newid) {
                   15468:             $itemids{'add'} = $newid;
                   15469:             push(@items,'add');
                   15470:             $changes{$newid} = 1;
                   15471:         } else {
                   15472:             my $error = &mt('Failed to acquire unique ID for new LTI configuration');
                   15473:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15474:         }
                   15475:     }
                   15476:     if (ref($domconfig{$action}) eq 'HASH') {
                   15477:         my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
                   15478:         if (@todelete) {
                   15479:             map { $deletions{$_} = 1; } @todelete;
                   15480:         }
                   15481:         my $maxnum = $env{'form.lti_maxnum'};
1.390     raeburn  15482:         for (my $i=0; $i<$maxnum; $i++) {
1.320     raeburn  15483:             my $itemid = $env{'form.lti_id_'.$i};
                   15484:             $itemid =~ s/\D+//g;
                   15485:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15486:                 if ($deletions{$itemid}) {
                   15487:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
                   15488:                 } else {
1.390     raeburn  15489:                     push(@items,$i);
                   15490:                     $itemids{$i} = $itemid;
1.320     raeburn  15491:                 }
                   15492:             }
                   15493:         }
                   15494:     }
                   15495:     foreach my $idx (@items) {
                   15496:         my $itemid = $itemids{$idx};
                   15497:         next unless ($itemid);
1.390     raeburn  15498:         my $position = $env{'form.lti_pos_'.$itemid};
1.320     raeburn  15499:         $position =~ s/\D+//g;
                   15500:         if ($position ne '') {
                   15501:             $allpos[$position] = $itemid;
                   15502:         }
1.391     raeburn  15503:         foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320     raeburn  15504:             my $formitem = 'form.lti_'.$item.'_'.$idx;
                   15505:             $env{$formitem} =~ s/(`)/'/g;
                   15506:             if ($item eq 'lifetime') {
                   15507:                 $env{$formitem} =~ s/[^\d.]//g;
                   15508:             }
                   15509:             if ($env{$formitem} ne '') {
                   15510:                 if (($item eq 'key') || ($item eq 'secret')) {
                   15511:                     $encconfig{$itemid}{$item} = $env{$formitem};
                   15512:                 } else {
                   15513:                     $confhash{$itemid}{$item} = $env{$formitem};
                   15514:                     unless (($idx eq 'add') || ($changes{$itemid})) {
                   15515:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   15516:                             $changes{$itemid} = 1;
                   15517:                         }
                   15518:                     }
                   15519:                 }
                   15520:             }
                   15521:         }
                   15522:         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
                   15523:             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
                   15524:         }
1.345     raeburn  15525:         if ($confhash{$itemid}{'requser'}) {
                   15526:             if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
                   15527:                 $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid'; 
                   15528:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
                   15529:                 $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
                   15530:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
                   15531:                 my $mapuser = $env{'form.lti_customuser_'.$idx};
                   15532:                 $mapuser =~ s/(`)/'/g;
                   15533:                 $mapuser =~ s/^\s+|\s+$//g; 
                   15534:                 $confhash{$itemid}{'mapuser'} = $mapuser; 
                   15535:             }
                   15536:             my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
                   15537:             my @makeuser;
                   15538:             foreach my $ltirole (sort(@possmakeuser)) {
                   15539:                 if ($posslti{$ltirole}) {
                   15540:                     push(@makeuser,$ltirole);
                   15541:                 }
                   15542:             }
                   15543:             $confhash{$itemid}{'makeuser'} = \@makeuser;
                   15544:             if (@makeuser) {
                   15545:                 my $lcauth = $env{'form.lti_lcauth_'.$idx};
                   15546:                 if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
                   15547:                     $confhash{$itemid}{'lcauth'} = $lcauth;
                   15548:                     if ($lcauth ne 'internal') {
                   15549:                         my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
                   15550:                         $lcauthparm =~ s/^(\s+|\s+)$//g;
                   15551:                         $lcauthparm =~ s/`//g;
                   15552:                         if ($lcauthparm ne '') {
                   15553:                             $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
                   15554:                         }
                   15555:                     }
                   15556:                 } else {
                   15557:                     $confhash{$itemid}{'lcauth'} = 'lti';
                   15558:                 }
1.320     raeburn  15559:             }
1.345     raeburn  15560:             my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
                   15561:             if (@possinstdata) {
                   15562:                 foreach my $field (@possinstdata) {
                   15563:                     if (exists($fieldtitles{$field})) {
                   15564:                         push(@{$confhash{$itemid}{'instdata'}});
1.325     raeburn  15565:                     }
                   15566:                 }
                   15567:             }
1.363     raeburn  15568:             if ($env{'form.lti_callback_'.$idx}) {
                   15569:                 if ($env{'form.lti_callbackparam_'.$idx}) {
                   15570:                     my $callback = $env{'form.lti_callbackparam_'.$idx};
                   15571:                     $callback =~ s/^\s+|\s+$//g;
                   15572:                     $confhash{$itemid}{'callback'} = $callback;
                   15573:                 }
                   15574:             }
1.391     raeburn  15575:             foreach my $field ('topmenu','inlinemenu') {
1.345     raeburn  15576:                 if ($env{'form.lti_'.$field.'_'.$idx}) {
                   15577:                     $confhash{$itemid}{$field} = 1;
                   15578:                 }
1.320     raeburn  15579:             }
1.345     raeburn  15580:             if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   15581:                 $confhash{$itemid}{lcmenu} = [];
                   15582:                 my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   15583:                 foreach my $field (@possmenu) {
                   15584:                     if (exists($menutitles{$field})) {
                   15585:                         if ($field eq 'grades') {
                   15586:                             next unless ($env{'form.lti_inlinemenu_'.$idx});
                   15587:                         }
                   15588:                         push(@{$confhash{$itemid}{lcmenu}},$field);
1.326     raeburn  15589:                     }
                   15590:                 }
                   15591:             }
1.391     raeburn  15592:             if ($confhash{$itemid}{'crsinc'}) {
                   15593:                 if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
                   15594:                     ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
                   15595:                     $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
                   15596:                 } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                   15597:                     my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
                   15598:                     $mapcrs =~ s/(`)/'/g;
                   15599:                     $mapcrs =~ s/^\s+|\s+$//g;
                   15600:                     $confhash{$itemid}{'mapcrs'} = $mapcrs;
                   15601:                 }
                   15602:                 my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                   15603:                 my @crstypes;
                   15604:                 foreach my $type (sort(@posstypes)) {
                   15605:                     if ($posscrstype{$type}) {
                   15606:                         push(@crstypes,$type);
                   15607:                     }
                   15608:                 }
                   15609:                 $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392     raeburn  15610:                 if ($env{'form.lti_storecrs_'.$idx}) {
                   15611:                     $confhash{$itemid}{'storecrs'} = 1;
                   15612:                 }       
1.391     raeburn  15613:                 if ($env{'form.lti_makecrs_'.$idx}) {
                   15614:                     $confhash{$itemid}{'makecrs'} = 1;
                   15615:                 }
                   15616:                 foreach my $ltirole (@lticourseroles) {
                   15617:                     my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                   15618:                     if (grep(/^\Q$possrole\E$/,@courseroles)) {
                   15619:                         $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
                   15620:                     }
                   15621:                 }
                   15622:                 my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
                   15623:                 my @selfenroll;
                   15624:                 foreach my $type (sort(@possenroll)) {
                   15625:                     if ($posslticrs{$type}) {
                   15626:                         push(@selfenroll,$type);
                   15627:                     }
                   15628:                 }
                   15629:                 $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                   15630:                 if ($env{'form.lti_crssec_'.$idx}) {
                   15631:                     if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                   15632:                         $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                   15633:                     } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                   15634:                         my $section = $env{'form.lti_customsection_'.$idx};
                   15635:                         $section =~ s/(`)/'/g;
                   15636:                         $section =~ s/^\s+|\s+$//g;
                   15637:                         if ($section ne '') {
                   15638:                             $confhash{$itemid}{'section'} = $section;
                   15639:                         }
                   15640:                     }
                   15641:                 }
                   15642:                 foreach my $field ('passback','roster') {
                   15643:                     if ($env{'form.lti_'.$field.'_'.$idx}) {
                   15644:                         $confhash{$itemid}{$field} = 1;
                   15645:                     }
                   15646:                 }
                   15647:                 if ($env{'form.lti_passback_'.$idx}) {
                   15648:                     if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                   15649:                         $confhash{$itemid}{'passbackformat'} = '1.0';
                   15650:                     } else {
                   15651:                         $confhash{$itemid}{'passbackformat'} = '1.1';
1.337     raeburn  15652:                     }
                   15653:                 }
1.391     raeburn  15654:             }
                   15655:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   15656:                 if ($confhash{$itemid}{'crsinc'}) {
1.392     raeburn  15657:                     foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391     raeburn  15658:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320     raeburn  15659:                             $changes{$itemid} = 1;
                   15660:                         }
1.345     raeburn  15661:                     }
                   15662:                     unless ($changes{$itemid}) {
1.391     raeburn  15663:                         if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
                   15664:                             if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320     raeburn  15665:                                 $changes{$itemid} = 1;
                   15666:                             }
                   15667:                         }
1.345     raeburn  15668:                     }
1.391     raeburn  15669:                     foreach my $field ('mapcrstype','selfenroll') {
                   15670:                         unless ($changes{$itemid}) {
                   15671:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   15672:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15673:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   15674:                                                                                    $confhash{$itemid}{$field});
                   15675:                                     if (@diffs) {
                   15676:                                         $changes{$itemid} = 1;
                   15677:                                     }
                   15678:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   15679:                                     $changes{$itemid} = 1;
                   15680:                                 }
                   15681:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15682:                                 if (@{$confhash{$itemid}{$field}} > 0) {
1.320     raeburn  15683:                                     $changes{$itemid} = 1;
                   15684:                                 }
                   15685:                             }
1.391     raeburn  15686:                         }
                   15687:                     }
                   15688:                     unless ($changes{$itemid}) {
                   15689:                         if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
                   15690:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15691:                                 foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
                   15692:                                     if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne 
                   15693:                                         $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345     raeburn  15694:                                         $changes{$itemid} = 1;
                   15695:                                         last;
                   15696:                                     }
                   15697:                                 }
1.391     raeburn  15698:                                 unless ($changes{$itemid}) {
                   15699:                                     foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                   15700:                                         if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
                   15701:                                             $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
                   15702:                                             $changes{$itemid} = 1;
                   15703:                                             last;
                   15704:                                         }
                   15705:                                     }
                   15706:                                 }
                   15707:                             } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
                   15708:                                 $changes{$itemid} = 1;
1.345     raeburn  15709:                             }
1.391     raeburn  15710:                         } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15711:                             unless ($changes{$itemid}) {
                   15712:                                 if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                   15713:                                     $changes{$itemid} = 1;
                   15714:                                 }
                   15715:                             }
                   15716:                         }
                   15717:                     }
                   15718:                 }
                   15719:                 unless ($changes{$itemid}) {
                   15720:                     foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
                   15721:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345     raeburn  15722:                             $changes{$itemid} = 1;
1.320     raeburn  15723:                         }
1.391     raeburn  15724:                     }
                   15725:                     unless ($changes{$itemid}) {
                   15726:                         foreach my $field ('makeuser','lcmenu') {
                   15727:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   15728:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15729:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   15730:                                                                                    $confhash{$itemid}{$field});
                   15731:                                     if (@diffs) {
                   15732:                                         $changes{$itemid} = 1;
                   15733:                                     }
                   15734:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   15735:                                     $changes{$itemid} = 1;
                   15736:                                 }
                   15737:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15738:                                 if (@{$confhash{$itemid}{$field}} > 0) {
                   15739:                                     $changes{$itemid} = 1;
                   15740:                                 }
1.345     raeburn  15741:                             }
1.320     raeburn  15742:                         }
                   15743:                     }
                   15744:                 }
                   15745:             }
                   15746:         }
                   15747:     }
                   15748:     if (@allpos > 0) {
                   15749:         my $idx = 0;
                   15750:         foreach my $itemid (@allpos) {
                   15751:             if ($itemid ne '') {
                   15752:                 $confhash{$itemid}{'order'} = $idx;
                   15753:                 if (ref($domconfig{$action}) eq 'HASH') {
                   15754:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15755:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   15756:                             $changes{$itemid} = 1;
                   15757:                         }
                   15758:                     }
                   15759:                 }
                   15760:                 $idx ++;
                   15761:             }
                   15762:         }
                   15763:     }
                   15764:     my %ltihash = (
                   15765:                           $action => { %confhash }
                   15766:                        );
                   15767:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
                   15768:                                              $dom);
                   15769:     if ($putresult eq 'ok') {
                   15770:         my %ltienchash = (
                   15771:                              $action => { %encconfig }
                   15772:                          );
1.384     raeburn  15773:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320     raeburn  15774:         if (keys(%changes) > 0) {
                   15775:             my $cachetime = 24*60*60;
                   15776:             my %ltiall = %confhash;
                   15777:             foreach my $id (keys(%ltiall)) {
                   15778:                 if (ref($encconfig{$id}) eq 'HASH') {
                   15779:                     foreach my $item ('key','secret') {
                   15780:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   15781:                     }
                   15782:                 }
                   15783:             }
                   15784:             &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
                   15785:             if (ref($lastactref) eq 'HASH') {
                   15786:                 $lastactref->{'lti'} = 1;
                   15787:             }
                   15788:             $resulttext = &mt('Changes made:').'<ul>';
                   15789:             my %bynum;
                   15790:             foreach my $itemid (sort(keys(%changes))) {
                   15791:                 my $position = $confhash{$itemid}{'order'};
                   15792:                 $bynum{$position} = $itemid;
                   15793:             }
                   15794:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15795:                 my $itemid = $bynum{$pos};
                   15796:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   15797:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   15798:                 } else {
1.390     raeburn  15799:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320     raeburn  15800:                     my $position = $pos + 1;
                   15801:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15802:                     foreach my $item ('version','lifetime') {
                   15803:                         if ($confhash{$itemid}{$item} ne '') {
                   15804:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   15805:                         }
                   15806:                     }
                   15807:                     if ($encconfig{$itemid}{'key'} ne '') {
                   15808:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   15809:                     }
                   15810:                     if ($encconfig{$itemid}{'secret'} ne '') {
                   15811:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15812:                         my $num = length($encconfig{$itemid}{'secret'});
                   15813:                         $resulttext .= ('*'x$num).'</li>';
                   15814:                     }
1.345     raeburn  15815:                     if ($confhash{$itemid}{'requser'}) {
1.391     raeburn  15816:                         if ($confhash{$itemid}{'callback'}) {
                   15817:                             $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
                   15818:                         } else {
1.392     raeburn  15819:                             $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391     raeburn  15820:                         }
1.345     raeburn  15821:                         if ($confhash{$itemid}{'mapuser'}) {
                   15822:                             my $shownmapuser;
                   15823:                             if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                   15824:                                 $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                   15825:                             } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                   15826:                                 $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                   15827:                             } else {
                   15828:                                 $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320     raeburn  15829:                             }
1.345     raeburn  15830:                             $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320     raeburn  15831:                         }
1.345     raeburn  15832:                         if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                   15833:                             if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                   15834:                                 $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                   15835:                                                           join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                   15836:                                 if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                   15837:                                     $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                   15838:                                 } else {
                   15839:                                     $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                   15840:                                                        $confhash{$itemid}{'lcauth'});
                   15841:                                     if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                   15842:                                         $resulttext .= '; '.&mt('a randomly generated password will be created');
                   15843:                                     } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                   15844:                                         if ($confhash{$itemid}{'lcauthparm'} ne '') {
                   15845:                                             $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                   15846:                                         }
                   15847:                                     } else {
                   15848:                                         $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                   15849:                                     }
                   15850:                                 }
                   15851:                                 $resulttext .= '</li>';
                   15852:                             } else {
                   15853:                                 $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                   15854:                             }
1.320     raeburn  15855:                         }
1.345     raeburn  15856:                         if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                   15857:                             if (@{$confhash{$itemid}{'instdata'}} > 0) {
                   15858:                                 $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                   15859:                                                           join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325     raeburn  15860:                             } else {
1.345     raeburn  15861:                                 $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325     raeburn  15862:                             }
1.320     raeburn  15863:                         }
1.391     raeburn  15864:                         foreach my $item ('topmenu','inlinemenu') {
1.345     raeburn  15865:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   15866:                             if ($confhash{$itemid}{$item}) {
                   15867:                                 $resulttext .= &mt('Yes');
                   15868:                             } else {
                   15869:                                 $resulttext .= &mt('No');
1.337     raeburn  15870:                             }
1.345     raeburn  15871:                             $resulttext .= '</li>';
1.320     raeburn  15872:                         }
1.345     raeburn  15873:                         if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   15874:                             if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   15875:                                 $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391     raeburn  15876:                                                join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
                   15877:                             } else {
                   15878:                                 $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
                   15879:                             }
                   15880:                         }
                   15881:                         if ($confhash{$itemid}{'crsinc'}) {
                   15882:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15883:                                 my $rolemaps;
                   15884:                                 foreach my $role (@ltiroles) {
                   15885:                                     if ($confhash{$itemid}{'maproles'}{$role}) {
                   15886:                                         $rolemaps .= ('&nbsp;'x2).$role.'='.
                   15887:                                                      &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                   15888:                                                                                 'Course').',';
                   15889:                                     }
                   15890:                                 }
                   15891:                                 if ($rolemaps) {
                   15892:                                     $rolemaps =~ s/,$//;
                   15893:                                     $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15894:                                 }
                   15895:                             }
                   15896:                             if ($confhash{$itemid}{'mapcrs'}) {
                   15897:                                 $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                   15898:                             }
                   15899:                             if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                   15900:                                 if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                   15901:                                     $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                   15902:                                                    join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                   15903:                                                    '</li>';
                   15904:                                 } else {
                   15905:                                     $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                   15906:                                 }
                   15907:                             }
1.392     raeburn  15908:                             if ($confhash{$itemid}{'storecrs'}) {
                   15909:                                 $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
                   15910:                             }
1.391     raeburn  15911:                             if ($confhash{$itemid}{'makecrs'}) {
                   15912:                                 $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
                   15913:                             } else {
                   15914:                                 $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
                   15915:                             }
                   15916:                             if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                   15917:                                 if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                   15918:                                     $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                   15919:                                                               join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                   15920:                                                    '</li>';
                   15921:                                 } else {
                   15922:                                     $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                   15923:                                 }
                   15924:                             }
                   15925:                             if ($confhash{$itemid}{'section'}) {
                   15926:                                 if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                   15927:                                     $resulttext .= '<li>'.&mt('User section from standard field:').
                   15928:                                                          ' (course_section_sourcedid)'.'</li>';  
                   15929:                                 } else {
                   15930:                                     $resulttext .= '<li>'.&mt('User section from:').' '.
                   15931:                                                           $confhash{$itemid}{'section'}.'</li>';
                   15932:                                 }
1.345     raeburn  15933:                             } else {
1.391     raeburn  15934:                                 $resulttext .= '<li>'.&mt('No section assignment').'</li>';
                   15935:                             }
                   15936:                             foreach my $item ('passback','roster','topmenu','inlinemenu') {
                   15937:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   15938:                                 if ($confhash{$itemid}{$item}) {
                   15939:                                     $resulttext .= &mt('Yes');
                   15940:                                     if ($item eq 'passback') {
                   15941:                                         if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                   15942:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                   15943:                                         } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                   15944:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                   15945:                                         }
                   15946:                                     }
                   15947:                                 } else {
                   15948:                                     $resulttext .= &mt('No');
                   15949:                                 }
                   15950:                                 $resulttext .= '</li>';
                   15951:                             }
                   15952:                             if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   15953:                                 if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   15954:                                     $resulttext .= '<li>'.&mt('Menu items:').' '.
                   15955:                                                    join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                   15956:                                 } else {
                   15957:                                     $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                   15958:                                 }
1.345     raeburn  15959:                             }
1.326     raeburn  15960:                         }
                   15961:                     }
1.320     raeburn  15962:                     $resulttext .= '</ul></li>';
                   15963:                 }
                   15964:             }
                   15965:             $resulttext .= '</ul>';
                   15966:         } else {
                   15967:             $resulttext = &mt('No changes made.');
                   15968:         }
                   15969:     } else {
                   15970:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15971:     }
                   15972:     if ($errors) {
                   15973:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15974:                        $errors.'</ul>';
                   15975:     }
                   15976:     return $resulttext;
                   15977: }
                   15978: 
                   15979: sub get_lti_id {
                   15980:     my ($domain,$consumer) = @_;
                   15981:     # get lock on lti db
                   15982:     my $lockhash = {
                   15983:                       lock => $env{'user.name'}.
                   15984:                               ':'.$env{'user.domain'},
                   15985:                    };
                   15986:     my $tries = 0;
                   15987:     my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   15988:     my ($id,$error);
                   15989: 
                   15990:     while (($gotlock ne 'ok') && ($tries<10)) {
                   15991:         $tries ++;
                   15992:         sleep (0.1);
                   15993:         $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   15994:     }
                   15995:     if ($gotlock eq 'ok') {
                   15996:         my %currids = &Apache::lonnet::dump_dom('lti',$domain);
                   15997:         if ($currids{'lock'}) {
                   15998:             delete($currids{'lock'});
                   15999:             if (keys(%currids)) {
                   16000:                 my @curr = sort { $a <=> $b } keys(%currids);
                   16001:                 if ($curr[-1] =~ /^\d+$/) {
                   16002:                     $id = 1 + $curr[-1];
                   16003:                 }
                   16004:             } else {
                   16005:                 $id = 1;
                   16006:             }
                   16007:             if ($id) {
                   16008:                 unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
                   16009:                     $error = 'nostore';
                   16010:                 }
                   16011:             } else {
                   16012:                 $error = 'nonumber';
                   16013:             }
                   16014:         }
                   16015:         my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
                   16016:     } else {
                   16017:         $error = 'nolock';
                   16018:     }
                   16019:     return ($id,$error);
                   16020: }
                   16021: 
1.3       raeburn  16022: sub modify_autoenroll {
1.205     raeburn  16023:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  16024:     my ($resulttext,%changes);
                   16025:     my %currautoenroll;
                   16026:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   16027:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   16028:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   16029:         }
                   16030:     }
                   16031:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   16032:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  16033:                   sender => 'Sender for notification messages',
1.274     raeburn  16034:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399     raeburn  16035:                   autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  16036:     my @offon = ('off','on');
1.17      raeburn  16037:     my $sender_uname = $env{'form.sender_uname'};
                   16038:     my $sender_domain = $env{'form.sender_domain'};
                   16039:     if ($sender_domain eq '') {
                   16040:         $sender_uname = '';
                   16041:     } elsif ($sender_uname eq '') {
                   16042:         $sender_domain = '';
                   16043:     }
1.129     raeburn  16044:     my $coowners = $env{'form.autoassign_coowners'};
1.399     raeburn  16045:     my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
                   16046:     $autofailsafe =~ s{^\s+|\s+$}{}g;
                   16047:     if ($autofailsafe =~ /\D/) {
                   16048:         undef($autofailsafe);
                   16049:     }
1.274     raeburn  16050:     my $failsafe = $env{'form.autoenroll_failsafe'};
1.399     raeburn  16051:     unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
                   16052:         $failsafe = 'off';
1.400     raeburn  16053:         undef($autofailsafe);
1.274     raeburn  16054:     }
1.1       raeburn  16055:     my %autoenrollhash =  (
1.129     raeburn  16056:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   16057:                                        'sender_uname' => $sender_uname,
                   16058:                                        'sender_domain' => $sender_domain,
                   16059:                                        'co-owners' => $coowners,
1.399     raeburn  16060:                                        'autofailsafe' => $autofailsafe,
1.400     raeburn  16061:                                        'failsafe' => $failsafe,
1.1       raeburn  16062:                                 }
                   16063:                      );
1.4       raeburn  16064:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   16065:                                              $dom);
1.1       raeburn  16066:     if ($putresult eq 'ok') {
                   16067:         if (exists($currautoenroll{'run'})) {
                   16068:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   16069:                  $changes{'run'} = 1;
                   16070:              }
                   16071:         } elsif ($autorun) {
                   16072:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  16073:                  $changes{'run'} = 1;
1.1       raeburn  16074:             }
                   16075:         }
1.17      raeburn  16076:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  16077:             $changes{'sender'} = 1;
                   16078:         }
1.17      raeburn  16079:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  16080:             $changes{'sender'} = 1;
                   16081:         }
1.129     raeburn  16082:         if ($currautoenroll{'co-owners'} ne '') {
                   16083:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   16084:                 $changes{'coowners'} = 1;
                   16085:             }
                   16086:         } elsif ($coowners) {
                   16087:             $changes{'coowners'} = 1;
1.274     raeburn  16088:         }
1.399     raeburn  16089:         if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274     raeburn  16090:             $changes{'autofailsafe'} = 1;
                   16091:         }
1.399     raeburn  16092:         if ($currautoenroll{'failsafe'} ne $failsafe) {
                   16093:             $changes{'failsafe'} = 1;
                   16094:         }
1.1       raeburn  16095:         if (keys(%changes) > 0) {
                   16096:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  16097:             if ($changes{'run'}) {
1.1       raeburn  16098:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   16099:             }
                   16100:             if ($changes{'sender'}) {
1.17      raeburn  16101:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   16102:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   16103:                 } else {
                   16104:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   16105:                 }
1.1       raeburn  16106:             }
1.129     raeburn  16107:             if ($changes{'coowners'}) {
                   16108:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   16109:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16110:                 if (ref($lastactref) eq 'HASH') {
                   16111:                     $lastactref->{'domainconfig'} = 1;
                   16112:                 }
1.129     raeburn  16113:             }
1.274     raeburn  16114:             if ($changes{'autofailsafe'}) {
1.399     raeburn  16115:                 if ($autofailsafe ne '') {
                   16116:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274     raeburn  16117:                 } else {
1.399     raeburn  16118:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274     raeburn  16119:                 }
1.399     raeburn  16120:             }
                   16121:             if ($changes{'failsafe'}) {
                   16122:                 if ($failsafe eq 'off') {
                   16123:                     unless ($changes{'autofailsafe'}) {
                   16124:                         $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
                   16125:                     }
                   16126:                 } elsif ($failsafe eq 'zero') {
                   16127:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
                   16128:                 } else {
                   16129:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
                   16130:                 }
                   16131:             }
                   16132:             if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274     raeburn  16133:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   16134:                 if (ref($lastactref) eq 'HASH') {
                   16135:                     $lastactref->{'domdefaults'} = 1;
                   16136:                 }
                   16137:             }
1.1       raeburn  16138:             $resulttext .= '</ul>';
                   16139:         } else {
                   16140:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   16141:         }
                   16142:     } else {
1.11      albertel 16143:         $resulttext = '<span class="LC_error">'.
                   16144: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16145:     }
1.3       raeburn  16146:     return $resulttext;
1.1       raeburn  16147: }
                   16148: 
                   16149: sub modify_autoupdate {
1.3       raeburn  16150:     my ($dom,%domconfig) = @_;
1.1       raeburn  16151:     my ($resulttext,%currautoupdate,%fields,%changes);
                   16152:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   16153:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   16154:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   16155:         }
                   16156:     }
                   16157:     my @offon = ('off','on');
                   16158:     my %title = &Apache::lonlocal::texthash (
1.385     raeburn  16159:                     run        => 'Auto-update:',
                   16160:                     classlists => 'Updates to user information in classlists?',
                   16161:                     unexpired  => 'Skip updates for users without active or future roles?',
                   16162:                     lastactive => 'Skip updates for inactive users?',
1.1       raeburn  16163:                 );
1.44      raeburn  16164:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  16165:     my %fieldtitles = &Apache::lonlocal::texthash (
                   16166:                         id => 'Student/Employee ID',
1.20      raeburn  16167:                         permanentemail => 'E-mail address',
1.1       raeburn  16168:                         lastname => 'Last Name',
                   16169:                         firstname => 'First Name',
                   16170:                         middlename => 'Middle Name',
1.132     raeburn  16171:                         generation => 'Generation',
1.1       raeburn  16172:                       );
1.142     raeburn  16173:     $othertitle = &mt('All users');
1.1       raeburn  16174:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  16175:         $othertitle = &mt('Other users');
1.1       raeburn  16176:     }
                   16177:     foreach my $key (keys(%env)) {
                   16178:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  16179:             my ($usertype,$item) = ($1,$2);
                   16180:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   16181:                 if ($usertype eq 'default') {   
                   16182:                     push(@{$fields{$1}},$2);
                   16183:                 } elsif (ref($types) eq 'ARRAY') {
                   16184:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   16185:                         push(@{$fields{$1}},$2);
                   16186:                     }
                   16187:                 }
                   16188:             }
1.1       raeburn  16189:         }
                   16190:     }
1.131     raeburn  16191:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   16192:     @lockablenames = sort(@lockablenames);
                   16193:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   16194:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16195:         if (@changed) {
                   16196:             $changes{'lockablenames'} = 1;
                   16197:         }
                   16198:     } else {
                   16199:         if (@lockablenames) {
                   16200:             $changes{'lockablenames'} = 1;
                   16201:         }
                   16202:     }
1.1       raeburn  16203:     my %updatehash = (
                   16204:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   16205:                                       classlists => $env{'form.classlists'},
1.385     raeburn  16206:                                       unexpired  => $env{'form.unexpired'},
1.1       raeburn  16207:                                       fields => {%fields},
1.131     raeburn  16208:                                       lockablenames => \@lockablenames,
1.1       raeburn  16209:                                     }
                   16210:                      );
1.385     raeburn  16211:     my $lastactivedays;
                   16212:     if ($env{'form.lastactive'}) {
                   16213:         $lastactivedays = $env{'form.lastactivedays'};
                   16214:         $lastactivedays =~ s/^\s+|\s+$//g;
                   16215:         unless ($lastactivedays =~ /^\d+$/) {
                   16216:             undef($lastactivedays);
                   16217:             $env{'form.lastactive'} = 0;
                   16218:         }
                   16219:     }
                   16220:     $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1       raeburn  16221:     foreach my $key (keys(%currautoupdate)) {
1.385     raeburn  16222:         if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1       raeburn  16223:             if (exists($updatehash{autoupdate}{$key})) {
                   16224:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   16225:                     $changes{$key} = 1;
                   16226:                 }
                   16227:             }
                   16228:         } elsif ($key eq 'fields') {
                   16229:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  16230:                 foreach my $item (@{$types},'default') {
1.1       raeburn  16231:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   16232:                         my $change = 0;
                   16233:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   16234:                             if (!exists($fields{$item})) {
                   16235:                                 $change = 1;
1.132     raeburn  16236:                                 last;
1.1       raeburn  16237:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  16238:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  16239:                                     $change = 1;
1.132     raeburn  16240:                                     last;
1.1       raeburn  16241:                                 }
                   16242:                             }
                   16243:                         }
                   16244:                         if ($change) {
                   16245:                             push(@{$changes{$key}},$item);
                   16246:                         }
1.26      raeburn  16247:                     } 
1.1       raeburn  16248:                 }
                   16249:             }
1.131     raeburn  16250:         } elsif ($key eq 'lockablenames') {
                   16251:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   16252:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16253:                 if (@changed) {
                   16254:                     $changes{'lockablenames'} = 1;
                   16255:                 }
                   16256:             } else {
                   16257:                 if (@lockablenames) {
                   16258:                     $changes{'lockablenames'} = 1;
                   16259:                 }
                   16260:             }
                   16261:         }
                   16262:     }
                   16263:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   16264:         if (@lockablenames) {
                   16265:             $changes{'lockablenames'} = 1;
1.1       raeburn  16266:         }
                   16267:     }
1.385     raeburn  16268:     unless (grep(/^unexpired$/,keys(%currautoupdate))) {
                   16269:         if ($updatehash{'autoupdate'}{'unexpired'}) {
                   16270:             $changes{'unexpired'} = 1;
                   16271:         }
                   16272:     }
                   16273:     unless (grep(/^lastactive$/,keys(%currautoupdate))) {
                   16274:         if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
                   16275:             $changes{'lastactive'} = 1;
                   16276:         }
                   16277:     }
1.26      raeburn  16278:     foreach my $item (@{$types},'default') {
                   16279:         if (defined($fields{$item})) {
                   16280:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  16281:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   16282:                     my $change = 0;
                   16283:                     if (ref($fields{$item}) eq 'ARRAY') {
                   16284:                         foreach my $type (@{$fields{$item}}) {
                   16285:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   16286:                                 $change = 1;
                   16287:                                 last;
                   16288:                             }
                   16289:                         }
                   16290:                     }
                   16291:                     if ($change) {
                   16292:                         push(@{$changes{'fields'}},$item);
                   16293:                     }
                   16294:                 } else {
1.26      raeburn  16295:                     push(@{$changes{'fields'}},$item);
                   16296:                 }
                   16297:             } else {
                   16298:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  16299:             }
                   16300:         }
                   16301:     }
                   16302:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   16303:                                              $dom);
                   16304:     if ($putresult eq 'ok') {
                   16305:         if (keys(%changes) > 0) {
                   16306:             $resulttext = &mt('Changes made:').'<ul>';
                   16307:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  16308:                 if ($key eq 'lockablenames') {
                   16309:                     $resulttext .= '<li>';
                   16310:                     if (@lockablenames) {
                   16311:                         $usertypes->{'default'} = $othertitle;
                   16312:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   16313:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   16314:                     } else {
                   16315:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   16316:                     }
                   16317:                     $resulttext .= '</li>';
                   16318:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  16319:                     foreach my $item (@{$changes{$key}}) {
                   16320:                         my @newvalues;
                   16321:                         foreach my $type (@{$fields{$item}}) {
                   16322:                             push(@newvalues,$fieldtitles{$type});
                   16323:                         }
1.3       raeburn  16324:                         my $newvaluestr;
                   16325:                         if (@newvalues > 0) {
                   16326:                             $newvaluestr = join(', ',@newvalues);
                   16327:                         } else {
                   16328:                             $newvaluestr = &mt('none');
1.6       raeburn  16329:                         }
1.1       raeburn  16330:                         if ($item eq 'default') {
1.26      raeburn  16331:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  16332:                         } else {
1.26      raeburn  16333:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  16334:                         }
                   16335:                     }
                   16336:                 } else {
                   16337:                     my $newvalue;
                   16338:                     if ($key eq 'run') {
                   16339:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385     raeburn  16340:                     } elsif ($key eq 'lastactive') {
                   16341:                         $newvalue = $offon[$env{'form.lastactive'}];
                   16342:                         unless ($lastactivedays eq '') {
                   16343:                             $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
                   16344:                         }
1.1       raeburn  16345:                     } else {
                   16346:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  16347:                     }
1.1       raeburn  16348:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   16349:                 }
                   16350:             }
                   16351:             $resulttext .= '</ul>';
                   16352:         } else {
1.3       raeburn  16353:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  16354:         }
                   16355:     } else {
1.11      albertel 16356:         $resulttext = '<span class="LC_error">'.
                   16357: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16358:     }
1.3       raeburn  16359:     return $resulttext;
1.1       raeburn  16360: }
                   16361: 
1.125     raeburn  16362: sub modify_autocreate {
                   16363:     my ($dom,%domconfig) = @_;
                   16364:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   16365:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   16366:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   16367:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   16368:         }
                   16369:     }
                   16370:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   16371:                  req => 'Auto-creation of validated requests for official courses',
                   16372:                  xmldc => 'Identity of course creator of courses from XML files',
                   16373:                );
                   16374:     my @types = ('xml','req');
                   16375:     foreach my $item (@types) {
                   16376:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   16377:         $newvals{$item} =~ s/\D//g;
                   16378:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   16379:     }
                   16380:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  16381:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  16382:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   16383:         $newvals{'xmldc'} = '';
                   16384:     } 
                   16385:     %autocreatehash =  (
                   16386:                         autocreate => { xml => $newvals{'xml'},
                   16387:                                         req => $newvals{'req'},
                   16388:                                       }
                   16389:                        );
                   16390:     if ($newvals{'xmldc'} ne '') {
                   16391:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   16392:     }
                   16393:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   16394:                                              $dom);
                   16395:     if ($putresult eq 'ok') {
                   16396:         my @items = @types;
                   16397:         if ($newvals{'xml'}) {
                   16398:             push(@items,'xmldc');
                   16399:         }
                   16400:         foreach my $item (@items) {
                   16401:             if (exists($currautocreate{$item})) {
                   16402:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   16403:                     $changes{$item} = 1;
                   16404:                 }
                   16405:             } elsif ($newvals{$item}) {
                   16406:                 $changes{$item} = 1;
                   16407:             }
                   16408:         }
                   16409:         if (keys(%changes) > 0) {
                   16410:             my @offon = ('off','on'); 
                   16411:             $resulttext = &mt('Changes made:').'<ul>';
                   16412:             foreach my $item (@types) {
                   16413:                 if ($changes{$item}) {
                   16414:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  16415:                     $resulttext .= '<li>'.
                   16416:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   16417:                                        '<b>','</b>').
                   16418:                                    '</li>';
1.125     raeburn  16419:                 }
                   16420:             }
                   16421:             if ($changes{'xmldc'}) {
                   16422:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   16423:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  16424:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  16425:             }
                   16426:             $resulttext .= '</ul>';
                   16427:         } else {
                   16428:             $resulttext = &mt('No changes made to auto-creation settings');
                   16429:         }
                   16430:     } else {
                   16431:         $resulttext = '<span class="LC_error">'.
                   16432:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16433:     }
                   16434:     return $resulttext;
                   16435: }
                   16436: 
1.23      raeburn  16437: sub modify_directorysrch {
1.295     raeburn  16438:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  16439:     my ($resulttext,%changes);
                   16440:     my %currdirsrch;
                   16441:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   16442:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   16443:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   16444:         }
                   16445:     }
1.277     raeburn  16446:     my %title = ( available => 'Institutional directory search available',
                   16447:                   localonly => 'Other domains can search institution',
                   16448:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  16449:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  16450:                   searchby => 'Search types',
                   16451:                   searchtypes => 'Search latitude');
                   16452:     my @offon = ('off','on');
1.24      raeburn  16453:     my @otherdoms = ('Yes','No');
1.23      raeburn  16454: 
1.25      raeburn  16455:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  16456:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   16457:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   16458: 
1.44      raeburn  16459:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  16460:     if (keys(%{$usertypes}) == 0) {
                   16461:         @cansearch = ('default');
                   16462:     } else {
                   16463:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   16464:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   16465:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   16466:                     push(@{$changes{'cansearch'}},$type);
                   16467:                 }
1.23      raeburn  16468:             }
1.26      raeburn  16469:             foreach my $type (@cansearch) {
                   16470:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   16471:                     push(@{$changes{'cansearch'}},$type);
                   16472:                 }
1.23      raeburn  16473:             }
1.26      raeburn  16474:         } else {
                   16475:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  16476:         }
                   16477:     }
                   16478: 
                   16479:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   16480:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   16481:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   16482:                 push(@{$changes{'searchby'}},$by);
                   16483:             }
                   16484:         }
                   16485:         foreach my $by (@searchby) {
                   16486:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   16487:                 push(@{$changes{'searchby'}},$by);
                   16488:             }
                   16489:         }
                   16490:     } else {
                   16491:         push(@{$changes{'searchby'}},@searchby);
                   16492:     }
1.25      raeburn  16493: 
                   16494:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   16495:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   16496:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   16497:                 push(@{$changes{'searchtypes'}},$type);
                   16498:             }
                   16499:         }
                   16500:         foreach my $type (@searchtypes) {
                   16501:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   16502:                 push(@{$changes{'searchtypes'}},$type);
                   16503:             }
                   16504:         }
                   16505:     } else {
                   16506:         if (exists($currdirsrch{'searchtypes'})) {
                   16507:             foreach my $type (@searchtypes) {  
                   16508:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   16509:                     push(@{$changes{'searchtypes'}},$type);
                   16510:                 }
                   16511:             }
                   16512:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   16513:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   16514:             }   
                   16515:         } else {
                   16516:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   16517:         }
                   16518:     }
                   16519: 
1.23      raeburn  16520:     my %dirsrch_hash =  (
                   16521:             directorysrch => { available => $env{'form.dirsrch_available'},
                   16522:                                cansearch => \@cansearch,
1.277     raeburn  16523:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   16524:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   16525:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  16526:                                searchby => \@searchby,
1.25      raeburn  16527:                                searchtypes => \@searchtypes,
1.23      raeburn  16528:                              }
                   16529:             );
                   16530:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   16531:                                              $dom);
                   16532:     if ($putresult eq 'ok') {
                   16533:         if (exists($currdirsrch{'available'})) {
                   16534:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   16535:                  $changes{'available'} = 1;
                   16536:              }
                   16537:         } else {
                   16538:             if ($env{'form.dirsrch_available'} eq '1') {
                   16539:                 $changes{'available'} = 1;
                   16540:             }
                   16541:         }
1.277     raeburn  16542:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  16543:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   16544:                 $changes{'lcavailable'} = 1;
                   16545:             }
1.277     raeburn  16546:         } else {
                   16547:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   16548:                 $changes{'lcavailable'} = 1;
                   16549:             }
                   16550:         }
1.24      raeburn  16551:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  16552:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   16553:                 $changes{'localonly'} = 1;
                   16554:             }
1.24      raeburn  16555:         } else {
1.277     raeburn  16556:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  16557:                 $changes{'localonly'} = 1;
                   16558:             }
                   16559:         }
1.277     raeburn  16560:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  16561:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   16562:                 $changes{'lclocalonly'} = 1;
                   16563:             }
1.277     raeburn  16564:         } else {
                   16565:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   16566:                 $changes{'lclocalonly'} = 1;
                   16567:             }
                   16568:         }
1.23      raeburn  16569:         if (keys(%changes) > 0) {
                   16570:             $resulttext = &mt('Changes made:').'<ul>';
                   16571:             if ($changes{'available'}) {
                   16572:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   16573:             }
1.277     raeburn  16574:             if ($changes{'lcavailable'}) {
                   16575:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   16576:             }
1.24      raeburn  16577:             if ($changes{'localonly'}) {
1.277     raeburn  16578:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  16579:             }
1.277     raeburn  16580:             if ($changes{'lclocalonly'}) {
                   16581:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  16582:             }
1.23      raeburn  16583:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   16584:                 my $chgtext;
1.26      raeburn  16585:                 if (ref($usertypes) eq 'HASH') {
                   16586:                     if (keys(%{$usertypes}) > 0) {
                   16587:                         foreach my $type (@{$types}) {
                   16588:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   16589:                                 $chgtext .= $usertypes->{$type}.'; ';
                   16590:                             }
                   16591:                         }
                   16592:                         if (grep(/^default$/,@cansearch)) {
                   16593:                             $chgtext .= $othertitle;
                   16594:                         } else {
                   16595:                             $chgtext =~ s/\; $//;
                   16596:                         }
1.210     raeburn  16597:                         $resulttext .=
1.178     raeburn  16598:                             '<li>'.
                   16599:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   16600:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   16601:                             '</li>';
1.23      raeburn  16602:                     }
                   16603:                 }
                   16604:             }
                   16605:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   16606:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   16607:                 my $chgtext;
                   16608:                 foreach my $type (@{$titleorder}) {
                   16609:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   16610:                         if (defined($searchtitles->{$type})) {
                   16611:                             $chgtext .= $searchtitles->{$type}.'; ';
                   16612:                         }
                   16613:                     }
                   16614:                 }
                   16615:                 $chgtext =~ s/\; $//;
                   16616:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   16617:             }
1.25      raeburn  16618:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   16619:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   16620:                 my $chgtext;
                   16621:                 foreach my $type (@{$srchtypeorder}) {
                   16622:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   16623:                         if (defined($srchtypes_desc->{$type})) {
                   16624:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   16625:                         }
                   16626:                     }
                   16627:                 }
                   16628:                 $chgtext =~ s/\; $//;
1.178     raeburn  16629:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  16630:             }
                   16631:             $resulttext .= '</ul>';
1.295     raeburn  16632:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   16633:             if (ref($lastactref) eq 'HASH') {
                   16634:                 $lastactref->{'directorysrch'} = 1;
                   16635:             }
1.23      raeburn  16636:         } else {
1.277     raeburn  16637:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  16638:         }
                   16639:     } else {
                   16640:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  16641:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   16642:     }
                   16643:     return $resulttext;
                   16644: }
                   16645: 
1.28      raeburn  16646: sub modify_contacts {
1.205     raeburn  16647:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  16648:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   16649:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   16650:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   16651:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   16652:         }
                   16653:     }
1.286     raeburn  16654:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  16655:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  16656:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350     raeburn  16657:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340     raeburn  16658:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   16659:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286     raeburn  16660:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  16661:     foreach my $type (@mailings) {
                   16662:         @{$newsetting{$type}} = 
                   16663:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   16664:         foreach my $item (@contacts) {
                   16665:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   16666:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   16667:             } else {
                   16668:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   16669:             }
1.289     raeburn  16670:         }
1.28      raeburn  16671:         $others{$type} = $env{'form.'.$type.'_others'};
                   16672:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  16673:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16674:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   16675:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  16676:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   16677:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   16678:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   16679:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   16680:             }
1.134     raeburn  16681:         }
1.28      raeburn  16682:     }
                   16683:     foreach my $item (@contacts) {
                   16684:         $to{$item} = $env{'form.'.$item};
                   16685:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   16686:     }
1.203     raeburn  16687:     foreach my $item (@toggles) {
                   16688:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   16689:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   16690:         }
                   16691:     }
1.340     raeburn  16692:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   16693:     foreach my $item (@lonstatus) {
                   16694:         if ($item eq 'excluded') {
                   16695:             my (%serverhomes,@excluded);
                   16696:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   16697:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   16698:             if (@possexcluded) {
                   16699:                 foreach my $id (sort(@possexcluded)) {
                   16700:                     if ($serverhomes{$id}) {
                   16701:                         push(@excluded,$id);
                   16702:                     }
                   16703:                 }
                   16704:             }
                   16705:             if (@excluded) {
                   16706:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   16707:             }
                   16708:         } elsif ($item eq 'weights') {
1.377     raeburn  16709:             foreach my $type ('E','W','N','U') {
1.340     raeburn  16710:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   16711:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   16712:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   16713:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   16714:                             $env{'form.error'.$item.'_'.$type};
                   16715:                     }
                   16716:                 }
                   16717:             }
                   16718:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   16719:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   16720:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   16721:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   16722:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   16723:                 }
                   16724:             }
                   16725:         }
                   16726:     }
1.286     raeburn  16727:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   16728:         foreach my $field (@{$fields}) {
                   16729:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   16730:                 my $value = $env{'form.helpform_'.$field};
                   16731:                 $value =~ s/^\s+|\s+$//g;
                   16732:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  16733:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  16734:                     if ($field eq 'screenshot') {
                   16735:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   16736:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  16737:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  16738:                         }
                   16739:                     }
                   16740:                 }
                   16741:             }
                   16742:         }
                   16743:     }
1.315     raeburn  16744:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   16745:     my (@statuses,%usertypeshash,@overrides);
                   16746:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   16747:         @statuses = @{$types};
                   16748:         if (ref($usertypes) eq 'HASH') {
                   16749:             %usertypeshash = %{$usertypes};
                   16750:         }
                   16751:     }
                   16752:     if (@statuses) {
                   16753:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   16754:         foreach my $type (@possoverrides) {
                   16755:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   16756:                 push(@overrides,$type);
                   16757:             }
                   16758:         }
                   16759:         if (@overrides) {
                   16760:             foreach my $type (@overrides) {
                   16761:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   16762:                 foreach my $item (@contacts) {
                   16763:                     if (grep(/^\Q$item\E$/,@standard)) {
                   16764:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   16765:                         $newsetting{'override_'.$type}{$item} = 1;
                   16766:                     } else {
                   16767:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   16768:                         $newsetting{'override_'.$type}{$item} = 0;
                   16769:                     }
                   16770:                 }
                   16771:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   16772:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   16773:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   16774:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   16775:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   16776:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   16777:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   16778:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   16779:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   16780:                 }
                   16781:             }     
                   16782:         }
                   16783:     }
1.28      raeburn  16784:     if (keys(%currsetting) > 0) {
                   16785:         foreach my $item (@contacts) {
                   16786:             if ($to{$item} ne $currsetting{$item}) {
                   16787:                 $changes{$item} = 1;
                   16788:             }
                   16789:         }
                   16790:         foreach my $type (@mailings) {
                   16791:             foreach my $item (@contacts) {
                   16792:                 if (ref($currsetting{$type}) eq 'HASH') {
                   16793:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   16794:                         push(@{$changes{$type}},$item);
                   16795:                     }
                   16796:                 } else {
                   16797:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   16798:                 }
                   16799:             }
                   16800:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   16801:                 push(@{$changes{$type}},'others');
                   16802:             }
1.289     raeburn  16803:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16804:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   16805:                     push(@{$changes{$type}},'bcc'); 
                   16806:                 }
1.286     raeburn  16807:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   16808:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   16809:                     push(@{$changes{$type}},'include');
                   16810:                 }
                   16811:             }
                   16812:         }
                   16813:         if (ref($fields) eq 'ARRAY') {
                   16814:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   16815:                 foreach my $field (@{$fields}) {
                   16816:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   16817:                         push(@{$changes{'helpform'}},$field);
                   16818:                     }
                   16819:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16820:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   16821:                             push(@{$changes{'helpform'}},'maxsize');
                   16822:                         }
                   16823:                     }
                   16824:                 }
                   16825:             } else {
                   16826:                 foreach my $field (@{$fields}) {
                   16827:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   16828:                         push(@{$changes{'helpform'}},$field);
                   16829:                     }
                   16830:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16831:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   16832:                             push(@{$changes{'helpform'}},'maxsize');
                   16833:                         }
                   16834:                     }
                   16835:                 }
1.134     raeburn  16836:             }
1.28      raeburn  16837:         }
1.315     raeburn  16838:         if (@statuses) {
                   16839:             if (ref($currsetting{'overrides'}) eq 'HASH') { 
                   16840:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   16841:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   16842:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   16843:                             foreach my $item (@contacts,'bcc','others','include') {
                   16844:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
                   16845:                                     push(@{$changes{'overrides'}},$key);
                   16846:                                     last;
                   16847:                                 }
                   16848:                             }
                   16849:                         } else {
                   16850:                             push(@{$changes{'overrides'}},$key);
                   16851:                         }
                   16852:                     }
                   16853:                 }
                   16854:                 foreach my $key (@overrides) {
                   16855:                     unless (exists($currsetting{'overrides'}{$key})) {
                   16856:                         push(@{$changes{'overrides'}},$key);
                   16857:                     }
                   16858:                 }
                   16859:             } else {
                   16860:                 foreach my $key (@overrides) {
                   16861:                     push(@{$changes{'overrides'}},$key); 
                   16862:                 }
                   16863:             }
                   16864:         }
1.340     raeburn  16865:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   16866:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   16867:                 if ($key eq 'excluded') {
                   16868:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   16869:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   16870:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   16871:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   16872:                             my @diffs =
                   16873:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   16874:                                                                    $currsetting{'lonstatus'}{$key});
                   16875:                             if (@diffs) {
                   16876:                                 push(@{$changes{'lonstatus'}},$key);
                   16877:                             }
                   16878:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   16879:                             push(@{$changes{'lonstatus'}},$key);
                   16880:                         }
                   16881:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   16882:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   16883:                         push(@{$changes{'lonstatus'}},$key);
                   16884:                     }
                   16885:                 } elsif ($key eq 'weights') {
                   16886:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   16887:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   16888:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  16889:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  16890:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   16891:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   16892:                                     push(@{$changes{'lonstatus'}},$key);
                   16893:                                     last;
                   16894:                                 }
                   16895:                             }
                   16896:                         } else {
1.341     raeburn  16897:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  16898:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   16899:                                     push(@{$changes{'lonstatus'}},$key);
                   16900:                                     last;
                   16901:                                 }
                   16902:                             }
                   16903:                         }
                   16904:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  16905:                         foreach my $type ('E','W','N','U') {
1.340     raeburn  16906:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   16907:                                 push(@{$changes{'lonstatus'}},$key);
                   16908:                                 last;
                   16909:                             }
                   16910:                         }
                   16911:                     }
                   16912:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   16913:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16914:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   16915:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   16916:                                 push(@{$changes{'lonstatus'}},$key);
                   16917:                             }
                   16918:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   16919:                             push(@{$changes{'lonstatus'}},$key);
                   16920:                         }
                   16921:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   16922:                         push(@{$changes{'lonstatus'}},$key);
                   16923:                     }
                   16924:                 }
                   16925:             }
                   16926:         } else {
                   16927:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16928:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   16929:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   16930:                         push(@{$changes{'lonstatus'}},$key);
                   16931:                     }
                   16932:                 }
                   16933:             }
                   16934:         }
1.28      raeburn  16935:     } else {
                   16936:         my %default;
                   16937:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   16938:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   16939:         $default{'errormail'} = 'adminemail';
                   16940:         $default{'packagesmail'} = 'adminemail';
                   16941:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  16942:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  16943:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  16944:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  16945:         $default{'updatesmail'} = 'adminemail';
1.350     raeburn  16946:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  16947:         foreach my $item (@contacts) {
                   16948:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  16949:                $changes{$item} = 1;
1.203     raeburn  16950:            }
1.28      raeburn  16951:         }
                   16952:         foreach my $type (@mailings) {
                   16953:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   16954:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   16955:             }
                   16956:             if ($others{$type} ne '') {
                   16957:                 push(@{$changes{$type}},'others');
1.134     raeburn  16958:             }
1.286     raeburn  16959:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16960:                 if ($bcc{$type} ne '') {
                   16961:                     push(@{$changes{$type}},'bcc');
                   16962:                 }
1.286     raeburn  16963:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   16964:                     push(@{$changes{$type}},'include');
                   16965:                 }
1.134     raeburn  16966:             }
1.28      raeburn  16967:         }
1.286     raeburn  16968:         if (ref($fields) eq 'ARRAY') {
                   16969:             foreach my $field (@{$fields}) {
                   16970:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   16971:                     push(@{$changes{'helpform'}},$field);
                   16972:                 }
                   16973:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16974:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   16975:                         push(@{$changes{'helpform'}},'maxsize');
                   16976:                     }
                   16977:                 }
                   16978:             }
1.289     raeburn  16979:         }
1.340     raeburn  16980:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16981:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   16982:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   16983:                     push(@{$changes{'lonstatus'}},$key);
                   16984:                 }
                   16985:             }
                   16986:         }
1.28      raeburn  16987:     }
1.203     raeburn  16988:     foreach my $item (@toggles) {
                   16989:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   16990:             $changes{$item} = 1;
                   16991:         } elsif ((!$env{'form.'.$item}) &&
                   16992:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   16993:             $changes{$item} = 1;
                   16994:         }
                   16995:     }
1.28      raeburn  16996:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   16997:                                              $dom);
                   16998:     if ($putresult eq 'ok') {
                   16999:         if (keys(%changes) > 0) {
1.205     raeburn  17000:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  17001:             if (ref($lastactref) eq 'HASH') {
                   17002:                 $lastactref->{'domainconfig'} = 1;
                   17003:             }
1.28      raeburn  17004:             my ($titles,$short_titles)  = &contact_titles();
                   17005:             $resulttext = &mt('Changes made:').'<ul>';
                   17006:             foreach my $item (@contacts) {
                   17007:                 if ($changes{$item}) {
                   17008:                     $resulttext .= '<li>'.$titles->{$item}.
                   17009:                                     &mt(' set to: ').
                   17010:                                     '<span class="LC_cusr_emph">'.
                   17011:                                     $to{$item}.'</span></li>';
                   17012:                 }
                   17013:             }
                   17014:             foreach my $type (@mailings) {
                   17015:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  17016:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  17017:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  17018:                     } else {
                   17019:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   17020:                     }
1.28      raeburn  17021:                     my @text;
                   17022:                     foreach my $item (@{$newsetting{$type}}) {
                   17023:                         push(@text,$short_titles->{$item});
                   17024:                     }
                   17025:                     if ($others{$type} ne '') {
                   17026:                         push(@text,$others{$type});
                   17027:                     }
1.286     raeburn  17028:                     if (@text) {
                   17029:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   17030:                                        join(', ',@text).'</span>';
                   17031:                     }
                   17032:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  17033:                         if ($bcc{$type} ne '') {
1.286     raeburn  17034:                             my $bcctext;
                   17035:                             if (@text) {
1.289     raeburn  17036:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  17037:                             } else {
                   17038:                                 $bcctext = '(Bcc)';
                   17039:                             }
                   17040:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   17041:                         } elsif (!@text) {
                   17042:                             $resulttext .= &mt('No one');
                   17043:                         }   
1.289     raeburn  17044:                         if ($includestr{$type} ne '') {
1.286     raeburn  17045:                             if ($includeloc{$type} eq 'b') {
                   17046:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   17047:                             } elsif ($includeloc{$type} eq 's') {
                   17048:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   17049:                             }
1.134     raeburn  17050:                         }
1.286     raeburn  17051:                     } elsif (!@text) {
                   17052:                         $resulttext .= &mt('No recipients');
1.134     raeburn  17053:                     }
                   17054:                     $resulttext .= '</li>';
1.28      raeburn  17055:                 }
                   17056:             }
1.315     raeburn  17057:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   17058:                 my @deletions;
                   17059:                 foreach my $type (@{$changes{'overrides'}}) {
                   17060:                     if ($usertypeshash{$type}) {
                   17061:                         if (grep(/^\Q$type\E/,@overrides)) {
                   17062:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   17063:                                                       $usertypeshash{$type}).'<ul><li>';
                   17064:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   17065:                                 my @text;
                   17066:                                 foreach my $item (@contacts) {
                   17067:                                     if ($newsetting{'override_'.$type}{$item}) { 
                   17068:                                         push(@text,$short_titles->{$item});
                   17069:                                     }
                   17070:                                 }
                   17071:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   17072:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   17073:                                 }
                   17074:   
                   17075:                                 if (@text) {
                   17076:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   17077:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   17078:                                 }
                   17079:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   17080:                                     my $bcctext;
                   17081:                                     if (@text) {
                   17082:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   17083:                                     } else {
                   17084:                                         $bcctext = '(Bcc)';
                   17085:                                     }
                   17086:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   17087:                                 } elsif (!@text) {
                   17088:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   17089:                                 }
                   17090:                                 $resulttext .= '</li>';
                   17091:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   17092:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   17093:                                     if ($loc eq 'b') {
                   17094:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   17095:                                     } elsif ($loc eq 's') {
                   17096:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   17097:                                     }
                   17098:                                 }
                   17099:                             }
                   17100:                             $resulttext .= '</li></ul></li>';
                   17101:                         } else {
                   17102:                             push(@deletions,$usertypeshash{$type});
                   17103:                         }
                   17104:                     }
                   17105:                 }
                   17106:                 if (@deletions) {
                   17107:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   17108:                                               join(', ',@deletions)).'</li>';
                   17109:                 }
                   17110:             }
1.203     raeburn  17111:             my @offon = ('off','on');
1.340     raeburn  17112:             my $corelink = &core_link_msu();
1.203     raeburn  17113:             if ($changes{'reporterrors'}) {
                   17114:                 $resulttext .= '<li>'.
                   17115:                                &mt('E-mail error reports to [_1] set to "'.
                   17116:                                    $offon[$env{'form.reporterrors'}].'".',
1.340     raeburn  17117:                                    $corelink).
1.203     raeburn  17118:                                '</li>';
                   17119:             }
                   17120:             if ($changes{'reportupdates'}) {
                   17121:                 $resulttext .= '<li>'.
                   17122:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   17123:                                     $offon[$env{'form.reportupdates'}].'".',
1.340     raeburn  17124:                                     $corelink).
1.203     raeburn  17125:                                 '</li>';
                   17126:             }
1.340     raeburn  17127:             if ($changes{'reportstatus'}) {
                   17128:                 $resulttext .= '<li>'.
                   17129:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   17130:                                     $offon[$env{'form.reportstatus'}].'".',
                   17131:                                     $corelink).
                   17132:                                 '</li>';
                   17133:             }
                   17134:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   17135:                 $resulttext .= '<li>'.
                   17136:                                &mt('Nightly status check e-mail settings').':<ul>';
                   17137:                 my (%defval,%use_def,%shown);
                   17138:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   17139:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   17140:                 $defval{'weights'} =
1.341     raeburn  17141:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340     raeburn  17142:                 $defval{'excluded'} = &mt('None');
                   17143:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   17144:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   17145:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   17146:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   17147:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   17148:                             } elsif ($item eq 'weights') {
                   17149:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341     raeburn  17150:                                     foreach my $type ('E','W','N','U') {
1.340     raeburn  17151:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   17152:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   17153:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   17154:                                         } else {
                   17155:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   17156:                                         }
                   17157:                                         $shown{$item} .= ', ';
                   17158:                                     }
                   17159:                                     $shown{$item} =~ s/, $//;
                   17160:                                 } else {
                   17161:                                     $shown{$item} = $defval{$item};
                   17162:                                 }
                   17163:                             } elsif ($item eq 'excluded') {
                   17164:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   17165:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   17166:                                 } else {
                   17167:                                     $shown{$item} = $defval{$item};
                   17168:                                 }
                   17169:                             }
                   17170:                         } else {
                   17171:                             $shown{$item} = $defval{$item};
                   17172:                         }
                   17173:                     }
                   17174:                 } else {
                   17175:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   17176:                         $shown{$item} = $defval{$item};
                   17177:                     }
                   17178:                 }
                   17179:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   17180:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   17181:                                           $shown{$item}).'</li>';
                   17182:                 }
                   17183:                 $resulttext .= '</ul></li>';
                   17184:             }
1.286     raeburn  17185:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   17186:                 my (@optional,@required,@unused,$maxsizechg);
                   17187:                 foreach my $field (@{$changes{'helpform'}}) {
                   17188:                     if ($field eq 'maxsize') {
                   17189:                         $maxsizechg = 1;
                   17190:                         next;
                   17191:                     }
                   17192:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  17193:                         push(@optional,$field);
1.286     raeburn  17194:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   17195:                         push(@unused,$field);
                   17196:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  17197:                         push(@required,$field);
1.286     raeburn  17198:                     }
                   17199:                 }
                   17200:                 if (@optional) {
                   17201:                     $resulttext .= '<li>'.
                   17202:                                    &mt('Help form fields changed to "Optional": [_1].',
                   17203:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   17204:                                    '</li>';
                   17205:                 }
                   17206:                 if (@required) {
                   17207:                     $resulttext .= '<li>'.
                   17208:                                    &mt('Help form fields changed to "Required": [_1].',
                   17209:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   17210:                                    '</li>';
                   17211:                 }
                   17212:                 if (@unused) {
                   17213:                     $resulttext .= '<li>'.
                   17214:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   17215:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   17216:                                    '</li>';
                   17217:                 }
                   17218:                 if ($maxsizechg) {
                   17219:                     $resulttext .= '<li>'.
                   17220:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   17221:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   17222:                                    '</li>';
                   17223:                 }
                   17224:             }
1.28      raeburn  17225:             $resulttext .= '</ul>';
                   17226:         } else {
1.288     raeburn  17227:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  17228:         }
                   17229:     } else {
                   17230:         $resulttext = '<span class="LC_error">'.
                   17231:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   17232:     }
                   17233:     return $resulttext;
                   17234: }
                   17235: 
1.357     raeburn  17236: sub modify_privacy {
                   17237:     my ($dom,%domconfig) = @_;
                   17238:     my ($resulttext,%current,%changes);
                   17239:     if (ref($domconfig{'privacy'}) eq 'HASH') {
                   17240:         %current = %{$domconfig{'privacy'}};
                   17241:     }
                   17242:     my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
                   17243:     my @items = ('domain','author','course','community');
                   17244:     my %names = &Apache::lonlocal::texthash (
                   17245:                    domain => 'Assigned domain role(s)',
                   17246:                    author => 'Assigned co-author role(s)',
                   17247:                    course => 'Assigned course role(s)',
                   17248:                    community => 'Assigned community role',
                   17249:                 );
                   17250:     my %roles = &Apache::lonlocal::texthash (
                   17251:                    domain => 'Domain role',
                   17252:                    author => 'Co-author role',
                   17253:                    course => 'Course role',
                   17254:                    community => 'Community role',
                   17255:                 );
                   17256:     my %titles = &Apache::lonlocal::texthash (
                   17257:                   approval => 'Approval for role in different domain',
                   17258:                   othdom   => 'User information available in other domain',
                   17259:                   priv     => 'Information viewable by privileged user in same domain',
                   17260:                   unpriv   => 'Information viewable by unprivileged user in same domain',
                   17261:                   instdom  => 'Other domain shares institution/provider',
                   17262:                   extdom   => 'Other domain has different institution/provider',
                   17263:                   none     => 'Not allowed',
                   17264:                   user     => 'User authorizes',
                   17265:                   domain   => 'Domain Coordinator authorizes',
                   17266:                   auto     => 'Unrestricted',
                   17267:     );
                   17268:     my %fieldnames = &Apache::lonlocal::texthash (
                   17269:                         id => 'Student/Employee ID',
                   17270:                         permanentemail => 'E-mail address',
                   17271:                         lastname => 'Last Name',
                   17272:                         firstname => 'First Name',
                   17273:                         middlename => 'Middle Name',
                   17274:                         generation => 'Generation',
                   17275:     );
                   17276:     my ($othertitle,$usertypes,$types) =
                   17277:         &Apache::loncommon::sorted_inst_types($dom);
                   17278:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   17279:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   17280: 
                   17281:     my %privacyhash = (
                   17282:                        'approval' => {
                   17283:                                        instdom => {},
                   17284:                                        extdom  => {},
                   17285:                                      },
                   17286:                        'othdom'   => {},
                   17287:                        'priv'     => {},
                   17288:                        'unpriv'   => {},
                   17289:                       );
                   17290:     foreach my $item (@items) {
                   17291:         if (@instdoms > 1) {
                   17292:             if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
                   17293:                 $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
                   17294:             }
                   17295:             if (ref($current{'approval'}) eq 'HASH') {
                   17296:                 if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                   17297:                     unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                   17298:                         $changes{'approval'} = 1;
                   17299:                     }
                   17300:                 }
                   17301:             } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   17302:                 $changes{'approval'} = 1;
                   17303:             }
                   17304:         }
                   17305:         if (keys(%by_location) > 0) {
                   17306:             if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   17307:                 $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
                   17308:             }
                   17309:             if (ref($current{'approval'}) eq 'HASH') {
                   17310:                 if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                   17311:                     unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                   17312:                         $changes{'approval'} = 1;
                   17313:                     }
                   17314:                 }
                   17315:             } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   17316:                 $changes{'approval'} = 1;
                   17317:             }
                   17318:         }
                   17319:         foreach my $status ('priv','unpriv') {
                   17320:             my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
                   17321:             my @newvalues;
                   17322:             foreach my $field (@possibles) {
                   17323:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17324:                     $privacyhash{$status}{$item}{$field} = 1;
                   17325:                     push(@newvalues,$field);
                   17326:                 }
                   17327:             }
                   17328:             @newvalues = sort(@newvalues);
                   17329:             if (ref($current{$status}) eq 'HASH') {
                   17330:                 if (ref($current{$status}{$item}) eq 'HASH') {
                   17331:                     my @currvalues = sort(keys(%{$current{$status}{$item}}));
                   17332:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17333:                     if (@diffs > 0) {
                   17334:                         $changes{$status} = 1;
                   17335:                     }
                   17336:                 }
                   17337:             } else {
                   17338:                 my @stdfields;
                   17339:                 foreach my $field (@fields) {
                   17340:                     if ($field eq 'id') {
                   17341:                         next if ($status eq 'unpriv');
                   17342:                         next if (($status eq 'priv') && ($item eq 'community'));
                   17343:                     }
                   17344:                     push(@stdfields,$field);
                   17345:                 }
                   17346:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17347:                 if (@diffs > 0) {
                   17348:                     $changes{$status} = 1;
                   17349:                 }
                   17350:             }
                   17351:         }
                   17352:     }
                   17353:     if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   17354:         my @statuses;
                   17355:         if (ref($types) eq 'ARRAY') {
                   17356:             @statuses = @{$types};
                   17357:         }
                   17358:         foreach my $type (@statuses,'default') {
                   17359:             my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
                   17360:             my @newvalues;
                   17361:             foreach my $field (sort(@possfields)) {
                   17362:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17363:                     $privacyhash{'othdom'}{$type}{$field} = 1;
                   17364:                     push(@newvalues,$field);
                   17365:                 }
                   17366:             }
                   17367:             @newvalues = sort(@newvalues);
                   17368:             if (ref($current{'othdom'}) eq 'HASH') {
                   17369:                 if (ref($current{'othdom'}{$type}) eq 'HASH') {
                   17370:                     my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                   17371:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17372:                     if (@diffs > 0) {
                   17373:                         $changes{'othdom'} = 1;
                   17374:                     }
                   17375:                 }
                   17376:             } else {
                   17377:                 my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   17378:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17379:                 if (@diffs > 0) {
                   17380:                     $changes{'othdom'} = 1;
                   17381:                 }
                   17382:             }
                   17383:         }
                   17384:     }
                   17385:     my %confighash = (
                   17386:                         privacy => \%privacyhash,
                   17387:                      );
                   17388:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   17389:     if ($putresult eq 'ok') {
                   17390:         if (keys(%changes) > 0) {
                   17391:             $resulttext = &mt('Changes made: ').'<ul>';
                   17392:             foreach my $key ('approval','othdom','priv','unpriv') {
                   17393:                 if ($changes{$key}) {
                   17394:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   17395:                     if ($key eq 'approval') {
                   17396:                         if (keys(%{$privacyhash{$key}{instdom}})) {
                   17397:                             $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                   17398:                             foreach my $item (@items) {
                   17399:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                   17400:                             }
                   17401:                             $resulttext .= '</ul></li>';
                   17402:                         }
                   17403:                         if (keys(%{$privacyhash{$key}{extdom}})) {
                   17404:                             $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                   17405:                             foreach my $item (@items) {
                   17406:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                   17407:                             }
                   17408:                             $resulttext .= '</ul></li>';
                   17409:                         }
                   17410:                     } elsif ($key eq 'othdom') {
                   17411:                         my @statuses;
                   17412:                         if (ref($types) eq 'ARRAY') {
                   17413:                             @statuses = @{$types};
                   17414:                         }
                   17415:                         if (ref($privacyhash{$key}) eq 'HASH') {
                   17416:                             foreach my $status (@statuses,'default') {
                   17417:                                 if ($status eq 'default') {
                   17418:                                     $resulttext .= '<li>'.$othertitle.': ';
                   17419:                                 } elsif (ref($usertypes) eq 'HASH') {
                   17420:                                     $resulttext .= '<li>'.$usertypes->{$status}.': ';
                   17421:                                 } else {
                   17422:                                     next;
                   17423:                                 }
                   17424:                                 if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                   17425:                                     if (keys(%{$privacyhash{$key}{$status}})) {
                   17426:                                         $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                   17427:                                     } else {
                   17428:                                         $resulttext .= &mt('none');
                   17429:                                     }
                   17430:                                 }
                   17431:                                 $resulttext .= '</li>';
                   17432:                             }
                   17433:                         }
                   17434:                     } else {
                   17435:                         foreach my $item (@items) {
                   17436:                             if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                   17437:                                 $resulttext .= '<li>'.$names{$item}.': ';
                   17438:                                 if (keys(%{$privacyhash{$key}{$item}})) {
                   17439:                                     $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                   17440:                                 } else {
                   17441:                                     $resulttext .= &mt('none');
                   17442:                                 }
                   17443:                                 $resulttext .= '</li>';
                   17444:                             }
                   17445:                         }
                   17446:                     }
                   17447:                     $resulttext .= '</ul></li>';
                   17448:                 }
                   17449:             }
                   17450:         } else {
                   17451:             $resulttext = &mt('No changes made to user information settings');
                   17452:         }
                   17453:     } else {
                   17454:         $resulttext = '<span class="LC_error">'.
                   17455:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17456:     }
                   17457:     return $resulttext;
                   17458: }
                   17459: 
1.354     raeburn  17460: sub modify_passwords {
                   17461:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355     raeburn  17462:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   17463:         $updatedefaults,$updateconf);
1.354     raeburn  17464:     my $customfn = 'resetpw.html';
                   17465:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   17466:         %current = %{$domconfig{'passwords'}};
                   17467:     }
                   17468:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   17469:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   17470:     if (ref($types) eq 'ARRAY') {
                   17471:         @oktypes = @{$types};
                   17472:     }
                   17473:     push(@oktypes,'default');
                   17474: 
                   17475:     my %titles = &Apache::lonlocal::texthash (
                   17476:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   17477:         intauth_check  => 'Check bcrypt cost if authenticated',
                   17478:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   17479:         permanent      => 'Permanent e-mail address',
                   17480:         critical       => 'Critical notification address',
                   17481:         notify         => 'Notification address',
                   17482:         min            => 'Minimum password length',
                   17483:         max            => 'Maximum password length',
                   17484:         chars          => 'Required characters',
                   17485:         expire         => 'Password expiration (days)',
1.356     raeburn  17486:         numsaved       => 'Number of previous passwords to save',
1.354     raeburn  17487:         reset          => 'Resetting Forgotten Password',
                   17488:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   17489:         rules          => 'Rules for LON-CAPA Passwords',
                   17490:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   17491:         username       => 'Username',
                   17492:         email          => 'E-mail address',
                   17493:     );
                   17494: 
                   17495: #
                   17496: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   17497: #
                   17498:     my (%curr_defaults,%save_defaults);
                   17499:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   17500:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   17501:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   17502:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   17503:             } else {
                   17504:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   17505:             }
                   17506:         }
                   17507:     }
                   17508:     my %staticdefaults = (
                   17509:         'resetlink'      => 2,
                   17510:         'resetcase'      => \@oktypes,
                   17511:         'resetprelink'   => 'both',
                   17512:         'resetemail'     => ['critical','notify','permanent'],
                   17513:         'intauth_cost'   => 10,
                   17514:         'intauth_check'  => 0,
                   17515:         'intauth_switch' => 0,
                   17516:     );
1.365     raeburn  17517:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354     raeburn  17518:     foreach my $type (@oktypes) {
                   17519:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   17520:     }
                   17521:     my $linklife = $env{'form.passwords_link'};
                   17522:     $linklife =~ s/^\s+|\s+$//g;
                   17523:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   17524:         $newvalues{'resetlink'} = $linklife;
                   17525:         if ($current{'resetlink'}) {
                   17526:             if ($current{'resetlink'} ne $linklife) {
                   17527:                 $changes{'reset'} = 1;
                   17528:             }
1.368     raeburn  17529:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17530:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   17531:                 $changes{'reset'} = 1;
                   17532:             }
                   17533:         }
                   17534:     } elsif ($current{'resetlink'}) {
                   17535:         $changes{'reset'} = 1;
                   17536:     }
                   17537:     my @casesens;
                   17538:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   17539:     foreach my $case (sort(@posscase)) {
                   17540:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   17541:             push(@casesens,$case);
                   17542:         }
                   17543:     }
                   17544:     $newvalues{'resetcase'} = \@casesens;
                   17545:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   17546:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   17547:         if (@diffs > 0) {
                   17548:             $changes{'reset'} = 1;
                   17549:         }
1.368     raeburn  17550:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17551:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   17552:         if (@diffs > 0) {
                   17553:             $changes{'reset'} = 1;
                   17554:         }
                   17555:     }
                   17556:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   17557:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   17558:         if (exists($current{'resetprelink'})) {
                   17559:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   17560:                 $changes{'reset'} = 1;
                   17561:             }
1.368     raeburn  17562:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17563:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   17564:                 $changes{'reset'} = 1;
                   17565:             }
                   17566:         }
                   17567:     } elsif ($current{'resetprelink'}) {
                   17568:         $changes{'reset'} = 1;
                   17569:     }
                   17570:     foreach my $type (@oktypes) {
                   17571:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   17572:         my @postlink;
                   17573:         foreach my $item (sort(@possplink)) {
                   17574:             if ($item =~ /^(email|username)$/) {
                   17575:                 push(@postlink,$item);
                   17576:             }
                   17577:         }
                   17578:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   17579:         unless ($changes{'reset'}) {
                   17580:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   17581:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   17582:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   17583:                     if (@diffs > 0) {
                   17584:                         $changes{'reset'} = 1;
                   17585:                     }
                   17586:                 } else {
                   17587:                     $changes{'reset'} = 1;
                   17588:                 }
1.368     raeburn  17589:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17590:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   17591:                 if (@diffs > 0) {
                   17592:                     $changes{'reset'} = 1;
                   17593:                 }
                   17594:             }
                   17595:         }
                   17596:     }
                   17597:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   17598:     my @resetemail;
                   17599:     foreach my $item (sort(@possemailsrc)) {
                   17600:         if ($item =~ /^(permanent|critical|notify)$/) {
                   17601:             push(@resetemail,$item);
                   17602:         }
                   17603:     }
                   17604:     $newvalues{'resetemail'} = \@resetemail;
                   17605:     unless ($changes{'reset'}) {
                   17606:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   17607:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   17608:             if (@diffs > 0) {
                   17609:                 $changes{'reset'} = 1;
                   17610:             }
1.368     raeburn  17611:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17612:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   17613:             if (@diffs > 0) {
                   17614:                 $changes{'reset'} = 1;
                   17615:             }
                   17616:         }
                   17617:     }
                   17618:     if ($env{'form.passwords_stdtext'} == 0) {
                   17619:         $newvalues{'resetremove'} = 1;
                   17620:         unless ($current{'resetremove'}) {
                   17621:             $changes{'reset'} = 1;
                   17622:         }
                   17623:     } elsif ($current{'resetremove'}) {
                   17624:         $changes{'reset'} = 1;
                   17625:     }
                   17626:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   17627:         my $servadm = $r->dir_config('lonAdmEMail');
                   17628:         my ($configuserok,$author_ok,$switchserver) =
                   17629:             &config_check($dom,$confname,$servadm);
                   17630:         my $error;
                   17631:         if ($configuserok eq 'ok') {
                   17632:             if ($switchserver) {
                   17633:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   17634:             } else {
                   17635:                 if ($author_ok eq 'ok') {
                   17636:                     my ($result,$customurl) =
                   17637:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   17638:                                      $confname,'customtext/resetpw','','',$customfn);
                   17639:                     if ($result eq 'ok') {
                   17640:                         $newvalues{'resetcustom'} = $customurl;
                   17641:                         $changes{'reset'} = 1;
                   17642:                     } else {
                   17643:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   17644:                     }
                   17645:                 } else {
                   17646:                     $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);
                   17647:                 }
                   17648:             }
                   17649:         } else {
                   17650:             $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);
                   17651:         }
                   17652:         if ($error) {
                   17653:             &Apache::lonnet::logthis($error);
                   17654:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   17655:         }
                   17656:     } elsif ($current{'resetcustom'}) {
                   17657:         if ($env{'form.passwords_custom_del'}) {
                   17658:             $changes{'reset'} = 1;
                   17659:         } else {
                   17660:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   17661:         }
                   17662:     }
                   17663:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   17664:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   17665:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   17666:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   17667:             $changes{'intauth'} = 1;
                   17668:         }
                   17669:     } else {
                   17670:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   17671:     }
                   17672:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   17673:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   17674:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   17675:             $changes{'intauth'} = 1;
                   17676:         }
                   17677:     } else {
                   17678:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   17679:     }
                   17680:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   17681:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   17682:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   17683:             $changes{'intauth'} = 1;
                   17684:         }
                   17685:     } else {
                   17686:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   17687:     }
                   17688:     foreach my $item ('cost','check','switch') {
                   17689:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   17690:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   17691:             $updatedefaults = 1;
                   17692:         }
                   17693:     }
1.356     raeburn  17694:     foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  17695:         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356     raeburn  17696:         my $ruleok;
                   17697:         if ($rule eq 'expire') {
1.365     raeburn  17698:             if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
                   17699:                 ($env{'form.passwords_'.$rule} ne '0')) {
1.359     raeburn  17700:                 $ruleok = 1;
1.356     raeburn  17701:             }
1.365     raeburn  17702:         } elsif ($rule eq 'min') {
                   17703:             if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   17704:                 if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
                   17705:                     $ruleok = 1;
                   17706:                 }
                   17707:             }
                   17708:         } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
                   17709:                  ($env{'form.passwords_'.$rule} ne '0')) {
1.356     raeburn  17710:             $ruleok = 1;
                   17711:         }
                   17712:         if ($ruleok) {
1.354     raeburn  17713:             $newvalues{$rule} = $env{'form.passwords_'.$rule};
                   17714:             if (exists($current{$rule})) {
                   17715:                 if ($newvalues{$rule} ne $current{$rule}) {
                   17716:                     $changes{'rules'} = 1;
                   17717:                 }
                   17718:             } elsif ($rule eq 'min') {
                   17719:                 if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                   17720:                     $changes{'rules'} = 1;
                   17721:                 }
1.370     raeburn  17722:             } else {
                   17723:                 $changes{'rules'} = 1;
1.354     raeburn  17724:             }
                   17725:         } elsif (exists($current{$rule})) {
                   17726:             $changes{'rules'} = 1;
                   17727:         }
                   17728:     }
                   17729:     my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
                   17730:     my @chars;
                   17731:     foreach my $item (sort(@posschars)) {
                   17732:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   17733:             push(@chars,$item);
                   17734:         }
                   17735:     }
                   17736:     $newvalues{'chars'} = \@chars;
                   17737:     unless ($changes{'rules'}) {
                   17738:         if (ref($current{'chars'}) eq 'ARRAY') {
                   17739:             my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
                   17740:             if (@diffs > 0) {
                   17741:                 $changes{'rules'} = 1;
                   17742:             }
                   17743:         } else {
                   17744:             if (@chars > 0) {
                   17745:                 $changes{'rules'} = 1;
                   17746:             }
                   17747:         }
                   17748:     }
1.359     raeburn  17749:     my %crsownerchg = (
                   17750:                         by => [],
                   17751:                         for => [],
                   17752:                       );
                   17753:     foreach my $item ('by','for') {
                   17754:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   17755:         foreach my $type (sort(@posstypes)) {
                   17756:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   17757:                 push(@{$crsownerchg{$item}},$type);
                   17758:             }
                   17759:         }
                   17760:     }
                   17761:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   17762:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   17763:         foreach my $item ('by','for') {
                   17764:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   17765:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   17766:                 if (@diffs > 0) {
                   17767:                     $changes{'crsownerchg'} = 1;
                   17768:                     last;
                   17769:                 }
                   17770:             }
                   17771:         }
1.368     raeburn  17772:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359     raeburn  17773:         foreach my $item ('by','for') {
                   17774:             if (@{$crsownerchg{$item}} > 0) {
                   17775:                 $changes{'crsownerchg'} = 1;
                   17776:                 last;
                   17777:             }
1.354     raeburn  17778:         }
                   17779:     }
                   17780: 
                   17781:     my %confighash = (
                   17782:                         defaults  => \%save_defaults,
                   17783:                         passwords => \%newvalues,
                   17784:                      );
                   17785:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   17786: 
                   17787:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   17788:     if ($putresult eq 'ok') {
                   17789:         if (keys(%changes) > 0) {
                   17790:             $resulttext = &mt('Changes made: ').'<ul>';
                   17791:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   17792:                 if ($changes{$key}) {
1.355     raeburn  17793:                     unless ($key eq 'intauth') {
                   17794:                         $updateconf = 1;
                   17795:                     }
1.354     raeburn  17796:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   17797:                     if ($key eq 'reset') {
                   17798:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   17799:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   17800:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   17801:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369     raeburn  17802:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   17803:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   17804:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   17805:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   17806:                             }
1.354     raeburn  17807:                         } else {
                   17808:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   17809:                         }
                   17810:                         if ($confighash{'passwords'}{'resetlink'}) {
                   17811:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   17812:                         } else {
                   17813:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   17814:                                                   &mt('Will default to 2 hours').'</li>';
                   17815:                         }
                   17816:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   17817:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   17818:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   17819:                             } else {
                   17820:                                 my $casesens;
                   17821:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   17822:                                     if ($type eq 'default') {
                   17823:                                         $casesens .= $othertitle.', ';
                   17824:                                     } elsif ($usertypes->{$type} ne '') {
                   17825:                                         $casesens .= $usertypes->{$type}.', ';
                   17826:                                     }
                   17827:                                 }
                   17828:                                 $casesens =~ s/\Q, \E$//;
                   17829:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   17830:                             }
                   17831:                         } else {
                   17832:                             $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>';
                   17833:                         }
                   17834:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   17835:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   17836:                         } else {
                   17837:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   17838:                         }
                   17839:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   17840:                             my $output;
                   17841:                             if (ref($types) eq 'ARRAY') {
                   17842:                                 foreach my $type (@{$types}) {
                   17843:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   17844:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   17845:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   17846:                                         } else {
                   17847:                                             $output .= $usertypes->{$type}.' -- '.
                   17848:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   17849:                                         }
                   17850:                                     }
                   17851:                                 }
                   17852:                             }
                   17853:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   17854:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   17855:                                     $output .= $othertitle.' -- '.&mt('none');
                   17856:                                 } else {
                   17857:                                     $output .= $othertitle.' -- '.
                   17858:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   17859:                                 }
                   17860:                             }
                   17861:                             if ($output) {
                   17862:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   17863:                             } else {
                   17864:                                 $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>';
                   17865:                             }
                   17866:                         } else {
                   17867:                             $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>';
                   17868:                         }
                   17869:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   17870:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   17871:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   17872:                             } else {
                   17873:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   17874:                             }
                   17875:                         } else {
1.379     raeburn  17876:                             $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  17877:                         }
                   17878:                         if ($confighash{'passwords'}{'resetremove'}) {
                   17879:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   17880:                         } else {
                   17881:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   17882:                         }
                   17883:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   17884:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369     raeburn  17885:                                                                             &mt('custom text'),600,500,undef,undef,
                   17886:                                                                             undef,undef,'background-color:#ffffff');
                   17887:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354     raeburn  17888:                         } else {
                   17889:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   17890:                         }
                   17891:                     } elsif ($key eq 'intauth') {
                   17892:                         foreach my $item ('cost','switch','check') {
                   17893:                             my $value = $save_defaults{$key.'_'.$item};
                   17894:                             if ($item eq 'switch') {
                   17895:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   17896:                                                      0 => 'No',
                   17897:                                                      1 => 'Yes',
                   17898:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   17899:                                                  );
                   17900:                                 if ($value =~ /^(0|1|2)$/) {
                   17901:                                     $value = $optiondesc{$value};
                   17902:                                 } else {
                   17903:                                     $value = &mt('none -- defaults to No');
                   17904:                                 }
                   17905:                             } elsif ($item eq 'check') {
                   17906:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   17907:                                                      0 => 'No',
                   17908:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   17909:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   17910:                                                  );
                   17911:                                 if ($value =~ /^(0|1|2)$/) {
                   17912:                                     $value = $optiondesc{$value};
                   17913:                                 } else {
                   17914:                                     $value = &mt('none -- defaults to No');
                   17915:                                 }
                   17916:                             }
                   17917:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   17918:                         }
                   17919:                     } elsif ($key eq 'rules') {
1.356     raeburn  17920:                         foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  17921:                             if ($confighash{'passwords'}{$rule} eq '') {
                   17922:                                 if ($rule eq 'min') {
1.356     raeburn  17923:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365     raeburn  17924:                                                    ' '.&mt('Default of [_1] will be used',
                   17925:                                                            $Apache::lonnet::passwdmin).'</li>';
1.356     raeburn  17926:                                 } else {
                   17927:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354     raeburn  17928:                                 }
                   17929:                             } else {
                   17930:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   17931:                             }
                   17932:                         }
1.370     raeburn  17933:                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   17934:                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   17935:                                 my %rulenames = &Apache::lonlocal::texthash(
                   17936:                                                      uc => 'At least one upper case letter',
                   17937:                                                      lc => 'At least one lower case letter',
                   17938:                                                      num => 'At least one number',
                   17939:                                                      spec => 'At least one non-alphanumeric',
                   17940:                                                    );
                   17941:                                 my $needed = '<ul><li>'.
                   17942:                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
                   17943:                                              '</li></ul>'; 
                   17944:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   17945:                             } else {
                   17946:                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   17947:                             }
                   17948:                         } else {
                   17949:                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   17950:                         }
1.354     raeburn  17951:                     } elsif ($key eq 'crsownerchg') {
1.359     raeburn  17952:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   17953:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   17954:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   17955:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   17956:                             } else {
                   17957:                                 my %crsownerstr;
                   17958:                                 foreach my $item ('by','for') {
                   17959:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   17960:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   17961:                                             if ($type eq 'default') {
                   17962:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   17963:                                             } elsif ($usertypes->{$type} ne '') {
                   17964:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   17965:                                             }
                   17966:                                         }
                   17967:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   17968:                                     }
                   17969:                                 }
                   17970:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   17971:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   17972:                             }
1.354     raeburn  17973:                         } else {
1.359     raeburn  17974:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354     raeburn  17975:                         }
                   17976:                     }
                   17977:                     $resulttext .= '</ul></li>';
                   17978:                 }
                   17979:             }
                   17980:             $resulttext .= '</ul>';
                   17981:         } else {
                   17982:             $resulttext = &mt('No changes made to password settings');
                   17983:         }
1.355     raeburn  17984:         my $cachetime = 24*60*60;
1.354     raeburn  17985:         if ($updatedefaults) {
                   17986:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   17987:             if (ref($lastactref) eq 'HASH') {
                   17988:                 $lastactref->{'domdefaults'} = 1;
                   17989:             }
                   17990:         }
1.355     raeburn  17991:         if ($updateconf) {
                   17992:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   17993:             if (ref($lastactref) eq 'HASH') {
                   17994:                 $lastactref->{'passwdconf'} = 1;
                   17995:             }
                   17996:         }
1.354     raeburn  17997:     } else {
                   17998:         $resulttext = '<span class="LC_error">'.
                   17999:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18000:     }
                   18001:     if ($errors) {
                   18002:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   18003:                        $errors.'</ul></p>';
                   18004:     }
                   18005:     return $resulttext;
                   18006: }
                   18007: 
1.28      raeburn  18008: sub modify_usercreation {
1.27      raeburn  18009:     my ($dom,%domconfig) = @_;
1.224     raeburn  18010:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  18011:     my $warningmsg;
1.27      raeburn  18012:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   18013:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  18014:             if ($key eq 'cancreate') {
                   18015:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   18016:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  18017:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   18018:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18019:                         } else {
1.224     raeburn  18020:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18021:                         }
                   18022:                     }
                   18023:                 }
                   18024:             } elsif ($key eq 'email_rule') {
                   18025:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   18026:             } else {
                   18027:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   18028:             }
1.27      raeburn  18029:         }
                   18030:     }
                   18031:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  18032:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  18033:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  18034:     foreach my $item(@contexts) {
1.224     raeburn  18035:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  18036:     }
1.34      raeburn  18037:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18038:         foreach my $item (@contexts) {
1.224     raeburn  18039:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   18040:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  18041:             }
1.27      raeburn  18042:         }
1.34      raeburn  18043:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   18044:         foreach my $item (@contexts) {
1.43      raeburn  18045:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  18046:                 if ($cancreate{$item} ne 'any') {
                   18047:                     push(@{$changes{'cancreate'}},$item);
                   18048:                 }
                   18049:             } else {
                   18050:                 if ($cancreate{$item} ne 'none') {
                   18051:                     push(@{$changes{'cancreate'}},$item);
                   18052:                 }
1.27      raeburn  18053:             }
                   18054:         }
                   18055:     } else {
1.43      raeburn  18056:         foreach my $item (@contexts)  {
1.34      raeburn  18057:             push(@{$changes{'cancreate'}},$item);
                   18058:         }
1.27      raeburn  18059:     }
1.34      raeburn  18060: 
1.27      raeburn  18061:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   18062:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   18063:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   18064:                 push(@{$changes{'username_rule'}},$type);
                   18065:             }
                   18066:         }
                   18067:         foreach my $type (@username_rule) {
                   18068:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   18069:                 push(@{$changes{'username_rule'}},$type);
                   18070:             }
                   18071:         }
                   18072:     } else {
                   18073:         push(@{$changes{'username_rule'}},@username_rule);
                   18074:     }
                   18075: 
1.32      raeburn  18076:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   18077:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   18078:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   18079:                 push(@{$changes{'id_rule'}},$type);
                   18080:             }
                   18081:         }
                   18082:         foreach my $type (@id_rule) {
                   18083:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   18084:                 push(@{$changes{'id_rule'}},$type);
                   18085:             }
                   18086:         }
                   18087:     } else {
                   18088:         push(@{$changes{'id_rule'}},@id_rule);
                   18089:     }
                   18090: 
1.43      raeburn  18091:     my @authen_contexts = ('author','course','domain');
1.325     raeburn  18092:     my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  18093:     my %authhash;
1.43      raeburn  18094:     foreach my $item (@authen_contexts) {
1.28      raeburn  18095:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   18096:         foreach my $auth (@authtypes) {
                   18097:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   18098:                 $authhash{$item}{$auth} = 1;
                   18099:             } else {
                   18100:                 $authhash{$item}{$auth} = 0;
                   18101:             }
                   18102:         }
                   18103:     }
                   18104:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  18105:         foreach my $item (@authen_contexts) {
1.28      raeburn  18106:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   18107:                 foreach my $auth (@authtypes) {
                   18108:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   18109:                         push(@{$changes{'authtypes'}},$item);
                   18110:                         last;
                   18111:                     }
                   18112:                 }
                   18113:             }
                   18114:         }
                   18115:     } else {
1.43      raeburn  18116:         foreach my $item (@authen_contexts) {
1.28      raeburn  18117:             push(@{$changes{'authtypes'}},$item);
                   18118:         }
                   18119:     }
                   18120: 
1.224     raeburn  18121:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   18122:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   18123:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   18124:     $save_usercreate{'id_rule'} = \@id_rule;
                   18125:     $save_usercreate{'username_rule'} = \@username_rule,
                   18126:     $save_usercreate{'authtypes'} = \%authhash;
                   18127: 
1.27      raeburn  18128:     my %usercreation_hash =  (
1.224     raeburn  18129:         usercreation     => \%save_usercreate,
                   18130:     );
1.27      raeburn  18131: 
                   18132:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   18133:                                              $dom);
1.50      raeburn  18134: 
1.224     raeburn  18135:     if ($putresult eq 'ok') {
                   18136:         if (keys(%changes) > 0) {
                   18137:             $resulttext = &mt('Changes made:').'<ul>';
                   18138:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   18139:                 my %lt = &usercreation_types();
                   18140:                 foreach my $type (@{$changes{'cancreate'}}) {
                   18141:                     my $chgtext = $lt{$type}.', ';
                   18142:                     if ($cancreate{$type} eq 'none') {
                   18143:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   18144:                     } elsif ($cancreate{$type} eq 'any') {
                   18145:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   18146:                     } elsif ($cancreate{$type} eq 'official') {
                   18147:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   18148:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   18149:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   18150:                     }
                   18151:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   18152:                 }
                   18153:             }
                   18154:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   18155:                 my ($rules,$ruleorder) = 
                   18156:                     &Apache::lonnet::inst_userrules($dom,'username');
                   18157:                 my $chgtext = '<ul>';
                   18158:                 foreach my $type (@username_rule) {
                   18159:                     if (ref($rules->{$type}) eq 'HASH') {
                   18160:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   18161:                     }
                   18162:                 }
                   18163:                 $chgtext .= '</ul>';
                   18164:                 if (@username_rule > 0) {
                   18165:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   18166:                 } else {
                   18167:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   18168:                 }
                   18169:             }
                   18170:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   18171:                 my ($idrules,$idruleorder) = 
                   18172:                     &Apache::lonnet::inst_userrules($dom,'id');
                   18173:                 my $chgtext = '<ul>';
                   18174:                 foreach my $type (@id_rule) {
                   18175:                     if (ref($idrules->{$type}) eq 'HASH') {
                   18176:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   18177:                     }
                   18178:                 }
                   18179:                 $chgtext .= '</ul>';
                   18180:                 if (@id_rule > 0) {
                   18181:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   18182:                 } else {
                   18183:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   18184:                 }
                   18185:             }
                   18186:             my %authname = &authtype_names();
                   18187:             my %context_title = &context_names();
                   18188:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   18189:                 my $chgtext = '<ul>';
                   18190:                 foreach my $type (@{$changes{'authtypes'}}) {
                   18191:                     my @allowed;
                   18192:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   18193:                     foreach my $auth (@authtypes) {
                   18194:                         if ($authhash{$type}{$auth}) {
                   18195:                             push(@allowed,$authname{$auth});
                   18196:                         }
                   18197:                     }
                   18198:                     if (@allowed > 0) {
                   18199:                         $chgtext .= join(', ',@allowed).'</li>';
                   18200:                     } else {
                   18201:                         $chgtext .= &mt('none').'</li>';
                   18202:                     }
                   18203:                 }
                   18204:                 $chgtext .= '</ul>';
                   18205:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   18206:                 $resulttext .= '</li>';
                   18207:             }
                   18208:             $resulttext .= '</ul>';
                   18209:         } else {
                   18210:             $resulttext = &mt('No changes made to user creation settings');
                   18211:         }
                   18212:     } else {
                   18213:         $resulttext = '<span class="LC_error">'.
                   18214:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18215:     }
                   18216:     if ($warningmsg ne '') {
                   18217:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   18218:     }
                   18219:     return $resulttext;
                   18220: }
                   18221: 
                   18222: sub modify_selfcreation {
1.305     raeburn  18223:     my ($dom,$lastactref,%domconfig) = @_;
                   18224:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   18225:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   18226:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  18227:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   18228:     if (ref($typesref) eq 'ARRAY') {
                   18229:         @types = @{$typesref};
                   18230:     }
                   18231:     if (ref($usertypesref) eq 'HASH') {
                   18232:         %usertypes = %{$usertypesref};
1.228     raeburn  18233:     }
1.303     raeburn  18234:     $usertypes{'default'} = $othertitle;
1.224     raeburn  18235: #
                   18236: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   18237: #
                   18238:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   18239:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   18240:             if ($key eq 'cancreate') {
                   18241:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   18242:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   18243:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  18244:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   18245:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   18246:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   18247:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  18248:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  18249:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18250:                         } else {
                   18251:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18252:                         }
                   18253:                     }
                   18254:                 }
                   18255:             } elsif ($key eq 'email_rule') {
                   18256:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   18257:             } else {
                   18258:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   18259:             }
                   18260:         }
                   18261:     }
                   18262: #
                   18263: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   18264: #
                   18265:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   18266:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   18267:             if ($key eq 'selfcreate') {
                   18268:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18269:             } else {
                   18270:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18271:             }
                   18272:         }
                   18273:     }
1.305     raeburn  18274: #
                   18275: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   18276: #
                   18277:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   18278:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   18279:             if ($key eq 'inststatusguest') {
                   18280:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18281:             } else {
                   18282:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18283:             }
                   18284:         }
                   18285:     }
1.224     raeburn  18286: 
                   18287:     my @contexts = ('selfcreate');
                   18288:     @{$cancreate{'selfcreate'}} = ();
                   18289:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  18290:     if (@types) {
                   18291:         @{$cancreate{'statustocreate'}} = ();
                   18292:     }
1.236     raeburn  18293:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  18294:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  18295:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  18296:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  18297:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  18298:     my %selfcreatetypes = (
                   18299:                              sso   => 'users authenticated by institutional single sign on',
                   18300:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  18301:                              email => 'users verified by e-mail',
1.50      raeburn  18302:                           );
1.224     raeburn  18303: #
                   18304: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   18305: # is permitted.
                   18306: #
1.305     raeburn  18307:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  18308: 
1.305     raeburn  18309:     my (@statuses,%email_rule);
1.228     raeburn  18310:     foreach my $item ('login','sso','email') {
1.224     raeburn  18311:         if ($item eq 'email') {
1.236     raeburn  18312:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  18313:                 if (@types) {
                   18314:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   18315:                     foreach my $status (@poss_statuses) {
                   18316:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   18317:                             push(@statuses,$status);
                   18318:                         }
                   18319:                     }
                   18320:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   18321:                 } else {
                   18322:                     push(@statuses,'default');
                   18323:                 }
                   18324:                 if (@statuses) {
                   18325:                     my %curr_rule;
                   18326:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   18327:                         foreach my $type (@statuses) {
                   18328:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  18329:                         }
1.305     raeburn  18330:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   18331:                         foreach my $type (@statuses) {
                   18332:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   18333:                         }
                   18334:                     }
                   18335:                     push(@{$cancreate{'selfcreate'}},'email');
                   18336:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   18337:                     my %curremaildom;
                   18338:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   18339:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   18340:                     }
                   18341:                     foreach my $type (@statuses) {
                   18342:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   18343:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   18344:                         }
                   18345:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   18346:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   18347:                         }
                   18348:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   18349: #
                   18350: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   18351: #
                   18352:                             my $chosen = $1;
                   18353:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   18354:                                 my $emaildom;
                   18355:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   18356:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                   18357:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   18358:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   18359:                                         if (exists($curremaildom{$type}{$chosen})) {
                   18360:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   18361:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   18362:                                             }
                   18363:                                         } elsif ($emaildom ne '') {
                   18364:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   18365:                                         }
                   18366:                                     } elsif ($emaildom ne '') {
                   18367:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   18368:                                     } 
                   18369:                                 }
                   18370:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   18371:                             } elsif ($chosen eq 'custom') {
                   18372:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   18373:                                 $email_rule{$type} = [];
                   18374:                                 if (ref($emailrules) eq 'HASH') {
                   18375:                                     foreach my $rule (@possemail_rules) {
                   18376:                                         if (exists($emailrules->{$rule})) {
                   18377:                                             push(@{$email_rule{$type}},$rule);
                   18378:                                         }
                   18379:                                     }
                   18380:                                 }
                   18381:                                 if (@{$email_rule{$type}}) {
                   18382:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   18383:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   18384:                                         if (@{$curr_rule{$type}} > 0) {
                   18385:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   18386:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   18387:                                                     push(@{$changes{'email_rule'}},$type);
                   18388:                                                 }
                   18389:                                             }
                   18390:                                         }
                   18391:                                         foreach my $type (@{$email_rule{$type}}) {
                   18392:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   18393:                                                 push(@{$changes{'email_rule'}},$type);
                   18394:                                             }
                   18395:                                         }
                   18396:                                     } else {
                   18397:                                         push(@{$changes{'email_rule'}},$type);
                   18398:                                     }
                   18399:                                 }
                   18400:                             } else {
                   18401:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   18402:                             }
                   18403:                         }
                   18404:                     }
                   18405:                     if (@types) {
                   18406:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18407:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   18408:                             if (@changed) {
                   18409:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   18410:                             }
                   18411:                         } else {
                   18412:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   18413:                         }
                   18414:                     }
                   18415:                 } else {
                   18416:                     delete($env{'form.cancreate_email'});
                   18417:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18418:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   18419:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   18420:                         }
                   18421:                     }
                   18422:                 }
                   18423:             } else {
                   18424:                 $save_inststatus{'inststatusguest'} = [];
                   18425:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18426:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   18427:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  18428:                     }
                   18429:                 }
1.224     raeburn  18430:             }
                   18431:         } else {
                   18432:             if ($env{'form.cancreate_'.$item}) {
                   18433:                 push(@{$cancreate{'selfcreate'}},$item);
                   18434:             }
                   18435:         }
                   18436:     }
1.305     raeburn  18437:     my (%userinfo,%savecaptcha);
1.224     raeburn  18438:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   18439: #
1.228     raeburn  18440: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   18441: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  18442: #
1.236     raeburn  18443: 
1.244     raeburn  18444:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  18445:         push(@contexts,'emailusername');
1.305     raeburn  18446:         if (@statuses) {
                   18447:             foreach my $type (@statuses) {
1.228     raeburn  18448:                 if (ref($infofields) eq 'ARRAY') {
                   18449:                     foreach my $field (@{$infofields}) {
                   18450:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   18451:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   18452:                         }
                   18453:                     }
1.224     raeburn  18454:                 }
                   18455:             }
                   18456:         }
                   18457: #
                   18458: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  18459: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  18460: #
                   18461: 
                   18462:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   18463:         @approvalnotify = sort(@approvalnotify);
                   18464:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   18465:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18466:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   18467:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   18468:                     push(@{$changes{'cancreate'}},'notify');
                   18469:                 }
                   18470:             } else {
                   18471:                 if ($cancreate{'notify'}{'approval'}) {
                   18472:                     push(@{$changes{'cancreate'}},'notify');
                   18473:                 }
                   18474:             }
                   18475:         } elsif ($cancreate{'notify'}{'approval'}) {
                   18476:             push(@{$changes{'cancreate'}},'notify');
                   18477:         }
                   18478: 
                   18479:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   18480:     }
                   18481: #  
1.236     raeburn  18482: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  18483: # institutional log-in.
                   18484: #
                   18485:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   18486:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   18487:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   18488:             $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.').' '.
                   18489:                           &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.');
                   18490:         }
                   18491:     }
                   18492:     my @fields = ('lastname','firstname','middlename','generation',
                   18493:                   'permanentemail','id');
1.240     raeburn  18494:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  18495:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   18496: #
                   18497: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   18498: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   18499: # may self-create accounts 
                   18500: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   18501: # which the user may supply, if institutional data is unavailable.
                   18502: #
                   18503:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  18504:         if (@types) {
1.305     raeburn  18505:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   18506:             push(@contexts,'statustocreate');
1.303     raeburn  18507:             foreach my $type (@types) {
1.224     raeburn  18508:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   18509:                 foreach my $field (@fields) {
                   18510:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   18511:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   18512:                     } else {
                   18513:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   18514:                     }
                   18515:                 }
                   18516:             }
                   18517:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  18518:                 foreach my $type (@types) {
1.224     raeburn  18519:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   18520:                         foreach my $field (@fields) {
                   18521:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   18522:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   18523:                                 push(@{$changes{'selfcreate'}},$type);
                   18524:                                 last;
                   18525:                             }
                   18526:                         }
                   18527:                     }
                   18528:                 }
                   18529:             } else {
1.303     raeburn  18530:                 foreach my $type (@types) {
1.224     raeburn  18531:                     push(@{$changes{'selfcreate'}},$type);
                   18532:                 }
                   18533:             }
                   18534:         }
1.240     raeburn  18535:         foreach my $field (@shibfields) {
                   18536:             if ($env{'form.shibenv_'.$field} ne '') {
                   18537:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   18538:             }
                   18539:         }
                   18540:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18541:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   18542:                 foreach my $field (@shibfields) {
                   18543:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   18544:                         push(@{$changes{'cancreate'}},'shibenv');
                   18545:                     }
                   18546:                 }
                   18547:             } else {
                   18548:                 foreach my $field (@shibfields) {
                   18549:                     if ($env{'form.shibenv_'.$field}) {
                   18550:                         push(@{$changes{'cancreate'}},'shibenv');
                   18551:                         last;
                   18552:                     }
                   18553:                 }
                   18554:             }
                   18555:         }
1.224     raeburn  18556:     }
                   18557:     foreach my $item (@contexts) {
                   18558:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   18559:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   18560:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   18561:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   18562:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18563:                             push(@{$changes{'cancreate'}},$item);
                   18564:                         }
                   18565:                     }
                   18566:                 }
                   18567:             }
                   18568:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   18569:                 foreach my $type (@{$cancreate{$item}}) {
                   18570:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   18571:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18572:                             push(@{$changes{'cancreate'}},$item);
                   18573:                         }
                   18574:                     }
                   18575:                 }
                   18576:             }
                   18577:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   18578:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  18579:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   18580:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   18581:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   18582:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  18583:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18584:                                     push(@{$changes{'cancreate'}},$item);
                   18585:                                 }
                   18586:                             }
                   18587:                         }
1.305     raeburn  18588:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18589:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  18590:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18591:                                 push(@{$changes{'cancreate'}},$item);
                   18592:                             }
1.224     raeburn  18593:                         }
                   18594:                     }
                   18595:                 }
1.305     raeburn  18596:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   18597:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   18598:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   18599:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   18600:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  18601:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18602:                                         push(@{$changes{'cancreate'}},$item);
                   18603:                                     }
                   18604:                                 }
                   18605:                             } else {
                   18606:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18607:                                     push(@{$changes{'cancreate'}},$item);
                   18608:                                 }
                   18609:                             }
                   18610:                         }
1.305     raeburn  18611:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18612:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  18613:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18614:                                 push(@{$changes{'cancreate'}},$item);
                   18615:                             }
1.224     raeburn  18616:                         }
                   18617:                     }
                   18618:                 }
                   18619:             }
                   18620:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   18621:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   18622:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   18623:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18624:                         push(@{$changes{'cancreate'}},$item);
                   18625:                     }
                   18626:                 }
1.305     raeburn  18627:             }
                   18628:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18629:             if (ref($cancreate{$item}) eq 'HASH') {
                   18630:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18631:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  18632:                 }
                   18633:             }
                   18634:         } elsif ($item eq 'emailusername') {
1.228     raeburn  18635:             if (ref($cancreate{$item}) eq 'HASH') {
                   18636:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   18637:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   18638:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   18639:                             if ($cancreate{$item}{$type}{$field}) {
                   18640:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18641:                                     push(@{$changes{'cancreate'}},$item);
                   18642:                                 }
                   18643:                                 last;
                   18644:                             }
                   18645:                         }
                   18646:                     }
                   18647:                 }
1.224     raeburn  18648:             }
                   18649:         }
                   18650:     }
                   18651: #
                   18652: # Populate %save_usercreate hash with updates to self-creation configuration.
                   18653: #
                   18654:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   18655:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  18656:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  18657:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   18658:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   18659:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   18660:     }
1.236     raeburn  18661:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   18662:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   18663:     }
1.303     raeburn  18664:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   18665:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   18666:     }
1.305     raeburn  18667:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   18668:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   18669:     }
1.303     raeburn  18670:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   18671:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   18672:     }
1.224     raeburn  18673:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   18674:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   18675:     }
1.240     raeburn  18676:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   18677:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   18678:     }
1.224     raeburn  18679:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  18680:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  18681: 
                   18682:     my %userconfig_hash = (
                   18683:             usercreation     => \%save_usercreate,
                   18684:             usermodification => \%save_usermodify,
1.305     raeburn  18685:             inststatus       => \%save_inststatus,
1.224     raeburn  18686:     );
1.305     raeburn  18687: 
1.224     raeburn  18688:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   18689:                                              $dom);
                   18690: #
1.305     raeburn  18691: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  18692: #
1.27      raeburn  18693:     if ($putresult eq 'ok') {
                   18694:         if (keys(%changes) > 0) {
                   18695:             $resulttext = &mt('Changes made:').'<ul>';
                   18696:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  18697:                 my %lt = &selfcreation_types();
1.34      raeburn  18698:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  18699:                     my $chgtext = '';
1.45      raeburn  18700:                     if ($type eq 'selfcreate') {
1.50      raeburn  18701:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  18702:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  18703:                         } else {
1.224     raeburn  18704:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   18705:                                         '<ul>';
1.50      raeburn  18706:                             foreach my $case (@{$cancreate{$type}}) {
                   18707:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   18708:                             }
                   18709:                             $chgtext .= '</ul>';
1.100     raeburn  18710:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   18711:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   18712:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   18713:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  18714:                                             $chgtext .= '<span class="LC_warning">'.
                   18715:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   18716:                                                         '</span><br />';
                   18717:                                         }
                   18718:                                     }
                   18719:                                 }
                   18720:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  18721:                                     if (!@statuses) {
                   18722:                                         $chgtext .= '<span class="LC_warning">'.
                   18723:                                                     &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.").
                   18724:                                                     '</span><br />';
1.303     raeburn  18725: 
1.100     raeburn  18726:                                     }
                   18727:                                 }
                   18728:                             }
1.43      raeburn  18729:                         }
1.240     raeburn  18730:                     } elsif ($type eq 'shibenv') {
                   18731:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  18732:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  18733:                         } else {
                   18734:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   18735:                                         '<ul>';
                   18736:                             foreach my $field (@shibfields) {
                   18737:                                 next if ($cancreate{$type}{$field} eq '');
                   18738:                                 if ($field eq 'inststatus') {
                   18739:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   18740:                                 } else {
                   18741:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   18742:                                 }
                   18743:                             }
                   18744:                             $chgtext .= '</ul>';
1.303     raeburn  18745:                         }
1.93      raeburn  18746:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  18747:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   18748:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   18749:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   18750:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  18751:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  18752:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  18753:                                         $chgtext .= '<br />'.
                   18754:                                                     '<span class="LC_warning">'.
                   18755:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   18756:                                                     '</span>';
                   18757:                                     }
1.303     raeburn  18758:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  18759:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  18760:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   18761:                                     } else {
                   18762:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   18763:                                     }
                   18764:                                     $chgtext .= '<ul>';
                   18765:                                     foreach my $case (@{$cancreate{$type}}) {
                   18766:                                         if ($case eq 'default') {
                   18767:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   18768:                                         } else {
1.303     raeburn  18769:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  18770:                                         }
                   18771:                                     }
1.100     raeburn  18772:                                     $chgtext .= '</ul>';
                   18773:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  18774:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  18775:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   18776:                                                     '</span>';
1.100     raeburn  18777:                                     }
                   18778:                                 }
                   18779:                             } else {
                   18780:                                 if (@{$cancreate{$type}} == 0) {
                   18781:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   18782:                                 } else {
                   18783:                                     $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  18784:                                 }
                   18785:                             }
1.303     raeburn  18786:                             $chgtext .= '<br />';
1.93      raeburn  18787:                         }
1.236     raeburn  18788:                     } elsif ($type eq 'selfcreateprocessing') {
                   18789:                         my %choices = &Apache::lonlocal::texthash (
                   18790:                                                                     automatic => 'Automatic approval',
                   18791:                                                                     approval  => 'Queued for approval',
                   18792:                                                                   );
1.305     raeburn  18793:                         if (@types) {
                   18794:                             if (@statuses) {
1.303     raeburn  18795:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
1.309     raeburn  18796:                                             '<ul>';
1.305     raeburn  18797:                                 foreach my $status (@statuses) {
                   18798:                                     if ($status eq 'default') {
                   18799:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  18800:                                     } else {
1.305     raeburn  18801:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  18802:                                     }
                   18803:                                 }
                   18804:                                 $chgtext .= '</ul>';
                   18805:                             }
                   18806:                         } else {
                   18807:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   18808:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   18809:                         }
                   18810:                     } elsif ($type eq 'emailverified') {
                   18811:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  18812:                                                                     all   => 'Same as e-mail',
                   18813:                                                                     first => 'Omit @domain',
                   18814:                                                                     free  => 'Free to choose',
1.303     raeburn  18815:                                                                   );
1.305     raeburn  18816:                         if (@types) {
                   18817:                             if (@statuses) {
1.303     raeburn  18818:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   18819:                                             '<ul>';
1.305     raeburn  18820:                                 foreach my $status (@statuses) {
1.362     raeburn  18821:                                     if ($status eq 'default') {
1.305     raeburn  18822:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  18823:                                     } else {
1.305     raeburn  18824:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  18825:                                     }
                   18826:                                 }
                   18827:                                 $chgtext .= '</ul>';
                   18828:                             }
                   18829:                         } else {
1.305     raeburn  18830:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  18831:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  18832:                         }
1.305     raeburn  18833:                     } elsif ($type eq 'emailoptions') {
                   18834:                         my %options = &Apache::lonlocal::texthash (
                   18835:                                                                     any     => 'Any e-mail',
                   18836:                                                                     inst    => 'Institutional only',
                   18837:                                                                     noninst => 'Non-institutional only',
                   18838:                                                                     custom  => 'Custom restrictions',
                   18839:                                                                   );
                   18840:                         if (@types) {
                   18841:                             if (@statuses) {
                   18842:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   18843:                                             '<ul>';
                   18844:                                 foreach my $status (@statuses) {
                   18845:                                     if ($type eq 'default') {
                   18846:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   18847:                                     } else {
                   18848:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  18849:                                     }
                   18850:                                 }
1.305     raeburn  18851:                                 $chgtext .= '</ul>';
                   18852:                             }
                   18853:                         } else {
                   18854:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   18855:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   18856:                             } else {
                   18857:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   18858:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  18859:                             }
1.305     raeburn  18860:                         }
                   18861:                     } elsif ($type eq 'emaildomain') {
                   18862:                         my $output;
                   18863:                         if (@statuses) {
                   18864:                             foreach my $type (@statuses) {
                   18865:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   18866:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   18867:                                         if ($type eq 'default') {
                   18868:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18869:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   18870:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18871:                                             } else {
                   18872:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   18873:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   18874:                                             }
1.303     raeburn  18875:                                         } else {
1.305     raeburn  18876:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18877:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   18878:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18879:                                             } else {
                   18880:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   18881:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                   18882:                                             }
1.303     raeburn  18883:                                         }
1.305     raeburn  18884:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   18885:                                         if ($type eq 'default') {
                   18886:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18887:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   18888:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18889:                                             } else {
                   18890:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   18891:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   18892:                                             }
1.303     raeburn  18893:                                         } else {
1.305     raeburn  18894:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18895:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   18896:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18897:                                             } else {
                   18898:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   18899:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                   18900:                                             }
1.303     raeburn  18901:                                         }
                   18902:                                     }
                   18903:                                 }
                   18904:                             }
1.305     raeburn  18905:                         }
                   18906:                         if ($output ne '') {
                   18907:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   18908:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  18909:                         }
1.165     raeburn  18910:                     } elsif ($type eq 'captcha') {
1.224     raeburn  18911:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  18912:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   18913:                         } else {
                   18914:                             my %captchas = &captcha_phrases();
1.224     raeburn  18915:                             if ($captchas{$savecaptcha{$type}}) {
                   18916:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  18917:                             } else {
1.210     raeburn  18918:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  18919:                             }
                   18920:                         }
                   18921:                     } elsif ($type eq 'recaptchakeys') {
                   18922:                         my ($privkey,$pubkey);
1.224     raeburn  18923:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   18924:                             $pubkey = $savecaptcha{$type}{'public'};
                   18925:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  18926:                         }
                   18927:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   18928:                         if (!$pubkey) {
                   18929:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   18930:                         } else {
                   18931:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   18932:                         }
                   18933:                         if (!$privkey) {
                   18934:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   18935:                         } else {
                   18936:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   18937:                         }
                   18938:                         $chgtext .= '</ul>';
1.269     raeburn  18939:                     } elsif ($type eq 'recaptchaversion') {
                   18940:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  18941:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  18942:                         }
1.224     raeburn  18943:                     } elsif ($type eq 'emailusername') {
                   18944:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  18945:                             if (@statuses) {
                   18946:                                 foreach my $type (@statuses) {
1.228     raeburn  18947:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   18948:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  18949:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  18950:                                                     '<ul>';
                   18951:                                             foreach my $field (@{$infofields}) {
                   18952:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   18953:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   18954:                                                 }
                   18955:                                             }
1.245     raeburn  18956:                                             $chgtext .= '</ul>';
                   18957:                                         } else {
1.303     raeburn  18958:                                             $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  18959:                                         }
                   18960:                                     } else {
1.303     raeburn  18961:                                         $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  18962:                                     }
                   18963:                                 }
                   18964:                             }
                   18965:                         }
                   18966:                     } elsif ($type eq 'notify') {
1.303     raeburn  18967:                         my $numapprove = 0;
1.224     raeburn  18968:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   18969:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   18970:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  18971:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   18972:                                     $numapprove ++;
1.224     raeburn  18973:                                 }
                   18974:                             }
1.43      raeburn  18975:                         }
1.303     raeburn  18976:                         unless ($numapprove) {
                   18977:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   18978:                         }
1.34      raeburn  18979:                     }
1.224     raeburn  18980:                     if ($chgtext) {
                   18981:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  18982:                     }
                   18983:                 }
                   18984:             }
1.305     raeburn  18985:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  18986:                 my ($emailrules,$emailruleorder) =
                   18987:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  18988:                 foreach my $type (@{$changes{'email_rule'}}) {
                   18989:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   18990:                         my $chgtext = '<ul>';
                   18991:                         foreach my $rule (@{$email_rule{$type}}) {
                   18992:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   18993:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   18994:                             }
                   18995:                         }
                   18996:                         $chgtext .= '</ul>';
1.310     raeburn  18997:                         my $typename;
1.305     raeburn  18998:                         if (@types) {
                   18999:                             if ($type eq 'default') {
                   19000:                                 $typename = $othertitle;
                   19001:                             } else {
                   19002:                                 $typename = $usertypes{$type};
                   19003:                             } 
                   19004:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   19005:                         }
                   19006:                         if (@{$email_rule{$type}} > 0) {
                   19007:                             $resulttext .= '<li>'.
                   19008:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   19009:                                                $usertypes{$type}).
                   19010:                                            $chgtext.
                   19011:                                            '</li>';
                   19012:                         } else {
                   19013:                             $resulttext .= '<li>'.
1.310     raeburn  19014:                                            &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  19015:                                            '</li>'.
1.310     raeburn  19016:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  19017:                         }
1.43      raeburn  19018:                     }
                   19019:                 }
1.305     raeburn  19020:             }
                   19021:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   19022:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   19023:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   19024:                         my $chgtext = '<ul>';
                   19025:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   19026:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   19027:                         }
                   19028:                         $chgtext .= '</ul>';
                   19029:                         $resulttext .= '<li>'.
                   19030:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   19031:                                           $chgtext.
                   19032:                                        '</li>';
                   19033:                     } else {
                   19034:                         $resulttext .= '<li>'.
                   19035:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   19036:                                        '</li>';
                   19037:                     }
1.43      raeburn  19038:                 }
                   19039:             }
1.224     raeburn  19040:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   19041:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   19042:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19043:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   19044:                     my $typename = $type;
1.303     raeburn  19045:                     if (keys(%usertypes) > 0) {
                   19046:                         if ($usertypes{$type} ne '') {
                   19047:                             $typename = $usertypes{$type};
1.224     raeburn  19048:                         }
                   19049:                     }
                   19050:                     my @modifiable;
                   19051:                     $resulttext .= '<li>'.
                   19052:                                     &mt('Self-creation of account by users with status: [_1]',
                   19053:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   19054:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   19055:                     foreach my $field (@fields) {
                   19056:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   19057:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  19058:                         }
                   19059:                     }
1.224     raeburn  19060:                     if (@modifiable > 0) {
                   19061:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  19062:                     } else {
1.224     raeburn  19063:                         $resulttext .= &mt('none');
1.43      raeburn  19064:                     }
1.224     raeburn  19065:                     $resulttext .= '</li>';
1.28      raeburn  19066:                 }
1.224     raeburn  19067:                 $resulttext .= '</ul></li>';
1.28      raeburn  19068:             }
1.27      raeburn  19069:             $resulttext .= '</ul>';
1.305     raeburn  19070:             my $cachetime = 24*60*60;
                   19071:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   19072:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   19073:             if (ref($lastactref) eq 'HASH') {
                   19074:                 $lastactref->{'domdefaults'} = 1;
                   19075:             }
1.27      raeburn  19076:         } else {
1.224     raeburn  19077:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  19078:         }
                   19079:     } else {
                   19080:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  19081:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19082:     }
1.43      raeburn  19083:     if ($warningmsg ne '') {
                   19084:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   19085:     }
1.23      raeburn  19086:     return $resulttext;
                   19087: }
                   19088: 
1.165     raeburn  19089: sub process_captcha {
1.369     raeburn  19090:     my ($container,$changes,$newsettings,$currsettings) = @_;
                   19091:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165     raeburn  19092:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   19093:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   19094:         $newsettings->{'captcha'} = 'original';
                   19095:     }
1.369     raeburn  19096:     my %current;
                   19097:     if (ref($currsettings) eq 'HASH') {
                   19098:         %current = %{$currsettings};
                   19099:     }
                   19100:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  19101:         if ($container eq 'cancreate') {
1.169     raeburn  19102:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19103:                 push(@{$changes->{'cancreate'}},'captcha');
                   19104:             } elsif (!defined($changes->{'cancreate'})) {
                   19105:                 $changes->{'cancreate'} = ['captcha'];
                   19106:             }
1.368     raeburn  19107:         } elsif ($container eq 'passwords') {
                   19108:             $changes->{'reset'} = 1;
1.169     raeburn  19109:         } else {
                   19110:             $changes->{'captcha'} = 1;
1.165     raeburn  19111:         }
                   19112:     }
1.269     raeburn  19113:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  19114:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   19115:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   19116:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  19117:         $newpub =~ s/[^\w\-]//g;
                   19118:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  19119:         $newsettings->{'recaptchakeys'} = {
                   19120:                                              public  => $newpub,
                   19121:                                              private => $newpriv,
                   19122:                                           };
1.269     raeburn  19123:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   19124:         $newversion =~ s/\D//g;
                   19125:         if ($newversion ne '2') {
                   19126:             $newversion = 1;
                   19127:         }
                   19128:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  19129:     }
1.369     raeburn  19130:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   19131:         $currpub = $current{'recaptchakeys'}{'public'};
                   19132:         $currpriv = $current{'recaptchakeys'}{'private'};
1.179     raeburn  19133:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   19134:             $newsettings->{'recaptchakeys'} = {
                   19135:                                                  public  => '',
                   19136:                                                  private => '',
                   19137:                                               }
                   19138:         }
1.165     raeburn  19139:     }
1.369     raeburn  19140:     if ($current{'captcha'} eq 'recaptcha') {
                   19141:         $currversion = $current{'recaptchaversion'};
1.269     raeburn  19142:         if ($currversion ne '2') {
                   19143:             $currversion = 1;
                   19144:         }
                   19145:     }
                   19146:     if ($currversion ne $newversion) {
                   19147:         if ($container eq 'cancreate') {
                   19148:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19149:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   19150:             } elsif (!defined($changes->{'cancreate'})) {
                   19151:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   19152:             }
1.368     raeburn  19153:         } elsif ($container eq 'passwords') {
                   19154:             $changes->{'reset'} = 1;
1.269     raeburn  19155:         } else {
                   19156:             $changes->{'recaptchaversion'} = 1;
                   19157:         }
                   19158:     }
1.165     raeburn  19159:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  19160:         if ($container eq 'cancreate') {
                   19161:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19162:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   19163:             } elsif (!defined($changes->{'cancreate'})) {
                   19164:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   19165:             }
1.368     raeburn  19166:         } elsif ($container eq 'passwords') {
                   19167:             $changes->{'reset'} = 1;
1.169     raeburn  19168:         } else {
1.210     raeburn  19169:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  19170:         }
                   19171:     }
                   19172:     return;
                   19173: }
                   19174: 
1.33      raeburn  19175: sub modify_usermodification {
                   19176:     my ($dom,%domconfig) = @_;
1.224     raeburn  19177:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  19178:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   19179:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  19180:             if ($key eq 'selfcreate') {
                   19181:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   19182:             } else {  
                   19183:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   19184:             }
1.33      raeburn  19185:         }
                   19186:     }
1.224     raeburn  19187:     my @contexts = ('author','course');
1.33      raeburn  19188:     my %context_title = (
                   19189:                            author => 'In author context',
                   19190:                            course => 'In course context',
                   19191:                         );
                   19192:     my @fields = ('lastname','firstname','middlename','generation',
                   19193:                   'permanentemail','id');
                   19194:     my %roles = (
                   19195:                   author => ['ca','aa'],
                   19196:                   course => ['st','ep','ta','in','cr'],
                   19197:                 );
                   19198:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19199:     foreach my $context (@contexts) {
                   19200:         foreach my $role (@{$roles{$context}}) {
                   19201:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   19202:             foreach my $item (@fields) {
                   19203:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   19204:                     $modifyhash{$context}{$role}{$item} = 1;
                   19205:                 } else {
                   19206:                     $modifyhash{$context}{$role}{$item} = 0;
                   19207:                 }
                   19208:             }
                   19209:         }
                   19210:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   19211:             foreach my $role (@{$roles{$context}}) {
                   19212:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   19213:                     foreach my $field (@fields) {
                   19214:                         if ($modifyhash{$context}{$role}{$field} ne 
                   19215:                                 $curr_usermodification{$context}{$role}{$field}) {
                   19216:                             push(@{$changes{$context}},$role);
                   19217:                             last;
                   19218:                         }
                   19219:                     }
                   19220:                 }
                   19221:             }
                   19222:         } else {
                   19223:             foreach my $context (@contexts) {
                   19224:                 foreach my $role (@{$roles{$context}}) {
                   19225:                     push(@{$changes{$context}},$role);
                   19226:                 }
                   19227:             }
                   19228:         }
                   19229:     }
                   19230:     my %usermodification_hash =  (
                   19231:                                    usermodification => \%modifyhash,
                   19232:                                  );
                   19233:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   19234:                                              \%usermodification_hash,$dom);
                   19235:     if ($putresult eq 'ok') {
                   19236:         if (keys(%changes) > 0) {
                   19237:             $resulttext = &mt('Changes made: ').'<ul>';
                   19238:             foreach my $context (@contexts) {
                   19239:                 if (ref($changes{$context}) eq 'ARRAY') {
                   19240:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   19241:                     if (ref($changes{$context}) eq 'ARRAY') {
                   19242:                         foreach my $role (@{$changes{$context}}) {
                   19243:                             my $rolename;
1.224     raeburn  19244:                             if ($role eq 'cr') {
                   19245:                                 $rolename = &mt('Custom');
1.33      raeburn  19246:                             } else {
1.224     raeburn  19247:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  19248:                             }
                   19249:                             my @modifiable;
1.224     raeburn  19250:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  19251:                             foreach my $field (@fields) {
                   19252:                                 if ($modifyhash{$context}{$role}{$field}) {
                   19253:                                     push(@modifiable,$fieldtitles{$field});
                   19254:                                 }
                   19255:                             }
                   19256:                             if (@modifiable > 0) {
                   19257:                                 $resulttext .= join(', ',@modifiable);
                   19258:                             } else {
                   19259:                                 $resulttext .= &mt('none'); 
                   19260:                             }
                   19261:                             $resulttext .= '</li>';
                   19262:                         }
                   19263:                         $resulttext .= '</ul></li>';
                   19264:                     }
                   19265:                 }
                   19266:             }
                   19267:             $resulttext .= '</ul>';
                   19268:         } else {
                   19269:             $resulttext = &mt('No changes made to user modification settings');
                   19270:         }
                   19271:     } else {
                   19272:         $resulttext = '<span class="LC_error">'.
                   19273:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19274:     }
                   19275:     return $resulttext;
                   19276: }
                   19277: 
1.43      raeburn  19278: sub modify_defaults {
1.212     raeburn  19279:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  19280:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  19281:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  19282:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354     raeburn  19283:                  'portal_def');
1.325     raeburn  19284:     my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43      raeburn  19285:     foreach my $item (@items) {
                   19286:         $newvalues{$item} = $env{'form.'.$item};
                   19287:         if ($item eq 'auth_def') {
                   19288:             if ($newvalues{$item} ne '') {
                   19289:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   19290:                     push(@errors,$item);
                   19291:                 }
                   19292:             }
                   19293:         } elsif ($item eq 'lang_def') {
                   19294:             if ($newvalues{$item} ne '') {
                   19295:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   19296:                     my $langcode = $1;
1.103     raeburn  19297:                     if ($langcode ne 'x_chef') {
                   19298:                         if (code2language($langcode) eq '') {
                   19299:                             push(@errors,$item);
                   19300:                         }
1.43      raeburn  19301:                     }
                   19302:                 } else {
                   19303:                     push(@errors,$item);
                   19304:                 }
                   19305:             }
1.54      raeburn  19306:         } elsif ($item eq 'timezone_def') {
                   19307:             if ($newvalues{$item} ne '') {
1.62      raeburn  19308:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  19309:                     push(@errors,$item);   
                   19310:                 }
                   19311:             }
1.68      raeburn  19312:         } elsif ($item eq 'datelocale_def') {
                   19313:             if ($newvalues{$item} ne '') {
                   19314:                 my @datelocale_ids = DateTime::Locale->ids();
                   19315:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   19316:                     push(@errors,$item);
                   19317:                 }
                   19318:             }
1.141     raeburn  19319:         } elsif ($item eq 'portal_def') {
                   19320:             if ($newvalues{$item} ne '') {
                   19321:                 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])\/?$/) {
                   19322:                     push(@errors,$item);
                   19323:                 }
                   19324:             }
1.43      raeburn  19325:         }
                   19326:         if (grep(/^\Q$item\E$/,@errors)) {
                   19327:             $newvalues{$item} = $domdefaults{$item};
                   19328:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   19329:             $changes{$item} = 1;
                   19330:         }
1.72      raeburn  19331:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  19332:     }
1.354     raeburn  19333:     my %staticdefaults = (
                   19334:                            'intauth_cost'   => 10,
                   19335:                            'intauth_check'  => 0,
                   19336:                            'intauth_switch' => 0,
                   19337:                          );
                   19338:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   19339:         if (exists($domdefaults{$item})) {
                   19340:             $newvalues{$item} = $domdefaults{$item};
                   19341:         } else {
                   19342:             $newvalues{$item} = $staticdefaults{$item};
                   19343:         }
                   19344:     }
1.43      raeburn  19345:     my %defaults_hash = (
1.72      raeburn  19346:                          defaults => \%newvalues,
                   19347:                         );
1.43      raeburn  19348:     my $title = &defaults_titles();
1.236     raeburn  19349: 
                   19350:     my $currinststatus;
                   19351:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   19352:         $currinststatus = $domconfig{'inststatus'};
                   19353:     } else {
                   19354:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   19355:         $currinststatus = {
                   19356:                              inststatustypes => $usertypes,
                   19357:                              inststatusorder => $types,
                   19358:                              inststatusguest => [],
                   19359:                           };
                   19360:     }
                   19361:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   19362:     my @allpos;
                   19363:     my %alltypes;
1.305     raeburn  19364:     my @inststatusguest;
                   19365:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   19366:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   19367:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   19368:                 push(@inststatusguest,$type);
                   19369:             }
                   19370:         }
                   19371:     }
                   19372:     my ($currtitles,$currorder);
1.236     raeburn  19373:     if (ref($currinststatus) eq 'HASH') {
                   19374:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   19375:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   19376:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   19377:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   19378:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   19379:                     }
                   19380:                 }
                   19381:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   19382:                     my $position = $env{'form.inststatus_pos_'.$type};
                   19383:                     $position =~ s/\D+//g;
                   19384:                     $allpos[$position] = $type;
                   19385:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   19386:                     $alltypes{$type} =~ s/`//g;
                   19387:                 }
                   19388:             }
                   19389:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   19390:             $currtitles =~ s/,$//;
                   19391:         }
                   19392:     }
                   19393:     if ($env{'form.addinststatus'}) {
                   19394:         my $newtype = $env{'form.addinststatus'};
                   19395:         $newtype =~ s/\W//g;
                   19396:         unless (exists($alltypes{$newtype})) {
                   19397:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   19398:             $alltypes{$newtype} =~ s/`//g; 
                   19399:             my $position = $env{'form.addinststatus_pos'};
                   19400:             $position =~ s/\D+//g;
                   19401:             if ($position ne '') {
                   19402:                 $allpos[$position] = $newtype;
                   19403:             }
                   19404:         }
                   19405:     }
1.305     raeburn  19406:     my @orderedstatus;
1.236     raeburn  19407:     foreach my $type (@allpos) {
                   19408:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   19409:             push(@orderedstatus,$type);
                   19410:         }
                   19411:     }
                   19412:     foreach my $type (keys(%alltypes)) {
                   19413:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   19414:             delete($alltypes{$type});
                   19415:         }
                   19416:     }
                   19417:     $defaults_hash{'inststatus'} = {
                   19418:                                      inststatustypes => \%alltypes,
                   19419:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  19420:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  19421:                                    };
                   19422:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   19423:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   19424:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   19425:         }
                   19426:     }
                   19427:     if ($currorder ne join(',',@orderedstatus)) {
                   19428:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   19429:     }
                   19430:     my $newtitles;
                   19431:     foreach my $item (@orderedstatus) {
                   19432:         $newtitles .= $alltypes{$item}.',';
                   19433:     }
                   19434:     $newtitles =~ s/,$//;
                   19435:     if ($currtitles ne $newtitles) {
                   19436:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   19437:     }
1.43      raeburn  19438:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   19439:                                              $dom);
                   19440:     if ($putresult eq 'ok') {
                   19441:         if (keys(%changes) > 0) {
                   19442:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  19443:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  19444:             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";
                   19445:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  19446:                 if ($item eq 'inststatus') {
                   19447:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  19448:                         if (@orderedstatus) {
1.236     raeburn  19449:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   19450:                             foreach my $type (@orderedstatus) { 
                   19451:                                 $resulttext .= $alltypes{$type}.', ';
                   19452:                             }
                   19453:                             $resulttext =~ s/, $//;
                   19454:                             $resulttext .= '</li>';
1.305     raeburn  19455:                         } else {
                   19456:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
1.236     raeburn  19457:                         }
                   19458:                     }
                   19459:                 } else {
                   19460:                     my $value = $env{'form.'.$item};
                   19461:                     if ($value eq '') {
                   19462:                         $value = &mt('none');
                   19463:                     } elsif ($item eq 'auth_def') {
                   19464:                         my %authnames = &authtype_names();
                   19465:                         my %shortauth = (
                   19466:                                           internal   => 'int',
                   19467:                                           krb4       => 'krb4',
                   19468:                                           krb5       => 'krb5',
                   19469:                                           localauth  => 'loc',
1.325     raeburn  19470:                                           lti        => 'lti',
1.236     raeburn  19471:                         );
                   19472:                         $value = $authnames{$shortauth{$value}};
                   19473:                     }
                   19474:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   19475:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  19476:                 }
                   19477:             }
                   19478:             $resulttext .= '</ul>';
                   19479:             $mailmsgtext .= "\n";
                   19480:             my $cachetime = 24*60*60;
1.72      raeburn  19481:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  19482:             if (ref($lastactref) eq 'HASH') {
                   19483:                 $lastactref->{'domdefaults'} = 1;
                   19484:             }
1.68      raeburn  19485:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  19486:                 my $notify = 1;
                   19487:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   19488:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   19489:                         $notify = 0;
                   19490:                     }
                   19491:                 }
                   19492:                 if ($notify) {
                   19493:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   19494:                                                "LON-CAPA Domain Settings Change - $dom",
                   19495:                                                $mailmsgtext);
                   19496:                 }
1.54      raeburn  19497:             }
1.43      raeburn  19498:         } else {
1.54      raeburn  19499:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  19500:         }
                   19501:     } else {
                   19502:         $resulttext = '<span class="LC_error">'.
                   19503:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19504:     }
                   19505:     if (@errors > 0) {
                   19506:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   19507:         foreach my $item (@errors) {
                   19508:             $resulttext .= ' "'.$title->{$item}.'",';
                   19509:         }
                   19510:         $resulttext =~ s/,$//;
                   19511:     }
                   19512:     return $resulttext;
                   19513: }
                   19514: 
1.46      raeburn  19515: sub modify_scantron {
1.205     raeburn  19516:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  19517:     my ($resulttext,%confhash,%changes,$errors);
                   19518:     my $custom = 'custom.tab';
                   19519:     my $default = 'default.tab';
                   19520:     my $servadm = $r->dir_config('lonAdmEMail');
1.346     raeburn  19521:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  19522:         &config_check($dom,$confname,$servadm);
                   19523:     if ($env{'form.scantronformat.filename'} ne '') {
                   19524:         my $error;
                   19525:         if ($configuserok eq 'ok') {
                   19526:             if ($switchserver) {
1.130     raeburn  19527:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  19528:             } else {
                   19529:                 if ($author_ok eq 'ok') {
                   19530:                     my ($result,$scantronurl) =
                   19531:                         &publishlogo($r,'upload','scantronformat',$dom,
                   19532:                                      $confname,'scantron','','',$custom);
                   19533:                     if ($result eq 'ok') {
                   19534:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  19535:                         $changes{'scantronformat'} = 1;
1.46      raeburn  19536:                     } else {
                   19537:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   19538:                     }
                   19539:                 } else {
                   19540:                     $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);
                   19541:                 }
                   19542:             }
                   19543:         } else {
                   19544:             $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);
                   19545:         }
                   19546:         if ($error) {
                   19547:             &Apache::lonnet::logthis($error);
                   19548:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   19549:         }
                   19550:     }
1.48      raeburn  19551:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   19552:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   19553:             if ($env{'form.scantronformat_del'}) {
                   19554:                 $confhash{'scantron'}{'scantronformat'} = '';
                   19555:                 $changes{'scantronformat'} = 1;
1.347     raeburn  19556:             } else {
                   19557:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46      raeburn  19558:             }
                   19559:         }
                   19560:     }
1.347     raeburn  19561:     my @options = ('hdr','pad','rem');
1.346     raeburn  19562:     my @fields = &scantroncsv_fields();
                   19563:     my %titles = &scantronconfig_titles();
1.347     raeburn  19564:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346     raeburn  19565:     my ($newdat,$currdat,%newcol,%currcol);
                   19566:     if (grep(/^dat$/,@formats)) {
                   19567:         $confhash{'scantron'}{config}{dat} = 1;
                   19568:         $newdat = 1;
                   19569:     } else {
                   19570:         $newdat = 0;
                   19571:     }
                   19572:     if (grep(/^csv$/,@formats)) {
                   19573:         my %bynum;
                   19574:         foreach my $field (@fields) {
                   19575:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   19576:                 my $posscol = $1;
                   19577:                 if (($posscol < 20) && (!$bynum{$posscol})) {
1.347     raeburn  19578:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346     raeburn  19579:                     $bynum{$posscol} = $field;
                   19580:                     $newcol{$field} = $posscol;
                   19581:                 }
                   19582:             }
                   19583:         }
1.347     raeburn  19584:         if (keys(%newcol)) {
                   19585:             foreach my $option (@options) {
                   19586:                 if ($env{'form.scantroncsv_'.$option}) {
                   19587:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   19588:                 }
                   19589:             }
                   19590:         }
1.346     raeburn  19591:     }
                   19592:     $currdat = 1;
                   19593:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   19594:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347     raeburn  19595:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346     raeburn  19596:                 $currdat = 0;
                   19597:             }
                   19598:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  19599:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   19600:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   19601:                 }
1.346     raeburn  19602:             }
                   19603:         }
                   19604:     }
                   19605:     if ($currdat != $newdat) {
                   19606:         $changes{'config'} = 1;
                   19607:     } else {
                   19608:         foreach my $field (@fields) {
                   19609:             if ($currcol{$field} ne '') {
                   19610:                 if ($currcol{$field} ne $newcol{$field}) {
                   19611:                     $changes{'config'} = 1;
                   19612:                     last;
1.347     raeburn  19613:                 }
1.346     raeburn  19614:             } elsif ($newcol{$field} ne '') {
                   19615:                 $changes{'config'} = 1;
                   19616:                 last;
                   19617:             }
                   19618:         }
                   19619:     }
1.46      raeburn  19620:     if (keys(%confhash) > 0) {
                   19621:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   19622:                                                  $dom);
                   19623:         if ($putresult eq 'ok') {
                   19624:             if (keys(%changes) > 0) {
1.48      raeburn  19625:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   19626:                     $resulttext = &mt('Changes made:').'<ul>';
1.346     raeburn  19627:                     if ($changes{'scantronformat'}) {
                   19628:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   19629:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   19630:                         } else {
                   19631:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   19632:                         }
                   19633:                     }
1.347     raeburn  19634:                     if ($changes{'config'}) {
1.346     raeburn  19635:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   19636:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   19637:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   19638:                             }
                   19639:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  19640:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   19641:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   19642:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   19643:                                         foreach my $field (@fields) {
                   19644:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   19645:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   19646:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   19647:                                             }
                   19648:                                         }
                   19649:                                         $resulttext .= '</ul></li>';
                   19650:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   19651:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   19652:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   19653:                                                 foreach my $option (@options) {
                   19654:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   19655:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   19656:                                                     }
                   19657:                                                 }
                   19658:                                                 $resulttext .= '</ul></li>';
                   19659:                                             }
1.346     raeburn  19660:                                         }
                   19661:                                     }
                   19662:                                 }
                   19663:                             }
                   19664:                         } else {
                   19665:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   19666:                         }
1.46      raeburn  19667:                     }
1.48      raeburn  19668:                     $resulttext .= '</ul>';
                   19669:                 } else {
1.130     raeburn  19670:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  19671:                 }
                   19672:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  19673:                 if (ref($lastactref) eq 'HASH') {
                   19674:                     $lastactref->{'domainconfig'} = 1;
                   19675:                 }
1.46      raeburn  19676:             } else {
1.346     raeburn  19677:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  19678:             }
                   19679:         } else {
                   19680:             $resulttext = '<span class="LC_error">'.
                   19681:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   19682:         }
                   19683:     } else {
1.130     raeburn  19684:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  19685:     }
                   19686:     if ($errors) {
1.353     raeburn  19687:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   19688:                        $errors.'</ul></p>';
1.46      raeburn  19689:     }
                   19690:     return $resulttext;
                   19691: }
                   19692: 
1.48      raeburn  19693: sub modify_coursecategories {
1.239     raeburn  19694:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  19695:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   19696:         $cathash);
1.48      raeburn  19697:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  19698:     my @catitems = ('unauth','auth');
                   19699:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  19700:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  19701:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   19702:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   19703:             $changes{'togglecats'} = 1;
                   19704:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   19705:         }
                   19706:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   19707:             $changes{'categorize'} = 1;
                   19708:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   19709:         }
1.120     raeburn  19710:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   19711:             $changes{'togglecatscomm'} = 1;
                   19712:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   19713:         }
                   19714:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   19715:             $changes{'categorizecomm'} = 1;
                   19716:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  19717: 
                   19718:         }
                   19719:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   19720:             $changes{'togglecatsplace'} = 1;
                   19721:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   19722:         }
                   19723:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   19724:             $changes{'categorizeplace'} = 1;
                   19725:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  19726:         }
1.238     raeburn  19727:         foreach my $item (@catitems) {
                   19728:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   19729:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   19730:                     $changes{$item} = 1;
                   19731:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   19732:                 }
                   19733:             }
                   19734:         }
1.57      raeburn  19735:     } else {
                   19736:         $changes{'togglecats'} = 1;
                   19737:         $changes{'categorize'} = 1;
1.124     raeburn  19738:         $changes{'togglecatscomm'} = 1;
                   19739:         $changes{'categorizecomm'} = 1;
1.272     raeburn  19740:         $changes{'togglecatsplace'} = 1;
                   19741:         $changes{'categorizeplace'} = 1;
1.87      raeburn  19742:         $domconfig{'coursecategories'} = {
                   19743:                                              togglecats => $env{'form.togglecats'},
                   19744:                                              categorize => $env{'form.categorize'},
1.124     raeburn  19745:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   19746:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  19747:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   19748:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  19749:                                          };
1.238     raeburn  19750:         foreach my $item (@catitems) {
                   19751:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   19752:                 $changes{$item} = 1;
                   19753:             }
                   19754:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   19755:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   19756:             }
                   19757:         }
1.57      raeburn  19758:     }
                   19759:     if (ref($cathash) eq 'HASH') {
                   19760:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  19761:             push (@deletecategory,'instcode::0');
                   19762:         }
1.120     raeburn  19763:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   19764:             push(@deletecategory,'communities::0');
                   19765:         }
1.272     raeburn  19766:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   19767:             push(@deletecategory,'placement::0');
                   19768:         }
1.48      raeburn  19769:     }
1.57      raeburn  19770:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   19771:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  19772:         if (@deletecategory > 0) {
                   19773:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  19774:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  19775:             foreach my $item (@deletecategory) {
1.57      raeburn  19776:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   19777:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  19778:                     $deletions{$item} = 1;
1.57      raeburn  19779:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  19780:                 }
                   19781:             }
                   19782:         }
1.57      raeburn  19783:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  19784:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  19785:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  19786:                 $reorderings{$item} = 1;
1.57      raeburn  19787:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  19788:             }
                   19789:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   19790:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   19791:                 my $newdepth = $depth+1;
                   19792:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  19793:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  19794:                 $adds{$newitem} = 1; 
                   19795:             }
                   19796:             if ($env{'form.subcat_'.$item} ne '') {
                   19797:                 my $newcat = $env{'form.subcat_'.$item};
                   19798:                 my $newdepth = $depth+1;
                   19799:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  19800:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  19801:                 $adds{$newitem} = 1;
                   19802:             }
                   19803:         }
                   19804:     }
                   19805:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  19806:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  19807:             my $newitem = 'instcode::0';
1.57      raeburn  19808:             if ($cathash->{$newitem} eq '') {  
                   19809:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  19810:                 $adds{$newitem} = 1;
                   19811:             }
                   19812:         } else {
                   19813:             my $newitem = 'instcode::0';
1.57      raeburn  19814:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  19815:             $adds{$newitem} = 1;
                   19816:         }
                   19817:     }
1.120     raeburn  19818:     if ($env{'form.communities'} eq '1') {
                   19819:         if (ref($cathash) eq 'HASH') {
                   19820:             my $newitem = 'communities::0';
                   19821:             if ($cathash->{$newitem} eq '') {
                   19822:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   19823:                 $adds{$newitem} = 1;
                   19824:             }
                   19825:         } else {
                   19826:             my $newitem = 'communities::0';
                   19827:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   19828:             $adds{$newitem} = 1;
                   19829:         }
                   19830:     }
1.272     raeburn  19831:     if ($env{'form.placement'} eq '1') {
                   19832:         if (ref($cathash) eq 'HASH') {
                   19833:             my $newitem = 'placement::0';
                   19834:             if ($cathash->{$newitem} eq '') {
                   19835:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   19836:                 $adds{$newitem} = 1;
                   19837:             }
                   19838:         } else {
                   19839:             my $newitem = 'placement::0';
                   19840:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   19841:             $adds{$newitem} = 1;
                   19842:         }
                   19843:     }
1.48      raeburn  19844:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  19845:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  19846:             ($env{'form.addcategory_name'} ne 'communities') &&
                   19847:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  19848:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   19849:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   19850:             $adds{$newitem} = 1;
                   19851:         }
1.48      raeburn  19852:     }
1.57      raeburn  19853:     my $putresult;
1.48      raeburn  19854:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19855:         if (keys(%deletions) > 0) {
                   19856:             foreach my $key (keys(%deletions)) {
                   19857:                 if ($predelallitems{$key} ne '') {
                   19858:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   19859:                 }
                   19860:             }
                   19861:         }
                   19862:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  19863:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  19864:         if (ref($chkcats[0]) eq 'ARRAY') {
                   19865:             my $depth = 0;
                   19866:             my $chg = 0;
                   19867:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   19868:                 my $name = $chkcats[0][$i];
                   19869:                 my $item;
                   19870:                 if ($name eq '') {
                   19871:                     $chg ++;
                   19872:                 } else {
                   19873:                     $item = &escape($name).'::0';
                   19874:                     if ($chg) {
1.57      raeburn  19875:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  19876:                     }
                   19877:                     $depth ++; 
1.57      raeburn  19878:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  19879:                     $depth --;
                   19880:                 }
                   19881:             }
                   19882:         }
1.57      raeburn  19883:     }
                   19884:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19885:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  19886:         if ($putresult eq 'ok') {
1.57      raeburn  19887:             my %title = (
1.120     raeburn  19888:                          togglecats     => 'Show/Hide a course in catalog',
                   19889:                          categorize     => 'Assign a category to a course',
                   19890:                          togglecatscomm => 'Show/Hide a community in catalog',
                   19891:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  19892:                         );
                   19893:             my %level = (
1.120     raeburn  19894:                          dom  => 'set in Domain ("Modify Course/Community")',
                   19895:                          crs  => 'set in Course ("Course Configuration")',
                   19896:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  19897:                          none     => 'No catalog',
                   19898:                          std      => 'Standard catalog',
                   19899:                          domonly  => 'Domain-only catalog',
                   19900:                          codesrch => 'Code search form',
1.57      raeburn  19901:                         );
1.48      raeburn  19902:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  19903:             if ($changes{'togglecats'}) {
                   19904:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   19905:             }
                   19906:             if ($changes{'categorize'}) {
                   19907:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  19908:             }
1.120     raeburn  19909:             if ($changes{'togglecatscomm'}) {
                   19910:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   19911:             }
                   19912:             if ($changes{'categorizecomm'}) {
                   19913:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   19914:             }
1.238     raeburn  19915:             if ($changes{'unauth'}) {
                   19916:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   19917:             }
                   19918:             if ($changes{'auth'}) {
                   19919:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   19920:             }
1.57      raeburn  19921:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19922:                 my $cathash;
                   19923:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   19924:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   19925:                 } else {
                   19926:                     $cathash = {};
                   19927:                 } 
                   19928:                 my (@cats,@trails,%allitems);
                   19929:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   19930:                 if (keys(%deletions) > 0) {
                   19931:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   19932:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   19933:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   19934:                     }
                   19935:                     $resulttext .= '</ul></li>';
                   19936:                 }
                   19937:                 if (keys(%reorderings) > 0) {
                   19938:                     my %sort_by_trail;
                   19939:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   19940:                     foreach my $key (keys(%reorderings)) {
                   19941:                         if ($allitems{$key} ne '') {
                   19942:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   19943:                         }
1.48      raeburn  19944:                     }
1.57      raeburn  19945:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   19946:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   19947:                     }
                   19948:                     $resulttext .= '</ul></li>';
1.48      raeburn  19949:                 }
1.57      raeburn  19950:                 if (keys(%adds) > 0) {
                   19951:                     my %sort_by_trail;
                   19952:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   19953:                     foreach my $key (keys(%adds)) {
                   19954:                         if ($allitems{$key} ne '') {
                   19955:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   19956:                         }
                   19957:                     }
                   19958:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   19959:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  19960:                     }
1.57      raeburn  19961:                     $resulttext .= '</ul></li>';
1.48      raeburn  19962:                 }
1.364     raeburn  19963:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   19964:                 if (ref($lastactref) eq 'HASH') {
                   19965:                     $lastactref->{'cats'} = 1;
                   19966:                 }
1.48      raeburn  19967:             }
                   19968:             $resulttext .= '</ul>';
1.239     raeburn  19969:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  19970:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   19971:                 if ($changes{'auth'}) {
                   19972:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   19973:                 }
                   19974:                 if ($changes{'unauth'}) {
                   19975:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   19976:                 }
                   19977:                 my $cachetime = 24*60*60;
                   19978:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  19979:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  19980:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  19981:                 }
                   19982:             }
1.48      raeburn  19983:         } else {
                   19984:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  19985:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  19986:         }
                   19987:     } else {
1.120     raeburn  19988:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  19989:     }
                   19990:     return $resulttext;
                   19991: }
                   19992: 
1.69      raeburn  19993: sub modify_serverstatuses {
                   19994:     my ($dom,%domconfig) = @_;
                   19995:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   19996:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   19997:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   19998:     }
                   19999:     my @pages = &serverstatus_pages();
                   20000:     foreach my $type (@pages) {
                   20001:         $newserverstatus{$type}{'namedusers'} = '';
                   20002:         $newserverstatus{$type}{'machines'} = '';
                   20003:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   20004:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   20005:             my @okusers;
                   20006:             foreach my $user (@users) {
                   20007:                 my ($uname,$udom) = split(/:/,$user);
                   20008:                 if (($udom =~ /^$match_domain$/) &&   
                   20009:                     (&Apache::lonnet::domain($udom)) &&
                   20010:                     ($uname =~ /^$match_username$/)) {
                   20011:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   20012:                         push(@okusers,$user);
                   20013:                     }
                   20014:                 }
                   20015:             }
                   20016:             if (@okusers > 0) {
                   20017:                  @okusers = sort(@okusers);
                   20018:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   20019:             }
                   20020:         }
                   20021:         if (defined($env{'form.'.$type.'_machines'})) {
                   20022:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   20023:             my @okmachines;
                   20024:             foreach my $ip (@machines) {
                   20025:                 my @parts = split(/\./,$ip);
                   20026:                 next if (@parts < 4);
                   20027:                 my $badip = 0;
                   20028:                 for (my $i=0; $i<4; $i++) {
                   20029:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   20030:                         $badip = 1;
                   20031:                         last;
                   20032:                     }
                   20033:                 }
                   20034:                 if (!$badip) {
                   20035:                     push(@okmachines,$ip);     
                   20036:                 }
                   20037:             }
                   20038:             @okmachines = sort(@okmachines);
                   20039:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   20040:         }
                   20041:     }
                   20042:     my %serverstatushash =  (
                   20043:                                 serverstatuses => \%newserverstatus,
                   20044:                             );
                   20045:     foreach my $type (@pages) {
1.83      raeburn  20046:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  20047:             my (@current,@new);
1.83      raeburn  20048:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  20049:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   20050:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   20051:                 }
                   20052:             }
                   20053:             if ($newserverstatus{$type}{$setting} ne '') {
                   20054:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  20055:             }
                   20056:             if (@current > 0) {
                   20057:                 if (@new > 0) {
                   20058:                     foreach my $item (@current) {
                   20059:                         if (!grep(/^\Q$item\E$/,@new)) {
                   20060:                             $changes{$type}{$setting} = 1;
1.82      raeburn  20061:                             last;
                   20062:                         }
                   20063:                     }
1.84      raeburn  20064:                     foreach my $item (@new) {
                   20065:                         if (!grep(/^\Q$item\E$/,@current)) {
                   20066:                             $changes{$type}{$setting} = 1;
                   20067:                             last;
1.82      raeburn  20068:                         }
                   20069:                     }
                   20070:                 } else {
1.83      raeburn  20071:                     $changes{$type}{$setting} = 1;
1.69      raeburn  20072:                 }
1.83      raeburn  20073:             } elsif (@new > 0) {
                   20074:                 $changes{$type}{$setting} = 1;
1.69      raeburn  20075:             }
                   20076:         }
                   20077:     }
                   20078:     if (keys(%changes) > 0) {
1.81      raeburn  20079:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  20080:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   20081:                                                  \%serverstatushash,$dom);
                   20082:         if ($putresult eq 'ok') {
                   20083:             $resulttext .= &mt('Changes made:').'<ul>';
                   20084:             foreach my $type (@pages) {
1.84      raeburn  20085:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  20086:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  20087:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  20088:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   20089:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   20090:                         } else {
                   20091:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   20092:                         }
1.84      raeburn  20093:                     }
                   20094:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  20095:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   20096:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   20097:                         } else {
                   20098:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   20099:                         }
                   20100: 
                   20101:                     }
                   20102:                     $resulttext .= '</ul></li>';
                   20103:                 }
                   20104:             }
                   20105:             $resulttext .= '</ul>';
                   20106:         } else {
                   20107:             $resulttext = '<span class="LC_error">'.
                   20108:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   20109: 
                   20110:         }
                   20111:     } else {
                   20112:         $resulttext = &mt('No changes made to access to server status pages');
                   20113:     }
                   20114:     return $resulttext;
                   20115: }
                   20116: 
1.118     jms      20117: sub modify_helpsettings {
1.285     raeburn  20118:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  20119:     my ($resulttext,$errors,%changes,%helphash);
                   20120:     my %defaultchecked = ('submitbugs' => 'on');
                   20121:     my @offon = ('off','on');
1.118     jms      20122:     my @toggles = ('submitbugs');
1.285     raeburn  20123:     my %current = ('submitbugs' => '',
                   20124:                    'adhoc'      => {},
                   20125:                   );
1.118     jms      20126:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  20127:         %current = %{$domconfig{'helpsettings'}};
                   20128:     }
1.285     raeburn  20129:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  20130:     foreach my $item (@toggles) {
                   20131:         if ($defaultchecked{$item} eq 'on') { 
                   20132:             if ($current{$item} eq '') {
                   20133:                 if ($env{'form.'.$item} eq '0') {
                   20134:                     $changes{$item} = 1;
                   20135:                 }
                   20136:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   20137:                 $changes{$item} = 1;
                   20138:             }
                   20139:         } elsif ($defaultchecked{$item} eq 'off') {
                   20140:             if ($current{$item} eq '') {
                   20141:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  20142:                     $changes{$item} = 1;
                   20143:                 }
1.282     raeburn  20144:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   20145:                 $changes{$item} = 1;
                   20146:             }
                   20147:         }
                   20148:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   20149:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   20150:         }
                   20151:     }
1.285     raeburn  20152:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  20153:     my $confname = $dom.'-domainconfig';
                   20154:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  20155:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   20156:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  20157:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  20158:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  20159:     my %lt = &Apache::lonlocal::texthash(
                   20160:                     s      => 'system',
                   20161:                     d      => 'domain',
                   20162:                     order  => 'Display order',
                   20163:                     access => 'Role usage',
1.291     raeburn  20164:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  20165:                     dh     => 'All with domain helpdesk role',
                   20166:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  20167:                     none   => 'None',
                   20168:                     status => 'Determined based on institutional status',
                   20169:                     inc    => 'Include all, but exclude specific personnel',
                   20170:                     exc    => 'Exclude all, but include specific personnel',
                   20171:     );
                   20172:     for (my $num=0; $num<=$maxnum; $num++) {
                   20173:         my ($prefix,$identifier,$rolename,%curr);
                   20174:         if ($num == $maxnum) {
                   20175:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   20176:             $identifier = 'custhelp'.$num;
                   20177:             $prefix = 'helproles_'.$num;
                   20178:             $rolename = $env{'form.custhelpname'.$num};
                   20179:             $rolename=~s/[^A-Za-z0-9]//gs;
                   20180:             next if ($rolename eq '');
                   20181:             next if (exists($existing{'rolesdef_'.$rolename}));
                   20182:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20183:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20184:                                                      $newprivs{'c'},$confname,$dom);
                   20185:             if ($result ne 'ok') {
                   20186:                 $errors .= '<li><span class="LC_error">'.
                   20187:                            &mt('An error occurred storing the new custom role: [_1]',
                   20188:                            $result).'</span></li>';
                   20189:                 next;
                   20190:             } else {
                   20191:                 $changedprivs{$rolename} = \%newprivs;
                   20192:                 $newrole = $rolename;
                   20193:             }
                   20194:         } else {
                   20195:             $prefix = 'helproles_'.$num;
                   20196:             $rolename = $env{'form.'.$prefix};
                   20197:             next if ($rolename eq '');
                   20198:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   20199:             $identifier = 'custhelp'.$num;
                   20200:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20201:             my %currprivs;
1.289     raeburn  20202:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  20203:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   20204:             foreach my $level ('c','d','s') {
                   20205:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   20206:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20207:                                                              $newprivs{'c'},$confname,$dom);
                   20208:                     if ($result ne 'ok') {
                   20209:                         $errors .= '<li><span class="LC_error">'.
                   20210:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   20211:                                        $rolename,$result).'</span></li>';
                   20212:                     } else {
                   20213:                         $changedprivs{$rolename} = \%newprivs;
                   20214:                     }
                   20215:                     last;
                   20216:                 }
                   20217:             }
                   20218:             if (ref($current{'adhoc'}) eq 'HASH') {
                   20219:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   20220:                     %curr = %{$current{'adhoc'}{$rolename}};
                   20221:                 }
                   20222:             }
                   20223:         }
                   20224:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   20225:         $newpos =~ s/\D+//g;
                   20226:         $allpos[$newpos] = $rolename;
                   20227:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   20228:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   20229:         if ($curr{'desc'}) {
                   20230:             if ($curr{'desc'} ne $newdesc) {
                   20231:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   20232:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   20233:             }
                   20234:         } elsif ($newdesc ne '') {
                   20235:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   20236:             $newsettings{$rolename}{'desc'} = $newdesc;
                   20237:         }
                   20238:         my $access = $env{'form.'.$prefix.'_access'};
                   20239:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   20240:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   20241:             if ($access eq 'status') {
                   20242:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   20243:                 if (scalar(@statuses) == 0) {
1.289     raeburn  20244:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  20245:                 } else {
                   20246:                     my (@shownstatus,$numtypes);
                   20247:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   20248:                     if (ref($types) eq 'ARRAY') {
                   20249:                         $numtypes = scalar(@{$types});
                   20250:                         foreach my $type (sort(@statuses)) {
                   20251:                             if ($type eq 'default') {
                   20252:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   20253:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   20254:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   20255:                                 push(@shownstatus,$usertypes->{$type});
                   20256:                             }
                   20257:                         }
                   20258:                     }
                   20259:                     if (grep(/^default$/,@statuses)) {
                   20260:                         push(@shownstatus,$othertitle);
                   20261:                     }
                   20262:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   20263:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   20264:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   20265:                     } else {
                   20266:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   20267:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   20268:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   20269:                             if (@diffs) {
                   20270:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   20271:                             }
                   20272:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20273:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  20274:                         }
1.166     raeburn  20275:                     }
                   20276:                 }
1.285     raeburn  20277:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   20278:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   20279:                 my @newspecstaff;
                   20280:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   20281:                 foreach my $person (sort(@personnel)) {
                   20282:                     if ($domhelpdesk{$person}) {
                   20283:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   20284:                     }
                   20285:                 }
                   20286:                 if (ref($curr{$access}) eq 'ARRAY') {
                   20287:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   20288:                     if (@diffs) {
                   20289:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   20290:                     }
                   20291:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20292:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   20293:                 }
                   20294:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20295:                     my ($uname,$udom) = split(/:/,$person);
                   20296:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   20297:                 }
                   20298:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  20299:             }
1.285     raeburn  20300:         } else {
                   20301:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   20302:         }
                   20303:         unless ($curr{'access'} eq $access) {
                   20304:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   20305:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  20306:         }
                   20307:     }
1.285     raeburn  20308:     if (@allpos > 0) {
                   20309:         my $idx = 0;
                   20310:         foreach my $rolename (@allpos) {
                   20311:             if ($rolename ne '') {
                   20312:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   20313:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   20314:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   20315:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   20316:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  20317:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  20318:                         }
                   20319:                     }
1.282     raeburn  20320:                 }
1.285     raeburn  20321:                 $idx ++;
1.166     raeburn  20322:             }
                   20323:         }
1.118     jms      20324:     }
1.123     jms      20325:     my $putresult;
                   20326:     if (keys(%changes) > 0) {
1.166     raeburn  20327:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  20328:         if ($putresult eq 'ok') {
1.285     raeburn  20329:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   20330:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   20331:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   20332:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   20333:                 }
                   20334:             }
                   20335:             my $cachetime = 24*60*60;
                   20336:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   20337:             if (ref($lastactref) eq 'HASH') {
                   20338:                 $lastactref->{'domdefaults'} = 1;
                   20339:             }
                   20340:         } else {
                   20341:             $errors .= '<li><span class="LC_error">'.
                   20342:                        &mt('An error occurred storing the settings: [_1]',
                   20343:                            $putresult).'</span></li>';
                   20344:         }
                   20345:     }
                   20346:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   20347:         $resulttext = &mt('Changes made:').'<ul>';
                   20348:         my (%shownprivs,@levelorder);
                   20349:         @levelorder = ('c','d','s');
                   20350:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  20351:             foreach my $item (sort(keys(%changes))) {
                   20352:                 if ($item eq 'submitbugs') {
                   20353:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   20354:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   20355:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  20356:                 } elsif ($item eq 'customrole') {
                   20357:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  20358:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   20359:                         my %keytext = &Apache::lonlocal::texthash(
                   20360:                                                                    order  => 'Order',
                   20361:                                                                    desc   => 'Role description',
                   20362:                                                                    access => 'Role usage',
1.300     droeschl 20363:                                                                    status => 'Allowed institutional types',
1.285     raeburn  20364:                                                                    exc    => 'Allowed personnel',
                   20365:                                                                    inc    => 'Disallowed personnel',
                   20366:                         );
1.282     raeburn  20367:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  20368:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   20369:                                 if ($role eq $newrole) {
                   20370:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   20371:                                                               $role).'<ul>';
                   20372:                                 } else {
                   20373:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   20374:                                                               $role).'<ul>';
                   20375:                                 }
                   20376:                                 foreach my $key (@keyorder) {
                   20377:                                     if ($changes{'customrole'}{$role}{$key}) {
                   20378:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   20379:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   20380:                                                        '</li>';
                   20381:                                     }
                   20382:                                 }
                   20383:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   20384:                                     $shownprivs{$role} = 1;
                   20385:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   20386:                                     foreach my $level (@levelorder) {
                   20387:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   20388:                                             next if ($item eq '');
                   20389:                                             my ($priv) = split(/\&/,$item,2);
                   20390:                                             if (&Apache::lonnet::plaintext($priv)) {
                   20391:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   20392:                                                 unless ($level eq 'c') {
                   20393:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   20394:                                                 }
                   20395:                                                 $resulttext .= '</li>';
                   20396:                                             }
                   20397:                                         }
                   20398:                                     }
                   20399:                                     $resulttext .= '</ul>';
                   20400:                                 }
                   20401:                                 $resulttext .= '</ul></li>';
                   20402:                             }
                   20403:                         }
                   20404:                     }
                   20405:                 }
                   20406:             }
                   20407:         }
                   20408:         if (keys(%changedprivs)) {
                   20409:             foreach my $role (sort(keys(%changedprivs))) {
                   20410:                 unless ($shownprivs{$role}) {
                   20411:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   20412:                                               $role).'<ul>'.
                   20413:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   20414:                     foreach my $level (@levelorder) {
                   20415:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   20416:                             next if ($item eq '');
                   20417:                             my ($priv) = split(/\&/,$item,2);
                   20418:                             if (&Apache::lonnet::plaintext($priv)) {
                   20419:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   20420:                                 unless ($level eq 'c') {
                   20421:                                     $resulttext .= ' ('.$lt{$level}.')';
                   20422:                                 }
                   20423:                                 $resulttext .= '</li>';
                   20424:                             }
1.282     raeburn  20425:                         }
                   20426:                     }
1.285     raeburn  20427:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  20428:                 }
                   20429:             }
                   20430:         }
1.285     raeburn  20431:         $resulttext .= '</ul>';
                   20432:     } else {
                   20433:         $resulttext = &mt('No changes made to help settings');
1.118     jms      20434:     }
                   20435:     if ($errors) {
1.168     raeburn  20436:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  20437:                                     $errors.'</ul>';
1.118     jms      20438:     }
                   20439:     return $resulttext;
                   20440: }
                   20441: 
1.121     raeburn  20442: sub modify_coursedefaults {
1.212     raeburn  20443:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  20444:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  20445:     my %defaultchecked = (
                   20446:                            'canuse_pdfforms' => 'off',
                   20447:                            'uselcmath'       => 'on',
1.398     raeburn  20448:                            'usejsme'         => 'on',
                   20449:                            'inline_chem'     => 'on',
1.257     raeburn  20450:                          );
1.398     raeburn  20451:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.198     raeburn  20452:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  20453:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   20454:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   20455:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  20456:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  20457:     my %staticdefaults = (
                   20458:                            anonsurvey_threshold => 10,
                   20459:                            uploadquota          => 500,
1.257     raeburn  20460:                            postsubmit           => 60,
1.276     raeburn  20461:                            mysqltables          => 172800,
1.198     raeburn  20462:                          );
1.314     raeburn  20463:     my %texoptions = (
                   20464:                         MathJax  => 'MathJax',
                   20465:                         mimetex  => &mt('Convert to Images'),
                   20466:                         tth      => &mt('TeX to HTML'),
                   20467:                      );
1.121     raeburn  20468:     $defaultshash{'coursedefaults'} = {};
                   20469: 
                   20470:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   20471:         if ($domconfig{'coursedefaults'} eq '') {
                   20472:             $domconfig{'coursedefaults'} = {};
                   20473:         }
                   20474:     }
                   20475: 
                   20476:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   20477:         foreach my $item (@toggles) {
                   20478:             if ($defaultchecked{$item} eq 'on') {
                   20479:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   20480:                     ($env{'form.'.$item} eq '0')) {
                   20481:                     $changes{$item} = 1;
1.192     raeburn  20482:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  20483:                     $changes{$item} = 1;
                   20484:                 }
                   20485:             } elsif ($defaultchecked{$item} eq 'off') {
                   20486:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   20487:                     ($env{'form.'.$item} eq '1')) {
                   20488:                     $changes{$item} = 1;
                   20489:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   20490:                     $changes{$item} = 1;
                   20491:                 }
                   20492:             }
                   20493:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   20494:         }
1.198     raeburn  20495:         foreach my $item (@numbers) {
                   20496:             my ($currdef,$newdef);
1.208     raeburn  20497:             $newdef = $env{'form.'.$item};
1.198     raeburn  20498:             if ($item eq 'anonsurvey_threshold') {
                   20499:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   20500:                 $newdef =~ s/\D//g;
                   20501:                 if ($newdef eq '' || $newdef < 1) {
                   20502:                     $newdef = 1;
                   20503:                 }
                   20504:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   20505:             } else {
1.276     raeburn  20506:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   20507:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   20508:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  20509:                 }
                   20510:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  20511:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  20512:             }
                   20513:             if ($currdef ne $newdef) {
                   20514:                 if ($item eq 'anonsurvey_threshold') {
                   20515:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   20516:                         $changes{$item} = 1;
                   20517:                     }
1.276     raeburn  20518:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289     raeburn  20519:                     my $setting = $1;
1.276     raeburn  20520:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   20521:                         $changes{$setting} = 1;
1.198     raeburn  20522:                     }
                   20523:                 }
1.139     raeburn  20524:             }
                   20525:         }
1.314     raeburn  20526:         my $texengine;
                   20527:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   20528:             $texengine = $env{'form.texengine'};
1.349     raeburn  20529:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   20530:             if ($currdef eq '') {
                   20531:                 unless ($texengine eq $Apache::lonnet::deftex) {
1.314     raeburn  20532:                     $changes{'texengine'} = 1;
                   20533:                 }
1.349     raeburn  20534:             } elsif ($currdef ne $texengine) {
1.314     raeburn  20535:                 $changes{'texengine'} = 1;
                   20536:             }
                   20537:         }
                   20538:         if ($texengine ne '') {
                   20539:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   20540:         }
1.264     raeburn  20541:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   20542:         my @currclonecode;
                   20543:         if (ref($currclone) eq 'HASH') {
                   20544:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   20545:                 @currclonecode = @{$currclone->{'instcode'}};
                   20546:             }
                   20547:         }
                   20548:         my $newclone;
1.289     raeburn  20549:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  20550:             $newclone = $env{'form.canclone'};
                   20551:         }
                   20552:         if ($newclone eq 'instcode') {
                   20553:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   20554:             my (%codedefaults,@code_order,@clonecode);
                   20555:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   20556:                                                     \@code_order);
                   20557:             foreach my $item (@code_order) {
                   20558:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   20559:                     push(@clonecode,$item);
                   20560:                 }
                   20561:             }
                   20562:             if (@clonecode) {
                   20563:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   20564:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   20565:                 if (@diffs) {
                   20566:                     $changes{'canclone'} = 1;
                   20567:                 }
                   20568:             } else {
                   20569:                 $newclone eq '';
                   20570:             }
                   20571:         } elsif ($newclone ne '') {
1.289     raeburn  20572:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   20573:         }
1.264     raeburn  20574:         if ($newclone ne $currclone) {
                   20575:             $changes{'canclone'} = 1;
                   20576:         }
1.257     raeburn  20577:         my %credits;
                   20578:         foreach my $type (@types) {
                   20579:             unless ($type eq 'community') {
                   20580:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   20581:                 $credits{$type} =~ s/[^\d.]+//g;
                   20582:             }
                   20583:         }
                   20584:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   20585:             ($env{'form.coursecredits'} eq '1')) {
                   20586:             $changes{'coursecredits'} = 1;
                   20587:             foreach my $type (keys(%credits)) {
                   20588:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   20589:             }
                   20590:         } else {
1.289     raeburn  20591:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  20592:                 foreach my $type (@types) {
                   20593:                     unless ($type eq 'community') {
1.289     raeburn  20594:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  20595:                             $changes{'coursecredits'} = 1;
                   20596:                         }
                   20597:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   20598:                     }
                   20599:                 }
                   20600:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   20601:                 foreach my $type (@types) {
                   20602:                     unless ($type eq 'community') {
                   20603:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   20604:                             $changes{'coursecredits'} = 1;
                   20605:                             last;
                   20606:                         }
                   20607:                     }
                   20608:                 }
                   20609:             }
                   20610:         }
                   20611:         if ($env{'form.postsubmit'} eq '1') {
                   20612:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   20613:             my %currtimeout;
                   20614:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20615:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   20616:                     $changes{'postsubmit'} = 1;
                   20617:                 }
                   20618:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20619:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   20620:                 }
                   20621:             } else {
                   20622:                 $changes{'postsubmit'} = 1;
                   20623:             }
                   20624:             foreach my $type (@types) {
                   20625:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   20626:                 $timeout =~ s/\D//g;
                   20627:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   20628:                     $timeout = '';
                   20629:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   20630:                     $timeout = '0';
                   20631:                 }
                   20632:                 unless ($timeout eq '') {
                   20633:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   20634:                 }
                   20635:                 if (exists($currtimeout{$type})) {
                   20636:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  20637:                         $changes{'postsubmit'} = 1;
1.257     raeburn  20638:                     }
                   20639:                 } elsif ($timeout ne '') {
                   20640:                     $changes{'postsubmit'} = 1;
                   20641:                 }
                   20642:             }
                   20643:         } else {
                   20644:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   20645:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20646:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   20647:                     $changes{'postsubmit'} = 1;
                   20648:                 }
                   20649:             } else {
                   20650:                 $changes{'postsubmit'} = 1;
                   20651:             }
1.192     raeburn  20652:         }
1.121     raeburn  20653:     }
                   20654:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   20655:                                              $dom);
                   20656:     if ($putresult eq 'ok') {
                   20657:         if (keys(%changes) > 0) {
1.213     raeburn  20658:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  20659:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  20660:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398     raeburn  20661:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
                   20662:                 ($changes{'inline_chem'})) {
                   20663:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine') {
1.257     raeburn  20664:                     if ($changes{$item}) {
                   20665:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   20666:                     }
1.289     raeburn  20667:                 }
1.192     raeburn  20668:                 if ($changes{'coursecredits'}) {
                   20669:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  20670:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   20671:                             $domdefaults{$type.'credits'} =
                   20672:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   20673:                         }
                   20674:                     }
                   20675:                 }
                   20676:                 if ($changes{'postsubmit'}) {
                   20677:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20678:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   20679:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20680:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   20681:                                 $domdefaults{$type.'postsubtimeout'} =
                   20682:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   20683:                             }
                   20684:                         }
1.192     raeburn  20685:                     }
                   20686:                 }
1.198     raeburn  20687:                 if ($changes{'uploadquota'}) {
                   20688:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   20689:                         foreach my $type (@types) {
                   20690:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   20691:                         }
                   20692:                     }
                   20693:                 }
1.264     raeburn  20694:                 if ($changes{'canclone'}) {
                   20695:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   20696:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   20697:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   20698:                             if (@clonecodes) {
                   20699:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   20700:                             }
                   20701:                         }
                   20702:                     } else {
                   20703:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   20704:                     }
                   20705:                 }
1.121     raeburn  20706:                 my $cachetime = 24*60*60;
                   20707:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  20708:                 if (ref($lastactref) eq 'HASH') {
                   20709:                     $lastactref->{'domdefaults'} = 1;
                   20710:                 }
1.121     raeburn  20711:             }
                   20712:             $resulttext = &mt('Changes made:').'<ul>';
                   20713:             foreach my $item (sort(keys(%changes))) {
                   20714:                 if ($item eq 'canuse_pdfforms') {
                   20715:                     if ($env{'form.'.$item} eq '1') {
                   20716:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   20717:                     } else {
                   20718:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   20719:                     }
1.257     raeburn  20720:                 } elsif ($item eq 'uselcmath') {
                   20721:                     if ($env{'form.'.$item} eq '1') {
                   20722:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   20723:                     } else {
                   20724:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   20725:                     }
                   20726:                 } elsif ($item eq 'usejsme') {
                   20727:                     if ($env{'form.'.$item} eq '1') {
                   20728:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   20729:                     } else {
1.289     raeburn  20730:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  20731:                     }
1.398     raeburn  20732:                 } elsif ($item eq 'inline_chem') {
                   20733:                     if ($env{'form.'.$item} eq '1') {
                   20734:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
                   20735:                     } else {
                   20736:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
                   20737:                     }
1.314     raeburn  20738:                 } elsif ($item eq 'texengine') {
                   20739:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   20740:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   20741:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   20742:                     }
1.139     raeburn  20743:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  20744:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  20745:                 } elsif ($item eq 'uploadquota') {
                   20746:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   20747:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   20748:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   20749:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  20750:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  20751:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  20752:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   20753:                                        '</ul>'.
                   20754:                                        '</li>';
                   20755:                     } else {
                   20756:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   20757:                     }
1.276     raeburn  20758:                 } elsif ($item eq 'mysqltables') {
                   20759:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   20760:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   20761:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   20762:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   20763:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   20764:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   20765:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   20766:                                        '</ul>'.
                   20767:                                        '</li>';
                   20768:                     } else {
                   20769:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   20770:                     }
1.257     raeburn  20771:                 } elsif ($item eq 'postsubmit') {
                   20772:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   20773:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   20774:                     } else {
                   20775:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  20776:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  20777:                             $resulttext .= &mt('durations:').'<ul>';
                   20778:                             foreach my $type (@types) {
                   20779:                                 $resulttext .= '<li>';
                   20780:                                 my $timeout;
                   20781:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20782:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   20783:                                 }
                   20784:                                 my $display;
                   20785:                                 if ($timeout eq '0') {
                   20786:                                     $display = &mt('unlimited');
                   20787:                                 } elsif ($timeout eq '') {
                   20788:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   20789:                                 } else {
                   20790:                                     $display = &mt('[quant,_1,second]',$timeout);
                   20791:                                 }
                   20792:                                 if ($type eq 'community') {
                   20793:                                     $resulttext .= &mt('Communities');
                   20794:                                 } elsif ($type eq 'official') {
                   20795:                                     $resulttext .= &mt('Official courses');
                   20796:                                 } elsif ($type eq 'unofficial') {
                   20797:                                     $resulttext .= &mt('Unofficial courses');
                   20798:                                 } elsif ($type eq 'textbook') {
                   20799:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  20800:                                 } elsif ($type eq 'placement') {
                   20801:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  20802:                                 }
                   20803:                                 $resulttext .= ' -- '.$display.'</li>';
                   20804:                             }
                   20805:                             $resulttext .= '</ul>';
                   20806:                         }
1.289     raeburn  20807:                         $resulttext .= '</li>';
1.257     raeburn  20808:                     }
1.192     raeburn  20809:                 } elsif ($item eq 'coursecredits') {
                   20810:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   20811:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  20812:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   20813:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  20814:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   20815:                         } else {
                   20816:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   20817:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   20818:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  20819:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  20820:                                            '</ul>'.
                   20821:                                            '</li>';
                   20822:                         }
                   20823:                     } else {
                   20824:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   20825:                     }
1.264     raeburn  20826:                 } elsif ($item eq 'canclone') {
                   20827:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   20828:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   20829:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   20830:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   20831:                         }
                   20832:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   20833:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   20834:                     } else {
1.289     raeburn  20835:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  20836:                     }
1.140     raeburn  20837:                 }
1.121     raeburn  20838:             }
                   20839:             $resulttext .= '</ul>';
                   20840:         } else {
                   20841:             $resulttext = &mt('No changes made to course defaults');
                   20842:         }
                   20843:     } else {
                   20844:         $resulttext = '<span class="LC_error">'.
                   20845:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   20846:     }
                   20847:     return $resulttext;
                   20848: }
                   20849: 
1.231     raeburn  20850: sub modify_selfenrollment {
                   20851:     my ($dom,$lastactref,%domconfig) = @_;
                   20852:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  20853:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  20854:     my %titles = &tool_titles();
1.232     raeburn  20855:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   20856:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  20857:     $ordered{'default'} = ['types','registered','approval','limit'];
                   20858: 
                   20859:     my (%roles,%shown,%toplevel);
                   20860:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   20861: 
                   20862:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   20863:         if ($domconfig{'selfenrollment'} eq '') {
                   20864:             $domconfig{'selfenrollment'} = {};
                   20865:         }
                   20866:     }
                   20867:     %toplevel = (
                   20868:                   admin      => 'Configuration Rights',
                   20869:                   default    => 'Default settings',
                   20870:                   validation => 'Validation of self-enrollment requests',
                   20871:                 );
1.233     raeburn  20872:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  20873: 
                   20874:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   20875:         foreach my $item (@{$ordered{'admin'}}) {
                   20876:             foreach my $type (@types) {
                   20877:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   20878:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   20879:                 } else {
                   20880:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   20881:                 }
                   20882:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   20883:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   20884:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   20885:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   20886:                             push(@{$changes{'admin'}{$type}},$item);
                   20887:                         }
                   20888:                     } else {
                   20889:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   20890:                             push(@{$changes{'admin'}{$type}},$item);
                   20891:                         }
                   20892:                     }
                   20893:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   20894:                     push(@{$changes{'admin'}{$type}},$item);
                   20895:                 }
                   20896:             }
                   20897:         }
                   20898:     }
                   20899: 
                   20900:     foreach my $item (@{$ordered{'default'}}) {
                   20901:         foreach my $type (@types) {
                   20902:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   20903:             if ($item eq 'types') {
                   20904:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   20905:                     $value = '';
                   20906:                 }
                   20907:             } elsif ($item eq 'registered') {
                   20908:                 unless ($value eq '1') {
                   20909:                     $value = 0;
                   20910:                 }
                   20911:             } elsif ($item eq 'approval') {
                   20912:                 unless ($value =~ /^[012]$/) {
                   20913:                     $value = 0;
                   20914:                 }
                   20915:             } else {
                   20916:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   20917:                     $value = 'none';
                   20918:                 }
                   20919:             }
                   20920:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   20921:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   20922:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   20923:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   20924:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   20925:                          push(@{$changes{'default'}{$type}},$item);
                   20926:                     }
                   20927:                 } else {
                   20928:                     push(@{$changes{'default'}{$type}},$item);
                   20929:                 }
                   20930:             } else {
                   20931:                 push(@{$changes{'default'}{$type}},$item);
                   20932:             }
                   20933:             if ($item eq 'limit') {
                   20934:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   20935:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   20936:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   20937:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   20938:                     }
                   20939:                 } else {
                   20940:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   20941:                 }
                   20942:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   20943:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   20944:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   20945:                          push(@{$changes{'default'}{$type}},'cap');
                   20946:                     }
                   20947:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   20948:                     push(@{$changes{'default'}{$type}},'cap');
                   20949:                 }
                   20950:             }
                   20951:         }
                   20952:     }
                   20953: 
                   20954:     foreach my $item (@{$itemsref}) {
                   20955:         if ($item eq 'fields') {
                   20956:             my @changed;
                   20957:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   20958:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   20959:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   20960:             }
                   20961:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   20962:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   20963:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   20964:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   20965:                 } else {
                   20966:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   20967:                 }
                   20968:             } else {
                   20969:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   20970:             }
                   20971:             if (@changed) {
                   20972:                 if ($selfenrollhash{'validation'}{$item}) { 
                   20973:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   20974:                 } else {
                   20975:                     $changes{'validation'}{$item} = &mt('None');
                   20976:                 }
                   20977:             }
                   20978:         } else {
                   20979:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   20980:             if ($item eq 'markup') {
                   20981:                if ($env{'form.selfenroll_validation_'.$item}) {
                   20982:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   20983:                }
                   20984:             }
                   20985:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   20986:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   20987:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   20988:                 }
                   20989:             }
                   20990:         }
                   20991:     }
                   20992: 
                   20993:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   20994:                                              $dom);
                   20995:     if ($putresult eq 'ok') {
                   20996:         if (keys(%changes) > 0) {
                   20997:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   20998:             $resulttext = &mt('Changes made:').'<ul>';
                   20999:             foreach my $key ('admin','default','validation') {
                   21000:                 if (ref($changes{$key}) eq 'HASH') {
                   21001:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   21002:                     if ($key eq 'validation') {
                   21003:                         foreach my $item (@{$itemsref}) {
                   21004:                             if (exists($changes{$key}{$item})) {
                   21005:                                 if ($item eq 'markup') {
                   21006:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   21007:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   21008:                                 } else {  
                   21009:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   21010:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   21011:                                 }
                   21012:                             }
                   21013:                         }
                   21014:                     } else {
                   21015:                         foreach my $type (@types) {
                   21016:                             if ($type eq 'community') {
                   21017:                                 $roles{'1'} = &mt('Community personnel');
                   21018:                             } else {
                   21019:                                 $roles{'1'} = &mt('Course personnel');
                   21020:                             }
                   21021:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  21022:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   21023:                                     if ($key eq 'admin') {
                   21024:                                         my @mgrdc = ();
                   21025:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   21026:                                             foreach my $item (@{$ordered{'admin'}}) {
                   21027:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   21028:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   21029:                                                         push(@mgrdc,$item);
                   21030:                                                     }
                   21031:                                                 }
                   21032:                                             }
                   21033:                                             if (@mgrdc) {
                   21034:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   21035:                                             } else {
                   21036:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   21037:                                             }
                   21038:                                         }
                   21039:                                     } else {
                   21040:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   21041:                                             foreach my $item (@{$ordered{$key}}) {
                   21042:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   21043:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   21044:                                                         $selfenrollhash{$key}{$type}{$item};
                   21045:                                                 }
                   21046:                                             }
                   21047:                                         }
                   21048:                                     }
                   21049:                                 }
1.231     raeburn  21050:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   21051:                                 foreach my $item (@{$ordered{$key}}) {
                   21052:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   21053:                                         $resulttext .= '<li>';
                   21054:                                         if ($key eq 'admin') {
                   21055:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   21056:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   21057:                                         } else {
                   21058:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   21059:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   21060:                                         }
                   21061:                                         $resulttext .= '</li>';
                   21062:                                     }
                   21063:                                 }
                   21064:                                 $resulttext .= '</ul></li>';
                   21065:                             }
                   21066:                         }
                   21067:                         $resulttext .= '</ul></li>'; 
                   21068:                     }
                   21069:                 }
1.305     raeburn  21070:             }
                   21071:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   21072:                 my $cachetime = 24*60*60;
                   21073:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21074:                 if (ref($lastactref) eq 'HASH') {
                   21075:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  21076:                 }
1.231     raeburn  21077:             }
                   21078:             $resulttext .= '</ul>';
                   21079:         } else {
                   21080:             $resulttext = &mt('No changes made to self-enrollment settings');
                   21081:         }
                   21082:     } else {
                   21083:         $resulttext = '<span class="LC_error">'.
                   21084:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   21085:     }
                   21086:     return $resulttext;
                   21087: }
                   21088: 
1.373     raeburn  21089: sub modify_wafproxy {
                   21090:     my ($dom,$action,$lastactref,%domconfig) = @_;
                   21091:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  21092:     my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
                   21093:         %wafproxy,%changes,%expirecache,%expiresaml);
1.373     raeburn  21094:     foreach my $server (sort(keys(%servers))) {
                   21095:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   21096:         if ($serverhome eq $server) {
                   21097:             my $serverdom = &Apache::lonnet::host_domain($server);
                   21098:             if ($serverdom eq $dom) {
                   21099:                 $canset{$server} = 1;
                   21100:             }
                   21101:         }
                   21102:     }
1.381     raeburn  21103:     if (ref($domconfig{'wafproxy'}) eq 'HASH') {
                   21104:         %{$values{$dom}} = ();
                   21105:         if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
                   21106:             %curralias = %{$domconfig{'wafproxy'}{'alias'}};
                   21107:         }
1.388     raeburn  21108:         if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
                   21109:             %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
                   21110:         }
1.382     raeburn  21111:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381     raeburn  21112:             $currvalue{$item} = $domconfig{'wafproxy'}{$item};
                   21113:         }
                   21114:     }
1.373     raeburn  21115:     my $output;
                   21116:     if (keys(%canset)) {
                   21117:         %{$wafproxy{'alias'}} = ();
1.388     raeburn  21118:         %{$wafproxy{'saml'}} = ();
1.373     raeburn  21119:         foreach my $key (sort(keys(%canset))) {
1.381     raeburn  21120:             if ($env{'form.wafproxy_'.$dom}) {
                   21121:                 $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
                   21122:                 $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
                   21123:                 if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
                   21124:                     $changes{'alias'} = 1;
                   21125:                 }
1.388     raeburn  21126:                 if ($env{'form.wafproxy_alias_saml_'.$key}) {
                   21127:                     $wafproxy{'saml'}{$key} = 1;
                   21128:                 }
                   21129:                 if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
                   21130:                     $changes{'saml'} = 1;
                   21131:                 }
1.381     raeburn  21132:             } else {
                   21133:                 $wafproxy{'alias'}{$key} = '';
1.388     raeburn  21134:                 $wafproxy{'saml'}{$key} = '';
1.381     raeburn  21135:                 if ($curralias{$key}) {
                   21136:                     $changes{'alias'} = 1;
                   21137:                 }
1.388     raeburn  21138:                 if ($currsaml{$key}) {
                   21139:                     $changes{'saml'} = 1;
                   21140:                 }
1.373     raeburn  21141:             }
                   21142:             if ($wafproxy{'alias'}{$key} eq '') {
                   21143:                 if ($curralias{$key}) {
                   21144:                     $expirecache{$key} = 1;
                   21145:                 }
                   21146:                 delete($wafproxy{'alias'}{$key});
                   21147:             }
1.388     raeburn  21148:             if ($wafproxy{'saml'}{$key} eq '') {
                   21149:                 if ($currsaml{$key}) {
                   21150:                     $expiresaml{$key} = 1;
                   21151:                 }
                   21152:                 delete($wafproxy{'saml'}{$key});
                   21153:             }
1.373     raeburn  21154:         }
                   21155:         unless (keys(%{$wafproxy{'alias'}})) {
                   21156:             delete($wafproxy{'alias'});
                   21157:         }
1.388     raeburn  21158:         unless (keys(%{$wafproxy{'saml'}})) {
                   21159:             delete($wafproxy{'saml'});
                   21160:         }
                   21161:         # Localization for values in %warn occurs in &mt() calls separately.
1.373     raeburn  21162:         my %warn = (
                   21163:                      trusted => 'trusted IP range(s)',
1.381     raeburn  21164:                      vpnint => 'internal IP range(s) for VPN sessions(s)',
                   21165:                      vpnext => 'IP range(s) for backend WAF connections',
1.373     raeburn  21166:                    );
1.382     raeburn  21167:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21168:             my $possible = $env{'form.wafproxy_'.$item};
                   21169:             $possible =~ s/^\s+|\s+$//g;
                   21170:             if ($possible ne '') {
1.381     raeburn  21171:                 if ($item eq 'remoteip') {
                   21172:                     if ($possible =~ /^[mhn]$/) {
                   21173:                         $wafproxy{$item} = $possible;
                   21174:                     }
                   21175:                 } elsif ($item eq 'ipheader') {
                   21176:                     if ($wafproxy{'remoteip'} eq 'h') {
                   21177:                         $wafproxy{$item} = $possible;
                   21178:                     }
1.382     raeburn  21179:                 } elsif ($item eq 'sslopt') {
                   21180:                     if ($possible =~ /^0|1$/) {
                   21181:                         $wafproxy{$item} = $possible;
                   21182:                     }
1.373     raeburn  21183:                 } else {
                   21184:                     my (@ok,$count);
1.381     raeburn  21185:                     if (($item eq 'vpnint') || ($item eq 'vpnext')) {
                   21186:                         unless ($env{'form.wafproxy_vpnaccess'}) {
                   21187:                             $possible = '';
                   21188:                         }
                   21189:                     } elsif ($item eq 'trusted') {
                   21190:                         unless ($wafproxy{'remoteip'} eq 'h') {
                   21191:                             $possible = '';
                   21192:                         }
                   21193:                     }
                   21194:                     unless ($possible eq '') {
                   21195:                         $possible =~ s/[\r\n]+/\s/g;
                   21196:                         $possible =~ s/\s*-\s*/-/g;
                   21197:                         $possible =~ s/\s+/,/g;
1.393     raeburn  21198:                         $possible =~ s/,+/,/g;
1.381     raeburn  21199:                     }
1.373     raeburn  21200:                     $count = 0;
1.381     raeburn  21201:                     if ($possible ne '') {
1.373     raeburn  21202:                         foreach my $poss (split(/\,/,$possible)) {
                   21203:                             $count ++;
1.393     raeburn  21204:                             $poss = &validate_ip_pattern($poss);
                   21205:                             if ($poss ne '') {
1.373     raeburn  21206:                                 push(@ok,$poss);
                   21207:                             }
                   21208:                         }
                   21209:                         my $diff = $count - scalar(@ok);
                   21210:                         if ($diff) {
                   21211:                             push(@warnings,'<li>'.
                   21212:                                  &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
                   21213:                                      $diff,$warn{$item}).
                   21214:                                  '</li>');
                   21215:                         }
1.393     raeburn  21216:                         if (@ok) {
                   21217:                             my @cidr_list;
                   21218:                             foreach my $item (@ok) {
                   21219:                                 @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   21220:                             }
                   21221:                             $wafproxy{$item} = join(',',@cidr_list);
                   21222:                         }
1.373     raeburn  21223:                     }
                   21224:                 }
1.381     raeburn  21225:                 if ($wafproxy{$item} ne $currvalue{$item}) {
1.373     raeburn  21226:                     $changes{$item} = 1;
                   21227:                 }
1.381     raeburn  21228:             } elsif ($currvalue{$item}) {
                   21229:                 $changes{$item} = 1;
                   21230:             } 
                   21231:         }
                   21232:     } else {
                   21233:         if (keys(%curralias)) {
                   21234:             $changes{'alias'} = 1;
1.388     raeburn  21235:         }
                   21236:         if (keys(%currsaml)) {
                   21237:             $changes{'saml'} = 1;
1.381     raeburn  21238:         } 
                   21239:         if (keys(%currvalue)) {
                   21240:             foreach my $key (keys(%currvalue)) {
                   21241:                 $changes{$key} = 1;
1.373     raeburn  21242:             }
                   21243:         }
                   21244:     }
                   21245:     if (keys(%changes)) {
                   21246:         my %defaultshash = (
                   21247:                               wafproxy => \%wafproxy,
                   21248:                            ); 
                   21249:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21250:                                                  $dom);
                   21251:         if ($putresult eq 'ok') {
                   21252:             my $cachetime = 24*60*60;
                   21253:             my (%domdefaults,$updatedomdefs);
1.382     raeburn  21254:             foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21255:                 if ($changes{$item}) {
                   21256:                     unless ($updatedomdefs) {
                   21257:                         %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   21258:                         $updatedomdefs = 1;
                   21259:                     }
                   21260:                     if ($wafproxy{$item}) {
                   21261:                         $domdefaults{'waf_'.$item} = $wafproxy{$item};
                   21262:                     } elsif (exists($domdefaults{'waf_'.$item})) {
                   21263:                         delete($domdefaults{'waf_'.$item});
                   21264:                     } 
                   21265:                 }
                   21266:             }
                   21267:             if ($updatedomdefs) {
                   21268:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21269:                 if (ref($lastactref) eq 'HASH') {
                   21270:                     $lastactref->{'domdefaults'} = 1;
                   21271:                 }
                   21272:             }
                   21273:             if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
                   21274:                 my %updates = %expirecache;
                   21275:                 foreach my $key (keys(%expirecache)) {
                   21276:                     &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
                   21277:                 }
                   21278:                 if (ref($wafproxy{'alias'}) eq 'HASH') {
                   21279:                     my $cachetime = 24*60*60;
                   21280:                     foreach my $key (keys(%{$wafproxy{'alias'}})) {
                   21281:                         $updates{$key} = 1;
                   21282:                         &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
                   21283:                                                       $cachetime);
                   21284:                     }
                   21285:                 }
                   21286:                 if (ref($lastactref) eq 'HASH') {
                   21287:                     $lastactref->{'proxyalias'} = \%updates;
                   21288:                 }
                   21289:             }
1.388     raeburn  21290:             if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
                   21291:                 my %samlupdates = %expiresaml;
                   21292:                 foreach my $key (keys(%expiresaml)) {
                   21293:                     &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
                   21294:                 }
                   21295:                 if (ref($wafproxy{'saml'}) eq 'HASH') {
                   21296:                     my $cachetime = 24*60*60;
                   21297:                     foreach my $key (keys(%{$wafproxy{'saml'}})) {
                   21298:                         $samlupdates{$key} = 1;
                   21299:                         &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
                   21300:                                                       $cachetime);
                   21301:                     }
                   21302:                 }
                   21303:                 if (ref($lastactref) eq 'HASH') {
                   21304:                     $lastactref->{'proxysaml'} = \%samlupdates;
                   21305:                 }
                   21306:             }
1.373     raeburn  21307:             $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401     raeburn  21308:             foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21309:                 if ($changes{$item}) {
                   21310:                     if ($item eq 'alias') {
                   21311:                         my $numaliased = 0;
                   21312:                         if (ref($wafproxy{'alias'}) eq 'HASH') {
                   21313:                             my $shown;
                   21314:                             if (keys(%{$wafproxy{'alias'}})) {
                   21315:                                 foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
                   21316:                                     $shown .= '<li>'.&mt('[_1] aliased by [_2]',
                   21317:                                                          &Apache::lonnet::hostname($server),
                   21318:                                                          $wafproxy{'alias'}{$server}).'</li>';
                   21319:                                     $numaliased ++;
                   21320:                                 }
                   21321:                                 if ($numaliased) {
                   21322:                                     $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
                   21323:                                                           '<ul>'.$shown.'</ul>').'</li>';
                   21324:                                 }
                   21325:                             }
                   21326:                         }
                   21327:                         unless ($numaliased) {
                   21328:                             $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
                   21329:                         }
1.388     raeburn  21330:                     } elsif ($item eq 'saml') {
                   21331:                         my $shown; 
                   21332:                         if (ref($wafproxy{'saml'}) eq 'HASH') {
                   21333:                             if (keys(%{$wafproxy{'saml'}})) {
                   21334:                                 $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
                   21335:                             }
                   21336:                         }
                   21337:                         if ($shown) {
1.396     raeburn  21338:                             $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388     raeburn  21339:                                                   $shown).'</li>';
                   21340:                         } else {
1.396     raeburn  21341:                             $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388     raeburn  21342:                         }
1.373     raeburn  21343:                     } else {
1.381     raeburn  21344:                         if ($item eq 'remoteip') {
                   21345:                             my %ip_methods = &remoteip_methods();
                   21346:                             if ($wafproxy{$item} =~ /^[mh]$/) {
                   21347:                                 $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
                   21348:                                                       $ip_methods{$wafproxy{$item}}).'</li>';
                   21349:                             } else {
                   21350:                                 if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
                   21351:                                     $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
                   21352:                                                '</li>';
                   21353:                                 } else {
                   21354:                                     $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
                   21355:                                 }
                   21356:                             }
                   21357:                         } elsif ($item eq 'ipheader') {
1.373     raeburn  21358:                             if ($wafproxy{$item}) {
1.381     raeburn  21359:                                 $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373     raeburn  21360:                                                       $wafproxy{$item}).'</li>';
                   21361:                             } else {
1.381     raeburn  21362:                                 $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373     raeburn  21363:                             }
                   21364:                         } elsif ($item eq 'trusted') {
                   21365:                             if ($wafproxy{$item}) {
1.381     raeburn  21366:                                 $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373     raeburn  21367:                                                       $wafproxy{$item}).'</li>';
                   21368:                             } else {
                   21369:                                 $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
                   21370:                             }
1.381     raeburn  21371:                         } elsif ($item eq 'vpnint') {
                   21372:                             if ($wafproxy{$item}) {
                   21373:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
                   21374:                                                        $wafproxy{$item}).'</li>';
                   21375:                             } else {
                   21376:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
                   21377:                             }
                   21378:                         } elsif ($item eq 'vpnext') {
1.373     raeburn  21379:                             if ($wafproxy{$item}) {
1.381     raeburn  21380:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373     raeburn  21381:                                                        $wafproxy{$item}).'</li>';
                   21382:                             } else {
1.381     raeburn  21383:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373     raeburn  21384:                             }
1.382     raeburn  21385:                         } elsif ($item eq 'sslopt') {
                   21386:                             if ($wafproxy{$item}) {
                   21387:                                 $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>';
                   21388:                             } else {
                   21389:                                 $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>';
                   21390:                             }
1.373     raeburn  21391:                         }
                   21392:                     }
                   21393:                 }
                   21394:             }
                   21395:         } else {
                   21396:             $output = '<span class="LC_error">'.
                   21397:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   21398:         }
                   21399:     } elsif (keys(%canset)) {
                   21400:         $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
                   21401:     }
                   21402:     if (@warnings) {
                   21403:         $output .= '<br />'.&mt('Warnings:').'<ul>'.
                   21404:                        join("\n",@warnings).'</ul>';
                   21405:     }
                   21406:     return $output;
                   21407: }
                   21408: 
                   21409: sub validate_ip_pattern {
                   21410:     my ($pattern) = @_;
                   21411:     if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
                   21412:         my ($start,$end) = ($1,$2);
                   21413:         if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393     raeburn  21414:             if (($start !~ m{/}) && ($end !~ m{/})) {
                   21415:                 return $start.'-'.$end;
                   21416:             }
                   21417:         }
                   21418:     } elsif ($pattern ne '') {
                   21419:         $pattern = &Net::CIDR::cidrvalidate($pattern);
                   21420:         if ($pattern ne '') {
                   21421:             return $pattern;
1.373     raeburn  21422:         }
                   21423:     }
1.393     raeburn  21424:     return;
1.373     raeburn  21425: }
                   21426: 
1.137     raeburn  21427: sub modify_usersessions {
1.212     raeburn  21428:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  21429:     my @hostingtypes = ('version','excludedomain','includedomain');
                   21430:     my @offloadtypes = ('primary','default');
                   21431:     my %types = (
                   21432:                   remote => \@hostingtypes,
                   21433:                   hosted => \@hostingtypes,
                   21434:                   spares => \@offloadtypes,
                   21435:                 );
                   21436:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  21437:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  21438:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21439:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  21440:     my @locations = sort(keys(%by_location));
1.137     raeburn  21441:     my (%defaultshash,%changes);
                   21442:     foreach my $prefix (@prefixes) {
                   21443:         $defaultshash{'usersessions'}{$prefix} = {};
                   21444:     }
1.212     raeburn  21445:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  21446:     my $resulttext;
1.138     raeburn  21447:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  21448:     foreach my $prefix (@prefixes) {
1.145     raeburn  21449:         next if ($prefix eq 'spares');
                   21450:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  21451:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21452:             if ($type eq 'version') {
                   21453:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   21454:                 my $okvalue;
                   21455:                 if ($value ne '') {
                   21456:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   21457:                         $okvalue = $value;
                   21458:                     }
                   21459:                 }
                   21460:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21461:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   21462:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   21463:                             if ($inuse == 0) {
                   21464:                                 $changes{$prefix}{$type} = 1;
                   21465:                             } else {
                   21466:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   21467:                                     $changes{$prefix}{$type} = 1;
                   21468:                                 }
                   21469:                                 if ($okvalue ne '') {
                   21470:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21471:                                 } 
                   21472:                             }
                   21473:                         } else {
                   21474:                             if (($inuse == 1) && ($okvalue ne '')) {
                   21475:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21476:                                 $changes{$prefix}{$type} = 1;
                   21477:                             }
                   21478:                         }
                   21479:                     } else {
                   21480:                         if (($inuse == 1) && ($okvalue ne '')) {
                   21481:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21482:                             $changes{$prefix}{$type} = 1;
                   21483:                         }
                   21484:                     }
                   21485:                 } else {
                   21486:                     if (($inuse == 1) && ($okvalue ne '')) {
                   21487:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21488:                         $changes{$prefix}{$type} = 1;
                   21489:                     }
                   21490:                 }
                   21491:             } else {
                   21492:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21493:                 my @okvals;
                   21494:                 foreach my $val (@vals) {
1.138     raeburn  21495:                     if ($val =~ /:/) {
                   21496:                         my @items = split(/:/,$val);
                   21497:                         foreach my $item (@items) {
                   21498:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   21499:                                 push(@okvals,$item);
                   21500:                             }
                   21501:                         }
                   21502:                     } else {
                   21503:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   21504:                             push(@okvals,$val);
                   21505:                         }
1.137     raeburn  21506:                     }
                   21507:                 }
                   21508:                 @okvals = sort(@okvals);
                   21509:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21510:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   21511:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   21512:                             if ($inuse == 0) {
                   21513:                                 $changes{$prefix}{$type} = 1; 
                   21514:                             } else {
                   21515:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21516:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   21517:                                 if (@changed > 0) {
                   21518:                                     $changes{$prefix}{$type} = 1;
                   21519:                                 }
                   21520:                             }
                   21521:                         } else {
                   21522:                             if ($inuse == 1) {
                   21523:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21524:                                 $changes{$prefix}{$type} = 1;
                   21525:                             }
                   21526:                         } 
                   21527:                     } else {
                   21528:                         if ($inuse == 1) {
                   21529:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21530:                             $changes{$prefix}{$type} = 1;
                   21531:                         }
                   21532:                     }
                   21533:                 } else {
                   21534:                     if ($inuse == 1) {
                   21535:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21536:                         $changes{$prefix}{$type} = 1;
                   21537:                     }
                   21538:                 }
                   21539:             }
                   21540:         }
                   21541:     }
1.145     raeburn  21542: 
                   21543:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  21544:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  21545:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   21546:     my $savespares;
                   21547: 
                   21548:     foreach my $lonhost (sort(keys(%servers))) {
                   21549:         my $serverhomeID =
                   21550:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  21551:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  21552:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   21553:         my %spareschg;
                   21554:         foreach my $type (@{$types{'spares'}}) {
                   21555:             my @okspares;
                   21556:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   21557:             foreach my $server (@checked) {
1.152     raeburn  21558:                 if (&Apache::lonnet::hostname($server) ne '') {
                   21559:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   21560:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   21561:                             push(@okspares,$server);
                   21562:                         }
1.145     raeburn  21563:                     }
                   21564:                 }
                   21565:             }
                   21566:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   21567:             my $newspare;
1.152     raeburn  21568:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   21569:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  21570:                     $newspare = $new;
                   21571:                 }
                   21572:             }
1.152     raeburn  21573:             my @spares;
                   21574:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   21575:                 @spares = sort(@okspares,$newspare);
                   21576:             } else {
                   21577:                 @spares = sort(@okspares);
                   21578:             }
                   21579:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  21580:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   21581:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  21582:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  21583:                     if (@diffs > 0) {
                   21584:                         $spareschg{$type} = 1;
                   21585:                     }
                   21586:                 }
                   21587:             }
                   21588:         }
                   21589:         if (keys(%spareschg) > 0) {
                   21590:             $changes{'spares'}{$lonhost} = \%spareschg;
                   21591:         }
                   21592:     }
1.261     raeburn  21593:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371     raeburn  21594:     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261     raeburn  21595:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   21596:     my @okoffload;
                   21597:     if (@offloadnow) {
                   21598:         foreach my $server (@offloadnow) {
                   21599:             if (&Apache::lonnet::hostname($server) ne '') {
                   21600:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   21601:                     push(@okoffload,$server);
                   21602:                 }
                   21603:             }
                   21604:         }
                   21605:         if (@okoffload) {
                   21606:             foreach my $lonhost (@okoffload) {
                   21607:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   21608:             }
                   21609:         }
                   21610:     }
1.371     raeburn  21611:     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   21612:     my @okoffloadoth;
                   21613:     if (@offloadoth) {
                   21614:         foreach my $server (@offloadoth) {
                   21615:             if (&Apache::lonnet::hostname($server) ne '') {
                   21616:                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   21617:                     push(@okoffloadoth,$server);
                   21618:                 }
                   21619:             }
                   21620:         }
                   21621:         if (@okoffloadoth) {
                   21622:             foreach my $lonhost (@okoffloadoth) {
                   21623:                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   21624:             }
                   21625:         }
                   21626:     }
1.145     raeburn  21627:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21628:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   21629:             if (ref($changes{'spares'}) eq 'HASH') {
                   21630:                 if (keys(%{$changes{'spares'}}) > 0) {
                   21631:                     $savespares = 1;
                   21632:                 }
                   21633:             }
                   21634:         } else {
                   21635:             $savespares = 1;
                   21636:         }
1.371     raeburn  21637:         foreach my $offload ('offloadnow','offloadoth') {
                   21638:             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   21639:                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   21640:                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   21641:                         $changes{$offload} = 1;
                   21642:                         last;
                   21643:                     }
1.261     raeburn  21644:                 }
1.371     raeburn  21645:                 unless ($changes{$offload}) {
                   21646:                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   21647:                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   21648:                             $changes{$offload} = 1;
                   21649:                             last;
                   21650:                         }
1.261     raeburn  21651:                     }
                   21652:                 }
1.371     raeburn  21653:             } else {
                   21654:                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   21655:                      $changes{'offloadnow'} = 1;
                   21656:                 }
                   21657:                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   21658:                     $changes{'offloadoth'} = 1;
                   21659:                 }
                   21660:             } 
                   21661:         }
                   21662:     } else {
                   21663:         if (@okoffload) {
1.261     raeburn  21664:             $changes{'offloadnow'} = 1;
                   21665:         }
1.371     raeburn  21666:         if (@okoffloadoth) {
                   21667:             $changes{'offloadoth'} = 1;
                   21668:         }
1.145     raeburn  21669:     }
1.147     raeburn  21670:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   21671:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  21672:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21673:                                                  $dom);
                   21674:         if ($putresult eq 'ok') {
                   21675:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   21676:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   21677:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   21678:                 }
                   21679:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   21680:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   21681:                 }
1.261     raeburn  21682:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   21683:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   21684:                 }
1.371     raeburn  21685:                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   21686:                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   21687:                 }
1.137     raeburn  21688:             }
                   21689:             my $cachetime = 24*60*60;
                   21690:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  21691:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  21692:             if (ref($lastactref) eq 'HASH') {
                   21693:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  21694:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  21695:             }
1.147     raeburn  21696:             if (keys(%changes) > 0) {
                   21697:                 my %lt = &usersession_titles();
                   21698:                 $resulttext = &mt('Changes made:').'<ul>';
                   21699:                 foreach my $prefix (@prefixes) {
                   21700:                     if (ref($changes{$prefix}) eq 'HASH') {
                   21701:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   21702:                         if ($prefix eq 'spares') {
                   21703:                             if (ref($changes{$prefix}) eq 'HASH') {
                   21704:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   21705:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  21706:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  21707:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   21708:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  21709:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   21710:                                         foreach my $type (@{$types{$prefix}}) {
                   21711:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   21712:                                                 my $offloadto = &mt('None');
                   21713:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   21714:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   21715:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   21716:                                                     }
1.145     raeburn  21717:                                                 }
1.147     raeburn  21718:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  21719:                                             }
1.137     raeburn  21720:                                         }
                   21721:                                     }
1.147     raeburn  21722:                                     $resulttext .= '</li>';
1.137     raeburn  21723:                                 }
                   21724:                             }
1.147     raeburn  21725:                         } else {
                   21726:                             foreach my $type (@{$types{$prefix}}) {
                   21727:                                 if (defined($changes{$prefix}{$type})) {
1.344     raeburn  21728:                                     my ($newvalue,$notinuse);
1.147     raeburn  21729:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   21730:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   21731:                                             if ($type eq 'version') {
                   21732:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344     raeburn  21733:                                             } else {
                   21734:                                                 if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   21735:                                                     if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   21736:                                                         $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   21737:                                                     }
                   21738:                                                 } else {
                   21739:                                                     $notinuse = 1;
1.147     raeburn  21740:                                                 }
1.145     raeburn  21741:                                             }
                   21742:                                         }
                   21743:                                     }
1.147     raeburn  21744:                                     if ($newvalue eq '') {
                   21745:                                         if ($type eq 'version') {
                   21746:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344     raeburn  21747:                                         } elsif ($notinuse) {
                   21748:                                             $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147     raeburn  21749:                                         } else {
                   21750:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   21751:                                         }
1.145     raeburn  21752:                                     } else {
1.147     raeburn  21753:                                         if ($type eq 'version') {
1.344     raeburn  21754:                                             $newvalue .= ' '.&mt('(or later)');
1.147     raeburn  21755:                                         }
                   21756:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  21757:                                     }
1.137     raeburn  21758:                                 }
                   21759:                             }
                   21760:                         }
1.147     raeburn  21761:                         $resulttext .= '</ul>';
1.137     raeburn  21762:                     }
                   21763:                 }
1.261     raeburn  21764:                 if ($changes{'offloadnow'}) {
                   21765:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   21766:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371     raeburn  21767:                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261     raeburn  21768:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   21769:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   21770:                             }
                   21771:                             $resulttext .= '</ul>';
                   21772:                         } else {
1.371     raeburn  21773:                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   21774:                         }
                   21775:                     } else {
                   21776:                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   21777:                     }
                   21778:                 }
                   21779:                 if ($changes{'offloadoth'}) {
                   21780:                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   21781:                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   21782:                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   21783:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   21784:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   21785:                             }
                   21786:                             $resulttext .= '</ul>';
                   21787:                         } else {
                   21788:                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261     raeburn  21789:                         }
                   21790:                     } else {
1.371     raeburn  21791:                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261     raeburn  21792:                     }
                   21793:                 }
1.147     raeburn  21794:                 $resulttext .= '</ul>';
                   21795:             } else {
                   21796:                 $resulttext = $nochgmsg;
1.137     raeburn  21797:             }
                   21798:         } else {
                   21799:             $resulttext = '<span class="LC_error">'.
                   21800:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   21801:         }
                   21802:     } else {
1.147     raeburn  21803:         $resulttext = $nochgmsg;
1.137     raeburn  21804:     }
                   21805:     return $resulttext;
                   21806: }
                   21807: 
1.275     raeburn  21808: sub modify_ssl {
                   21809:     my ($dom,$lastactref,%domconfig) = @_;
                   21810:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21811:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   21812:     my @locations = sort(keys(%by_location));
                   21813:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   21814:     my (%defaultshash,%changes);
                   21815:     my $action = 'ssl';
1.293     raeburn  21816:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  21817:     foreach my $prefix (@prefixes) {
                   21818:         $defaultshash{$action}{$prefix} = {};
                   21819:     }
                   21820:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   21821:     my $resulttext;
                   21822:     my %iphost = &Apache::lonnet::get_iphost();
                   21823:     my @reptypes = ('certreq','nocertreq');
                   21824:     my @connecttypes = ('dom','intdom','other');
                   21825:     my %types = (
1.293     raeburn  21826:                   connto      => \@connecttypes,
                   21827:                   connfrom    => \@connecttypes,
                   21828:                   replication => \@reptypes,
1.275     raeburn  21829:                 );
                   21830:     foreach my $prefix (sort(keys(%types))) {
                   21831:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  21832:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  21833:                 my $value = 'yes';
                   21834:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   21835:                     $value = $env{'form.'.$prefix.'_'.$type};
                   21836:                 }
1.335     raeburn  21837:                 if (ref($domconfig{$action}) eq 'HASH') {
                   21838:                     if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   21839:                         if ($domconfig{$action}{$prefix}{$type} ne '') {
                   21840:                             if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   21841:                                 $changes{$prefix}{$type} = 1;
                   21842:                             }
                   21843:                             $defaultshash{$action}{$prefix}{$type} = $value;
                   21844:                         } else {
                   21845:                             $defaultshash{$action}{$prefix}{$type} = $value;
1.275     raeburn  21846:                             $changes{$prefix}{$type} = 1;
                   21847:                         }
                   21848:                     } else {
                   21849:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   21850:                         $changes{$prefix}{$type} = 1;
                   21851:                     }
                   21852:                 } else {
                   21853:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   21854:                     $changes{$prefix}{$type} = 1;
                   21855:                 }
                   21856:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   21857:                     delete($changes{$prefix}{$type});
                   21858:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   21859:                     delete($changes{$prefix}{$type});
                   21860:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   21861:                     delete($changes{$prefix}{$type});
                   21862:                 }
                   21863:             } elsif ($prefix eq 'replication') {
                   21864:                 if (@locations > 0) {
                   21865:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21866:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21867:                     my @okvals;
                   21868:                     foreach my $val (@vals) {
                   21869:                         if ($val =~ /:/) {
                   21870:                             my @items = split(/:/,$val);
                   21871:                             foreach my $item (@items) {
                   21872:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   21873:                                     push(@okvals,$item);
                   21874:                                 }
                   21875:                             }
                   21876:                         } else {
                   21877:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   21878:                                 push(@okvals,$val);
                   21879:                             }
                   21880:                         }
                   21881:                     }
                   21882:                     @okvals = sort(@okvals);
                   21883:                     if (ref($domconfig{$action}) eq 'HASH') {
                   21884:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   21885:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   21886:                                 if ($inuse == 0) {
                   21887:                                     $changes{$prefix}{$type} = 1;
                   21888:                                 } else {
                   21889:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21890:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   21891:                                     if (@changed > 0) {
                   21892:                                         $changes{$prefix}{$type} = 1;
                   21893:                                     }
                   21894:                                 }
                   21895:                             } else {
                   21896:                                 if ($inuse == 1) {
                   21897:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21898:                                     $changes{$prefix}{$type} = 1;
                   21899:                                 }
                   21900:                             }
                   21901:                         } else {
                   21902:                             if ($inuse == 1) {
                   21903:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21904:                                 $changes{$prefix}{$type} = 1;
                   21905:                             }
                   21906:                         }
                   21907:                     } else {
                   21908:                         if ($inuse == 1) {
                   21909:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21910:                             $changes{$prefix}{$type} = 1;
                   21911:                         }
                   21912:                     }
                   21913:                 }
                   21914:             }
                   21915:         }
                   21916:     }
1.336     raeburn  21917:     if (keys(%changes)) {
                   21918:         foreach my $prefix (keys(%changes)) {
                   21919:             if (ref($changes{$prefix}) eq 'HASH') {
                   21920:                 if (scalar(keys(%{$changes{$prefix}})) == 0) {
                   21921:                     delete($changes{$prefix});
                   21922:                 }
                   21923:             } else {
                   21924:                 delete($changes{$prefix});
                   21925:             }
                   21926:         }
                   21927:     }
1.275     raeburn  21928:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   21929:     if (keys(%changes) > 0) {
                   21930:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21931:                                                  $dom);
                   21932:         if ($putresult eq 'ok') {
                   21933:             if (ref($defaultshash{$action}) eq 'HASH') {
                   21934:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   21935:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   21936:                 }
1.293     raeburn  21937:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335     raeburn  21938:                     $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293     raeburn  21939:                 }
                   21940:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335     raeburn  21941:                     $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275     raeburn  21942:                 }
                   21943:             }
                   21944:             my $cachetime = 24*60*60;
                   21945:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21946:             if (ref($lastactref) eq 'HASH') {
                   21947:                 $lastactref->{'domdefaults'} = 1;
                   21948:             }
                   21949:             if (keys(%changes) > 0) {
                   21950:                 my %titles = &ssl_titles();
                   21951:                 $resulttext = &mt('Changes made:').'<ul>';
                   21952:                 foreach my $prefix (@prefixes) {
                   21953:                     if (ref($changes{$prefix}) eq 'HASH') {
                   21954:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   21955:                         foreach my $type (@{$types{$prefix}}) {
                   21956:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  21957:                                 my ($newvalue,$notinuse);
1.275     raeburn  21958:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   21959:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  21960:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  21961:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344     raeburn  21962:                                         } else {
                   21963:                                             if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   21964:                                                 if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   21965:                                                     $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   21966:                                                 }
                   21967:                                             } else {
                   21968:                                                 $notinuse = 1;
1.275     raeburn  21969:                                             }
                   21970:                                         }
                   21971:                                     }
1.344     raeburn  21972:                                     if ($notinuse) {
                   21973:                                         $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                   21974:                                     } elsif ($newvalue eq '') {
1.275     raeburn  21975:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   21976:                                     } else {
                   21977:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   21978:                                     }
                   21979:                                 }
                   21980:                             }
                   21981:                         }
                   21982:                         $resulttext .= '</ul>';
                   21983:                     }
                   21984:                 }
                   21985:             } else {
                   21986:                 $resulttext = $nochgmsg;
                   21987:             }
                   21988:         } else {
                   21989:             $resulttext = '<span class="LC_error">'.
                   21990:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   21991:         }
                   21992:     } else {
                   21993:         $resulttext = $nochgmsg;
                   21994:     }
                   21995:     return $resulttext;
                   21996: }
                   21997: 
1.279     raeburn  21998: sub modify_trust {
                   21999:     my ($dom,$lastactref,%domconfig) = @_;
                   22000:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   22001:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   22002:     my @locations = sort(keys(%by_location));
                   22003:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   22004:     my @types = ('exc','inc');
                   22005:     my (%defaultshash,%changes);
                   22006:     foreach my $prefix (@prefixes) {
                   22007:         $defaultshash{'trust'}{$prefix} = {};
                   22008:     }
                   22009:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   22010:     my $resulttext;
                   22011:     foreach my $prefix (@prefixes) {
                   22012:         foreach my $type (@types) {
                   22013:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   22014:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   22015:             my @okvals;
                   22016:             foreach my $val (@vals) {
                   22017:                 if ($val =~ /:/) {
                   22018:                     my @items = split(/:/,$val);
                   22019:                     foreach my $item (@items) {
                   22020:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   22021:                             push(@okvals,$item);
                   22022:                         }
                   22023:                     }
                   22024:                 } else {
                   22025:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   22026:                         push(@okvals,$val);
                   22027:                     }
                   22028:                 }
                   22029:             }
                   22030:             @okvals = sort(@okvals);
                   22031:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   22032:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   22033:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   22034:                         if ($inuse == 0) {
                   22035:                             $changes{$prefix}{$type} = 1;
                   22036:                         } else {
                   22037:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22038:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   22039:                             if (@changed > 0) {
                   22040:                                 $changes{$prefix}{$type} = 1;
                   22041:                             }
                   22042:                         }
                   22043:                     } else {
                   22044:                         if ($inuse == 1) {
                   22045:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22046:                             $changes{$prefix}{$type} = 1;
                   22047:                         }
                   22048:                     }
                   22049:                 } else {
                   22050:                     if ($inuse == 1) {
                   22051:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22052:                         $changes{$prefix}{$type} = 1;
                   22053:                     }
                   22054:                 }
                   22055:             } else {
                   22056:                 if ($inuse == 1) {
                   22057:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   22058:                     $changes{$prefix}{$type} = 1;
                   22059:                 }
                   22060:             }
                   22061:         }
                   22062:     }
                   22063:     my $nochgmsg = &mt('No changes made to trust settings.');
                   22064:     if (keys(%changes) > 0) {
                   22065:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   22066:                                                  $dom);
                   22067:         if ($putresult eq 'ok') {
                   22068:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   22069:                 foreach my $prefix (@prefixes) {
                   22070:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   22071:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   22072:                     }
                   22073:                 }
                   22074:             }
                   22075:             my $cachetime = 24*60*60;
                   22076:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   22077:             if (ref($lastactref) eq 'HASH') {
                   22078:                 $lastactref->{'domdefaults'} = 1;
                   22079:             }
                   22080:             if (keys(%changes) > 0) {
                   22081:                 my %lt = &trust_titles();
                   22082:                 $resulttext = &mt('Changes made:').'<ul>';
                   22083:                 foreach my $prefix (@prefixes) {
                   22084:                     if (ref($changes{$prefix}) eq 'HASH') {
                   22085:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   22086:                         foreach my $type (@types) {
                   22087:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  22088:                                 my ($newvalue,$notinuse);
1.279     raeburn  22089:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   22090:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   22091:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   22092:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   22093:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   22094:                                             }
1.344     raeburn  22095:                                         } else {
                   22096:                                             $notinuse = 1;
1.279     raeburn  22097:                                         }
                   22098:                                     }
                   22099:                                 }
1.344     raeburn  22100:                                 if ($notinuse) {
                   22101:                                     $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                   22102:                                 } elsif ($newvalue eq '') {
1.279     raeburn  22103:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   22104:                                 } else {
                   22105:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   22106:                                 }
                   22107:                             }
                   22108:                         }
                   22109:                         $resulttext .= '</ul>';
                   22110:                     }
                   22111:                 }
                   22112:                 $resulttext .= '</ul>';
                   22113:             } else {
                   22114:                 $resulttext = $nochgmsg;
                   22115:             }
                   22116:         } else {
                   22117:             $resulttext = '<span class="LC_error">'.
                   22118:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   22119:         }
                   22120:     } else {
                   22121:         $resulttext = $nochgmsg;
                   22122:     }
                   22123:     return $resulttext;
                   22124: }
                   22125: 
1.150     raeburn  22126: sub modify_loadbalancing {
                   22127:     my ($dom,%domconfig) = @_;
                   22128:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   22129:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   22130:     my ($othertitle,$usertypes,$types) =
                   22131:         &Apache::loncommon::sorted_inst_types($dom);
                   22132:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  22133:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  22134:     my @sparestypes = ('primary','default');
                   22135:     my %typetitles = &sparestype_titles();
                   22136:     my $resulttext;
1.342     raeburn  22137:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  22138:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   22139:         %existing = %{$domconfig{'loadbalancing'}};
                   22140:     }
                   22141:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  22142:                               \%currtargets,\%currrules,\%currcookies);
1.171     raeburn  22143:     my ($saveloadbalancing,%defaultshash,%changes);
                   22144:     my ($alltypes,$othertypes,$titles) =
                   22145:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   22146:     my %ruletitles = &offloadtype_text();
                   22147:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   22148:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   22149:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   22150:         if ($balancer eq '') {
                   22151:             next;
                   22152:         }
1.210     raeburn  22153:         if (!exists($servers{$balancer})) {
1.171     raeburn  22154:             if (exists($currbalancer{$balancer})) {
                   22155:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  22156:             }
1.171     raeburn  22157:             next;
                   22158:         }
                   22159:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   22160:             push(@{$changes{'delete'}},$balancer);
                   22161:             next;
                   22162:         }
                   22163:         if (!exists($currbalancer{$balancer})) {
                   22164:             push(@{$changes{'add'}},$balancer);
                   22165:         }
                   22166:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   22167:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   22168:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   22169:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   22170:             $saveloadbalancing = 1;
                   22171:         }
                   22172:         foreach my $sparetype (@sparestypes) {
                   22173:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   22174:             my @offloadto;
                   22175:             foreach my $target (@targets) {
                   22176:                 if (($servers{$target}) && ($target ne $balancer)) {
                   22177:                     if ($sparetype eq 'default') {
                   22178:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   22179:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  22180:                         }
                   22181:                     }
1.171     raeburn  22182:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   22183:                         push(@offloadto,$target);
                   22184:                     }
1.150     raeburn  22185:                 }
                   22186:             }
1.284     raeburn  22187:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   22188:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   22189:                     push(@offloadto,$balancer);
                   22190:                 }
                   22191:             }
                   22192:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  22193:         }
1.342     raeburn  22194:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   22195:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   22196:             if (exists($currbalancer{$balancer})) { 
                   22197:                 unless ($currcookies{$balancer}) {
                   22198:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   22199:                 }
                   22200:             }
                   22201:         } elsif (exists($currbalancer{$balancer})) {
                   22202:             if ($currcookies{$balancer}) {
                   22203:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   22204:             }
                   22205:         }
1.171     raeburn  22206:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  22207:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  22208:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   22209:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  22210:                     if (@targetdiffs > 0) {
1.171     raeburn  22211:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  22212:                     }
1.171     raeburn  22213:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22214:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22215:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  22216:                     }
                   22217:                 }
                   22218:             }
                   22219:         } else {
1.171     raeburn  22220:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  22221:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  22222:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22223:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22224:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   22225:                         }
1.150     raeburn  22226:                     }
                   22227:                 }
1.210     raeburn  22228:             }
1.150     raeburn  22229:         }
                   22230:         my $ishomedom;
1.171     raeburn  22231:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   22232:             $ishomedom = 1;
1.150     raeburn  22233:         }
                   22234:         if (ref($alltypes) eq 'ARRAY') {
                   22235:             foreach my $type (@{$alltypes}) {
                   22236:                 my $rule;
1.210     raeburn  22237:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  22238:                          (!$ishomedom)) {
1.171     raeburn  22239:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   22240:                 }
                   22241:                 if ($rule eq 'specific') {
1.255     raeburn  22242:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  22243:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  22244:                         $rule = $specifiedhost;
                   22245:                     }
1.150     raeburn  22246:                 }
1.171     raeburn  22247:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   22248:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   22249:                     if ($rule ne $currrules{$balancer}{$type}) {
                   22250:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  22251:                     }
                   22252:                 } elsif ($rule ne '') {
1.171     raeburn  22253:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  22254:                 }
                   22255:             }
                   22256:         }
1.171     raeburn  22257:     }
                   22258:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   22259:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   22260:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   22261:             $defaultshash{'loadbalancing'} = {};
                   22262:         }
                   22263:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   22264:                                                  \%defaultshash,$dom);
                   22265:         if ($putresult eq 'ok') {
                   22266:             if (keys(%changes) > 0) {
1.252     raeburn  22267:                 my %toupdate;
1.171     raeburn  22268:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   22269:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   22270:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  22271:                         $toupdate{$balancer} = 1;
1.150     raeburn  22272:                     }
1.171     raeburn  22273:                 }
                   22274:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  22275:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  22276:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  22277:                         $toupdate{$balancer} = 1;
1.171     raeburn  22278:                     }
                   22279:                 }
                   22280:                 if (ref($changes{'curr'}) eq 'HASH') {
                   22281:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  22282:                         $toupdate{$balancer} = 1;
1.171     raeburn  22283:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   22284:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   22285:                                 my %offloadstr;
                   22286:                                 foreach my $sparetype (@sparestypes) {
                   22287:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22288:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22289:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   22290:                                         }
                   22291:                                     }
1.150     raeburn  22292:                                 }
1.171     raeburn  22293:                                 if (keys(%offloadstr) == 0) {
                   22294:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  22295:                                 } else {
1.171     raeburn  22296:                                     my $showoffload;
                   22297:                                     foreach my $sparetype (@sparestypes) {
                   22298:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   22299:                                         if (defined($offloadstr{$sparetype})) {
                   22300:                                             $showoffload .= $offloadstr{$sparetype};
                   22301:                                         } else {
                   22302:                                             $showoffload .= &mt('None');
                   22303:                                         }
                   22304:                                         $showoffload .= ('&nbsp;'x3);
                   22305:                                     }
                   22306:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  22307:                                 }
                   22308:                             }
                   22309:                         }
1.171     raeburn  22310:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   22311:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   22312:                                 foreach my $type (@{$alltypes}) {
                   22313:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   22314:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   22315:                                         my $balancetext;
                   22316:                                         if ($rule eq '') {
                   22317:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  22318:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  22319:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  22320:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  22321:                                                 foreach my $sparetype (@sparestypes) {
                   22322:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22323:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   22324:                                                     }
                   22325:                                                 }
1.253     raeburn  22326:                                                 foreach my $item (@{$alltypes}) {
                   22327:                                                     next if ($item =~  /^_LC_ipchange/);
                   22328:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   22329:                                                     if ($hasrule eq 'homeserver') {
                   22330:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   22331:                                                     } else {
                   22332:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   22333:                                                             if ($servers{$hasrule}) {
                   22334:                                                                 $toupdate{$hasrule} = 1;
                   22335:                                                             }
                   22336:                                                         }
                   22337:                                                     }
                   22338:                                                 }
1.254     raeburn  22339:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   22340:                                                     $balancetext =  $ruletitles{$rule};
                   22341:                                                 } else {
                   22342:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   22343:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   22344:                                                     if ($receiver) {
                   22345:                                                         $toupdate{$receiver};
                   22346:                                                     }
                   22347:                                                 }
                   22348:                                             } else {
                   22349:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  22350:                                             }
1.171     raeburn  22351:                                         } else {
                   22352:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   22353:                                         }
1.210     raeburn  22354:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  22355:                                     }
                   22356:                                 }
                   22357:                             }
                   22358:                         }
1.342     raeburn  22359:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389     raeburn  22360:                             if ($currcookies{$balancer}) {
                   22361:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
                   22362:                                                           $balancer).'</li>';
                   22363:                             } else {
                   22364:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   22365:                                                           $balancer).'</li>';
                   22366:                             }
1.342     raeburn  22367:                         }
1.375     raeburn  22368:                     }
                   22369:                 }
                   22370:                 if (keys(%toupdate)) {
                   22371:                     my %thismachine;
                   22372:                     my $updatedhere;
                   22373:                     my $cachetime = 60*60*24;
                   22374:                     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   22375:                     foreach my $lonhost (keys(%toupdate)) {
                   22376:                         if ($thismachine{$lonhost}) {
                   22377:                             unless ($updatedhere) {
                   22378:                                 &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   22379:                                                               $defaultshash{'loadbalancing'},
                   22380:                                                               $cachetime);
                   22381:                                 $updatedhere = 1;
1.252     raeburn  22382:                             }
1.375     raeburn  22383:                         } else {
                   22384:                             my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   22385:                             &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252     raeburn  22386:                         }
1.150     raeburn  22387:                     }
1.171     raeburn  22388:                 }
                   22389:                 if ($resulttext ne '') {
                   22390:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  22391:                 } else {
                   22392:                     $resulttext = $nochgmsg;
                   22393:                 }
                   22394:             } else {
1.171     raeburn  22395:                 $resulttext = $nochgmsg;
1.150     raeburn  22396:             }
                   22397:         } else {
1.171     raeburn  22398:             $resulttext = '<span class="LC_error">'.
                   22399:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  22400:         }
                   22401:     } else {
1.171     raeburn  22402:         $resulttext = $nochgmsg;
1.150     raeburn  22403:     }
                   22404:     return $resulttext;
                   22405: }
                   22406: 
1.48      raeburn  22407: sub recurse_check {
                   22408:     my ($chkcats,$categories,$depth,$name) = @_;
                   22409:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   22410:         my $chg = 0;
                   22411:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   22412:             my $category = $chkcats->[$depth]{$name}[$j];
                   22413:             my $item;
                   22414:             if ($category eq '') {
                   22415:                 $chg ++;
                   22416:             } else {
                   22417:                 my $deeper = $depth + 1;
                   22418:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   22419:                 if ($chg) {
                   22420:                     $categories->{$item} -= $chg;
                   22421:                 }
                   22422:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   22423:                 $deeper --;
                   22424:             }
                   22425:         }
                   22426:     }
                   22427:     return;
                   22428: }
                   22429: 
                   22430: sub recurse_cat_deletes {
                   22431:     my ($item,$coursecategories,$deletions) = @_;
                   22432:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   22433:     my $subdepth = $depth + 1;
                   22434:     if (ref($coursecategories) eq 'HASH') {
                   22435:         foreach my $subitem (keys(%{$coursecategories})) {
                   22436:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   22437:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   22438:                 delete($coursecategories->{$subitem});
                   22439:                 $deletions->{$subitem} = 1;
                   22440:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  22441:             }
1.48      raeburn  22442:         }
                   22443:     }
                   22444:     return;
                   22445: }
                   22446: 
1.125     raeburn  22447: sub active_dc_picker {
1.191     raeburn  22448:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  22449:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  22450:     my @domcoord = keys(%domcoords);
                   22451:     if (keys(%currhash)) {
                   22452:         foreach my $dc (keys(%currhash)) {
                   22453:             unless (exists($domcoords{$dc})) {
                   22454:                 push(@domcoord,$dc);
                   22455:             }
                   22456:         }
                   22457:     }
                   22458:     @domcoord = sort(@domcoord);
1.210     raeburn  22459:     my $numdcs = scalar(@domcoord);
1.191     raeburn  22460:     my $rows = 0;
                   22461:     my $table;
1.125     raeburn  22462:     if ($numdcs > 1) {
1.191     raeburn  22463:         $table = '<table>';
                   22464:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  22465:             my $rem = $i%($numinrow);
                   22466:             if ($rem == 0) {
                   22467:                 if ($i > 0) {
1.191     raeburn  22468:                     $table .= '</tr>';
1.125     raeburn  22469:                 }
1.191     raeburn  22470:                 $table .= '<tr>';
                   22471:                 $rows ++;
1.125     raeburn  22472:             }
1.191     raeburn  22473:             my $check = '';
                   22474:             if ($inputtype eq 'radio') {
                   22475:                 if (keys(%currhash) == 0) {
                   22476:                     if (!$i) {
                   22477:                         $check = ' checked="checked"';
                   22478:                     }
                   22479:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   22480:                     $check = ' checked="checked"';
                   22481:                 }
                   22482:             } else {
                   22483:                 if (exists($currhash{$domcoord[$i]})) {
                   22484:                     $check = ' checked="checked"';
1.125     raeburn  22485:                 }
                   22486:             }
1.191     raeburn  22487:             if ($i == @domcoord - 1) {
1.125     raeburn  22488:                 my $colsleft = $numinrow - $rem;
                   22489:                 if ($colsleft > 1) {
1.191     raeburn  22490:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  22491:                 } else {
1.191     raeburn  22492:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  22493:                 }
                   22494:             } else {
1.191     raeburn  22495:                 $table .= '<td class="LC_left_item">';
                   22496:             }
                   22497:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   22498:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   22499:             $table .= '<span class="LC_nobreak"><label>'.
                   22500:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   22501:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   22502:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  22503:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  22504:             }
1.219     raeburn  22505:             $table .= '</label></span></td>';
1.191     raeburn  22506:         }
                   22507:         $table .= '</tr></table>';
                   22508:     } elsif ($numdcs == 1) {
1.219     raeburn  22509:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   22510:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  22511:         if ($inputtype eq 'radio') {
1.247     raeburn  22512:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  22513:             if ($user ne $dcname.':'.$dcdom) {
                   22514:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   22515:             }
1.191     raeburn  22516:         } else {
                   22517:             my $check;
                   22518:             if (exists($currhash{$domcoord[0]})) {
                   22519:                 $check = ' checked="checked"';
1.125     raeburn  22520:             }
1.247     raeburn  22521:             $table = '<span class="LC_nobreak"><label>'.
                   22522:                      '<input type="checkbox" name="'.$name.'" '.
                   22523:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  22524:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  22525:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  22526:             }
1.220     raeburn  22527:             $table .= '</label></span>';
1.191     raeburn  22528:             $rows ++;
1.125     raeburn  22529:         }
                   22530:     }
1.191     raeburn  22531:     return ($numdcs,$table,$rows);
1.125     raeburn  22532: }
                   22533: 
1.137     raeburn  22534: sub usersession_titles {
                   22535:     return &Apache::lonlocal::texthash(
                   22536:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   22537:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  22538:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  22539:                version => 'LON-CAPA version requirement',
1.138     raeburn  22540:                excludedomain => 'Allow all, but exclude specific domains',
                   22541:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  22542:                primary => 'Primary (checked first)',
1.154     raeburn  22543:                default => 'Default',
1.137     raeburn  22544:            );
                   22545: }
                   22546: 
1.152     raeburn  22547: sub id_for_thisdom {
                   22548:     my (%servers) = @_;
                   22549:     my %altids;
                   22550:     foreach my $server (keys(%servers)) {
                   22551:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   22552:         if ($serverhome ne $server) {
                   22553:             $altids{$serverhome} = $server;
                   22554:         }
                   22555:     }
                   22556:     return %altids;
                   22557: }
                   22558: 
1.150     raeburn  22559: sub count_servers {
                   22560:     my ($currbalancer,%servers) = @_;
                   22561:     my (@spares,$numspares);
                   22562:     foreach my $lonhost (sort(keys(%servers))) {
                   22563:         next if ($currbalancer eq $lonhost);
                   22564:         push(@spares,$lonhost);
                   22565:     }
                   22566:     if ($currbalancer) {
                   22567:         $numspares = scalar(@spares);
                   22568:     } else {
                   22569:         $numspares = scalar(@spares) - 1;
                   22570:     }
                   22571:     return ($numspares,@spares);
                   22572: }
                   22573: 
                   22574: sub lonbalance_targets_js {
1.171     raeburn  22575:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  22576:     my $select = &mt('Select');
                   22577:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   22578:     if (ref($servers) eq 'HASH') {
                   22579:         $alltargets = join("','",sort(keys(%{$servers})));
                   22580:         my @homedoms;
                   22581:         foreach my $server (sort(keys(%{$servers}))) {
                   22582:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   22583:                 push(@homedoms,'1');
                   22584:             } else {
                   22585:                 push(@homedoms,'0');
                   22586:             }
                   22587:         }
                   22588:         $allishome = join("','",@homedoms);
                   22589:     }
                   22590:     if (ref($types) eq 'ARRAY') {
                   22591:         if (@{$types} > 0) {
                   22592:             @alltypes = @{$types};
                   22593:         }
                   22594:     }
                   22595:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   22596:     $allinsttypes = join("','",@alltypes);
1.342     raeburn  22597:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  22598:     if (ref($settings) eq 'HASH') {
                   22599:         %existing = %{$settings};
                   22600:     }
                   22601:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342     raeburn  22602:                               \%currtargets,\%currrules,\%currcookies);
1.210     raeburn  22603:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  22604:     return <<"END";
                   22605: 
                   22606: <script type="text/javascript">
                   22607: // <![CDATA[
                   22608: 
1.171     raeburn  22609: currBalancers = new Array('$balancers');
                   22610: 
                   22611: function toggleTargets(balnum) {
                   22612:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   22613:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   22614:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   22615:     var prevbalancer = prevhostitem.value;
                   22616:     var baltotal = document.getElementById('loadbalancing_total').value;
                   22617:     prevhostitem.value = balancer;
                   22618:     if (prevbalancer != '') {
                   22619:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   22620:         if (prevIdx != -1) {
                   22621:             currBalancers.splice(prevIdx,1);
                   22622:         }
                   22623:     }
1.150     raeburn  22624:     if (balancer == '') {
1.171     raeburn  22625:         hideSpares(balnum);
1.150     raeburn  22626:     } else {
1.171     raeburn  22627:         var currIdx = currBalancers.indexOf(balancer);
                   22628:         if (currIdx == -1) {
                   22629:             currBalancers.push(balancer);
                   22630:         }
1.150     raeburn  22631:         var homedoms = new Array('$allishome');
1.171     raeburn  22632:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   22633:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  22634:     }
1.171     raeburn  22635:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  22636:     return;
                   22637: }
                   22638: 
1.171     raeburn  22639: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  22640:     var alltargets = new Array('$alltargets');
                   22641:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  22642:     var offloadtypes = new Array('primary','default');
                   22643: 
1.171     raeburn  22644:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   22645:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  22646:  
1.151     raeburn  22647:     for (var i=0; i<offloadtypes.length; i++) {
                   22648:         var count = 0;
                   22649:         for (var j=0; j<alltargets.length; j++) {
                   22650:             if (alltargets[j] != balancer) {
1.171     raeburn  22651:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   22652:                 item.value = alltargets[j];
                   22653:                 item.style.textAlign='left';
                   22654:                 item.style.textFace='normal';
                   22655:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   22656:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   22657:                     item.disabled = '';
                   22658:                 } else {
                   22659:                     item.disabled = 'disabled';
                   22660:                     item.checked = false;
                   22661:                 }
1.151     raeburn  22662:                 count ++;
                   22663:             }
1.150     raeburn  22664:         }
                   22665:     }
1.151     raeburn  22666:     for (var k=0; k<insttypes.length; k++) {
                   22667:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  22668:             if (ishomedom == 1) {
1.171     raeburn  22669:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   22670:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  22671:             } else {
1.171     raeburn  22672:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   22673:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  22674:             }
                   22675:         } else {
1.171     raeburn  22676:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   22677:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  22678:         }
1.151     raeburn  22679:         if ((insttypes[k] != '_LC_external') && 
                   22680:             ((insttypes[k] != '_LC_internetdom') ||
                   22681:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  22682:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   22683:             item.options.length = 0;
                   22684:             item.options[0] = new Option("","",true,true);
1.210     raeburn  22685:             var idx = 0;
1.151     raeburn  22686:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  22687:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   22688:                     idx ++;
                   22689:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  22690:                 }
                   22691:             }
                   22692:         }
                   22693:     }
                   22694:     return;
                   22695: }
                   22696: 
1.171     raeburn  22697: function hideSpares(balnum) {
1.150     raeburn  22698:     var alltargets = new Array('$alltargets');
                   22699:     var insttypes = new Array('$allinsttypes');
                   22700:     var offloadtypes = new Array('primary','default');
                   22701: 
1.171     raeburn  22702:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   22703:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  22704: 
                   22705:     var total = alltargets.length - 1;
                   22706:     for (var i=0; i<offloadtypes; i++) {
                   22707:         for (var j=0; j<total; j++) {
1.171     raeburn  22708:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   22709:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   22710:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  22711:         }
1.150     raeburn  22712:     }
                   22713:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  22714:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   22715:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  22716:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  22717:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   22718:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  22719:         }
                   22720:     }
                   22721:     return;
                   22722: }
                   22723: 
1.171     raeburn  22724: function checkOffloads(item,balnum,type) {
1.150     raeburn  22725:     var alltargets = new Array('$alltargets');
                   22726:     var offloadtypes = new Array('primary','default');
                   22727:     if (item.checked) {
                   22728:         var total = alltargets.length - 1;
                   22729:         var other;
                   22730:         if (type == offloadtypes[0]) {
1.151     raeburn  22731:             other = offloadtypes[1];
1.150     raeburn  22732:         } else {
1.151     raeburn  22733:             other = offloadtypes[0];
1.150     raeburn  22734:         }
                   22735:         for (var i=0; i<total; i++) {
1.171     raeburn  22736:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  22737:             if (server == item.value) {
1.171     raeburn  22738:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   22739:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  22740:                 }
                   22741:             }
                   22742:         }
                   22743:     }
                   22744:     return;
                   22745: }
                   22746: 
1.171     raeburn  22747: function singleServerToggle(balnum,type) {
                   22748:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  22749:     if (offloadtoSelIdx == 0) {
1.171     raeburn  22750:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   22751:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  22752: 
                   22753:     } else {
1.171     raeburn  22754:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   22755:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  22756:     }
                   22757:     return;
                   22758: }
                   22759: 
1.171     raeburn  22760: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  22761:     if (type == '_LC_external') {
1.171     raeburn  22762:         return;
1.150     raeburn  22763:     }
1.171     raeburn  22764:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  22765:     for (var i=0; i<typesRules.length; i++) {
                   22766:         if (formname.elements[typesRules[i]].checked) {
                   22767:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  22768:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   22769:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  22770:             } else {
1.171     raeburn  22771:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   22772:             }
                   22773:         }
                   22774:     }
                   22775:     return;
                   22776: }
                   22777: 
                   22778: function balancerDeleteChange(balnum) {
                   22779:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   22780:     var baltotal = document.getElementById('loadbalancing_total').value;
                   22781:     var addtarget;
                   22782:     var removetarget;
                   22783:     var action = 'delete';
                   22784:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   22785:         var lonhost = hostitem.value;
                   22786:         var currIdx = currBalancers.indexOf(lonhost);
                   22787:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   22788:             if (currIdx != -1) {
                   22789:                 currBalancers.splice(currIdx,1);
                   22790:             }
                   22791:             addtarget = lonhost;
                   22792:         } else {
                   22793:             if (currIdx == -1) {
                   22794:                 currBalancers.push(lonhost);
                   22795:             }
                   22796:             removetarget = lonhost;
                   22797:             action = 'undelete';
                   22798:         }
                   22799:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   22800:     }
                   22801:     return;
                   22802: }
                   22803: 
                   22804: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   22805:     if (baltotal > 1) {
                   22806:         var offloadtypes = new Array('primary','default');
                   22807:         var alltargets = new Array('$alltargets');
                   22808:         var insttypes = new Array('$allinsttypes');
                   22809:         for (var i=0; i<baltotal; i++) {
                   22810:             if (i != balnum) {
                   22811:                 for (var j=0; j<offloadtypes.length; j++) {
                   22812:                     var total = alltargets.length - 1;
                   22813:                     for (var k=0; k<total; k++) {
                   22814:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   22815:                         var server = serveritem.value;
                   22816:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   22817:                             if (server == addtarget) {
                   22818:                                 serveritem.disabled = '';
                   22819:                             }
                   22820:                         }
                   22821:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   22822:                             if (server == removetarget) {
                   22823:                                 serveritem.disabled = 'disabled';
                   22824:                                 serveritem.checked = false;
                   22825:                             }
                   22826:                         }
                   22827:                     }
                   22828:                 }
                   22829:                 for (var j=0; j<insttypes.length; j++) {
                   22830:                     if (insttypes[j] != '_LC_external') {
                   22831:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   22832:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   22833:                             var currSel = singleserver.selectedIndex;
                   22834:                             var currVal = singleserver.options[currSel].value;
                   22835:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   22836:                                 var numoptions = singleserver.options.length;
                   22837:                                 var needsnew = 1;
                   22838:                                 for (var k=0; k<numoptions; k++) {
                   22839:                                     if (singleserver.options[k] == addtarget) {
                   22840:                                         needsnew = 0;
                   22841:                                         break;
                   22842:                                     }
                   22843:                                 }
                   22844:                                 if (needsnew == 1) {
                   22845:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   22846:                                 }
                   22847:                             }
                   22848:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   22849:                                 singleserver.options.length = 0;
                   22850:                                 if ((currVal) && (currVal != removetarget)) {
                   22851:                                     singleserver.options[0] = new Option("","",false,false);
                   22852:                                 } else {
                   22853:                                     singleserver.options[0] = new Option("","",true,true);
                   22854:                                 }
                   22855:                                 var idx = 0;
                   22856:                                 for (var m=0; m<alltargets.length; m++) {
                   22857:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   22858:                                         idx ++;
                   22859:                                         if (currVal == alltargets[m]) {
                   22860:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   22861:                                         } else {
                   22862:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   22863:                                         }
                   22864:                                     }
                   22865:                                 }
                   22866:                             }
                   22867:                         }
                   22868:                     }
                   22869:                 }
1.150     raeburn  22870:             }
                   22871:         }
                   22872:     }
                   22873:     return;
                   22874: }
                   22875: 
1.152     raeburn  22876: // ]]>
                   22877: </script>
                   22878: 
                   22879: END
                   22880: }
                   22881: 
1.372     raeburn  22882: 
1.152     raeburn  22883: sub new_spares_js {
                   22884:     my @sparestypes = ('primary','default');
                   22885:     my $types = join("','",@sparestypes);
                   22886:     my $select = &mt('Select');
                   22887:     return <<"END";
                   22888: 
                   22889: <script type="text/javascript">
                   22890: // <![CDATA[
                   22891: 
                   22892: function updateNewSpares(formname,lonhost) {
                   22893:     var types = new Array('$types');
                   22894:     var include = new Array();
                   22895:     var exclude = new Array();
                   22896:     for (var i=0; i<types.length; i++) {
                   22897:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   22898:         for (var j=0; j<spareboxes.length; j++) {
                   22899:             if (formname.elements[spareboxes[j]].checked) {
                   22900:                 exclude.push(formname.elements[spareboxes[j]].value);
                   22901:             } else {
                   22902:                 include.push(formname.elements[spareboxes[j]].value);
                   22903:             }
                   22904:         }
                   22905:     }
                   22906:     for (var i=0; i<types.length; i++) {
                   22907:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   22908:         var selIdx = newSpare.selectedIndex;
                   22909:         var currnew = newSpare.options[selIdx].value;
                   22910:         var okSpares = new Array();
                   22911:         for (var j=0; j<newSpare.options.length; j++) {
                   22912:             var possible = newSpare.options[j].value;
                   22913:             if (possible != '') {
                   22914:                 if (exclude.indexOf(possible) == -1) {
                   22915:                     okSpares.push(possible);
                   22916:                 } else {
                   22917:                     if (currnew == possible) {
                   22918:                         selIdx = 0;
                   22919:                     }
                   22920:                 }
                   22921:             }
                   22922:         }
                   22923:         for (var k=0; k<include.length; k++) {
                   22924:             if (okSpares.indexOf(include[k]) == -1) {
                   22925:                 okSpares.push(include[k]);
                   22926:             }
                   22927:         }
                   22928:         okSpares.sort();
                   22929:         newSpare.options.length = 0;
                   22930:         if (selIdx == 0) {
                   22931:             newSpare.options[0] = new Option("$select","",true,true);
                   22932:         } else {
                   22933:             newSpare.options[0] = new Option("$select","",false,false);
                   22934:         }
                   22935:         for (var m=0; m<okSpares.length; m++) {
                   22936:             var idx = m+1;
                   22937:             var selThis = 0;
                   22938:             if (selIdx != 0) {
                   22939:                 if (okSpares[m] == currnew) {
                   22940:                     selThis = 1;
                   22941:                 }
                   22942:             }
                   22943:             if (selThis == 1) {
                   22944:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   22945:             } else {
                   22946:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   22947:             }
                   22948:         }
                   22949:     }
                   22950:     return;
                   22951: }
                   22952: 
                   22953: function checkNewSpares(lonhost,type) {
                   22954:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   22955:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
1.372     raeburn  22956:     if (chosen != '') {
1.152     raeburn  22957:         var othertype;
                   22958:         var othernewSpare;
                   22959:         if (type == 'primary') {
                   22960:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   22961:         }
                   22962:         if (type == 'default') {
                   22963:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   22964:         }
                   22965:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   22966:             othernewSpare.selectedIndex = 0;
                   22967:         }
                   22968:     }
                   22969:     return;
                   22970: }
                   22971: 
                   22972: // ]]>
                   22973: </script>
                   22974: 
                   22975: END
                   22976: 
                   22977: }
                   22978: 
                   22979: sub common_domprefs_js {
                   22980:     return <<"END";
                   22981: 
                   22982: <script type="text/javascript">
                   22983: // <![CDATA[
                   22984: 
1.150     raeburn  22985: function getIndicesByName(formname,item) {
1.152     raeburn  22986:     var group = new Array();
1.150     raeburn  22987:     for (var i=0;i<formname.elements.length;i++) {
                   22988:         if (formname.elements[i].name == item) {
1.152     raeburn  22989:             group.push(formname.elements[i].id);
1.150     raeburn  22990:         }
                   22991:     }
1.152     raeburn  22992:     return group;
1.150     raeburn  22993: }
                   22994: 
                   22995: // ]]>
                   22996: </script>
                   22997: 
                   22998: END
1.152     raeburn  22999: 
1.150     raeburn  23000: }
                   23001: 
1.165     raeburn  23002: sub recaptcha_js {
                   23003:     my %lt = &captcha_phrases();
                   23004:     return <<"END";
                   23005: 
                   23006: <script type="text/javascript">
                   23007: // <![CDATA[
                   23008: 
                   23009: function updateCaptcha(caller,context) {
                   23010:     var privitem;
                   23011:     var pubitem;
                   23012:     var privtext;
                   23013:     var pubtext;
1.269     raeburn  23014:     var versionitem;
                   23015:     var versiontext;
1.165     raeburn  23016:     if (document.getElementById(context+'_recaptchapub')) {
                   23017:         pubitem = document.getElementById(context+'_recaptchapub');
                   23018:     } else {
                   23019:         return;
                   23020:     }
                   23021:     if (document.getElementById(context+'_recaptchapriv')) {
                   23022:         privitem = document.getElementById(context+'_recaptchapriv');
                   23023:     } else {
                   23024:         return;
                   23025:     }
                   23026:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   23027:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   23028:     } else {
                   23029:         return;
                   23030:     }
                   23031:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   23032:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   23033:     } else {
                   23034:         return;
                   23035:     }
1.269     raeburn  23036:     if (document.getElementById(context+'_recaptchaversion')) {
                   23037:         versionitem = document.getElementById(context+'_recaptchaversion');
                   23038:     } else {
                   23039:         return;
                   23040:     }
                   23041:     if (document.getElementById(context+'_recaptchavertxt')) {
                   23042:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   23043:     } else {
                   23044:         return;
                   23045:     }
1.165     raeburn  23046:     if (caller.checked) {
                   23047:         if (caller.value == 'recaptcha') {
                   23048:             pubitem.type = 'text';
                   23049:             privitem.type = 'text';
                   23050:             pubitem.size = '40';
                   23051:             privitem.size = '40';
                   23052:             pubtext.innerHTML = "$lt{'pub'}";
                   23053:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  23054:             versionitem.type = 'text';
                   23055:             versionitem.size = '3';
1.289     raeburn  23056:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  23057:         } else {
                   23058:             pubitem.type = 'hidden';
                   23059:             privitem.type = 'hidden';
1.269     raeburn  23060:             versionitem.type = 'hidden';
1.165     raeburn  23061:             pubtext.innerHTML = '';
                   23062:             privtext.innerHTML = '';
1.269     raeburn  23063:             versiontext.innerHTML = '';
1.165     raeburn  23064:         }
                   23065:     }
                   23066:     return;
                   23067: }
                   23068: 
                   23069: // ]]>
                   23070: </script>
                   23071: 
                   23072: END
                   23073: 
                   23074: }
                   23075: 
1.236     raeburn  23076: sub toggle_display_js {
1.192     raeburn  23077:     return <<"END";
                   23078: 
                   23079: <script type="text/javascript">
                   23080: // <![CDATA[
                   23081: 
1.236     raeburn  23082: function toggleDisplay(domForm,caller) {
                   23083:     if (document.getElementById(caller)) {
                   23084:         var divitem = document.getElementById(caller);
                   23085:         var optionsElement = domForm.coursecredits;
1.264     raeburn  23086:         var checkval = 1;
                   23087:         var dispval = 'block';
1.303     raeburn  23088:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  23089:         if (caller == 'emailoptions') {
1.372     raeburn  23090:             optionsElement = domForm.cancreate_email;
1.236     raeburn  23091:         }
1.257     raeburn  23092:         if (caller == 'studentsubmission') {
                   23093:             optionsElement = domForm.postsubmit;
                   23094:         }
1.264     raeburn  23095:         if (caller == 'cloneinstcode') {
                   23096:             optionsElement = domForm.canclone;
                   23097:             checkval = 'instcode';
                   23098:         }
1.303     raeburn  23099:         if (selfcreateRegExp.test(caller)) {
                   23100:             optionsElement = domForm.elements[caller];
                   23101:             checkval = 'other';
                   23102:             dispval = 'inline'
                   23103:         }
1.236     raeburn  23104:         if (optionsElement.length) {
1.192     raeburn  23105:             var currval;
1.236     raeburn  23106:             for (var i=0; i<optionsElement.length; i++) {
                   23107:                 if (optionsElement[i].checked) {
                   23108:                    currval = optionsElement[i].value;
1.192     raeburn  23109:                 }
                   23110:             }
1.264     raeburn  23111:             if (currval == checkval) {
                   23112:                 divitem.style.display = dispval;
1.192     raeburn  23113:             } else {
1.236     raeburn  23114:                 divitem.style.display = 'none';
1.192     raeburn  23115:             }
                   23116:         }
                   23117:     }
                   23118:     return;
                   23119: }
                   23120: 
                   23121: // ]]>
                   23122: </script>
                   23123: 
                   23124: END
                   23125: 
                   23126: }
                   23127: 
1.165     raeburn  23128: sub captcha_phrases {
                   23129:     return &Apache::lonlocal::texthash (
                   23130:                  priv => 'Private key',
                   23131:                  pub  => 'Public key',
                   23132:                  original  => 'original (CAPTCHA)',
                   23133:                  recaptcha => 'successor (ReCAPTCHA)',
                   23134:                  notused   => 'unused',
1.289     raeburn  23135:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  23136:     );
                   23137: }
                   23138: 
1.205     raeburn  23139: sub devalidate_remote_domconfs {
1.212     raeburn  23140:     my ($dom,$cachekeys) = @_;
                   23141:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  23142:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   23143:     my %thismachine;
                   23144:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355     raeburn  23145:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394     raeburn  23146:                       'directorysrch','passwdconf','cats','proxyalias','proxysaml',
                   23147:                       'ipaccess');
1.386     raeburn  23148:     my %cache_by_lonhost;
                   23149:     if (exists($cachekeys->{'samllanding'})) {
                   23150:         if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
                   23151:             my %landing = %{$cachekeys->{'samllanding'}};
                   23152:             my %domservers = &Apache::lonnet::get_servers($dom);
                   23153:             if (keys(%domservers)) {
                   23154:                 foreach my $server (keys(%domservers)) {
                   23155:                     my @cached;
                   23156:                     next if ($thismachine{$server});
                   23157:                     if ($landing{$server}) {
                   23158:                         push(@cached,&escape('samllanding').':'.&escape($server));
                   23159:                     }
                   23160:                     if (@cached) {
                   23161:                         $cache_by_lonhost{$server} = \@cached;
                   23162:                     }
                   23163:                 }
                   23164:             }
                   23165:         }
                   23166:     }
1.260     raeburn  23167:     if (keys(%servers)) {
1.205     raeburn  23168:         foreach my $server (keys(%servers)) {
                   23169:             next if ($thismachine{$server});
1.212     raeburn  23170:             my @cached;
                   23171:             foreach my $name (@posscached) {
                   23172:                 if ($cachekeys->{$name}) {
1.388     raeburn  23173:                     if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386     raeburn  23174:                         if (ref($cachekeys->{$name}) eq 'HASH') {
1.373     raeburn  23175:                             foreach my $key (keys(%{$cachekeys->{$name}})) {
                   23176:                                 push(@cached,&escape($name).':'.&escape($key));
                   23177:                             }
                   23178:                         }
                   23179:                     } else {
                   23180:                         push(@cached,&escape($name).':'.&escape($dom));
                   23181:                     }
1.212     raeburn  23182:                 }
                   23183:             }
1.386     raeburn  23184:             if ((exists($cache_by_lonhost{$server})) &&
                   23185:                 (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
                   23186:                 push(@cached,@{$cache_by_lonhost{$server}});
                   23187:             }
1.212     raeburn  23188:             if (@cached) {
                   23189:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   23190:             }
1.205     raeburn  23191:         }
                   23192:     }
                   23193:     return;
                   23194: }
                   23195: 
1.3       raeburn  23196: 1;

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