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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.395   ! raeburn     4: # $Id: domainprefs.pm,v 1.394 2021/11/28 19:17:59 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.386     raeburn   880:     } elsif ($action eq 'login') {
                    881:         $output .= &saml_javascript();
1.394     raeburn   882:     } elsif ($action eq 'ipaccess') {
                    883:         $output .= &ipaccess_javascript($settings);
1.91      raeburn   884:     }
1.236     raeburn   885:     $output .=
1.30      raeburn   886:          '<table class="LC_nested_outer">
1.3       raeburn   887:           <tr>
1.306     raeburn   888:            <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66      raeburn   889:            &mt($item->{text}).'&nbsp;'.
                    890:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    891:           '</tr>';
1.30      raeburn   892:     $rowtotal ++;
1.110     raeburn   893:     my $numheaders = 1;
                    894:     if (ref($item->{'header'}) eq 'ARRAY') {
                    895:         $numheaders = scalar(@{$item->{'header'}});
                    896:     }
                    897:     if ($numheaders > 1) {
1.64      raeburn   898:         my $colspan = '';
1.145     raeburn   899:         my $rightcolspan = '';
1.369     raeburn   900:         my $leftnobr = '';
1.238     raeburn   901:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   902:             ($action eq 'directorysrch') ||
1.386     raeburn   903:             (($action eq 'login') && ($numheaders < 5))) {
1.64      raeburn   904:             $colspan = ' colspan="2"';
                    905:         }
1.145     raeburn   906:         if ($action eq 'usersessions') {
                    907:             $rightcolspan = ' colspan="3"'; 
                    908:         }
1.369     raeburn   909:         if ($action eq 'passwords') {
                    910:             $leftnobr = ' LC_nobreak';
                    911:         }
1.30      raeburn   912:         $output .= '
1.3       raeburn   913:           <tr>
                    914:            <td>
                    915:             <table class="LC_nested">
                    916:              <tr class="LC_info_row">
1.369     raeburn   917:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   918:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   919:              </tr>';
1.69      raeburn   920:         $rowtotal ++;
1.230     raeburn   921:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   922:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   923:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286     raeburn   924:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373     raeburn   925:             ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230     raeburn   926:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354     raeburn   927:         } elsif ($action eq 'passwords') {
                    928:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   929:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   930:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346     raeburn   931:         } elsif ($action eq 'scantron') {
                    932:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   933:         } elsif ($action eq 'login') {
1.386     raeburn   934:             if ($numheaders == 5) {
1.168     raeburn   935:                 $colspan = ' colspan="2"';
                    936:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    937:             } else {
                    938:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    939:             }
1.230     raeburn   940:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   941:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       942:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   943:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   944:         }
1.30      raeburn   945:         $output .= '
1.6       raeburn   946:            </table>
                    947:           </td>
                    948:          </tr>
                    949:          <tr>
                    950:            <td>
                    951:             <table class="LC_nested">
                    952:              <tr class="LC_info_row">
1.230     raeburn   953:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    954:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   955:              </tr>';
                    956:             $rowtotal ++;
1.230     raeburn   957:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    958:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn   959:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.357     raeburn   960:             ($action eq 'trust') || ($action eq 'contacts') ||
                    961:             ($action eq 'privacy') || ($action eq 'passwords')) {
1.238     raeburn   962:             if ($action eq 'coursecategories') {
                    963:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    964:                 $colspan = ' colspan="2"';
1.279     raeburn   965:             } elsif ($action eq 'trust') {
                    966:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354     raeburn   967:             } elsif ($action eq 'passwords') {
                    968:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238     raeburn   969:             } else {
                    970:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    971:             }
1.279     raeburn   972:             if ($action eq 'trust') {
                    973:                 $output .= '
                    974:             </table>
                    975:           </td>
                    976:          </tr>';
                    977:                 my @trusthdrs = qw(2 3 4 5 6 7);
                    978:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                    979:                 for (my $i=0; $i<@trusthdrs; $i++) {
                    980:                     $output .= '
                    981:          <tr>
                    982:            <td>
                    983:             <table class="LC_nested">
                    984:              <tr class="LC_info_row">
                    985:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                    986:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                    987:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                    988:             </table>
                    989:           </td>
                    990:          </tr>';
                    991:                 }
                    992:                 $output .= '
                    993:          <tr>
                    994:            <td>
                    995:             <table class="LC_nested">
                    996:              <tr class="LC_info_row">
                    997:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                    998:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                    999:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1000:             } else {
                   1001:                 $output .= '
1.63      raeburn  1002:            </table>
                   1003:           </td>
                   1004:          </tr>
                   1005:          <tr>
                   1006:            <td>
                   1007:             <table class="LC_nested">
                   1008:              <tr class="LC_info_row">
                   1009:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn  1010:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn  1011:              </tr>'."\n";
1.279     raeburn  1012:                 if ($action eq 'coursecategories') {
                   1013:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357     raeburn  1014:                 } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354     raeburn  1015:                     if ($action eq 'passwords') {
                   1016:                         $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                   1017:                     } else {
                   1018:                         $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                   1019:                     }
                   1020:                     $output .= '
1.340     raeburn  1021:              </tr>
                   1022:             </table>
                   1023:            </td>
                   1024:           </tr>
                   1025:           <tr>
                   1026:            <td>
                   1027:             <table class="LC_nested">
                   1028:              <tr class="LC_info_row">
1.369     raeburn  1029:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354     raeburn  1030:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
                   1031:                     if ($action eq 'passwords') {
                   1032:                         $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                   1033:                     } else {
                   1034:                         $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1035:                     }
                   1036:                     $output .= '
1.340     raeburn  1037:             </table>
                   1038:           </td>
                   1039:          </tr>
                   1040:          <tr>';
1.279     raeburn  1041:                 } else {
                   1042:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                   1043:                 }
1.238     raeburn  1044:             }
1.63      raeburn  1045:             $rowtotal ++;
1.236     raeburn  1046:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282     raeburn  1047:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373     raeburn  1048:                  ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230     raeburn  1049:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346     raeburn  1050:         } elsif ($action eq 'scantron') {
                   1051:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293     raeburn  1052:         } elsif ($action eq 'ssl') {
                   1053:             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
                   1054:             </table>
                   1055:           </td>
                   1056:          </tr>
                   1057:          <tr>
                   1058:            <td>
                   1059:             <table class="LC_nested">
                   1060:              <tr class="LC_info_row">
                   1061:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1062:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                   1063:                            $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
                   1064:             </table>
                   1065:           </td>
                   1066:          </tr>
                   1067:          <tr>
                   1068:            <td>
                   1069:             <table class="LC_nested">
                   1070:              <tr class="LC_info_row">
                   1071:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1072:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                   1073:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn  1074:         } elsif ($action eq 'login') {
1.386     raeburn  1075:             if ($numheaders == 5) {
1.168     raeburn  1076:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1077:            </table>
                   1078:           </td>
                   1079:          </tr>
                   1080:          <tr>
                   1081:            <td>
                   1082:             <table class="LC_nested">
                   1083:              <tr class="LC_info_row">
                   1084:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn  1085:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn  1086:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1087:                 $rowtotal ++;
                   1088:             } else {
                   1089:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1090:             }
1.256     raeburn  1091:             $output .= '
                   1092:            </table>
                   1093:           </td>
                   1094:          </tr>
                   1095:          <tr>
                   1096:            <td>
                   1097:             <table class="LC_nested">
                   1098:              <tr class="LC_info_row">';
1.386     raeburn  1099:             if ($numheaders == 5) {
1.256     raeburn  1100:                 $output .= '
                   1101:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1102:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1103:              </tr>';
                   1104:             } else {
                   1105:                 $output .= '
                   1106:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1107:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                   1108:              </tr>';
                   1109:             }
                   1110:             $rowtotal ++;
1.386     raeburn  1111:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1112:            </table>
                   1113:           </td>
                   1114:          </tr>
                   1115:          <tr>
                   1116:            <td>
                   1117:             <table class="LC_nested">
                   1118:              <tr class="LC_info_row">';
                   1119:             if ($numheaders == 5) {
                   1120:                 $output .= '
                   1121:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1122:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
                   1123:              </tr>';
                   1124:             } else {
                   1125:                 $output .= '
                   1126:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1127:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1128:              </tr>';
                   1129:             }
                   1130:             $rowtotal ++;
                   1131:             $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn  1132:         } elsif ($action eq 'requestcourses') {
1.247     raeburn  1133:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                   1134:             $rowtotal ++;
                   1135:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn  1136:            </table>
                   1137:           </td>
                   1138:          </tr>
                   1139:          <tr>
                   1140:            <td>
                   1141:             <table class="LC_nested">
                   1142:              <tr class="LC_info_row">
                   1143:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1144:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn  1145:                        &textbookcourses_javascript($settings).
                   1146:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                   1147:             </table>
                   1148:            </td>
                   1149:           </tr>
                   1150:          <tr>
                   1151:            <td>
                   1152:             <table class="LC_nested">
                   1153:              <tr class="LC_info_row">
                   1154:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1155:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                   1156:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn  1157:             </table>
                   1158:            </td>
                   1159:           </tr>
                   1160:           <tr>
                   1161:            <td>
                   1162:             <table class="LC_nested">
                   1163:              <tr class="LC_info_row">
1.306     raeburn  1164:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1165:               <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn  1166:              </tr>'.
                   1167:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn  1168:         } elsif ($action eq 'requestauthor') {
                   1169:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn  1170:             $rowtotal ++;
1.122     jms      1171:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1172:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn  1173:            </table>
                   1174:           </td>
                   1175:          </tr>
                   1176:          <tr>
                   1177:            <td>
                   1178:             <table class="LC_nested">
                   1179:              <tr class="LC_info_row">
1.306     raeburn  1180:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69      raeburn  1181:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306     raeburn  1182:               <td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1183:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1184:              </tr>'.
1.30      raeburn  1185:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1186:            </table>
                   1187:           </td>
                   1188:          </tr>
                   1189:          <tr>
                   1190:            <td>
                   1191:             <table class="LC_nested">
                   1192:              <tr class="LC_info_row">
1.59      bisitz   1193:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1194:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1195:              </tr>'.
1.30      raeburn  1196:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1197:             $rowtotal += 2;
1.6       raeburn  1198:         }
1.3       raeburn  1199:     } else {
1.30      raeburn  1200:         $output .= '
1.3       raeburn  1201:           <tr>
                   1202:            <td>
                   1203:             <table class="LC_nested">
1.30      raeburn  1204:              <tr class="LC_info_row">';
1.277     raeburn  1205:         if ($action eq 'login') {
1.30      raeburn  1206:             $output .= '  
1.59      bisitz   1207:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1208:         } elsif ($action eq 'serverstatuses') {
                   1209:             $output .= '
1.306     raeburn  1210:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69      raeburn  1211:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1212: 
1.6       raeburn  1213:         } else {
1.30      raeburn  1214:             $output .= '
1.306     raeburn  1215:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1216:         }
1.72      raeburn  1217:         if (defined($item->{'header'}->[0]->{'col3'})) {
1.306     raeburn  1218:             $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72      raeburn  1219:                        &mt($item->{'header'}->[0]->{'col2'});
                   1220:             if ($action eq 'serverstatuses') {
                   1221:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1222:             } 
1.69      raeburn  1223:         } else {
1.306     raeburn  1224:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1225:                        &mt($item->{'header'}->[0]->{'col2'});
                   1226:         }
                   1227:         $output .= '</td>';
                   1228:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1229:             if (defined($item->{'header'}->[0]->{'col4'})) {
1.306     raeburn  1230:                 $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150     raeburn  1231:                             &mt($item->{'header'}->[0]->{'col3'});
                   1232:             } else {
1.306     raeburn  1233:                 $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1234:                            &mt($item->{'header'}->[0]->{'col3'});
                   1235:             }
1.69      raeburn  1236:             if ($action eq 'serverstatuses') {
                   1237:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1238:             }
                   1239:             $output .= '</td>';
1.6       raeburn  1240:         }
1.150     raeburn  1241:         if ($item->{'header'}->[0]->{'col4'}) {
1.306     raeburn  1242:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1243:                        &mt($item->{'header'}->[0]->{'col4'});
                   1244:         }
1.69      raeburn  1245:         $output .= '</tr>';
1.48      raeburn  1246:         $rowtotal ++;
1.168     raeburn  1247:         if ($action eq 'quotas') {
1.86      raeburn  1248:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1249:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.286     raeburn  1250:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
1.372     raeburn  1251:                  ($action eq 'ltitools') || ($action eq 'lti') ||
1.394     raeburn  1252:                  ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230     raeburn  1253:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1254:         }
1.3       raeburn  1255:     }
1.30      raeburn  1256:     $output .= '
1.3       raeburn  1257:    </table>
                   1258:   </td>
                   1259:  </tr>
1.30      raeburn  1260: </table><br />';
                   1261:     return ($output,$rowtotal);
1.1       raeburn  1262: }
                   1263: 
1.3       raeburn  1264: sub print_login {
1.168     raeburn  1265:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386     raeburn  1266:     my ($css_class,$datatable,$switchserver,%lt);
1.6       raeburn  1267:     my %choices = &login_choices();
1.386     raeburn  1268:     if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
                   1269:         %lt = &login_file_options();
                   1270:         $switchserver = &check_switchserver($dom,$confname);
                   1271:     }
1.168     raeburn  1272:     if ($caller eq 'service') {
1.149     raeburn  1273:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1274:         my $choice = $choices{'disallowlogin'};
                   1275:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1276:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306     raeburn  1277:                       '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1278:                       '<th>'.$choices{'server'}.'</th>'.
                   1279:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1280:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1281:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1282:         my %disallowed;
                   1283:         if (ref($settings) eq 'HASH') {
                   1284:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1285:                %disallowed = %{$settings->{'loginvia'}};
                   1286:             }
                   1287:         }
                   1288:         foreach my $lonhost (sort(keys(%servers))) {
                   1289:             my $direct = 'selected="selected"';
1.128     raeburn  1290:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1291:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1292:                     $direct = '';
                   1293:                 }
1.110     raeburn  1294:             }
1.115     raeburn  1295:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1296:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1297:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1298:                           '</option>';
1.184     raeburn  1299:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1300:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1301:                 my $selected = '';
1.128     raeburn  1302:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1303:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1304:                         $selected = 'selected="selected"';
                   1305:                     }
1.110     raeburn  1306:                 }
                   1307:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1308:                               $servers{$hostid}.'</option>';
                   1309:             }
1.128     raeburn  1310:             $datatable .= '</select></td>'.
                   1311:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1312:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1313:                 my $pathname = $path;
                   1314:                 if ($path eq 'custom') {
                   1315:                     $pathname = &mt('Custom Path').' ->';
                   1316:                 }
                   1317:                 my $selected = '';
                   1318:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1319:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1320:                         $selected = 'selected="selected"';
                   1321:                     }
                   1322:                 } elsif ($path eq '') {
                   1323:                     $selected = 'selected="selected"';
                   1324:                 }
                   1325:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1326:             }
                   1327:             $datatable .= '</select></td>';
                   1328:             my ($custom,$exempt);
                   1329:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1330:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1331:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1332:             }
                   1333:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1334:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1335:                           '</tr>';
1.110     raeburn  1336:         }
                   1337:         $datatable .= '</table></td></tr>';
                   1338:         return $datatable;
1.168     raeburn  1339:     } elsif ($caller eq 'page') {
                   1340:         my %defaultchecked = ( 
                   1341:                                'coursecatalog' => 'on',
1.188     raeburn  1342:                                'helpdesk'      => 'on',
1.168     raeburn  1343:                                'adminmail'     => 'off',
                   1344:                                'newuser'       => 'off',
                   1345:                              );
1.188     raeburn  1346:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1347:         my (%checkedon,%checkedoff);
1.42      raeburn  1348:         foreach my $item (@toggles) {
1.168     raeburn  1349:             if ($defaultchecked{$item} eq 'on') { 
                   1350:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1351:                 $checkedoff{$item} = ' ';
1.168     raeburn  1352:             } elsif ($defaultchecked{$item} eq 'off') {
                   1353:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1354:                 $checkedon{$item} = ' ';
                   1355:             }
1.1       raeburn  1356:         }
1.168     raeburn  1357:         my @images = ('img','logo','domlogo','login');
                   1358:         my @logintext = ('textcol','bgcol');
                   1359:         my @bgs = ('pgbg','mainbg','sidebg');
                   1360:         my @links = ('link','alink','vlink');
                   1361:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1362:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1363:         my (%is_custom,%designs);
                   1364:         my %defaults = (
                   1365:                        font => $defaultdesign{'login.font'},
                   1366:                        );
1.6       raeburn  1367:         foreach my $item (@images) {
1.168     raeburn  1368:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1369:             $defaults{'showlogo'}{$item} = 1;
                   1370:         }
                   1371:         foreach my $item (@bgs) {
                   1372:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1373:         }
1.41      raeburn  1374:         foreach my $item (@logintext) {
1.168     raeburn  1375:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1376:         }
1.168     raeburn  1377:         foreach my $item (@links) {
                   1378:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1379:         }
1.168     raeburn  1380:         if (ref($settings) eq 'HASH') {
                   1381:             foreach my $item (@toggles) {
                   1382:                 if ($settings->{$item} eq '1') {
                   1383:                     $checkedon{$item} =  ' checked="checked" ';
                   1384:                     $checkedoff{$item} = ' ';
                   1385:                 } elsif ($settings->{$item} eq '0') {
                   1386:                     $checkedoff{$item} =  ' checked="checked" ';
                   1387:                     $checkedon{$item} = ' ';
                   1388:                 }
                   1389:             }
                   1390:             foreach my $item (@images) {
                   1391:                 if (defined($settings->{$item})) {
                   1392:                     $designs{$item} = $settings->{$item};
                   1393:                     $is_custom{$item} = 1;
                   1394:                 }
                   1395:                 if (defined($settings->{'showlogo'}{$item})) {
                   1396:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1397:                 }
                   1398:             }
                   1399:             foreach my $item (@logintext) {
                   1400:                 if ($settings->{$item} ne '') {
                   1401:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1402:                     $is_custom{$item} = 1;
                   1403:                 }
                   1404:             }
                   1405:             if ($settings->{'font'} ne '') {
                   1406:                 $designs{'font'} = $settings->{'font'};
                   1407:                 $is_custom{'font'} = 1;
                   1408:             }
                   1409:             foreach my $item (@bgs) {
                   1410:                 if ($settings->{$item} ne '') {
                   1411:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1412:                     $is_custom{$item} = 1;
                   1413:                 }
                   1414:             }
                   1415:             foreach my $item (@links) {
                   1416:                 if ($settings->{$item} ne '') {
                   1417:                     $designs{'links'}{$item} = $settings->{$item};
                   1418:                     $is_custom{$item} = 1;
                   1419:                 }
                   1420:             }
                   1421:         } else {
                   1422:             if ($designhash{$dom.'.login.font'} ne '') {
                   1423:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1424:                 $is_custom{'font'} = 1;
                   1425:             }
                   1426:             foreach my $item (@images) {
                   1427:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1428:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1429:                     $is_custom{$item} = 1;
                   1430:                 }
                   1431:             }
                   1432:             foreach my $item (@bgs) {
                   1433:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1434:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1435:                     $is_custom{$item} = 1;
                   1436:                 }
1.6       raeburn  1437:             }
1.168     raeburn  1438:             foreach my $item (@links) {
                   1439:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1440:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1441:                     $is_custom{$item} = 1;
                   1442:                 }
1.6       raeburn  1443:             }
                   1444:         }
1.168     raeburn  1445:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1446:                                                       logo => 'Institution Logo',
                   1447:                                                       domlogo => 'Domain Logo',
                   1448:                                                       login => 'Login box');
                   1449:         my $itemcount = 1;
                   1450:         foreach my $item (@toggles) {
                   1451:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1452:             $datatable .=  
                   1453:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1454:                 '</td><td>'.
                   1455:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1456:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1457:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1458:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1459:                 '</tr>';
                   1460:             $itemcount ++;
1.6       raeburn  1461:         }
1.168     raeburn  1462:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1463:         $datatable .= '</tr></table></td></tr>';
                   1464:     } elsif ($caller eq 'help') {
1.386     raeburn  1465:         my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168     raeburn  1466:         my $itemcount = 1;
                   1467:         $defaulturl = '/adm/loginproblems.html';
                   1468:         $defaulttype = 'default';
                   1469:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1470:         my @currlangs;
                   1471:         if (ref($settings) eq 'HASH') {
                   1472:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1473:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1474:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1475:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1476:                     $type{$key} = 'custom';
                   1477:                     unless ($key eq 'nolang') {
                   1478:                         push(@currlangs,$key);
                   1479:                     }
                   1480:                 }
                   1481:             } elsif ($settings->{'helpurl'} ne '') {
                   1482:                 $type{'nolang'} = 'custom';
                   1483:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1484:             }
                   1485:         }
1.168     raeburn  1486:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1487:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1488:             $datatable .= '<tr'.$css_class.'>';
                   1489:             if ($url{$lang} eq '') {
                   1490:                 $url{$lang} = $defaulturl;
                   1491:             }
                   1492:             if ($type{$lang} eq '') {
                   1493:                 $type{$lang} = $defaulttype;
                   1494:             }
                   1495:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1496:             if ($lang eq 'nolang') {
                   1497:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1498:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1499:             } else {
                   1500:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1501:                                   $langchoices{$lang},
                   1502:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1503:             }
                   1504:             $datatable .= '</span></td>'."\n".
                   1505:                           '<td class="LC_left_item">';
                   1506:             if ($type{$lang} eq 'custom') {
                   1507:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1508:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1509:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1510:             } else {
                   1511:                 $datatable .= $lt{'upl'};
                   1512:             }
                   1513:             $datatable .='<br />';
                   1514:             if ($switchserver) {
                   1515:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1516:             } else {
                   1517:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1518:             }
1.168     raeburn  1519:             $datatable .= '</td></tr>';
                   1520:             $itemcount ++;
1.6       raeburn  1521:         }
1.168     raeburn  1522:         my @addlangs;
                   1523:         foreach my $lang (sort(keys(%langchoices))) {
                   1524:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1525:             push(@addlangs,$lang);
                   1526:         }
                   1527:         if (@addlangs > 0) {
                   1528:             my %toadd;
                   1529:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1530:             $toadd{''} = &mt('Select');
                   1531:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1532:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1533:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1534:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1535:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1536:             if ($switchserver) {
                   1537:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1538:             } else {
                   1539:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1540:             }
1.168     raeburn  1541:             $datatable .= '</td></tr>';
1.169     raeburn  1542:             $itemcount ++;
1.6       raeburn  1543:         }
1.169     raeburn  1544:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1545:     } elsif ($caller eq 'headtag') {
                   1546:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1547:         my $choice = $choices{'headtag'};
                   1548:         $css_class = ' class="LC_odd_row"';
                   1549:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1550:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1551:                       '<th>'.$choices{'current'}.'</th>'.
                   1552:                       '<th>'.$choices{'action'}.'</th>'.
                   1553:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1554:         my (%currurls,%currexempt);
                   1555:         if (ref($settings) eq 'HASH') {
                   1556:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1557:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1558:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1559:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1560:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1561:                     }
                   1562:                 }
                   1563:             }
                   1564:         }
                   1565:         foreach my $lonhost (sort(keys(%domservers))) {
                   1566:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1567:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1568:             if ($currurls{$lonhost}) {
                   1569:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1570:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1571:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1572:                               '">'.$lt{'curr'}.'</a></td>'.
                   1573:                               '<td><span class="LC_nobreak"><label>'.
                   1574:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1575:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1576:             } else {
                   1577:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1578:             }
                   1579:             $datatable .='<br />';
                   1580:             if ($switchserver) {
                   1581:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1582:             } else {
                   1583:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1584:             }
1.330     raeburn  1585:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256     raeburn  1586:         }
                   1587:         $datatable .= '</table></td></tr>';
1.386     raeburn  1588:     } elsif ($caller eq 'saml') {
                   1589:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1590:         $datatable .= '<tr><td colspan="3" style="text-align: left">'.
                   1591:                       '<table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1592:                       '<th>'.$choices{'samllanding'}.'</th>'.
                   1593:                       '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
                   1594:         my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
                   1595:         foreach my $lonhost (keys(%domservers)) {
                   1596:             $samlurl{$lonhost} = '/adm/sso';
                   1597:             $styleon{$lonhost} = 'display:none';
                   1598:             $styleoff{$lonhost} = '';
                   1599:         }
                   1600:         if (ref($settings->{'saml'}) eq 'HASH') {
                   1601:             foreach my $lonhost (keys(%{$settings->{'saml'}})) {
                   1602:                 if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
                   1603:                     $saml{$lonhost} = 1;
                   1604:                     $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
                   1605:                     $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
                   1606:                     $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                   1607:                     $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                   1608:                     $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
                   1609:                     $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                   1610:                     $styleon{$lonhost} = '';
                   1611:                     $styleoff{$lonhost} = 'display:none';
                   1612:                 } else {
                   1613:                     $styleon{$lonhost} = 'display:none';
                   1614:                     $styleoff{$lonhost} = '';
                   1615:                 }
                   1616:             }
                   1617:         }
                   1618:         my $itemcount = 1;
                   1619:         foreach my $lonhost (sort(keys(%domservers))) {
                   1620:             my $samlon = ' ';
                   1621:             my $samloff = ' checked="checked" ';
                   1622:             if ($saml{$lonhost}) {
                   1623:                 $samlon = $samloff;
                   1624:                 $samloff = ' ';
                   1625:             }
                   1626:             my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1627:             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
                   1628:                           '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
                   1629:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
                   1630:                           &mt('No').'</label>'.('&nbsp;'x2).
                   1631:                           '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
                   1632:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
                   1633:                           &mt('Yes').'</label></span></td>'.
                   1634:                           '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
                   1635:                           '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
                   1636:                           '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
                   1637:                           '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
                   1638:                           '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
                   1639:                           '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
                   1640:                           '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
                   1641:                           $samltext{$lonhost}.'" /></td><td>';
                   1642:             if ($samlimg{$lonhost}) {
                   1643:                 $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
                   1644:                               '<span class="LC_nobreak"><label>'.
                   1645:                               '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
                   1646:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1647:             } else {
                   1648:                 $datatable .= $lt{'upl'};
                   1649:             }
                   1650:             $datatable .='<br />';
                   1651:             if ($switchserver) {
                   1652:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1653:             } else {
                   1654:                 $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
                   1655:             }
                   1656:             $datatable .= '</td>'.
                   1657:                           '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
                   1658:                           'value="'.$samlalt{$lonhost}.'" /></td>'.
                   1659:                           '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
                   1660:                           'value="'.$samlurl{$lonhost}.'" /></td>'.
                   1661:                           '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
                   1662:                           $samltitle{$lonhost}.'</textarea></td>'.
                   1663:                           '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
                   1664:                           'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                   1665:                           '</table></td>'.
                   1666:                           '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%">&nbsp;</td></tr>';
                   1667:            $itemcount ++;
                   1668:         }
                   1669:         $datatable .= '</table></td></tr>';
1.1       raeburn  1670:     }
1.6       raeburn  1671:     return $datatable;
                   1672: }
                   1673: 
                   1674: sub login_choices {
                   1675:     my %choices =
                   1676:         &Apache::lonlocal::texthash (
1.116     bisitz   1677:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1678:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1679:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1680:             disallowlogin => "Login page requests redirected",
                   1681:             hostid        => "Server",
1.128     raeburn  1682:             server        => "Redirect to:",
                   1683:             serverpath    => "Path",
                   1684:             custompath    => "Custom", 
                   1685:             exempt        => "Exempt IP(s)",
1.110     raeburn  1686:             directlogin   => "No redirect",
                   1687:             newuser       => "Link to create a user account",
                   1688:             img           => "Header",
                   1689:             logo          => "Main Logo",
                   1690:             domlogo       => "Domain Logo",
                   1691:             login         => "Log-in Header", 
                   1692:             textcol       => "Text color",
                   1693:             bgcol         => "Box color",
                   1694:             bgs           => "Background colors",
                   1695:             links         => "Link colors",
                   1696:             font          => "Font color",
                   1697:             pgbg          => "Header",
                   1698:             mainbg        => "Page",
                   1699:             sidebg        => "Login box",
                   1700:             link          => "Link",
                   1701:             alink         => "Active link",
                   1702:             vlink         => "Visited link",
1.256     raeburn  1703:             headtag       => "Custom markup",
                   1704:             action        => "Action",
                   1705:             current       => "Current",
1.386     raeburn  1706:             samllanding   => "Dual login?",
                   1707:             samloptions   => "Options",
1.6       raeburn  1708:         );
                   1709:     return %choices;
                   1710: }
                   1711: 
1.386     raeburn  1712: sub login_file_options {
                   1713:       return &Apache::lonlocal::texthash(
                   1714:                                            del     => 'Delete?',
                   1715:                                            rep     => 'Replace:',
                   1716:                                            upl     => 'Upload:',
                   1717:                                            curr    => 'View contents',
                   1718:                                            default => 'Default',
                   1719:                                            custom  => 'Custom',
                   1720:                                            none    => 'None',
                   1721:       );
                   1722: }
                   1723: 
1.394     raeburn  1724: sub print_ipaccess {
                   1725:     my ($dom,$settings,$rowtotal) = @_;
                   1726:     my $css_class;
                   1727:     my $itemcount = 0;
                   1728:     my $datatable;
                   1729:     my %ordered;
                   1730:     if (ref($settings) eq 'HASH') {
                   1731:         foreach my $item (keys(%{$settings})) {
                   1732:             if (ref($settings->{$item}) eq 'HASH') {
                   1733:                 my $num = $settings->{$item}{'order'};
                   1734:                 if ($num eq '') {
                   1735:                     $num = scalar(keys(%{$settings}));
                   1736:                 }
                   1737:                 $ordered{$num} = $item;
                   1738:             }
                   1739:         }
                   1740:     }
                   1741:     my $maxnum = scalar(keys(%ordered));
                   1742:     if (keys(%ordered)) {
                   1743:         my @items = sort { $a <=> $b } keys(%ordered);
                   1744:         for (my $i=0; $i<@items; $i++) {
                   1745:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1746:             my $item = $ordered{$items[$i]};
                   1747:             my ($name,$ipranges,%commblocks,%courses);
                   1748:             if (ref($settings->{$item}) eq 'HASH') {
                   1749:                 $name = $settings->{$item}->{'name'};
                   1750:                 $ipranges = $settings->{$item}->{'ip'};
                   1751:                 if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
                   1752:                     %commblocks = %{$settings->{$item}->{'commblocks'}};
                   1753:                 }
                   1754:                 if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
                   1755:                     %courses = %{$settings->{$item}->{'courses'}};
                   1756:                 }
                   1757:             }
                   1758:             my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
                   1759:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   1760:                          .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
                   1761:             for (my $k=0; $k<=$maxnum; $k++) {
                   1762:                 my $vpos = $k+1;
                   1763:                 my $selstr;
                   1764:                 if ($k == $i) {
                   1765:                     $selstr = ' selected="selected" ';
                   1766:                 }
                   1767:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1768:             }
                   1769:             $datatable .= '</select>'.('&nbsp;'x2).
                   1770:                 '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
                   1771:                 &mt('Delete?').'</label></span></td>'.
                   1772:                 '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
                   1773:                 &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
                   1774:                 '</td></tr>';
                   1775:             $itemcount ++;
                   1776:         }
                   1777:     }
                   1778:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1779:     my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
                   1780:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   1781:                   '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
                   1782:                   '<select name="ipaccess_pos_add"'.$chgstr.'>';
                   1783:     for (my $k=0; $k<$maxnum+1; $k++) {
                   1784:         my $vpos = $k+1;
                   1785:         my $selstr;
                   1786:         if ($k == $maxnum) {
                   1787:             $selstr = ' selected="selected" ';
                   1788:         }
                   1789:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1790:     }
                   1791:     $datatable .= '</select>&nbsp;'."\n".
                   1792:                   '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   1793:                   '<td colspan="2">'.
                   1794:                   &ipaccess_options('add',$itemcount,$dom).
                   1795:                   '</td>'."\n".
                   1796:                   '</tr>'."\n";
                   1797:     $$rowtotal ++;
                   1798:     return $datatable;
                   1799: }
                   1800: 
                   1801: sub ipaccess_options {
                   1802:     my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
                   1803:     my (%currblocks,%currcourses,$output);
                   1804:     if (ref($blocksref) eq 'HASH') {
                   1805:         %currblocks = %{$blocksref};
                   1806:     }
                   1807:     if (ref($coursesref) eq 'HASH') {
                   1808:         %currcourses = %{$coursesref};
                   1809:     }
                   1810:     $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
                   1811:               '<span class="LC_nobreak">'.&mt('Name').':&nbsp;'.
                   1812:               '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
                   1813:               '</span></fieldset>'.
                   1814:               '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
                   1815:               &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   1816:               &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
                   1817:               '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
                   1818:               $ipranges.'</textarea></fieldset>'.
                   1819:               '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
                   1820:               &blocker_checkboxes($num,$blocksref).'</fieldset>'.
                   1821:               '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
                   1822:               '<table>';
                   1823:     foreach my $cid (sort(keys(%currcourses))) {
                   1824:         my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   1825:         $output .= '<tr><td><span class="LC_nobreak">'.
                   1826:                    '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
                   1827:                    &mt('Delete?').'&nbsp;<span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
                   1828:                    ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
                   1829:     }
                   1830:     $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').':&nbsp;'.
                   1831:                '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
                   1832:                 &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
                   1833:                '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
                   1834:                '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
                   1835:                '</span></td></tr></table>'."\n".
                   1836:                '</fieldset>';
                   1837:     return $output;
                   1838: }
                   1839: 
                   1840: sub blocker_checkboxes {
                   1841:     my ($num,$blocks) = @_;
                   1842:     my ($typeorder,$types) = &commblocktype_text();
                   1843:     my $numinrow = 6;
                   1844:     my $output = '<table>';
                   1845:     for (my $i=0; $i<@{$typeorder}; $i++) {
                   1846:         my $block = $typeorder->[$i];
                   1847:         my $blockstatus;
                   1848:         if (ref($blocks) eq 'HASH') {
                   1849:             if ($blocks->{$block} eq 'on') {
                   1850:                 $blockstatus = 'checked="checked"';
                   1851:             }
                   1852:         }
                   1853:         my $rem = $i%($numinrow);
                   1854:         if ($rem == 0) {
                   1855:             if ($i > 0) {
                   1856:                 $output .= '</tr>';
                   1857:             }
                   1858:             $output .= '<tr>';
                   1859:         }
                   1860:         if ($i == scalar(@{$typeorder})-1) {
                   1861:             my $colsleft = $numinrow-$rem;
                   1862:             if ($colsleft > 1) {
                   1863:                 $output .= '<td colspan="'.$colsleft.'">';
                   1864:             } else {
                   1865:                 $output .= '<td>';
                   1866:             }
                   1867:         } else {
                   1868:             $output .= '<td>';
                   1869:         }
                   1870:         my $item = 'ipaccess_block_'.$num;
                   1871:         if ($blockstatus) {
                   1872:             $blockstatus = ' '.$blockstatus;
                   1873:         }
                   1874:         $output .= '<span class="LC_nobreak"><label>'."\n".
                   1875:                    '<input type="checkbox" name="'.$item.'"'.
                   1876:                    $blockstatus.' value="'.$block.'"'.' />'.
                   1877:                    $types->{$block}.'</label></span>'."\n".
                   1878:                    '<br /></td>';
                   1879:     }
                   1880:     $output .= '</tr></table>';
                   1881:     return $output;
                   1882: }
                   1883: 
                   1884: sub commblocktype_text {
                   1885:     my %types = &Apache::lonlocal::texthash(
                   1886:         'com' => 'Messaging',
                   1887:         'chat' => 'Chat Room',
                   1888:         'boards' => 'Discussion',
                   1889:         'port' => 'Portfolio',
                   1890:         'groups' => 'Groups',
                   1891:         'blogs' => 'Blogs',
                   1892:         'about' => 'User Information',
                   1893:         'printout' => 'Printouts',
                   1894:         'passwd' => 'Change Password',
                   1895:         'grades' => 'Gradebook',
                   1896:     );
                   1897:     my $typeorder = ['com','chat','boards','port','groups','blogs','about','printout','grades','passwd'];
                   1898:     return ($typeorder,\%types);
                   1899: }
                   1900: 
1.6       raeburn  1901: sub print_rolecolors {
1.30      raeburn  1902:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1903:     my %choices = &color_font_choices();
                   1904:     my @bgs = ('pgbg','tabbg','sidebg');
                   1905:     my @links = ('link','alink','vlink');
                   1906:     my @images = ('img');
                   1907:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1908:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1909:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1910:     my (%is_custom,%designs);
1.200     raeburn  1911:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1912:     if (ref($settings) eq 'HASH') {
                   1913:         if (ref($settings->{$role}) eq 'HASH') {
                   1914:             if ($settings->{$role}->{'img'} ne '') {
                   1915:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1916:                 $is_custom{'img'} = 1;
                   1917:             }
                   1918:             if ($settings->{$role}->{'font'} ne '') {
                   1919:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1920:                 $is_custom{'font'} = 1;
                   1921:             }
1.97      tempelho 1922:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1923:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1924:                 $is_custom{'fontmenu'} = 1;
                   1925:             }
1.6       raeburn  1926:             foreach my $item (@bgs) {
                   1927:                 if ($settings->{$role}->{$item} ne '') {
                   1928:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1929:                     $is_custom{$item} = 1;
                   1930:                 }
                   1931:             }
                   1932:             foreach my $item (@links) {
                   1933:                 if ($settings->{$role}->{$item} ne '') {
                   1934:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1935:                     $is_custom{$item} = 1;
                   1936:                 }
                   1937:             }
                   1938:         }
                   1939:     } else {
                   1940:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1941:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1942:             $is_custom{'img'} = 1;
                   1943:         }
1.97      tempelho 1944:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1945:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1946:             $is_custom{'fontmenu'} = 1; 
                   1947:         }
1.6       raeburn  1948:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1949:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1950:             $is_custom{'font'} = 1;
                   1951:         }
                   1952:         foreach my $item (@bgs) {
                   1953:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1954:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1955:                 $is_custom{$item} = 1;
                   1956:             
                   1957:             }
                   1958:         }
                   1959:         foreach my $item (@links) {
                   1960:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1961:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1962:                 $is_custom{$item} = 1;
                   1963:             }
                   1964:         }
                   1965:     }
                   1966:     my $itemcount = 1;
1.30      raeburn  1967:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1968:     $datatable .= '</tr></table></td></tr>';
                   1969:     return $datatable;
                   1970: }
                   1971: 
1.200     raeburn  1972: sub role_defaults {
                   1973:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1974:     my %defaults;
                   1975:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1976:         return %defaults;
                   1977:     }
                   1978:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1979:     if ($role eq 'login') {
                   1980:         %defaults = (
                   1981:                        font => $defaultdesign{$role.'.font'},
                   1982:                     );
                   1983:         if (ref($logintext) eq 'ARRAY') {
                   1984:             foreach my $item (@{$logintext}) {
                   1985:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1986:             }
                   1987:         }
                   1988:         foreach my $item (@{$images}) {
                   1989:             $defaults{'showlogo'}{$item} = 1;
                   1990:         }
                   1991:     } else {
                   1992:         %defaults = (
                   1993:                        img => $defaultdesign{$role.'.img'},
                   1994:                        font => $defaultdesign{$role.'.font'},
                   1995:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1996:                     );
                   1997:     }
                   1998:     foreach my $item (@{$bgs}) {
                   1999:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   2000:     }
                   2001:     foreach my $item (@{$links}) {
                   2002:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   2003:     }
                   2004:     foreach my $item (@{$images}) {
                   2005:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   2006:     }
                   2007:     return %defaults;
                   2008: }
                   2009: 
1.6       raeburn  2010: sub display_color_options {
1.9       raeburn  2011:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   2012:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  2013:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  2014:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  2015:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  2016:         '<td>'.$choices->{'font'}.'</td>';
                   2017:     if (!$is_custom->{'font'}) {
1.329     raeburn  2018:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  2019:     } else {
                   2020:         $datatable .= '<td>&nbsp;</td>';
                   2021:     }
1.174     foxr     2022:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   2023: 
1.8       raeburn  2024:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2025:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  2026:                   ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2027:                   '&nbsp;</span></td></tr>';
1.107     raeburn  2028:     unless ($role eq 'login') { 
                   2029:         $datatable .= '<tr'.$css_class.'>'.
                   2030:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   2031:         if (!$is_custom->{'fontmenu'}) {
1.329     raeburn  2032:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  2033:         } else {
                   2034:             $datatable .= '<td>&nbsp;</td>';
                   2035:         }
1.202     raeburn  2036: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     2037: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  2038:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     2039:                       '<input class="colorchooser" type="text" size="10" name="'
                   2040: 		      .$role.'_fontmenu"'.
                   2041:                       ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  2042:                       '&nbsp;</span></td></tr>';
1.97      tempelho 2043:     }
1.9       raeburn  2044:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  2045:     foreach my $img (@{$images}) {
1.18      albertel 2046: 	$itemcount ++;
1.6       raeburn  2047:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  2048:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  2049:                       '<td>'.$choices->{$img};
1.41      raeburn  2050:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  2051:         if ($role eq 'login') {
                   2052:             if ($img eq 'login') {
                   2053:                 $login_hdr_pick =
1.135     bisitz   2054:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  2055:                 $logincolors =
                   2056:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  2057:                                        $designs,$defaults);
1.70      raeburn  2058:             } elsif ($img ne 'domlogo') {
                   2059:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   2060:             }
                   2061:         }
                   2062:         $datatable .= '</td>';
1.6       raeburn  2063:         if ($designs->{$img} ne '') {
                   2064:             $imgfile = $designs->{$img};
1.18      albertel 2065: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  2066:         } else {
                   2067:             $imgfile = $defaults->{$img};
                   2068:         }
                   2069:         if ($imgfile) {
1.9       raeburn  2070:             my ($showfile,$fullsize);
                   2071:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  2072:                 my $urldir = $1;
                   2073:                 my $filename = $2;
                   2074:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   2075:                 if (@info) {
                   2076:                     my $thumbfile = 'tn-'.$filename;
                   2077:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   2078:                     if (@thumb) {
                   2079:                         $showfile = $urldir.'/'.$thumbfile;
                   2080:                     } else {
                   2081:                         $showfile = $imgfile;
                   2082:                     }
                   2083:                 } else {
                   2084:                     $showfile = '';
                   2085:                 }
                   2086:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  2087:                 $showfile = $imgfile;
1.6       raeburn  2088:                 my $imgdir = $1;
                   2089:                 my $filename = $2;
1.159     raeburn  2090:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  2091:                     $showfile = "/$imgdir/tn-".$filename;
                   2092:                 } else {
1.159     raeburn  2093:                     my $input = $londocroot.$imgfile;
                   2094:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  2095:                     if (!-e $output) {
1.9       raeburn  2096:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  2097:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   2098:                         if ($fullwidth ne '' && $fullheight ne '') {
                   2099:                             if ($fullwidth > $width && $fullheight > $height) { 
                   2100:                                 my $size = $width.'x'.$height;
1.316     raeburn  2101:                                 my @args = ('convert','-sample',$size,$input,$output);
                   2102:                                 system({$args[0]} @args);
1.159     raeburn  2103:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  2104:                             }
                   2105:                         }
1.6       raeburn  2106:                     }
                   2107:                 }
1.16      raeburn  2108:             }
1.6       raeburn  2109:             if ($showfile) {
1.40      raeburn  2110:                 if ($showfile =~ m{^/(adm|res)/}) {
                   2111:                     if ($showfile =~ m{^/res/}) {
                   2112:                         my $local_showfile =
                   2113:                             &Apache::lonnet::filelocation('',$showfile);
                   2114:                         &Apache::lonnet::repcopy($local_showfile);
                   2115:                     }
                   2116:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   2117:                 }
                   2118:                 if ($imgfile) {
                   2119:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   2120:                         if ($imgfile =~ m{^/res/}) {
                   2121:                             my $local_imgfile =
                   2122:                                 &Apache::lonnet::filelocation('',$imgfile);
                   2123:                             &Apache::lonnet::repcopy($local_imgfile);
                   2124:                         }
                   2125:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   2126:                     } else {
                   2127:                         $fullsize = $imgfile;
                   2128:                     }
                   2129:                 }
1.41      raeburn  2130:                 $datatable .= '<td>';
                   2131:                 if ($img eq 'login') {
1.135     bisitz   2132:                     $datatable .= $login_hdr_pick;
                   2133:                 } 
1.41      raeburn  2134:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   2135:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  2136:             } else {
1.201     raeburn  2137:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2138:                               &mt('Upload:').'<br />';
1.6       raeburn  2139:             }
                   2140:         } else {
1.201     raeburn  2141:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2142:                           &mt('Upload:').'<br />';
1.6       raeburn  2143:         }
1.9       raeburn  2144:         if ($switchserver) {
                   2145:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2146:         } else {
1.135     bisitz   2147:             if ($img ne 'login') { # suppress file selection for Log-in header
                   2148:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   2149:             }
1.9       raeburn  2150:         }
                   2151:         $datatable .= '</td></tr>';
1.6       raeburn  2152:     }
                   2153:     $itemcount ++;
                   2154:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2155:     $datatable .= '<tr'.$css_class.'>'.
                   2156:                   '<td>'.$choices->{'bgs'}.'</td>';
                   2157:     my $bgs_def;
                   2158:     foreach my $item (@{$bgs}) {
                   2159:         if (!$is_custom->{$item}) {
1.329     raeburn  2160:             $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  2161:         }
                   2162:     }
                   2163:     if ($bgs_def) {
1.8       raeburn  2164:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  2165:     } else {
                   2166:         $datatable .= '<td>&nbsp;</td>';
                   2167:     }
                   2168:     $datatable .= '<td class="LC_right_item">'.
                   2169:                   '<table border="0"><tr>';
1.174     foxr     2170: 
1.6       raeburn  2171:     foreach my $item (@{$bgs}) {
1.306     raeburn  2172:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     2173: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  2174:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     2175:             $datatable .= '&nbsp;';
1.6       raeburn  2176:         }
1.174     foxr     2177:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  2178:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  2179:     }
                   2180:     $datatable .= '</tr></table></td></tr>';
                   2181:     $itemcount ++;
                   2182:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2183:     $datatable .= '<tr'.$css_class.'>'.
                   2184:                   '<td>'.$choices->{'links'}.'</td>';
                   2185:     my $links_def;
                   2186:     foreach my $item (@{$links}) {
                   2187:         if (!$is_custom->{$item}) {
1.329     raeburn  2188:             $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  2189:         }
                   2190:     }
                   2191:     if ($links_def) {
1.8       raeburn  2192:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  2193:     } else {
                   2194:         $datatable .= '<td>&nbsp;</td>';
                   2195:     }
                   2196:     $datatable .= '<td class="LC_right_item">'.
                   2197:                   '<table border="0"><tr>';
                   2198:     foreach my $item (@{$links}) {
1.234     raeburn  2199: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  2200:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  2201:         if ($designs->{'links'}{$item}) {
1.174     foxr     2202:             $datatable.='&nbsp;';
1.6       raeburn  2203:         }
1.174     foxr     2204:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  2205:                       '" /></td>';
                   2206:     }
1.30      raeburn  2207:     $$rowtotal += $itemcount;
1.3       raeburn  2208:     return $datatable;
                   2209: }
                   2210: 
1.70      raeburn  2211: sub logo_display_options {
                   2212:     my ($img,$defaults,$designs) = @_;
                   2213:     my $checkedon;
                   2214:     if (ref($defaults) eq 'HASH') {
                   2215:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   2216:             if ($defaults->{'showlogo'}{$img}) {
                   2217:                 $checkedon = 'checked="checked" ';     
                   2218:             }
                   2219:         } 
                   2220:     }
                   2221:     if (ref($designs) eq 'HASH') {
                   2222:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   2223:             if (defined($designs->{'showlogo'}{$img})) {
                   2224:                 if ($designs->{'showlogo'}{$img} == 0) {
                   2225:                     $checkedon = '';
                   2226:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   2227:                     $checkedon = 'checked="checked" ';
                   2228:                 }
                   2229:             }
                   2230:         }
                   2231:     }
                   2232:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   2233:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   2234:            &mt('show').'</label>'."\n";
                   2235: }
                   2236: 
1.41      raeburn  2237: sub login_header_options  {
1.135     bisitz   2238:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   2239:     my $output = '';
1.41      raeburn  2240:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   2241:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  2242:         if (!$is_custom->{'textcol'}) {
                   2243:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   2244:                        '&nbsp;&nbsp;&nbsp;';
                   2245:         }
                   2246:         if (!$is_custom->{'bgcol'}) {
                   2247:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   2248:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   2249:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   2250:         }
                   2251:         $output .= '<br />';
                   2252:     }
                   2253:     $output .='<br />';
                   2254:     return $output;
                   2255: }
                   2256: 
                   2257: sub login_text_colors {
1.201     raeburn  2258:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  2259:     my $color_menu = '<table border="0"><tr>';
                   2260:     foreach my $item (@{$logintext}) {
1.306     raeburn  2261:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  2262:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   2263:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   2264:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  2265:     }
                   2266:     $color_menu .= '</tr></table><br />';
                   2267:     return $color_menu;
                   2268: }
                   2269: 
                   2270: sub image_changes {
                   2271:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   2272:     my $output;
1.135     bisitz   2273:     if ($img eq 'login') {
1.331     raeburn  2274:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   2275:     } elsif (!$is_custom) {
1.70      raeburn  2276:         if ($img ne 'domlogo') {
1.331     raeburn  2277:             $output = &mt('Default image:').'<br />';
1.41      raeburn  2278:         } else {
1.331     raeburn  2279:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  2280:         }
                   2281:     }
1.331     raeburn  2282:     if ($img ne 'login') {
1.135     bisitz   2283:         if ($img_import) {
                   2284:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   2285:         }
                   2286:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   2287:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   2288:         if ($is_custom) {
                   2289:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   2290:                        '<input type="checkbox" name="'.
                   2291:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   2292:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   2293:         } else {
1.306     raeburn  2294:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   2295:         }
1.41      raeburn  2296:     }
                   2297:     return $output;
                   2298: }
                   2299: 
1.3       raeburn  2300: sub print_quotas {
1.86      raeburn  2301:     my ($dom,$settings,$rowtotal,$action) = @_;
                   2302:     my $context;
                   2303:     if ($action eq 'quotas') {
                   2304:         $context = 'tools';
                   2305:     } else {
                   2306:         $context = $action;
                   2307:     }
1.197     raeburn  2308:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  2309:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  2310:     my $typecount = 0;
1.101     raeburn  2311:     my ($css_class,%titles);
1.86      raeburn  2312:     if ($context eq 'requestcourses') {
1.325     raeburn  2313:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  2314:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  2315:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   2316:         %titles = &courserequest_titles();
1.163     raeburn  2317:     } elsif ($context eq 'requestauthor') {
                   2318:         @usertools = ('author');
                   2319:         @options = ('norequest','approval','automatic');
1.210     raeburn  2320:         %titles = &authorrequest_titles();
1.86      raeburn  2321:     } else {
1.162     raeburn  2322:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  2323:         %titles = &tool_titles();
1.86      raeburn  2324:     }
1.26      raeburn  2325:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  2326:         foreach my $type (@{$types}) {
1.197     raeburn  2327:             my ($currdefquota,$currauthorquota);
1.163     raeburn  2328:             unless (($context eq 'requestcourses') ||
                   2329:                     ($context eq 'requestauthor')) {
1.86      raeburn  2330:                 if (ref($settings) eq 'HASH') {
                   2331:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  2332:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  2333:                     } else {
                   2334:                         $currdefquota = $settings->{$type};
                   2335:                     }
1.197     raeburn  2336:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   2337:                         $currauthorquota = $settings->{authorquota}->{$type};
                   2338:                     }
1.78      raeburn  2339:                 }
1.72      raeburn  2340:             }
1.3       raeburn  2341:             if (defined($usertypes->{$type})) {
                   2342:                 $typecount ++;
                   2343:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  2344:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  2345:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  2346:                               '<td class="LC_left_item">';
1.101     raeburn  2347:                 if ($context eq 'requestcourses') {
                   2348:                     $datatable .= '<table><tr>';
                   2349:                 }
                   2350:                 my %cell;  
1.72      raeburn  2351:                 foreach my $item (@usertools) {
1.101     raeburn  2352:                     if ($context eq 'requestcourses') {
                   2353:                         my ($curroption,$currlimit);
                   2354:                         if (ref($settings) eq 'HASH') {
                   2355:                             if (ref($settings->{$item}) eq 'HASH') {
                   2356:                                 $curroption = $settings->{$item}->{$type};
                   2357:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2358:                                     $currlimit = $1; 
                   2359:                                 }
                   2360:                             }
                   2361:                         }
                   2362:                         if (!$curroption) {
                   2363:                             $curroption = 'norequest';
                   2364:                         }
                   2365:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2366:                         foreach my $option (@options) {
                   2367:                             my $val = $option;
                   2368:                             if ($option eq 'norequest') {
                   2369:                                 $val = 0;  
                   2370:                             }
                   2371:                             if ($option eq 'validate') {
                   2372:                                 my $canvalidate = 0;
                   2373:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2374:                                     if ($validations{$item}{$type}) {
                   2375:                                         $canvalidate = 1;
                   2376:                                     }
                   2377:                                 }
                   2378:                                 next if (!$canvalidate);
                   2379:                             }
                   2380:                             my $checked = '';
                   2381:                             if ($option eq $curroption) {
                   2382:                                 $checked = ' checked="checked"';
                   2383:                             } elsif ($option eq 'autolimit') {
                   2384:                                 if ($curroption =~ /^autolimit/) {
                   2385:                                     $checked = ' checked="checked"';
                   2386:                                 }                       
                   2387:                             } 
                   2388:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2389:                                   '<input type="radio" name="crsreq_'.$item.
                   2390:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2391:                                   $titles{$option}.'</label>';
1.101     raeburn  2392:                             if ($option eq 'autolimit') {
1.127     raeburn  2393:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2394:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2395:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2396:                             }
1.127     raeburn  2397:                             $cell{$item} .= '</span> ';
1.103     raeburn  2398:                             if ($option eq 'autolimit') {
1.127     raeburn  2399:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2400:                             }
1.101     raeburn  2401:                         }
1.163     raeburn  2402:                     } elsif ($context eq 'requestauthor') {
                   2403:                         my $curroption;
                   2404:                         if (ref($settings) eq 'HASH') {
                   2405:                             $curroption = $settings->{$type};
                   2406:                         }
                   2407:                         if (!$curroption) {
                   2408:                             $curroption = 'norequest';
                   2409:                         }
                   2410:                         foreach my $option (@options) {
                   2411:                             my $val = $option;
                   2412:                             if ($option eq 'norequest') {
                   2413:                                 $val = 0;
                   2414:                             }
                   2415:                             my $checked = '';
                   2416:                             if ($option eq $curroption) {
                   2417:                                 $checked = ' checked="checked"';
                   2418:                             }
                   2419:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2420:                                   '<input type="radio" name="authorreq_'.$type.
                   2421:                                   '" value="'.$val.'"'.$checked.' />'.
                   2422:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2423:                         }
1.101     raeburn  2424:                     } else {
                   2425:                         my $checked = 'checked="checked" ';
                   2426:                         if (ref($settings) eq 'HASH') {
                   2427:                             if (ref($settings->{$item}) eq 'HASH') {
                   2428:                                 if ($settings->{$item}->{$type} == 0) {
                   2429:                                     $checked = '';
                   2430:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2431:                                     $checked =  'checked="checked" ';
                   2432:                                 }
1.78      raeburn  2433:                             }
1.72      raeburn  2434:                         }
1.101     raeburn  2435:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2436:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2437:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2438:                                       '</label></span>&nbsp; ';
1.72      raeburn  2439:                     }
1.101     raeburn  2440:                 }
                   2441:                 if ($context eq 'requestcourses') {
                   2442:                     $datatable .= '</tr><tr>';
                   2443:                     foreach my $item (@usertools) {
1.106     raeburn  2444:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2445:                     }
                   2446:                     $datatable .= '</tr></table>';
1.72      raeburn  2447:                 }
1.86      raeburn  2448:                 $datatable .= '</td>';
1.163     raeburn  2449:                 unless (($context eq 'requestcourses') ||
                   2450:                         ($context eq 'requestauthor')) {
1.86      raeburn  2451:                     $datatable .= 
1.197     raeburn  2452:                               '<td class="LC_right_item">'.
                   2453:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2454:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2455:                               '" value="'.$currdefquota.
1.197     raeburn  2456:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2457:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2458:                               '<input type="text" name="authorquota_'.$type.
                   2459:                               '" value="'.$currauthorquota.
                   2460:                               '" size="5" /></span></td>';
1.86      raeburn  2461:                 }
                   2462:                 $datatable .= '</tr>';
1.3       raeburn  2463:             }
                   2464:         }
                   2465:     }
1.163     raeburn  2466:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2467:         $defaultquota = '20';
1.197     raeburn  2468:         $authorquota = '500';
1.86      raeburn  2469:         if (ref($settings) eq 'HASH') {
                   2470:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2471:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2472:             } elsif (defined($settings->{'default'})) {
                   2473:                 $defaultquota = $settings->{'default'};
                   2474:             }
1.197     raeburn  2475:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2476:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2477:             }
1.3       raeburn  2478:         }
                   2479:     }
                   2480:     $typecount ++;
                   2481:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2482:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2483:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2484:                   '<td class="LC_left_item">';
1.101     raeburn  2485:     if ($context eq 'requestcourses') {
                   2486:         $datatable .= '<table><tr>';
                   2487:     }
                   2488:     my %defcell;
1.72      raeburn  2489:     foreach my $item (@usertools) {
1.101     raeburn  2490:         if ($context eq 'requestcourses') {
                   2491:             my ($curroption,$currlimit);
                   2492:             if (ref($settings) eq 'HASH') {
                   2493:                 if (ref($settings->{$item}) eq 'HASH') {
                   2494:                     $curroption = $settings->{$item}->{'default'};
                   2495:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2496:                         $currlimit = $1;
                   2497:                     }
                   2498:                 }
                   2499:             }
                   2500:             if (!$curroption) {
                   2501:                 $curroption = 'norequest';
                   2502:             }
                   2503:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2504:             foreach my $option (@options) {
                   2505:                 my $val = $option;
                   2506:                 if ($option eq 'norequest') {
                   2507:                     $val = 0;
                   2508:                 }
                   2509:                 if ($option eq 'validate') {
                   2510:                     my $canvalidate = 0;
                   2511:                     if (ref($validations{$item}) eq 'HASH') {
                   2512:                         if ($validations{$item}{'default'}) {
                   2513:                             $canvalidate = 1;
                   2514:                         }
                   2515:                     }
                   2516:                     next if (!$canvalidate);
                   2517:                 }
                   2518:                 my $checked = '';
                   2519:                 if ($option eq $curroption) {
                   2520:                     $checked = ' checked="checked"';
                   2521:                 } elsif ($option eq 'autolimit') {
                   2522:                     if ($curroption =~ /^autolimit/) {
                   2523:                         $checked = ' checked="checked"';
                   2524:                     }
                   2525:                 }
                   2526:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2527:                                   '<input type="radio" name="crsreq_'.$item.
                   2528:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2529:                                   $titles{$option}.'</label>';
                   2530:                 if ($option eq 'autolimit') {
1.127     raeburn  2531:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2532:                                        $item.'_limit_default" size="1" '.
                   2533:                                        'value="'.$currlimit.'" />';
                   2534:                 }
1.127     raeburn  2535:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2536:                 if ($option eq 'autolimit') {
1.127     raeburn  2537:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2538:                 }
1.101     raeburn  2539:             }
1.163     raeburn  2540:         } elsif ($context eq 'requestauthor') {
                   2541:             my $curroption;
                   2542:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2543:                 $curroption = $settings->{'default'};
1.163     raeburn  2544:             }
                   2545:             if (!$curroption) {
                   2546:                 $curroption = 'norequest';
                   2547:             }
                   2548:             foreach my $option (@options) {
                   2549:                 my $val = $option;
                   2550:                 if ($option eq 'norequest') {
                   2551:                     $val = 0;
                   2552:                 }
                   2553:                 my $checked = '';
                   2554:                 if ($option eq $curroption) {
                   2555:                     $checked = ' checked="checked"';
                   2556:                 }
                   2557:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2558:                               '<input type="radio" name="authorreq_default"'.
                   2559:                               ' value="'.$val.'"'.$checked.' />'.
                   2560:                               $titles{$option}.'</label></span>&nbsp; ';
                   2561:             }
1.101     raeburn  2562:         } else {
                   2563:             my $checked = 'checked="checked" ';
                   2564:             if (ref($settings) eq 'HASH') {
                   2565:                 if (ref($settings->{$item}) eq 'HASH') {
                   2566:                     if ($settings->{$item}->{'default'} == 0) {
                   2567:                         $checked = '';
                   2568:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2569:                         $checked = 'checked="checked" ';
                   2570:                     }
1.78      raeburn  2571:                 }
1.72      raeburn  2572:             }
1.101     raeburn  2573:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2574:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2575:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2576:                           '</label></span>&nbsp; ';
                   2577:         }
                   2578:     }
                   2579:     if ($context eq 'requestcourses') {
                   2580:         $datatable .= '</tr><tr>';
                   2581:         foreach my $item (@usertools) {
1.106     raeburn  2582:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2583:         }
1.101     raeburn  2584:         $datatable .= '</tr></table>';
1.72      raeburn  2585:     }
1.86      raeburn  2586:     $datatable .= '</td>';
1.163     raeburn  2587:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2588:         $datatable .= '<td class="LC_right_item">'.
                   2589:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2590:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2591:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2592:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2593:                       '<input type="text" name="authorquota" value="'.
                   2594:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2595:     }
                   2596:     $datatable .= '</tr>';
1.72      raeburn  2597:     $typecount ++;
                   2598:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2599:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2600:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2601:     if ($context eq 'requestcourses') {
1.109     raeburn  2602:         $datatable .= &mt('(overrides affiliation, if set)').
                   2603:                       '</td>'.
                   2604:                       '<td class="LC_left_item">'.
                   2605:                       '<table><tr>';
1.101     raeburn  2606:     } else {
1.109     raeburn  2607:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2608:                       '</td>'.
                   2609:                       '<td class="LC_left_item" colspan="2">'.
                   2610:                       '<br />';
1.101     raeburn  2611:     }
                   2612:     my %advcell;
1.72      raeburn  2613:     foreach my $item (@usertools) {
1.101     raeburn  2614:         if ($context eq 'requestcourses') {
                   2615:             my ($curroption,$currlimit);
                   2616:             if (ref($settings) eq 'HASH') {
                   2617:                 if (ref($settings->{$item}) eq 'HASH') {
                   2618:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2619:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2620:                         $currlimit = $1;
                   2621:                     }
                   2622:                 }
                   2623:             }
                   2624:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2625:             my $checked = '';
                   2626:             if ($curroption eq '') {
                   2627:                 $checked = ' checked="checked"';
                   2628:             }
                   2629:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2630:                                '<input type="radio" name="crsreq_'.$item.
                   2631:                                '__LC_adv" value=""'.$checked.' />'.
                   2632:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2633:             foreach my $option (@options) {
                   2634:                 my $val = $option;
                   2635:                 if ($option eq 'norequest') {
                   2636:                     $val = 0;
                   2637:                 }
                   2638:                 if ($option eq 'validate') {
                   2639:                     my $canvalidate = 0;
                   2640:                     if (ref($validations{$item}) eq 'HASH') {
                   2641:                         if ($validations{$item}{'_LC_adv'}) {
                   2642:                             $canvalidate = 1;
                   2643:                         }
                   2644:                     }
                   2645:                     next if (!$canvalidate);
                   2646:                 }
                   2647:                 my $checked = '';
1.104     raeburn  2648:                 if ($val eq $curroption) {
1.101     raeburn  2649:                     $checked = ' checked="checked"';
                   2650:                 } elsif ($option eq 'autolimit') {
                   2651:                     if ($curroption =~ /^autolimit/) {
                   2652:                         $checked = ' checked="checked"';
                   2653:                     }
                   2654:                 }
                   2655:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2656:                                   '<input type="radio" name="crsreq_'.$item.
                   2657:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2658:                                   $titles{$option}.'</label>';
                   2659:                 if ($option eq 'autolimit') {
1.127     raeburn  2660:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2661:                                        $item.'_limit__LC_adv" size="1" '.
                   2662:                                        'value="'.$currlimit.'" />';
                   2663:                 }
1.127     raeburn  2664:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2665:                 if ($option eq 'autolimit') {
1.127     raeburn  2666:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2667:                 }
1.101     raeburn  2668:             }
1.163     raeburn  2669:         } elsif ($context eq 'requestauthor') {
                   2670:             my $curroption;
                   2671:             if (ref($settings) eq 'HASH') {
                   2672:                 $curroption = $settings->{'_LC_adv'};
                   2673:             }
                   2674:             my $checked = '';
                   2675:             if ($curroption eq '') {
                   2676:                 $checked = ' checked="checked"';
                   2677:             }
                   2678:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2679:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2680:                           ' value=""'.$checked.' />'.
                   2681:                           &mt('No override set').'</label></span>&nbsp; ';
                   2682:             foreach my $option (@options) {
                   2683:                 my $val = $option;
                   2684:                 if ($option eq 'norequest') {
                   2685:                     $val = 0;
                   2686:                 }
                   2687:                 my $checked = '';
                   2688:                 if ($val eq $curroption) {
                   2689:                     $checked = ' checked="checked"';
                   2690:                 }
                   2691:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2692:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2693:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2694:                               $titles{$option}.'</label></span>&nbsp; ';
                   2695:             }
1.101     raeburn  2696:         } else {
                   2697:             my $checked = 'checked="checked" ';
                   2698:             if (ref($settings) eq 'HASH') {
                   2699:                 if (ref($settings->{$item}) eq 'HASH') {
                   2700:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2701:                         $checked = '';
                   2702:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2703:                         $checked = 'checked="checked" ';
                   2704:                     }
1.79      raeburn  2705:                 }
1.72      raeburn  2706:             }
1.101     raeburn  2707:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2708:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2709:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2710:                           '</label></span>&nbsp; ';
                   2711:         }
                   2712:     }
                   2713:     if ($context eq 'requestcourses') {
                   2714:         $datatable .= '</tr><tr>';
                   2715:         foreach my $item (@usertools) {
1.106     raeburn  2716:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2717:         }
1.101     raeburn  2718:         $datatable .= '</tr></table>';
1.72      raeburn  2719:     }
1.98      raeburn  2720:     $datatable .= '</td></tr>';
1.30      raeburn  2721:     $$rowtotal += $typecount;
1.3       raeburn  2722:     return $datatable;
                   2723: }
                   2724: 
1.163     raeburn  2725: sub print_requestmail {
1.305     raeburn  2726:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2727:     my ($now,$datatable,%currapp);
1.102     raeburn  2728:     $now = time;
                   2729:     if (ref($settings) eq 'HASH') {
                   2730:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2731:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2732:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2733:             }
                   2734:         }
                   2735:     }
1.191     raeburn  2736:     my $numinrow = 2;
1.224     raeburn  2737:     my $css_class;
1.305     raeburn  2738:     if ($$rowtotal%2) {
                   2739:         $css_class = 'LC_odd_row';
                   2740:     }
                   2741:     if ($customcss) {
                   2742:         $css_class .= " $customcss";
                   2743:     }
                   2744:     $css_class =~ s/^\s+//;
                   2745:     if ($css_class) {
                   2746:         $css_class = ' class="'.$css_class.'"';
                   2747:     }
                   2748:     if ($rowstyle) {
                   2749:         $css_class .= ' style="'.$rowstyle.'"';
                   2750:     }
1.163     raeburn  2751:     my $text;
                   2752:     if ($action eq 'requestcourses') {
                   2753:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2754:     } elsif ($action eq 'requestauthor') {
                   2755:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2756:     } else {
1.224     raeburn  2757:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2758:     }
1.224     raeburn  2759:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2760:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2761:                  ' <td class="LC_left_item">';
1.191     raeburn  2762:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2763:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2764:     if ($numdc > 0) {
                   2765:         $datatable .= $table;
1.102     raeburn  2766:     } else {
                   2767:         $datatable .= &mt('There are no active Domain Coordinators');
                   2768:     }
                   2769:     $datatable .='</td></tr>';
                   2770:     return $datatable;
                   2771: }
                   2772: 
1.216     raeburn  2773: sub print_studentcode {
                   2774:     my ($settings,$rowtotal) = @_;
                   2775:     my $rownum = 0; 
1.218     raeburn  2776:     my ($output,%current);
1.325     raeburn  2777:     my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248     raeburn  2778:     if (ref($settings) eq 'HASH') {
                   2779:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2780:             foreach my $type (@crstypes) {
                   2781:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2782:             }
1.218     raeburn  2783:         }
                   2784:     }
                   2785:     $output .= '<tr>'.
                   2786:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2787:                '<td class="LC_left_item">';
                   2788:     foreach my $type (@crstypes) {
                   2789:         my $check = ' ';
                   2790:         if ($current{$type}) {
                   2791:             $check = ' checked="checked" ';
                   2792:         }
                   2793:         $output .= '<span class="LC_nobreak"><label>'.
                   2794:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2795:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2796:     }
                   2797:     $output .= '</td></tr>';
                   2798:     $$rowtotal ++;
                   2799:     return $output;
1.216     raeburn  2800: }
                   2801: 
                   2802: sub print_textbookcourses {
1.242     raeburn  2803:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2804:     my $rownum = 0;
                   2805:     my $css_class;
                   2806:     my $itemcount = 1;
                   2807:     my $maxnum = 0;
                   2808:     my $bookshash;
                   2809:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2810:         $bookshash = $settings->{$type};
1.216     raeburn  2811:     }
                   2812:     my %ordered;
                   2813:     if (ref($bookshash) eq 'HASH') {
                   2814:         foreach my $item (keys(%{$bookshash})) {
                   2815:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2816:                 my $num = $bookshash->{$item}{'order'};
                   2817:                 $ordered{$num} = $item;
                   2818:             }
                   2819:         }
                   2820:     }
                   2821:     my $confname = $dom.'-domainconfig';
                   2822:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2823:     my $maxnum = scalar(keys(%ordered));
                   2824:     my $datatable;
1.216     raeburn  2825:     if (keys(%ordered)) {
                   2826:         my @items = sort { $a <=> $b } keys(%ordered);
                   2827:         for (my $i=0; $i<@items; $i++) {
                   2828:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2829:             my $key = $ordered{$items[$i]};
                   2830:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2831:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2832:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2833:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2834:                 $subject = $bookshash->{$key}->{'subject'};
                   2835:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2836:                 if ($type eq 'textbooks') {
1.243     raeburn  2837:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2838:                     $author = $bookshash->{$key}->{'author'};
                   2839:                     $image = $bookshash->{$key}->{'image'};
                   2840:                     if ($image ne '') {
                   2841:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2842:                         my $imagethumb = "$path/tn-".$imagefile;
                   2843:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2844:                     }
1.216     raeburn  2845:                 }
                   2846:             }
1.242     raeburn  2847:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2848:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2849:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2850:             for (my $k=0; $k<=$maxnum; $k++) {
                   2851:                 my $vpos = $k+1;
                   2852:                 my $selstr;
                   2853:                 if ($k == $i) {
                   2854:                     $selstr = ' selected="selected" ';
                   2855:                 }
                   2856:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2857:             }
                   2858:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2859:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2860:                 &mt('Delete?').'</label></span></td>'.
                   2861:                 '<td colspan="2">'.
1.242     raeburn  2862:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2863:                 ('&nbsp;'x2).
1.242     raeburn  2864:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2865:             if ($type eq 'textbooks') {
                   2866:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2867:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2868:                               ('&nbsp;'x2).
1.242     raeburn  2869:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2870:                               ('&nbsp;'x2).
                   2871:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2872:                 if ($image) {
1.267     raeburn  2873:                     $datatable .= $imgsrc.
1.242     raeburn  2874:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2875:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2876:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2877:                 }
                   2878:                 if ($switchserver) {
                   2879:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2880:                 } else {
                   2881:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2882:                 }
1.216     raeburn  2883:             }
1.242     raeburn  2884:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2885:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2886:                           $coursetitle.'</span></td></tr>'."\n";
                   2887:             $itemcount ++;
                   2888:         }
                   2889:     }
                   2890:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2891:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2892:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2893:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2894:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2895:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2896:         my $vpos = $k+1;
                   2897:         my $selstr;
                   2898:         if ($k == $maxnum) {
                   2899:             $selstr = ' selected="selected" ';
                   2900:         }
                   2901:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2902:     }
                   2903:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  2904:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216     raeburn  2905:                   '<td colspan="2">'.
1.242     raeburn  2906:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2907:                   ('&nbsp;'x2).
1.242     raeburn  2908:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2909:                   ('&nbsp;'x2);
                   2910:     if ($type eq 'textbooks') {
1.243     raeburn  2911:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2912:                       ('&nbsp;'x2).
                   2913:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2914:                       ('&nbsp;'x2).
                   2915:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2916:         if ($switchserver) {
                   2917:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2918:         } else {
                   2919:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2920:         }
1.334     raeburn  2921:         $datatable .= '</span>'."\n";
1.216     raeburn  2922:     }
1.334     raeburn  2923:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2924:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2925:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2926:                   &Apache::loncommon::selectcourse_link
1.334     raeburn  2927:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216     raeburn  2928:                   '</span></td>'."\n".
                   2929:                   '</tr>'."\n";
                   2930:     $itemcount ++;
                   2931:     return $datatable;
                   2932: }
                   2933: 
1.217     raeburn  2934: sub textbookcourses_javascript {
1.242     raeburn  2935:     my ($settings) = @_;
                   2936:     return unless(ref($settings) eq 'HASH');
                   2937:     my (%ordered,%total,%jstext);
                   2938:     foreach my $type ('textbooks','templates') {
                   2939:         $total{$type} = 0;
                   2940:         if (ref($settings->{$type}) eq 'HASH') {
                   2941:             foreach my $item (keys(%{$settings->{$type}})) {
                   2942:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2943:                     my $num = $settings->{$type}->{$item}{'order'};
                   2944:                     $ordered{$type}{$num} = $item;
                   2945:                 }
                   2946:             }
                   2947:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2948:         }
                   2949:         my @jsarray = ();
                   2950:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2951:             push(@jsarray,$ordered{$type}{$item});
                   2952:         }
                   2953:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2954:     }
                   2955:     return <<"ENDSCRIPT";
                   2956: <script type="text/javascript">
                   2957: // <![CDATA[
1.242     raeburn  2958: function reorderBooks(form,item,caller) {
1.217     raeburn  2959:     var changedVal;
1.242     raeburn  2960: $jstext{'textbooks'};
                   2961: $jstext{'templates'};
                   2962:     var newpos;
                   2963:     var maxh;
                   2964:     if (caller == 'textbooks') {  
                   2965:         newpos = 'textbooks_addbook_pos';
                   2966:         maxh = 1 + $total{'textbooks'};
                   2967:     } else {
                   2968:         newpos = 'templates_addbook_pos';
                   2969:         maxh = 1 + $total{'templates'};
                   2970:     }
1.217     raeburn  2971:     var current = new Array;
                   2972:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2973:     if (item == newpos) {
                   2974:         changedVal = newitemVal;
                   2975:     } else {
                   2976:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2977:         current[newitemVal] = newpos;
                   2978:     }
1.242     raeburn  2979:     if (caller == 'textbooks') {
                   2980:         for (var i=0; i<textbooks.length; i++) {
                   2981:             var elementName = 'textbooks_'+textbooks[i];
                   2982:             if (elementName != item) {
                   2983:                 if (form.elements[elementName]) {
                   2984:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2985:                     current[currVal] = elementName;
                   2986:                 }
                   2987:             }
                   2988:         }
                   2989:     }
                   2990:     if (caller == 'templates') {
                   2991:         for (var i=0; i<templates.length; i++) {
                   2992:             var elementName = 'templates_'+templates[i];
                   2993:             if (elementName != item) {
                   2994:                 if (form.elements[elementName]) {
                   2995:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2996:                     current[currVal] = elementName;
                   2997:                 }
1.217     raeburn  2998:             }
                   2999:         }
                   3000:     }
                   3001:     var oldVal;
                   3002:     for (var j=0; j<maxh; j++) {
                   3003:         if (current[j] == undefined) {
                   3004:             oldVal = j;
                   3005:         }
                   3006:     }
                   3007:     if (oldVal < changedVal) {
                   3008:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3009:            var elementName = current[k];
                   3010:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3011:         }
                   3012:     } else {
                   3013:         for (var k=changedVal; k<oldVal; k++) {
                   3014:             var elementName = current[k];
                   3015:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3016:         }
                   3017:     }
                   3018:     return;
                   3019: }
                   3020: 
                   3021: // ]]>
                   3022: </script>
                   3023: 
                   3024: ENDSCRIPT
                   3025: }
                   3026: 
1.267     raeburn  3027: sub ltitools_javascript {
                   3028:     my ($settings) = @_;
1.319     raeburn  3029:     my $togglejs = &ltitools_toggle_js();
                   3030:     unless (ref($settings) eq 'HASH') {
                   3031:         return $togglejs;
                   3032:     }
1.267     raeburn  3033:     my (%ordered,$total,%jstext);
                   3034:     $total = 0;
                   3035:     foreach my $item (keys(%{$settings})) {
                   3036:         if (ref($settings->{$item}) eq 'HASH') {
                   3037:             my $num = $settings->{$item}{'order'};
                   3038:             $ordered{$num} = $item;
                   3039:         }
                   3040:     }
                   3041:     $total = scalar(keys(%{$settings}));
                   3042:     my @jsarray = ();
                   3043:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3044:         push(@jsarray,$ordered{$item});
                   3045:     }
                   3046:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3047:     return <<"ENDSCRIPT";
                   3048: <script type="text/javascript">
                   3049: // <![CDATA[
1.319     raeburn  3050: function reorderLTITools(form,item) {
1.267     raeburn  3051:     var changedVal;
                   3052: $jstext
                   3053:     var newpos = 'ltitools_add_pos';
                   3054:     var maxh = 1 + $total;
                   3055:     var current = new Array;
                   3056:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3057:     if (item == newpos) {
                   3058:         changedVal = newitemVal;
                   3059:     } else {
                   3060:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3061:         current[newitemVal] = newpos;
                   3062:     }
                   3063:     for (var i=0; i<ltitools.length; i++) {
                   3064:         var elementName = 'ltitools_'+ltitools[i];
                   3065:         if (elementName != item) {
                   3066:             if (form.elements[elementName]) {
                   3067:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3068:                 current[currVal] = elementName;
                   3069:             }
                   3070:         }
                   3071:     }
                   3072:     var oldVal;
                   3073:     for (var j=0; j<maxh; j++) {
                   3074:         if (current[j] == undefined) {
                   3075:             oldVal = j;
                   3076:         }
                   3077:     }
                   3078:     if (oldVal < changedVal) {
                   3079:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3080:            var elementName = current[k];
                   3081:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3082:         }
                   3083:     } else {
                   3084:         for (var k=changedVal; k<oldVal; k++) {
                   3085:             var elementName = current[k];
                   3086:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3087:         }
                   3088:     }
                   3089:     return;
                   3090: }
                   3091: 
                   3092: // ]]>
                   3093: </script>
                   3094: 
1.319     raeburn  3095: $togglejs
                   3096: 
                   3097: ENDSCRIPT
                   3098: }
                   3099: 
                   3100: sub ltitools_toggle_js {
                   3101:     return <<"ENDSCRIPT";
                   3102: <script type="text/javascript">
                   3103: // <![CDATA[
                   3104: 
                   3105: function toggleLTITools(form,setting,item) {
                   3106:     var radioname = '';
                   3107:     var divid = '';
                   3108:     if ((setting == 'passback') || (setting == 'roster')) {
                   3109:         radioname = 'ltitools_'+setting+'_'+item;
                   3110:         divid = 'ltitools_'+setting+'time_'+item;
                   3111:         var num = form.elements[radioname].length;
                   3112:         if (num) {
                   3113:             var setvis = '';
                   3114:             for (var i=0; i<num; i++) {
                   3115:                 if (form.elements[radioname][i].checked) {
                   3116:                     if (form.elements[radioname][i].value == '1') {
                   3117:                         if (document.getElementById(divid)) {
                   3118:                             document.getElementById(divid).style.display = 'inline-block';
                   3119:                         }
                   3120:                         setvis = 1;
                   3121:                     }
                   3122:                     break;
                   3123:                 }
                   3124:             }
                   3125:         }
                   3126:         if (!setvis) {
                   3127:             if (document.getElementById(divid)) {
                   3128:                 document.getElementById(divid).style.display = 'none';
                   3129:             }
                   3130:         }
                   3131:     }
1.324     raeburn  3132:     if (setting == 'user') {
                   3133:         divid = 'ltitools_'+setting+'_div_'+item;
                   3134:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   3135:         if (document.getElementById(divid)) {
                   3136:             if (document.getElementById(checkid)) {
                   3137:                 if (document.getElementById(checkid).checked) {
                   3138:                     document.getElementById(divid).style.display = 'inline-block';
                   3139:                 } else {
                   3140:                     document.getElementById(divid).style.display = 'none';
                   3141:                 }
                   3142:             }
                   3143:         }
                   3144:     }
1.319     raeburn  3145:     return;
                   3146: }
                   3147: // ]]>
                   3148: </script>
                   3149: 
1.267     raeburn  3150: ENDSCRIPT
                   3151: }
                   3152: 
1.381     raeburn  3153: sub wafproxy_javascript {
                   3154:     my ($dom) = @_;
                   3155:     return <<"ENDSCRIPT";
                   3156: <script type="text/javascript">
                   3157: // <![CDATA[
                   3158: function updateWAF() {
                   3159:     if (document.getElementById('wafproxy_remoteip')) {
                   3160:         var wafremote = 0;
                   3161:         if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
                   3162:             wafremote = 1;
                   3163:         }
                   3164:         var fields = new Array('header','trust');
                   3165:         for (var i=0; i<fields.length; i++) {
                   3166:             if (document.getElementById('wafproxy_'+fields[i])) {
                   3167:                 if (wafremote == 1) {
                   3168:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
                   3169:                 }
                   3170:                 else {
                   3171:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
                   3172:                 }
                   3173:             }
                   3174:         }
                   3175:         if (document.getElementById('wafproxyranges_$dom')) {
                   3176:             if (wafremote == 1) {
                   3177:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3178:             } else {
                   3179:                 for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3180:                     if (document.display.wafproxy_vpnaccess[i].checked) {
                   3181:                         if (document.display.wafproxy_vpnaccess[i].value == 0) {
                   3182:                             document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3183:                         }
                   3184:                     }
                   3185:                 }
                   3186:             }
                   3187:         }
                   3188:     }
                   3189:     return;
                   3190: }
                   3191: 
                   3192: function checkWAF() {
                   3193:     if (document.getElementById('wafproxy_remoteip')) {
                   3194:         var wafvpn = 0;
                   3195:         for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3196:             if (document.display.wafproxy_vpnaccess[i].checked) {
                   3197:                 if (document.display.wafproxy_vpnaccess[i].value == 1) {
                   3198:                     wafvpn = 1;
                   3199:                 }
                   3200:                 break;
                   3201:             }
                   3202:         }
                   3203:         var vpn = new Array('vpnint','vpnext');
                   3204:         for (var i=0; i<vpn.length; i++) {
                   3205:             if (document.getElementById('wafproxy_show_'+vpn[i])) {
                   3206:                 if (wafvpn == 1) {
                   3207:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
                   3208:                 }
                   3209:                 else {
                   3210:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
                   3211:                 }
                   3212:             }
                   3213:         }
                   3214:         if (document.getElementById('wafproxyranges_$dom')) {
                   3215:             if (wafvpn == 1) {
                   3216:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3217:             }
                   3218:             else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
                   3219:                 document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3220:             }
                   3221:         }
                   3222:     }
                   3223:     return;
                   3224: }
                   3225: 
                   3226: function toggleWAF() {
                   3227:     if (document.getElementById('wafproxy_table')) {
                   3228:         var wafproxy = 0;
                   3229:         for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
                   3230:              if (document.display.wafproxy_${dom}[i].checked) {
                   3231:                  if (document.display.wafproxy_${dom}[i].value == 1) {
                   3232:                      wafproxy = 1;
                   3233:                      break;
                   3234:                 }
                   3235:             }
                   3236:         }
                   3237:         if (wafproxy == 1) {
                   3238:             document.getElementById('wafproxy_table').style.display='inline';
                   3239:         }
                   3240:         else {
                   3241:            document.getElementById('wafproxy_table').style.display='none';
                   3242:         }
                   3243:         if (document.getElementById('wafproxyrow_${dom}')) {
                   3244:             if (wafproxy == 1) {
                   3245:                 document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
                   3246:             }
                   3247:             else {
                   3248:                 document.getElementById('wafproxyrow_${dom}').style.display = 'none';
                   3249:             }
                   3250:         }
                   3251:         if (document.getElementById('nowafproxyrow_$dom')) {
                   3252:             if (wafproxy == 1) {
                   3253:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
                   3254:             }
                   3255:             else {
                   3256:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
                   3257:             }
                   3258:         }
                   3259:     }
                   3260:     return;
                   3261: }
                   3262: // ]]>
                   3263: </script>
                   3264: 
                   3265: ENDSCRIPT
                   3266: }
                   3267: 
1.372     raeburn  3268: sub proctoring_javascript {
                   3269:     my ($settings) = @_;
                   3270:     my (%ordered,$total,%jstext);
                   3271:     $total = 0;
                   3272:     if (ref($settings) eq 'HASH') {
                   3273:         foreach my $item (keys(%{$settings})) {
                   3274:             if (ref($settings->{$item}) eq 'HASH') {
                   3275:                 my $num = $settings->{$item}{'order'};
                   3276:                 $ordered{$num} = $item;
                   3277:             }
                   3278:         }
                   3279:         $total = scalar(keys(%{$settings}));
                   3280:     } else {
                   3281:         %ordered = (
                   3282:                        0 => 'proctorio',
                   3283:                        1 => 'examity',
                   3284:                    );
                   3285:         $total = 2; 
                   3286:     }
                   3287:     my @jsarray = ();
                   3288:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3289:         push(@jsarray,$ordered{$item});
                   3290:     }
                   3291:     my $jstext = '    var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3292:     return <<"ENDSCRIPT";
                   3293: <script type="text/javascript">
                   3294: // <![CDATA[
                   3295: function reorderProctoring(form,item) {
                   3296:     var changedVal;
                   3297: $jstext
                   3298:     var maxh = $total;
                   3299:     var current = new Array;
                   3300:     var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3301:     for (var i=0; i<proctors.length; i++) {
                   3302:         var elementName = 'proctoring_pos_'+proctors[i];
                   3303:         if (elementName != item) {
                   3304:             if (form.elements[elementName]) {
                   3305:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3306:                 current[currVal] = elementName;
                   3307:             }
                   3308:         }
                   3309:     }
                   3310:     var oldVal;
                   3311:     for (var j=0; j<maxh; j++) {
                   3312:         if (current[j] == undefined) {
                   3313:             oldVal = j;
                   3314:         }
                   3315:     }
                   3316:     if (oldVal < changedVal) {
                   3317:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3318:            var elementName = current[k];
                   3319:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3320:         }
                   3321:     } else {
                   3322:         for (var k=changedVal; k<oldVal; k++) {
                   3323:             var elementName = current[k];
                   3324:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3325:         }
                   3326:     }
                   3327:     return;
                   3328: }
                   3329: 
                   3330: function toggleProctoring(form,item) {
                   3331:     var fieldsets = document.getElementsByClassName('proctoring_'+item);
                   3332:     if (fieldsets.length) {
                   3333:         var radioname = 'proctoring_available_'+item;
                   3334:         var num = form.elements[radioname].length;
                   3335:         if (num) {
                   3336:             var setvis = '';
                   3337:             for (var i=0; i<num; i++) {
                   3338:                 if (form.elements[radioname][i].checked) {
                   3339:                     if (form.elements[radioname][i].value == '1') {
                   3340:                        setvis = 1;
                   3341:                        break;
                   3342:                     }
                   3343:                 }
                   3344:             }
                   3345:             for (var j=0; j<fieldsets.length; j++) {
                   3346:                 if (setvis) {
                   3347:                     fieldsets[j].style.display = 'block';
                   3348:                 } else {
                   3349:                     fieldsets[j].style.display = 'none';
                   3350:                 }
                   3351:             }
                   3352:         }
                   3353:     }
                   3354:     return;
                   3355: }
                   3356: 
                   3357: // ]]>
                   3358: </script>
                   3359: 
                   3360: ENDSCRIPT
                   3361: }
                   3362: 
                   3363: 
1.320     raeburn  3364: sub lti_javascript {
                   3365:     my ($settings) = @_;
                   3366:     my $togglejs = &lti_toggle_js();
                   3367:     unless (ref($settings) eq 'HASH') {
                   3368:         return $togglejs;
                   3369:     }
                   3370:     my (%ordered,$total,%jstext);
1.390     raeburn  3371:     $total = scalar(keys(%{$settings}));
1.320     raeburn  3372:     foreach my $item (keys(%{$settings})) {
                   3373:         if (ref($settings->{$item}) eq 'HASH') {
                   3374:             my $num = $settings->{$item}{'order'};
1.390     raeburn  3375:             if ($num eq '') {
                   3376:                 $num = $total - 1;
                   3377:             }
1.320     raeburn  3378:             $ordered{$num} = $item;
                   3379:         }
                   3380:     }
                   3381:     my @jsarray = ();
                   3382:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3383:         push(@jsarray,$ordered{$item});
                   3384:     }
                   3385:     my $jstext = '    var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3386:     return <<"ENDSCRIPT";
                   3387: <script type="text/javascript">
                   3388: // <![CDATA[
                   3389: function reorderLTI(form,item) {
                   3390:     var changedVal;
                   3391: $jstext
                   3392:     var newpos = 'lti_pos_add';
                   3393:     var maxh = 1 + $total;
                   3394:     var current = new Array;
                   3395:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3396:     if (item == newpos) {
                   3397:         changedVal = newitemVal;
                   3398:     } else {
                   3399:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3400:         current[newitemVal] = newpos;
                   3401:     }
                   3402:     for (var i=0; i<lti.length; i++) {
                   3403:         var elementName = 'lti_pos_'+lti[i];
                   3404:         if (elementName != item) {
                   3405:             if (form.elements[elementName]) {
                   3406:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3407:                 current[currVal] = elementName;
                   3408:             }
                   3409:         }
                   3410:     }
                   3411:     var oldVal;
                   3412:     for (var j=0; j<maxh; j++) {
                   3413:         if (current[j] == undefined) {
                   3414:             oldVal = j;
                   3415:         }
                   3416:     }
                   3417:     if (oldVal < changedVal) {
                   3418:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3419:            var elementName = current[k];
                   3420:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3421:         }
                   3422:     } else {
                   3423:         for (var k=changedVal; k<oldVal; k++) {
                   3424:             var elementName = current[k];
                   3425:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3426:         }
                   3427:     }
                   3428:     return;
                   3429: }
                   3430: // ]]>
                   3431: </script>
                   3432: 
                   3433: $togglejs
                   3434: 
                   3435: ENDSCRIPT
                   3436: }
                   3437: 
                   3438: sub lti_toggle_js {
1.325     raeburn  3439:     my %lcauthparmtext = &Apache::lonlocal::texthash (
                   3440:                             localauth => 'Local auth argument',
                   3441:                             krb       => 'Kerberos domain',
                   3442:                          );
1.391     raeburn  3443:     my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
                   3444:     &js_escape(\$crsincalert);
1.320     raeburn  3445:     return <<"ENDSCRIPT";
                   3446: <script type="text/javascript">
                   3447: // <![CDATA[
                   3448: 
                   3449: function toggleLTI(form,setting,item) {
1.391     raeburn  3450:     if ((setting == 'requser') || (setting == 'crsinc')) {
                   3451:         var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
                   3452:         var setvis = '';
                   3453:         var radioname = 'lti_requser_'+item;
                   3454:         var num = form.elements[radioname].length;
                   3455:         if (num) {
                   3456:             for (var i=0; i<num; i++) {
                   3457:                 if (form.elements[radioname][i].checked) {
                   3458:                     if (form.elements[radioname][i].value == '1') {
                   3459:                         setvis = 1;
                   3460:                         break;
                   3461:                     }
                   3462:                 }
                   3463:             }
                   3464:         }
                   3465:         if (usrfieldsets.length) {
                   3466:             for (var j=0; j<usrfieldsets.length; j++) {
                   3467:                 if (setvis) {
                   3468:                     usrfieldsets[j].style.display = 'block';
                   3469:                 } else {
                   3470:                     usrfieldsets[j].style.display = 'none';
                   3471:                 }
                   3472:             }
                   3473:         }
                   3474:         var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
                   3475:         if (crsfieldsets.length) {
                   3476:             radioname = 'lti_crsinc_'+item;
1.345     raeburn  3477:             var num = form.elements[radioname].length;
                   3478:             if (num) {
1.391     raeburn  3479:                 var crsvis = '';
1.345     raeburn  3480:                 for (var i=0; i<num; i++) {
                   3481:                     if (form.elements[radioname][i].checked) {
                   3482:                         if (form.elements[radioname][i].value == '1') {
1.391     raeburn  3483:                             if (setvis == '') {
                   3484:                                 if (setting == 'crsinc'){
                   3485:                                     alert("$crsincalert");
                   3486:                                     form.elements[radioname][0].checked = true;
                   3487:                                 }
                   3488:                             } else {
                   3489:                                 crsvis = 1;
                   3490:                             }
                   3491:                             break;
1.345     raeburn  3492:                         }
                   3493:                     }
                   3494:                 }
1.391     raeburn  3495:                 setvis = crsvis;
                   3496:             }
                   3497:             for (var j=0; j<crsfieldsets.length; j++) {
                   3498:                 if (setvis) {
                   3499:                     crsfieldsets[j].style.display = 'block';
                   3500:                 } else {
                   3501:                     crsfieldsets[j].style.display = 'none';
1.345     raeburn  3502:                 }
                   3503:             }
                   3504:         }
1.363     raeburn  3505:     } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320     raeburn  3506:         var radioname = '';
                   3507:         var divid = '';
                   3508:         if (setting == 'user') {
                   3509:             radioname = 'lti_mapuser_'+item;
                   3510:             divid = 'lti_userfield_'+item;
1.343     raeburn  3511:         } else if (setting == 'crs') {
1.320     raeburn  3512:             radioname = 'lti_mapcrs_'+item;
                   3513:             divid = 'lti_crsfield_'+item;
1.363     raeburn  3514:         } else if (setting == 'callback') {
                   3515:             radioname = 'lti_callback_'+item;
                   3516:             divid = 'lti_callbackfield_'+item;
1.337     raeburn  3517:         } else {
1.351     raeburn  3518:             radioname = 'lti_passback_'+item;
1.337     raeburn  3519:             divid =  'lti_passback_'+item;
1.320     raeburn  3520:         }
                   3521:         var num = form.elements[radioname].length;
                   3522:         if (num) {
                   3523:             var setvis = '';
                   3524:             for (var i=0; i<num; i++) {
                   3525:                if (form.elements[radioname][i].checked) {
1.363     raeburn  3526:                    if ((setting == 'passback') || (setting == 'callback')) {
1.337     raeburn  3527:                        if (form.elements[radioname][i].value == '1') {
                   3528:                            if (document.getElementById(divid)) {
                   3529:                                document.getElementById(divid).style.display = 'inline-block';
                   3530:                            }
                   3531:                            setvis = 1;
                   3532:                            break;
                   3533:                        }
                   3534:                    } else {
                   3535:                        if (form.elements[radioname][i].value == 'other') {
                   3536:                            if (document.getElementById(divid)) {
                   3537:                                document.getElementById(divid).style.display = 'inline-block';
                   3538:                            }
                   3539:                            setvis = 1;
                   3540:                            break;
1.320     raeburn  3541:                        }
                   3542:                    }
                   3543:                } 
                   3544:             }
                   3545:             if (!setvis) {
                   3546:                 if (document.getElementById(divid)) {
                   3547:                     document.getElementById(divid).style.display = 'none';
                   3548:                 }
                   3549:             }
                   3550:         }
                   3551:     } else if ((setting == 'sec') || (setting == 'secsrc')) {
                   3552:         var numsec = form.elements['lti_crssec_'+item].length;
                   3553:         if (numsec) {
                   3554:             var setvis = '';
                   3555:             for (var i=0; i<numsec; i++) {
                   3556:                 if (form.elements['lti_crssec_'+item][i].checked) {
                   3557:                     if (form.elements['lti_crssec_'+item][i].value == '1') {
                   3558:                         if (document.getElementById('lti_crssecfield_'+item)) {
                   3559:                             document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
                   3560:                             setvis = 1;
                   3561:                             var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
                   3562:                             if (numsrcsec) {
                   3563:                                 var setsrcvis = '';
                   3564:                                 for (var j=0; j<numsrcsec; j++) {
                   3565:                                     if (form.elements['lti_crssecsrc_'+item][j].checked) {
                   3566:                                         if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
                   3567:                                             if (document.getElementById('lti_secsrcfield_'+item)) {
                   3568:                                                 document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
                   3569:                                                 setsrcvis = 1;
                   3570:                                             }
                   3571:                                         }
                   3572:                                     }
                   3573:                                 }
                   3574:                                 if (!setsrcvis) {
                   3575:                                     if (document.getElementById('lti_secsrcfield_'+item)) {
                   3576:                                         document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3577:                                     }
                   3578:                                 }
                   3579:                             }
                   3580:                         }
                   3581:                     }
                   3582:                 }
                   3583:             }
                   3584:             if (!setvis) {
                   3585:                 if (document.getElementById('lti_crssecfield_'+item)) {
                   3586:                     document.getElementById('lti_crssecfield_'+item).style.display = 'none';
                   3587:                 }
                   3588:                 if (document.getElementById('lti_secsrcfield_'+item)) {
                   3589:                     document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   3590:                 }
                   3591:             }
                   3592:         }
1.325     raeburn  3593:     } else if (setting == 'lcauth') {
                   3594:         var numauth = form.elements['lti_lcauth_'+item].length;
                   3595:         if (numauth) {
                   3596:             for (var i=0; i<numauth; i++) {
                   3597:                 if (form.elements['lti_lcauth_'+item][i].checked) {
                   3598:                     if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                   3599:                         if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                   3600:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                   3601:                         } else {
                   3602:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                   3603:                             if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                   3604:                                 if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                   3605:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                   3606:                                 } else {
                   3607:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                   3608:                                 }
                   3609:                             }
                   3610:                         }
                   3611:                     }
                   3612:                 }
                   3613:             }
                   3614:         }
1.326     raeburn  3615:     } else if (setting == 'lcmenu') {
                   3616:         var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
                   3617:         var divid = 'lti_menufield_'+item;
                   3618:         var setvis = '';
                   3619:         for (var i=0; i<menus.length; i++) {
                   3620:             var radioname = menus[i];  
                   3621:             var num = form.elements[radioname].length;
                   3622:             if (num) {
                   3623:                 for (var j=0; j<num; j++) {
                   3624:                     if (form.elements[radioname][j].checked) {
                   3625:                         if (form.elements[radioname][j].value == '1') {
                   3626:                             if (document.getElementById(divid)) {
                   3627:                                 document.getElementById(divid).style.display = 'inline-block';
                   3628:                             }
                   3629:                             setvis = 1;
                   3630:                             break;
                   3631:                         }
                   3632:                     }
                   3633:                 }
                   3634:             }
                   3635:             if (setvis == 1) {
                   3636:                 break;
                   3637:             }
                   3638:         }
                   3639:         if (!setvis) {
                   3640:             if (document.getElementById(divid)) {
                   3641:                 document.getElementById(divid).style.display = 'none';
                   3642:             }
                   3643:         }
1.320     raeburn  3644:     }
                   3645:     return;
                   3646: }
                   3647: // ]]>
                   3648: </script>
                   3649: 
                   3650: ENDSCRIPT
                   3651: }
                   3652: 
1.385     raeburn  3653: sub autoupdate_javascript {
                   3654:     return <<"ENDSCRIPT";
                   3655: <script type="text/javascript">
                   3656: // <![CDATA[
                   3657: function toggleLastActiveDays(form) {
                   3658:     var radioname = 'lastactive';
                   3659:     var divid = 'lastactive_div';
                   3660:     var num = form.elements[radioname].length;
                   3661:     if (num) {
                   3662:         var setvis = '';
                   3663:         for (var i=0; i<num; i++) {
                   3664:             if (form.elements[radioname][i].checked) {
                   3665:                 if (form.elements[radioname][i].value == '1') {
                   3666:                     if (document.getElementById(divid)) {
                   3667:                         document.getElementById(divid).style.display = 'inline-block';
                   3668:                     }
                   3669:                     setvis = 1;
                   3670:                 }
                   3671:                 break;
                   3672:             }
                   3673:         }
                   3674:         if (!setvis) {
                   3675:             if (document.getElementById(divid)) {
                   3676:                 document.getElementById(divid).style.display = 'none';
                   3677:             }
                   3678:         }
                   3679:     }
                   3680:     return;
                   3681: }
                   3682: // ]]>
                   3683: </script>
                   3684: 
                   3685: ENDSCRIPT
                   3686: }
                   3687: 
1.386     raeburn  3688: sub saml_javascript {
                   3689:     return <<"ENDSCRIPT";
                   3690: <script type="text/javascript">
                   3691: // <![CDATA[
                   3692: function toggleSamlOptions(form,hostid) { 
                   3693:     var radioname = 'saml_'+hostid;
                   3694:     var tablecellon = 'samloptionson_'+hostid;
                   3695:     var tablecelloff = 'samloptionsoff_'+hostid;
                   3696:     var num = form.elements[radioname].length;
                   3697:     if (num) {
                   3698:         var setvis = ''; 
                   3699:         for (var i=0; i<num; i++) {
                   3700:             if (form.elements[radioname][i].checked) {
                   3701:                 if (form.elements[radioname][i].value == '1') { 
                   3702:                     if (document.getElementById(tablecellon)) {
                   3703:                         document.getElementById(tablecellon).style.display='';
                   3704:                     }
                   3705:                     if (document.getElementById(tablecelloff)) {
                   3706:                         document.getElementById(tablecelloff).style.display='none';
                   3707:                     }
                   3708:                     setvis = 1;
                   3709:                 }
                   3710:                 break;
                   3711:             }
                   3712:         }
                   3713:         if (!setvis) {
                   3714:             if (document.getElementById(tablecellon)) {
                   3715:                 document.getElementById(tablecellon).style.display='none';
                   3716:             }
                   3717:             if (document.getElementById(tablecelloff)) {
                   3718:                 document.getElementById(tablecelloff).style.display='';
                   3719:             }
                   3720:         }
                   3721:     }
                   3722:     return;
                   3723: }
                   3724: // ]]>
                   3725: </script>
                   3726: 
                   3727: ENDSCRIPT
                   3728: }
                   3729: 
1.394     raeburn  3730: sub ipaccess_javascript {
                   3731:     my ($settings) = @_;
                   3732:     my (%ordered,$total,%jstext);
                   3733:     $total = 0;
                   3734:     if (ref($settings) eq 'HASH') {
                   3735:         foreach my $item (keys(%{$settings})) {
                   3736:             if (ref($settings->{$item}) eq 'HASH') {
                   3737:                 my $num = $settings->{$item}{'order'};
                   3738:                 $ordered{$num} = $item;
                   3739:             }
                   3740:         }
                   3741:         $total = scalar(keys(%{$settings}));
                   3742:     }
                   3743:     my @jsarray = ();
                   3744:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3745:         push(@jsarray,$ordered{$item});
                   3746:     }
                   3747:     my $jstext = '    var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3748:     return <<"ENDSCRIPT";
                   3749: <script type="text/javascript">
                   3750: // <![CDATA[
                   3751: function reorderIPaccess(form,item) {
                   3752:     var changedVal;
                   3753: $jstext
                   3754:     var newpos = 'ipaccess_pos_add';
                   3755:     var maxh = 1 + $total;
                   3756:     var current = new Array;
                   3757:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3758:     if (item == newpos) {
                   3759:         changedVal = newitemVal;
                   3760:     } else {
                   3761:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3762:         current[newitemVal] = newpos;
                   3763:     }
                   3764:     for (var i=0; i<ipaccess.length; i++) {
                   3765:         var elementName = 'ipaccess_pos_'+ipaccess[i];
                   3766:         if (elementName != item) {
                   3767:             if (form.elements[elementName]) {
                   3768:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3769:                 current[currVal] = elementName;
                   3770:             }
                   3771:         }
                   3772:     }
                   3773:     var oldVal;
                   3774:     for (var j=0; j<maxh; j++) {
                   3775:         if (current[j] == undefined) {
                   3776:             oldVal = j;
                   3777:         }
                   3778:     }
                   3779:     if (oldVal < changedVal) {
                   3780:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3781:            var elementName = current[k];
                   3782:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3783:         }
                   3784:     } else {
                   3785:         for (var k=changedVal; k<oldVal; k++) {
                   3786:             var elementName = current[k];
                   3787:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3788:         }
                   3789:     }
                   3790:     return;
                   3791: }
                   3792: // ]]>
                   3793: </script>
                   3794: 
                   3795: ENDSCRIPT
                   3796: }
                   3797: 
1.3       raeburn  3798: sub print_autoenroll {
1.30      raeburn  3799:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  3800:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274     raeburn  3801:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  3802:     if (ref($settings) eq 'HASH') {
                   3803:         if (exists($settings->{'run'})) {
                   3804:             if ($settings->{'run'} eq '0') {
                   3805:                 $runoff = ' checked="checked" ';
                   3806:                 $runon = ' ';
                   3807:             } else {
                   3808:                 $runon = ' checked="checked" ';
                   3809:                 $runoff = ' ';
                   3810:             }
                   3811:         } else {
                   3812:             if ($autorun) {
                   3813:                 $runon = ' checked="checked" ';
                   3814:                 $runoff = ' ';
                   3815:             } else {
                   3816:                 $runoff = ' checked="checked" ';
                   3817:                 $runon = ' ';
                   3818:             }
                   3819:         }
1.129     raeburn  3820:         if (exists($settings->{'co-owners'})) {
                   3821:             if ($settings->{'co-owners'} eq '0') {
                   3822:                 $coownersoff = ' checked="checked" ';
                   3823:                 $coownerson = ' ';
                   3824:             } else {
                   3825:                 $coownerson = ' checked="checked" ';
                   3826:                 $coownersoff = ' ';
                   3827:             }
                   3828:         } else {
                   3829:             $coownersoff = ' checked="checked" ';
                   3830:             $coownerson = ' ';
                   3831:         }
1.3       raeburn  3832:         if (exists($settings->{'sender_domain'})) {
                   3833:             $defdom = $settings->{'sender_domain'};
                   3834:         }
1.274     raeburn  3835:         if (exists($settings->{'autofailsafe'})) {
                   3836:             $failsafe = $settings->{'autofailsafe'};
                   3837:         }
1.14      raeburn  3838:     } else {
                   3839:         if ($autorun) {
                   3840:             $runon = ' checked="checked" ';
                   3841:             $runoff = ' ';
                   3842:         } else {
                   3843:             $runoff = ' checked="checked" ';
                   3844:             $runon = ' ';
                   3845:         }
1.3       raeburn  3846:     }
                   3847:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  3848:     my $notif_sender;
                   3849:     if (ref($settings) eq 'HASH') {
                   3850:         $notif_sender = $settings->{'sender_uname'};
                   3851:     }
1.3       raeburn  3852:     my $datatable='<tr class="LC_odd_row">'.
                   3853:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  3854:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3855:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  3856:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3857:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  3858:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3859:                   '</tr><tr>'.
                   3860:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  3861:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  3862:                   &mt('username').':&nbsp;'.
                   3863:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  3864:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  3865:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   3866:                   '<tr class="LC_odd_row">'.
                   3867:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   3868:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3869:                   '<input type="radio" name="autoassign_coowners"'.
                   3870:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3871:                   '<label><input type="radio" name="autoassign_coowners"'.
                   3872:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  3873:                   '</tr><tr>'.
                   3874:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   3875:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3876:                   '<input type="text" name="autoenroll_failsafe"'.
1.333     raeburn  3877:                   ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274     raeburn  3878:     $$rowtotal += 4;
1.3       raeburn  3879:     return $datatable;
                   3880: }
                   3881: 
                   3882: sub print_autoupdate {
1.30      raeburn  3883:     my ($position,$dom,$settings,$rowtotal) = @_;
1.385     raeburn  3884:     my ($enable,$datatable);
1.3       raeburn  3885:     if ($position eq 'top') {
1.385     raeburn  3886:         my %choices = &Apache::lonlocal::texthash (
                   3887:                           run        => 'Auto-update active?',
                   3888:                           classlists => 'Update information in classlists?',
                   3889:                           unexpired  => 'Skip updates for users without active or future roles?',
                   3890:                           lastactive => 'Skip updates for inactive users?',
                   3891:         );
                   3892:         my $itemcount = 0;
1.3       raeburn  3893:         my $updateon = ' ';
                   3894:         my $updateoff = ' checked="checked" ';
                   3895:         if (ref($settings) eq 'HASH') {
                   3896:             if ($settings->{'run'} eq '1') {
                   3897:                 $updateon = $updateoff;
                   3898:                 $updateoff = ' ';
                   3899:             }
                   3900:         }
1.385     raeburn  3901:         $enable = '<tr class="LC_odd_row">'.
                   3902:                   '<td>'.$choices{'run'}.'</td>'.
                   3903:                   '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3904:                   '<input type="radio" name="autoupdate_run"'.
1.385     raeburn  3905:                   $updateoff.' value="0" />'.&mt('No').'</label>&nbsp;'.
1.8       raeburn  3906:                   '<label><input type="radio" name="autoupdate_run"'.
1.385     raeburn  3907:                   $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3       raeburn  3908:                   '</tr>';
1.385     raeburn  3909:         my @toggles = ('classlists','unexpired');
                   3910:         my %defaultchecked = ('classlists' => 'off',
                   3911:                               'unexpired'  => 'off'
                   3912:                               );
                   3913:         $$rowtotal ++;
                   3914:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3915:                                                      \%choices,$itemcount,'','','left','no');
                   3916:         $datatable = $enable.$datatable;
                   3917:         $$rowtotal += $itemcount;
                   3918:         my $lastactiveon = ' ';
                   3919:         my $lastactiveoff = ' checked="checked" ';
                   3920:         my $lastactivestyle = 'none';
                   3921:         my $lastactivedays;
                   3922:         my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
                   3923:         if (ref($settings) eq 'HASH') {
                   3924:             if ($settings->{'lastactive'} =~ /^\d+$/) {
                   3925:                 $lastactiveon = $lastactiveoff;
                   3926:                 $lastactiveoff = ' ';
                   3927:                 $lastactivestyle = 'inline-block';
                   3928:                 $lastactivedays = $settings->{'lastactive'};
                   3929:             }
                   3930:         }
                   3931:         my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3932:         $datatable .= '<tr'.$css_class.'>'.
                   3933:                       '<td>'.$choices{'lastactive'}.'</td>'.
                   3934:                       '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                   3935:                       '<input type="radio" name="lastactive"'.
                   3936:                       $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3937:                       '&nbsp;<label>'.
                   3938:                       '<input type="radio" name="lastactive"'.
                   3939:                       $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
                   3940:                       '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
                   3941:                       ':&nbsp;'.&mt('inactive = no activity in last [_1] days',
                   3942:                           '<input type="text" size="5" name="lastactivedays" value="'.
                   3943:                           $lastactivedays.'" />').
                   3944:                       '</span></td>'.
                   3945:                       '</tr>';
                   3946:         $$rowtotal ++;
1.131     raeburn  3947:     } elsif ($position eq 'middle') {
                   3948:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3949:         my $numinrow = 3;
                   3950:         my $locknamesettings;
                   3951:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   3952:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  3953:                                     'lockablenames',$rowtotal);
1.131     raeburn  3954:         $$rowtotal ++;
1.3       raeburn  3955:     } else {
1.44      raeburn  3956:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  3957:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  3958:                       'permanentemail','id');
1.33      raeburn  3959:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  3960:         my $numrows = 0;
1.26      raeburn  3961:         if (ref($types) eq 'ARRAY') {
                   3962:             if (@{$types} > 0) {
                   3963:                 $datatable = 
                   3964:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   3965:                                          \@fields,$types,\$numrows);
1.30      raeburn  3966:                     $$rowtotal += @{$types}; 
1.26      raeburn  3967:             }
1.3       raeburn  3968:         }
                   3969:         $datatable .= 
                   3970:             &usertype_update_row($settings,{'default' => $othertitle},
                   3971:                                  \%fieldtitles,\@fields,['default'],
                   3972:                                  \$numrows);
1.30      raeburn  3973:         $$rowtotal ++;     
1.3       raeburn  3974:     }
                   3975:     return $datatable;
                   3976: }
                   3977: 
1.125     raeburn  3978: sub print_autocreate {
                   3979:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  3980:     my (%createon,%createoff,%currhash);
1.125     raeburn  3981:     my @types = ('xml','req');
                   3982:     if (ref($settings) eq 'HASH') {
                   3983:         foreach my $item (@types) {
                   3984:             $createoff{$item} = ' checked="checked" ';
                   3985:             $createon{$item} = ' ';
                   3986:             if (exists($settings->{$item})) {
                   3987:                 if ($settings->{$item}) {
                   3988:                     $createon{$item} = ' checked="checked" ';
                   3989:                     $createoff{$item} = ' ';
                   3990:                 }
                   3991:             }
                   3992:         }
1.210     raeburn  3993:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  3994:             $currhash{$settings->{'xmldc'}} = 1;
                   3995:         }
1.125     raeburn  3996:     } else {
                   3997:         foreach my $item (@types) {
                   3998:             $createoff{$item} = ' checked="checked" ';
                   3999:             $createon{$item} = ' ';
                   4000:         }
                   4001:     }
                   4002:     $$rowtotal += 2;
1.191     raeburn  4003:     my $numinrow = 2;
1.125     raeburn  4004:     my $datatable='<tr class="LC_odd_row">'.
                   4005:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   4006:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4007:                   '<input type="radio" name="autocreate_xml"'.
                   4008:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4009:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  4010:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   4011:                   '</td></tr><tr>'.
                   4012:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   4013:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4014:                   '<input type="radio" name="autocreate_req"'.
                   4015:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4016:                   '<label><input type="radio" name="autocreate_req"'.
                   4017:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  4018:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4019:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  4020:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  4021:     if ($numdc > 1) {
1.247     raeburn  4022:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   4023:                       '</td><td class="LC_left_item">';
1.125     raeburn  4024:     } else {
1.247     raeburn  4025:         $datatable .= &mt('Course creation processed as:').
                   4026:                       '</td><td class="LC_right_item">';
1.125     raeburn  4027:     }
1.247     raeburn  4028:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  4029:     $$rowtotal += $rows;
1.125     raeburn  4030:     return $datatable;
                   4031: }
                   4032: 
1.23      raeburn  4033: sub print_directorysrch {
1.277     raeburn  4034:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4035:     my $datatable;
                   4036:     if ($position eq 'top') {
                   4037:         my $instsrchon = ' ';
                   4038:         my $instsrchoff = ' checked="checked" ';
                   4039:         my ($exacton,$containson,$beginson);
                   4040:         my $instlocalon = ' ';
                   4041:         my $instlocaloff = ' checked="checked" ';
                   4042:         if (ref($settings) eq 'HASH') {
                   4043:             if ($settings->{'available'} eq '1') {
                   4044:                 $instsrchon = $instsrchoff;
                   4045:                 $instsrchoff = ' ';
                   4046:             }
                   4047:             if ($settings->{'localonly'} eq '1') {
                   4048:                 $instlocalon = $instlocaloff;
                   4049:                 $instlocaloff = ' ';
                   4050:             }
                   4051:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   4052:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   4053:                     if ($type eq 'exact') {
                   4054:                         $exacton = ' checked="checked" ';
                   4055:                     } elsif ($type eq 'contains') {
                   4056:                         $containson = ' checked="checked" ';
                   4057:                     } elsif ($type eq 'begins') {
                   4058:                         $beginson = ' checked="checked" ';
                   4059:                     }
                   4060:                 }
                   4061:             } else {
                   4062:                 if ($settings->{'searchtypes'} eq 'exact') {
                   4063:                     $exacton = ' checked="checked" ';
                   4064:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   4065:                     $containson = ' checked="checked" ';
                   4066:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  4067:                     $exacton = ' checked="checked" ';
                   4068:                     $containson = ' checked="checked" ';
                   4069:                 }
                   4070:             }
1.277     raeburn  4071:         }
                   4072:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   4073:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4074: 
                   4075:         my $numinrow = 4;
                   4076:         my $cansrchrow = 0;
                   4077:         $datatable='<tr class="LC_odd_row">'.
                   4078:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   4079:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4080:                    '<input type="radio" name="dirsrch_available"'.
                   4081:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4082:                    '<label><input type="radio" name="dirsrch_available"'.
                   4083:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4084:                    '</tr><tr>'.
                   4085:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   4086:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4087:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   4088:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4089:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   4090:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4091:                    '</tr>';
                   4092:         $$rowtotal += 2;
                   4093:         if (ref($usertypes) eq 'HASH') {
                   4094:             if (keys(%{$usertypes}) > 0) {
                   4095:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  4096:                                              $numinrow,$othertitle,'cansearch',
                   4097:                                              $rowtotal);
1.277     raeburn  4098:                 $cansrchrow = 1;
1.25      raeburn  4099:             }
1.23      raeburn  4100:         }
1.277     raeburn  4101:         if ($cansrchrow) {
                   4102:             $$rowtotal ++;
                   4103:             $datatable .= '<tr>';
                   4104:         } else {
                   4105:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  4106:         }
1.277     raeburn  4107:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   4108:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   4109:         foreach my $title (@{$titleorder}) {
                   4110:             if (defined($searchtitles->{$title})) {
                   4111:                 my $check = ' ';
                   4112:                 if (ref($settings) eq 'HASH') {
                   4113:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   4114:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   4115:                             $check = ' checked="checked" ';
                   4116:                         }
1.39      raeburn  4117:                     }
1.25      raeburn  4118:                 }
1.277     raeburn  4119:                 $datatable .= '<td class="LC_left_item">'.
                   4120:                               '<span class="LC_nobreak"><label>'.
                   4121:                               '<input type="checkbox" name="searchby" '.
                   4122:                               'value="'.$title.'"'.$check.'/>'.
                   4123:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  4124:             }
                   4125:         }
1.277     raeburn  4126:         $datatable .= '</tr></table></td></tr>';
                   4127:         $$rowtotal ++;
                   4128:         if ($cansrchrow) {
                   4129:             $datatable .= '<tr class="LC_odd_row">';
                   4130:         } else {
                   4131:             $datatable .= '<tr>';
                   4132:         }
                   4133:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   4134:                       '<td class="LC_left_item" colspan="2">'.
                   4135:                       '<span class="LC_nobreak"><label>'.
                   4136:                       '<input type="checkbox" name="searchtypes" '.
                   4137:                       $exacton.' value="exact" />'.&mt('Exact match').
                   4138:                       '</label>&nbsp;'.
                   4139:                       '<label><input type="checkbox" name="searchtypes" '.
                   4140:                       $beginson.' value="begins" />'.&mt('Begins with').
                   4141:                       '</label>&nbsp;'.
                   4142:                       '<label><input type="checkbox" name="searchtypes" '.
                   4143:                       $containson.' value="contains" />'.&mt('Contains').
                   4144:                       '</label></span></td></tr>';
                   4145:         $$rowtotal ++;
1.26      raeburn  4146:     } else {
1.277     raeburn  4147:         my $domsrchon = ' checked="checked" ';
                   4148:         my $domsrchoff = ' ';
                   4149:         my $domlocalon = ' ';
                   4150:         my $domlocaloff = ' checked="checked" ';
                   4151:         if (ref($settings) eq 'HASH') {
                   4152:             if ($settings->{'lclocalonly'} eq '1') {
                   4153:                 $domlocalon = $domlocaloff;
                   4154:                 $domlocaloff = ' ';
                   4155:             }
                   4156:             if ($settings->{'lcavailable'} eq '0') {
                   4157:                 $domsrchoff = $domsrchon;
                   4158:                 $domsrchon = ' ';
                   4159:             }
                   4160:         }
                   4161:         $datatable='<tr class="LC_odd_row">'.
                   4162:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   4163:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4164:                       '<input type="radio" name="dirsrch_domavailable"'.
                   4165:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   4166:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   4167:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   4168:                       '</tr><tr>'.
                   4169:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   4170:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4171:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   4172:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   4173:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   4174:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   4175:                       '</tr>';
                   4176:         $$rowtotal += 2;
1.26      raeburn  4177:     }
1.25      raeburn  4178:     return $datatable;
                   4179: }
                   4180: 
1.28      raeburn  4181: sub print_contacts {
1.286     raeburn  4182:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  4183:     my $datatable;
                   4184:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  4185:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340     raeburn  4186:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286     raeburn  4187:     if ($position eq 'top') {
                   4188:         if (ref($settings) eq 'HASH') {
                   4189:             foreach my $item (@contacts) {
                   4190:                 if (exists($settings->{$item})) {
                   4191:                     $to{$item} = $settings->{$item};
                   4192:                 }
                   4193:             }
                   4194:         }
                   4195:     } elsif ($position eq 'middle') {
                   4196:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350     raeburn  4197:                      'updatesmail','idconflictsmail','hostipmail');
1.288     raeburn  4198:         foreach my $type (@mailings) {
                   4199:             $otheremails{$type} = '';
                   4200:         }
1.340     raeburn  4201:     } elsif ($position eq 'lower') {
                   4202:         if (ref($settings) eq 'HASH') {
                   4203:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   4204:                 %lonstatus = %{$settings->{'lonstatus'}};
                   4205:             }
                   4206:         }
1.286     raeburn  4207:     } else {
                   4208:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  4209:         foreach my $type (@mailings) {
                   4210:             $otheremails{$type} = '';
                   4211:         }
1.286     raeburn  4212:         $bccemails{'helpdeskmail'} = '';
                   4213:         $bccemails{'otherdomsmail'} = '';
                   4214:         $includestr{'helpdeskmail'} = '';
                   4215:         $includestr{'otherdomsmail'} = '';
                   4216:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   4217:     }
1.28      raeburn  4218:     if (ref($settings) eq 'HASH') {
1.340     raeburn  4219:         unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4220:             foreach my $type (@mailings) {
                   4221:                 if (exists($settings->{$type})) {
                   4222:                     if (ref($settings->{$type}) eq 'HASH') {
                   4223:                         foreach my $item (@contacts) {
                   4224:                             if ($settings->{$type}{$item}) {
                   4225:                                 $checked{$type}{$item} = ' checked="checked" ';
                   4226:                             }
                   4227:                         }
                   4228:                         $otheremails{$type} = $settings->{$type}{'others'};
                   4229:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4230:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   4231:                             if ($settings->{$type}{'include'} ne '') {
                   4232:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4233:                                 $includestr{$type} = &unescape($includestr{$type});
                   4234:                             }
                   4235:                         }
                   4236:                     }
                   4237:                 } elsif ($type eq 'lonstatusmail') {
                   4238:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   4239:                 }
1.28      raeburn  4240:             }
                   4241:         }
1.286     raeburn  4242:         if ($position eq 'bottom') {
                   4243:             foreach my $type (@mailings) {
                   4244:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   4245:                 if ($settings->{$type}{'include'} ne '') {
                   4246:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   4247:                     $includestr{$type} = &unescape($includestr{$type});
                   4248:                 }
                   4249:             }
                   4250:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   4251:                 if (ref($fields) eq 'ARRAY') {
                   4252:                     foreach my $field (@{$fields}) {
                   4253:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  4254:                     }
1.286     raeburn  4255:                 }
                   4256:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   4257:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   4258:                 } else {
1.289     raeburn  4259:                     $maxsize = '1.0';
1.286     raeburn  4260:                 }
                   4261:             } else {
                   4262:                 if (ref($fields) eq 'ARRAY') {
                   4263:                     foreach my $field (@{$fields}) {
                   4264:                         $currfield{$field} = 'yes';
1.134     raeburn  4265:                     }
1.28      raeburn  4266:                 }
1.286     raeburn  4267:                 $maxsize = '1.0';
1.28      raeburn  4268:             }
                   4269:         }
                   4270:     } else {
1.286     raeburn  4271:         if ($position eq 'top') {
                   4272:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   4273:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   4274:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   4275:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  4276:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4277:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   4278:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   4279:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350     raeburn  4280:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  4281:         } elsif ($position eq 'bottom') {
                   4282:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   4283:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   4284:             if (ref($fields) eq 'ARRAY') {
                   4285:                 foreach my $field (@{$fields}) {
                   4286:                     $currfield{$field} = 'yes';
                   4287:                 }
                   4288:             }
                   4289:             $maxsize = '1.0';
                   4290:         }
1.28      raeburn  4291:     }
                   4292:     my ($titles,$short_titles) = &contact_titles();
                   4293:     my $rownum = 0;
                   4294:     my $css_class;
1.286     raeburn  4295:     if ($position eq 'top') {
                   4296:         foreach my $item (@contacts) {
                   4297:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4298:             $datatable .= '<tr'.$css_class.'>'. 
                   4299:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   4300:                           '</span></td><td class="LC_right_item">'.
                   4301:                           '<input type="text" name="'.$item.'" value="'.
                   4302:                           $to{$item}.'" /></td></tr>';
                   4303:             $rownum ++;
                   4304:         }
1.315     raeburn  4305:     } elsif ($position eq 'bottom') {
                   4306:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4307:         $datatable .= '<tr'.$css_class.'>'.
                   4308:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   4309:                       &mt('(e-mail, subject, and description always shown)').
                   4310:                       '</td><td class="LC_left_item">';
                   4311:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   4312:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   4313:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   4314:             foreach my $field (@{$fields}) {
                   4315:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   4316:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   4317:                     $datatable .= ' '.&mt('(logged-in users)');
                   4318:                 }
                   4319:                 $datatable .='</td><td>';
                   4320:                 my $clickaction;
                   4321:                 if ($field eq 'screenshot') {
                   4322:                     $clickaction = ' onclick="screenshotSize(this);"';
                   4323:                 }
                   4324:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   4325:                     foreach my $option (@{$possoptions->{$field}}) {
                   4326:                         my $checked;
                   4327:                         if ($currfield{$field} eq $option) {
                   4328:                             $checked = ' checked="checked"';
                   4329:                         }
                   4330:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   4331:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   4332:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   4333:                                       '</label></span>'.('&nbsp;'x2);
                   4334:                     }
                   4335:                 }
                   4336:                 if ($field eq 'screenshot') {
                   4337:                     my $display;
                   4338:                     if ($currfield{$field} eq 'no') {
                   4339:                         $display = ' style="display:none"';
                   4340:                     }
1.334     raeburn  4341:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315     raeburn  4342:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   4343:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   4344:                 }
                   4345:                 $datatable .= '</td></tr>';
                   4346:             }
                   4347:             $datatable .= '</table>';
                   4348:         }
                   4349:         $datatable .= '</td></tr>'."\n";
                   4350:         $rownum ++;
                   4351:     }
1.340     raeburn  4352:     unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  4353:         foreach my $type (@mailings) {
                   4354:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4355:             $datatable .= '<tr'.$css_class.'>'.
                   4356:                           '<td><span class="LC_nobreak">'.
                   4357:                           $titles->{$type}.': </span></td>'.
                   4358:                           '<td class="LC_left_item">';
                   4359:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4360:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   4361:             }
                   4362:             $datatable .= '<span class="LC_nobreak">';
                   4363:             foreach my $item (@contacts) {
                   4364:                 $datatable .= '<label>'.
                   4365:                               '<input type="checkbox" name="'.$type.'"'.
                   4366:                               $checked{$type}{$item}.
                   4367:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   4368:                               '</label>&nbsp;';
                   4369:             }
                   4370:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4371:                           '<input type="text" name="'.$type.'_others" '.
                   4372:                           'value="'.$otheremails{$type}.'"  />';
                   4373:             my %locchecked;
                   4374:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4375:                 foreach my $loc ('s','b') {
                   4376:                     if ($includeloc{$type} eq $loc) {
                   4377:                         $locchecked{$loc} = ' checked="checked"';
                   4378:                         last;
                   4379:                     }
                   4380:                 }
                   4381:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4382:                               '<input type="text" name="'.$type.'_bcc" '.
                   4383:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   4384:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4385:                               &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4386:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286     raeburn  4387:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4388:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4389:                               ('&nbsp;'x2).
                   4390:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4391:                               '</span></fieldset>';
                   4392:             }
                   4393:             $datatable .= '</td></tr>'."\n";
                   4394:             $rownum ++;
                   4395:         }
1.28      raeburn  4396:     }
1.286     raeburn  4397:     if ($position eq 'middle') {
                   4398:         my %choices;
1.340     raeburn  4399:         my $corelink = &core_link_msu();
                   4400:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286     raeburn  4401:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340     raeburn  4402:                                         $corelink);
                   4403:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   4404:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286     raeburn  4405:         my %defaultchecked = ('reporterrors'  => 'on',
1.340     raeburn  4406:                               'reportupdates' => 'on',
                   4407:                               'reportstatus'  => 'on');
1.286     raeburn  4408:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4409:                                                    \%choices,$rownum);
                   4410:         $datatable .= $reports;
1.340     raeburn  4411:     } elsif ($position eq 'lower') {
1.378     raeburn  4412:         my (%current,%excluded,%weights);
1.340     raeburn  4413:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   4414:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378     raeburn  4415:             $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340     raeburn  4416:         } else {
1.378     raeburn  4417:             $current{'errorthreshold'} = $defaults->{'threshold'};
1.340     raeburn  4418:         }
                   4419:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378     raeburn  4420:             $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340     raeburn  4421:         } else {
1.378     raeburn  4422:             $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340     raeburn  4423:         }
                   4424:         if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341     raeburn  4425:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4426:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   4427:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   4428:                 } else {
                   4429:                     $weights{$type} = $defaults->{$type};
                   4430:                 }
                   4431:             }
                   4432:         } else {
1.341     raeburn  4433:             foreach my $type ('E','W','N','U') {
1.340     raeburn  4434:                 $weights{$type} = $defaults->{$type};
                   4435:             }
                   4436:         }
                   4437:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   4438:             if (@{$lonstatus{'excluded'}} > 0) {
                   4439:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   4440:             }
                   4441:         }
1.378     raeburn  4442:         foreach my $item ('errorthreshold','errorsysmail') { 
                   4443:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4444:             $datatable .= '<tr'.$css_class.'>'.
                   4445:                           '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4446:                           $titles->{$item}.
                   4447:                           '</span></td><td class="LC_left_item">'.
                   4448:                           '<input type="text" name="'.$item.'" value="'.
                   4449:                           $current{$item}.'" size="5" /></td></tr>';
                   4450:             $rownum ++;
                   4451:         }
1.340     raeburn  4452:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4453:         $datatable .= '<tr'.$css_class.'>'.
                   4454:                       '<td class="LC_left_item">'.
                   4455:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   4456:                       '</span></td><td class="LC_left_item"><table><tr>';
1.341     raeburn  4457:         foreach my $type ('E','W','N','U') {
1.340     raeburn  4458:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   4459:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   4460:                           $weights{$type}.'" size="5" /></td>';
                   4461:         }
                   4462:         $datatable .= '</tr></table></tr>';
                   4463:         $rownum ++;
                   4464:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4465:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   4466:                       $titles->{'errorexcluded'}.'</td>'.
                   4467:                       '<td class="LC_left_item"><table>';
                   4468:         my $numinrow = 4;
                   4469:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   4470:         for (my $i=0; $i<@ids; $i++) {
                   4471:             my $rem = $i%($numinrow);
                   4472:             if ($rem == 0) {
                   4473:                 if ($i > 0) {
                   4474:                     $datatable .= '</tr>';
                   4475:                 }
                   4476:                 $datatable .= '<tr>';
                   4477:             }
                   4478:             my $check;
                   4479:             if ($excluded{$ids[$i]}) {
                   4480:                 $check = ' checked="checked" ';
                   4481:             }
                   4482:             $datatable .= '<td class="LC_left_item">'.
                   4483:                           '<span class="LC_nobreak"><label>'.
                   4484:                           '<input type="checkbox" name="errorexcluded" '.
                   4485:                           'value="'.$ids[$i].'"'.$check.' />'.
                   4486:                           $ids[$i].'</label></span></td>';
                   4487:         }
                   4488:         my $colsleft = $numinrow - @ids%($numinrow);
                   4489:         if ($colsleft > 1 ) {
                   4490:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4491:                           '&nbsp;</td>';
                   4492:         } elsif ($colsleft == 1) {
                   4493:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4494:         }
                   4495:         $datatable .= '</tr></table></td></tr>';
                   4496:         $rownum ++;
1.286     raeburn  4497:     } elsif ($position eq 'bottom') {
1.315     raeburn  4498:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4499:         my (@posstypes,%usertypeshash);
                   4500:         if (ref($types) eq 'ARRAY') {
                   4501:             @posstypes = @{$types};
                   4502:         }
                   4503:         if (@posstypes) {
                   4504:             if (ref($usertypes) eq 'HASH') {
                   4505:                 %usertypeshash = %{$usertypes};
                   4506:             }
                   4507:             my @overridden;
                   4508:             my $numinrow = 4;
                   4509:             if (ref($settings) eq 'HASH') {
                   4510:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   4511:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   4512:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   4513:                             push(@overridden,$key);
                   4514:                             foreach my $item (@contacts) {
                   4515:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   4516:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   4517:                                 }
                   4518:                             }
                   4519:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   4520:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   4521:                             $includeloc{'override_'.$key} = '';
                   4522:                             $includestr{'override_'.$key} = '';
                   4523:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   4524:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
                   4525:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   4526:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   4527:                             }
1.286     raeburn  4528:                         }
                   4529:                     }
                   4530:                 }
1.315     raeburn  4531:             }
                   4532:             my $customclass = 'LC_helpdesk_override';
                   4533:             my $optionsprefix = 'LC_options_helpdesk_';
                   4534: 
                   4535:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   4536:  
                   4537:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   4538:                                          $numinrow,$othertitle,'overrides',
                   4539:                                          \$rownum,$onclicktypes,$customclass);
                   4540:             $rownum ++;
                   4541:             $usertypeshash{'default'} = $othertitle;
                   4542:             foreach my $status (@posstypes) {
                   4543:                 my $css_class;
                   4544:                 if ($rownum%2) {
                   4545:                     $css_class = 'LC_odd_row ';
                   4546:                 }
                   4547:                 $css_class .= $customclass;
                   4548:                 my $rowid = $optionsprefix.$status;
                   4549:                 my $hidden = 1;
                   4550:                 my $currstyle = 'display:none';
                   4551:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   4552:                     $currstyle = 'display:table-row';
                   4553:                     $hidden = 0;
                   4554:                 }
                   4555:                 my $key = 'override_'.$status;
                   4556:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   4557:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   4558:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   4559:                                                   \@contacts,$short_titles);
                   4560:                 unless ($hidden) {
                   4561:                     $rownum ++;
1.286     raeburn  4562:                 }
                   4563:             }
1.134     raeburn  4564:         }
1.28      raeburn  4565:     }
1.30      raeburn  4566:     $$rowtotal += $rownum;
1.28      raeburn  4567:     return $datatable;
                   4568: }
                   4569: 
1.340     raeburn  4570: sub core_link_msu {
                   4571:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   4572:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   4573: }
                   4574: 
1.315     raeburn  4575: sub overridden_helpdesk {
                   4576:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   4577:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   4578:     my $class = 'LC_left_item';
                   4579:     if ($css_class) {
                   4580:         $css_class = ' class="'.$css_class.'"';
                   4581:     }
                   4582:     if ($rowid) {
                   4583:         $rowid = ' id="'.$rowid.'"';
                   4584:     }
                   4585:     if ($rowstyle) {
                   4586:         $rowstyle = ' style="'.$rowstyle.'"';
                   4587:     }
                   4588:     my ($output,$description);
                   4589:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   4590:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   4591:               "<td>$description</td>\n".
                   4592:               '<td class="'.$class.'" colspan="2">'.
                   4593:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   4594:               '<span class="LC_nobreak">';
                   4595:     if (ref($contacts) eq 'ARRAY') {
                   4596:         foreach my $item (@{$contacts}) {
                   4597:             my $check;
                   4598:             if (ref($checked) eq 'HASH') {
                   4599:                $check = $checked->{$item};
                   4600:             }
                   4601:             my $title;
                   4602:             if (ref($short_titles) eq 'HASH') {
                   4603:                 $title = $short_titles->{$item}; 
                   4604:             }
                   4605:             $output .= '<label>'.
                   4606:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   4607:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   4608:         }
                   4609:     }
                   4610:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4611:                '<input type="text" name="override_'.$type.'_others" '.
                   4612:                'value="'.$otheremails.'"  />';
                   4613:     my %locchecked;
                   4614:     foreach my $loc ('s','b') {
                   4615:         if ($includeloc eq $loc) {
                   4616:             $locchecked{$loc} = ' checked="checked"';
                   4617:             last;
                   4618:         }
                   4619:     }
                   4620:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4621:                '<input type="text" name="override_'.$type.'_bcc" '.
                   4622:                'value="'.$bccemails.'"  /></fieldset>'.
                   4623:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4624:                &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  4625:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315     raeburn  4626:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4627:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4628:                ('&nbsp;'x2).
                   4629:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4630:                '</span></fieldset>'.
                   4631:                '</td></tr>'."\n";
                   4632:     return $output;
                   4633: }
                   4634: 
1.286     raeburn  4635: sub contacts_javascript {
                   4636:     return <<"ENDSCRIPT";
                   4637: 
                   4638: <script type="text/javascript">
                   4639: // <![CDATA[
                   4640: 
                   4641: function screenshotSize(field) {
                   4642:     if (document.getElementById('help_screenshotsize')) {
                   4643:         if (field.value == 'no') {
1.289     raeburn  4644:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  4645:         } else {
                   4646:             document.getElementById('help_screenshotsize').style.display="";
                   4647:         }
                   4648:     }
                   4649:     return;
                   4650: }
                   4651: 
1.315     raeburn  4652: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   4653:     if (form.elements[checkbox].length != undefined) {
                   4654:         var count = 0;
                   4655:         if (docount) {
                   4656:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   4657:                 if (form.elements[checkbox][i].checked) {
                   4658:                     count ++;
                   4659:                 }
                   4660:             }
                   4661:         }
                   4662:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   4663:             var type = form.elements[checkbox][i].value;
                   4664:             if (document.getElementById(prefix+type)) {
                   4665:                 if (form.elements[checkbox][i].checked) {
                   4666:                     document.getElementById(prefix+type).style.display = 'table-row';
                   4667:                     if (count % 2 == 1) {
                   4668:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   4669:                     } else {
                   4670:                         document.getElementById(prefix+type).className = target;
                   4671:                     }
                   4672:                     count ++;
                   4673:                 } else {
                   4674:                     document.getElementById(prefix+type).style.display = 'none';
                   4675:                 }
                   4676:             }
                   4677:         }
                   4678:     }
                   4679:     return;
                   4680: }
                   4681: 
                   4682: 
1.286     raeburn  4683: // ]]>
                   4684: </script>
                   4685: 
                   4686: ENDSCRIPT
                   4687: }
                   4688: 
1.118     jms      4689: sub print_helpsettings {
1.282     raeburn  4690:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4691:     my $confname = $dom.'-domainconfig';
1.285     raeburn  4692:     my $formname = 'display';
1.168     raeburn  4693:     my ($datatable,$itemcount);
1.282     raeburn  4694:     if ($position eq 'top') {
                   4695:         $itemcount = 1;
                   4696:         my (%choices,%defaultchecked,@toggles);
                   4697:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   4698:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   4699:                                      &mt('LON-CAPA bug tracker'),600,500));
                   4700:         %defaultchecked = ('submitbugs' => 'on');
                   4701:         @toggles = ('submitbugs');
                   4702:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4703:                                                      \%choices,$itemcount);
                   4704:         $$rowtotal ++;
                   4705:     } else {
                   4706:         my $css_class;
                   4707:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  4708:         my (%customroles,%ordered,%current);
1.301     raeburn  4709:         if (ref($settings) eq 'HASH') {
                   4710:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   4711:                 %current = %{$settings->{'adhoc'}};
                   4712:             }
1.285     raeburn  4713:         }
                   4714:         my $count = 0;
                   4715:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  4716:             if ($key=~/^rolesdef\_(\w+)$/) {
                   4717:                 my $rolename = $1;
1.285     raeburn  4718:                 my (%privs,$order);
1.282     raeburn  4719:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   4720:                 $customroles{$rolename} = \%privs;
1.285     raeburn  4721:                 if (ref($current{$rolename}) eq 'HASH') {
                   4722:                     $order = $current{$rolename}{'order'};
                   4723:                 }
                   4724:                 if ($order eq '') {
                   4725:                     $order = $count;
                   4726:                 }
                   4727:                 $ordered{$order} = $rolename;
                   4728:                 $count++;
                   4729:             }
                   4730:         }
                   4731:         my $maxnum = scalar(keys(%ordered));
                   4732:         my @roles_by_num = ();
                   4733:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   4734:             push(@roles_by_num,$item);
                   4735:         }
                   4736:         my $context = 'domprefs';
                   4737:         my $crstype = 'Course';
                   4738:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  4739:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  4740:         my ($numstatustypes,@jsarray);
                   4741:         if (ref($types) eq 'ARRAY') {
                   4742:             if (@{$types} > 0) {
                   4743:                 $numstatustypes = scalar(@{$types});
                   4744:                 push(@accesstypes,'status');
                   4745:                 @jsarray = ('bystatus');
1.282     raeburn  4746:             }
                   4747:         }
1.290     raeburn  4748:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  4749:         if (keys(%domhelpdesk)) {
                   4750:             push(@accesstypes,('inc','exc'));
                   4751:             push(@jsarray,('notinc','notexc'));
                   4752:         }
                   4753:         my $hiddenstr = join("','",@jsarray);
1.282     raeburn  4754:         my $context = 'domprefs';
                   4755:         my $crstype = 'Course';
1.285     raeburn  4756:         my $prefix = 'helproles_';
                   4757:         my $add_class = 'LC_hidden';
                   4758:         foreach my $num (@roles_by_num) {
                   4759:             my $role = $ordered{$num};
                   4760:             my ($desc,$access,@statuses);
                   4761:             if (ref($current{$role}) eq 'HASH') {
                   4762:                 $desc = $current{$role}{'desc'};
                   4763:                 $access = $current{$role}{'access'};
                   4764:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   4765:                     @statuses = @{$current{$role}{'insttypes'}};
                   4766:                 }
                   4767:             }
                   4768:             if ($desc eq '') {
                   4769:                 $desc = $role;
                   4770:             }
                   4771:             my $identifier = 'custhelp'.$num;
1.282     raeburn  4772:             my %full=();
                   4773:             my %levels= (
                   4774:                          course => {},
                   4775:                          domain => {},
                   4776:                          system => {},
                   4777:                         );
                   4778:             my %levelscurrent=(
                   4779:                                course => {},
                   4780:                                domain => {},
                   4781:                                system => {},
                   4782:                               );
                   4783:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   4784:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   4785:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  4786:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  4787:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  4788:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   4789:             for (my $k=0; $k<=$maxnum; $k++) {
                   4790:                 my $vpos = $k+1;
                   4791:                 my $selstr;
                   4792:                 if ($k == $num) {
                   4793:                     $selstr = ' selected="selected" ';
                   4794:                 }
                   4795:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4796:             }
                   4797:             $datatable .= '</select>'.('&nbsp;'x2).
                   4798:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   4799:                           '</td>'.
                   4800:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4801:                           &mt('Name shown to users:').
                   4802:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   4803:                           '</fieldset>'.
                   4804:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   4805:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   4806:                           '<fieldset>'.
                   4807:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  4808:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  4809:                                                                    \%levelscurrent,$identifier,
                   4810:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   4811:                           '</fieldset></td>';
1.282     raeburn  4812:             $itemcount ++;
                   4813:         }
                   4814:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4815:         my $newcust = 'custhelp'.$count;
                   4816:         my (%privs,%levelscurrent);
                   4817:         my %full=();
                   4818:         my %levels= (
                   4819:                      course => {},
                   4820:                      domain => {},
                   4821:                      system => {},
                   4822:                     );
                   4823:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   4824:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  4825:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  4826:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  4827:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   4828:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   4829:         for (my $k=0; $k<$maxnum+1; $k++) {
                   4830:             my $vpos = $k+1;
                   4831:             my $selstr;
                   4832:             if ($k == $maxnum) {
                   4833:                 $selstr = ' selected="selected" ';
                   4834:             }
                   4835:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4836:         }
                   4837:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  4838:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   4839:                       '</label></span></td>'.
1.285     raeburn  4840:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4841:                       '<span class="LC_nobreak">'.
                   4842:                       &mt('Internal name:').
                   4843:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   4844:                       '</span>'.('&nbsp;'x4).
                   4845:                       '<span class="LC_nobreak">'.
                   4846:                       &mt('Name shown to users:').
                   4847:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   4848:                       '</span></fieldset>'.
                   4849:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   4850:                                              $usertypes,$types,\%domhelpdesk).
                   4851:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  4852:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   4853:                                                                 \@templateroles,$newcust).
                   4854:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   4855:                                                                \%levelscurrent,$newcust).
1.334     raeburn  4856:                       '</fieldset>'.
                   4857:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   4858:                       '</td></tr>';
1.282     raeburn  4859:         $count ++;
                   4860:         $$rowtotal += $count;
                   4861:     }
1.166     raeburn  4862:     return $datatable;
1.121     raeburn  4863: }
                   4864: 
1.285     raeburn  4865: sub adhocbutton {
                   4866:     my ($prefix,$num,$field,$visibility) = @_;
                   4867:     my %lt = &Apache::lonlocal::texthash(
                   4868:                                           show => 'Show details',
                   4869:                                           hide => 'Hide details',
                   4870:                                         );
                   4871:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   4872:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   4873:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   4874:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   4875: }
                   4876: 
                   4877: sub helpsettings_javascript {
                   4878:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   4879:     return unless(ref($roles_by_num) eq 'ARRAY');
                   4880:     my %html_js_lt = &Apache::lonlocal::texthash(
                   4881:                                           show => 'Show details',
                   4882:                                           hide => 'Hide details',
                   4883:                                         );
                   4884:     &html_escape(\%html_js_lt);
                   4885:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   4886:     return <<"ENDSCRIPT";
                   4887: <script type="text/javascript">
                   4888: // <![CDATA[
                   4889: 
                   4890: function reorderHelpRoles(form,item) {
                   4891:     var changedVal;
                   4892: $jstext
                   4893:     var newpos = 'helproles_${total}_pos';
                   4894:     var maxh = 1 + $total;
                   4895:     var current = new Array();
                   4896:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4897:     if (item == newpos) {
                   4898:         changedVal = newitemVal;
                   4899:     } else {
                   4900:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4901:         current[newitemVal] = newpos;
                   4902:     }
                   4903:     for (var i=0; i<helproles.length; i++) {
                   4904:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   4905:         if (elementName != item) {
                   4906:             if (form.elements[elementName]) {
                   4907:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4908:                 current[currVal] = elementName;
                   4909:             }
                   4910:         }
                   4911:     }
                   4912:     var oldVal;
                   4913:     for (var j=0; j<maxh; j++) {
                   4914:         if (current[j] == undefined) {
                   4915:             oldVal = j;
                   4916:         }
                   4917:     }
                   4918:     if (oldVal < changedVal) {
                   4919:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4920:            var elementName = current[k];
                   4921:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4922:         }
                   4923:     } else {
                   4924:         for (var k=changedVal; k<oldVal; k++) {
                   4925:             var elementName = current[k];
                   4926:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4927:         }
                   4928:     }
                   4929:     return;
                   4930: }
                   4931: 
                   4932: function helpdeskAccess(num) {
                   4933:     var curraccess = null;
                   4934:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   4935:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   4936:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   4937:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   4938:             }
                   4939:         }
                   4940:     }
                   4941:     var shown = Array();
                   4942:     var hidden = Array();
                   4943:     if (curraccess == 'none') {
                   4944:         hidden = Array('$hiddenstr');
                   4945:     } else {
                   4946:         if (curraccess == 'status') {
                   4947:             shown = Array('bystatus');
                   4948:             hidden = Array('notinc','notexc');
                   4949:         } else {
                   4950:             if (curraccess == 'exc') {
                   4951:                 shown = Array('notexc');
                   4952:                 hidden = Array('notinc','bystatus');
                   4953:             }
                   4954:             if (curraccess == 'inc') {
                   4955:                 shown = Array('notinc');
                   4956:                 hidden = Array('notexc','bystatus');
                   4957:             }
1.293     raeburn  4958:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  4959:                 hidden = Array('notinc','notexc','bystatus');
                   4960:             }
                   4961:         }
                   4962:     }
                   4963:     if (hidden.length > 0) {
                   4964:         for (var i=0; i<hidden.length; i++) {
                   4965:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   4966:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   4967:             }
                   4968:         }
                   4969:     }
                   4970:     if (shown.length > 0) {
                   4971:         for (var i=0; i<shown.length; i++) {
                   4972:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   4973:                 if (shown[i] == 'privs') {
                   4974:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   4975:                 } else {
                   4976:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   4977:                 }
                   4978:             }
                   4979:         }
                   4980:     }
                   4981:     return;
                   4982: }
                   4983: 
                   4984: function toggleHelpdeskItem(num,field) {
                   4985:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   4986:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  4987:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  4988:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   4989:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4990:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   4991:             }
                   4992:         } else {
                   4993:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   4994:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4995:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   4996:             }
                   4997:         }
                   4998:     }
                   4999:     return;
                   5000: }
                   5001: 
                   5002: // ]]>
                   5003: </script>
                   5004: 
                   5005: ENDSCRIPT
                   5006: }
                   5007: 
                   5008: sub helpdeskroles_access {
                   5009:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   5010:         $usertypes,$types,$domhelpdesk) = @_;
                   5011:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   5012:     my %lt = &Apache::lonlocal::texthash(
                   5013:                     'rou'    => 'Role usage',
                   5014:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  5015:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   5016:                     'dh'     => 'All with domain helpdesk role',
                   5017:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  5018:                     'none'   => 'None',
                   5019:                     'status' => 'Determined based on institutional status',
                   5020:                     'inc'    => 'Include all, but exclude specific personnel',
                   5021:                     'exc'    => 'Exclude all, but include specific personnel',
                   5022:                   );
                   5023:     my %usecheck = (
                   5024:                      all => ' checked="checked"',
                   5025:                    );
                   5026:     my %displaydiv = (
                   5027:                       status => 'none',
                   5028:                       inc    => 'none',
                   5029:                       exc    => 'none',
                   5030:                       priv   => 'block',
                   5031:                      );
                   5032:     my $output;
                   5033:     if (ref($current) eq 'HASH') {
                   5034:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   5035:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   5036:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   5037:                 delete($usecheck{'all'});
                   5038:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   5039:                     my $access = $1;
                   5040:                     $displaydiv{$access} = 'inline';
                   5041:                 } elsif ($current->{access} eq 'none') {
                   5042:                     $displaydiv{'priv'} = 'none';
                   5043:                 }
                   5044:             }
                   5045:         }
                   5046:     }
                   5047:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   5048:               '<p>'.$lt{'whi'}.'</p>';
                   5049:     foreach my $access (@{$accesstypes}) {
                   5050:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   5051:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   5052:                    $lt{$access}.'</label>';
                   5053:         if ($access eq 'status') {
                   5054:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   5055:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   5056:                                                                  $othertitle,$usertypes,$types).
                   5057:                        '</div>';
                   5058:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   5059:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   5060:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5061:                        '</div>';
                   5062:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   5063:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   5064:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   5065:                        '</div>';
                   5066:         }
                   5067:         $output .= '</p>';
                   5068:     }
                   5069:     $output .= '</fieldset>';
                   5070:     return $output;
                   5071: }
                   5072: 
1.121     raeburn  5073: sub radiobutton_prefs {
1.192     raeburn  5074:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385     raeburn  5075:         $additional,$align,$firstval) = @_;
1.121     raeburn  5076:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   5077:                    (ref($choices) eq 'HASH'));
                   5078: 
1.170     raeburn  5079:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  5080: 
                   5081:     foreach my $item (@{$toggles}) {
                   5082:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      5083:             $checkedon{$item} = ' checked="checked" ';
                   5084:             $checkedoff{$item} = ' ';
1.121     raeburn  5085:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      5086:             $checkedoff{$item} = ' checked="checked" ';
                   5087:             $checkedon{$item} = ' ';
                   5088:         }
                   5089:     }
                   5090:     if (ref($settings) eq 'HASH') {
1.121     raeburn  5091:         foreach my $item (@{$toggles}) {
1.118     jms      5092:             if ($settings->{$item} eq '1') {
                   5093:                 $checkedon{$item} =  ' checked="checked" ';
                   5094:                 $checkedoff{$item} = ' ';
                   5095:             } elsif ($settings->{$item} eq '0') {
                   5096:                 $checkedoff{$item} =  ' checked="checked" ';
                   5097:                 $checkedon{$item} = ' ';
                   5098:             }
                   5099:         }
1.121     raeburn  5100:     }
1.192     raeburn  5101:     if ($onclick) {
                   5102:         $onclick = ' onclick="'.$onclick.'"';
                   5103:     }
1.121     raeburn  5104:     foreach my $item (@{$toggles}) {
1.118     jms      5105:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  5106:         $datatable .=
1.306     raeburn  5107:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  5108:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  5109:             '</span></td>';
                   5110:         if ($align eq 'left') {
                   5111:             $datatable .= '<td class="LC_left_item">';
                   5112:         } else {
                   5113:             $datatable .= '<td class="LC_right_item">';
                   5114:         }
1.385     raeburn  5115:         $datatable .= '<span class="LC_nobreak">';
                   5116:         if ($firstval eq 'no') {
                   5117:             $datatable .=
                   5118:                 '<label><input type="radio" name="'.
                   5119:                 $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
                   5120:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5121:                 $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
                   5122:         } else {
                   5123:             $datatable .=
                   5124:                 '<label><input type="radio" name="'.
                   5125:                 $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
                   5126:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   5127:                 $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
                   5128:         }
                   5129:         $datatable .= '</span>'.$additional.'</td></tr>';
1.118     jms      5130:         $itemcount ++;
1.121     raeburn  5131:     }
                   5132:     return ($datatable,$itemcount);
                   5133: }
                   5134: 
1.267     raeburn  5135: sub print_ltitools {
                   5136:     my ($dom,$settings,$rowtotal) = @_;
                   5137:     my $rownum = 0;
                   5138:     my $css_class;
                   5139:     my $itemcount = 1;
                   5140:     my $maxnum = 0;
                   5141:     my %ordered;
                   5142:     if (ref($settings) eq 'HASH') {
                   5143:         foreach my $item (keys(%{$settings})) {
                   5144:             if (ref($settings->{$item}) eq 'HASH') {
                   5145:                 my $num = $settings->{$item}{'order'};
                   5146:                 $ordered{$num} = $item;
                   5147:             }
                   5148:         }
                   5149:     }
                   5150:     my $confname = $dom.'-domainconfig';
                   5151:     my $switchserver = &check_switchserver($dom,$confname);
                   5152:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  5153:     my $datatable;
1.267     raeburn  5154:     my %lt = &ltitools_names();
                   5155:     my @courseroles = ('cc','in','ta','ep','st');
                   5156:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324     raeburn  5157:     my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267     raeburn  5158:     if (keys(%ordered)) {
                   5159:         my @items = sort { $a <=> $b } keys(%ordered);
                   5160:         for (my $i=0; $i<@items; $i++) {
                   5161:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5162:             my $item = $ordered{$items[$i]};
1.323     raeburn  5163:             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267     raeburn  5164:             if (ref($settings->{$item}) eq 'HASH') {
                   5165:                 $title = $settings->{$item}->{'title'};
                   5166:                 $url = $settings->{$item}->{'url'};
                   5167:                 $key = $settings->{$item}->{'key'};
                   5168:                 $secret = $settings->{$item}->{'secret'};
1.322     raeburn  5169:                 $lifetime = $settings->{$item}->{'lifetime'};
1.267     raeburn  5170:                 my $image = $settings->{$item}->{'image'};
                   5171:                 if ($image ne '') {
                   5172:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   5173:                 }
1.323     raeburn  5174:                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   5175:                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   5176:                 } else {
                   5177:                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   5178:                 }
1.267     raeburn  5179:             }
1.319     raeburn  5180:             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267     raeburn  5181:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5182:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   5183:             for (my $k=0; $k<=$maxnum; $k++) {
                   5184:                 my $vpos = $k+1;
                   5185:                 my $selstr;
                   5186:                 if ($k == $i) {
                   5187:                     $selstr = ' selected="selected" ';
                   5188:                 }
                   5189:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5190:             }
                   5191:             $datatable .= '</select>'.('&nbsp;'x2).
                   5192:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   5193:                 &mt('Delete?').'</label></span></td>'.
                   5194:                 '<td colspan="2">'.
                   5195:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5196:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267     raeburn  5197:                 ('&nbsp;'x2).
                   5198:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   5199:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   5200:                 ('&nbsp;'x2).
                   5201:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   5202:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5203:                 ('&nbsp;'x2).
                   5204:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   5205:                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   5206:                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267     raeburn  5207:                 '<br /><br />'.
1.323     raeburn  5208:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267     raeburn  5209:                 ' value="'.$url.'" /></span>'.
                   5210:                 ('&nbsp;'x2).
1.319     raeburn  5211:                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267     raeburn  5212:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   5213:                 ('&nbsp;'x2).
1.322     raeburn  5214:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   5215:                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   5216:                 ('&nbsp;'x2).
1.267     raeburn  5217:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   5218:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   5219:                 '<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>'.
                   5220:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   5221:                 '</fieldset>'.
                   5222:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5223:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   5224:             my %currdisp;
                   5225:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   5226:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   5227:                     $currdisp{'window'} = ' checked="checked"';
1.298     raeburn  5228:                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   5229:                     $currdisp{'tab'} = ' checked="checked"';
1.267     raeburn  5230:                 } else {
                   5231:                     $currdisp{'iframe'} = ' checked="checked"';
                   5232:                 }
                   5233:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   5234:                     $currdisp{'width'} = $1;
                   5235:                 }
                   5236:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   5237:                      $currdisp{'height'} = $1;
                   5238:                 }
1.296     raeburn  5239:                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   5240:                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267     raeburn  5241:             } else {
                   5242:                 $currdisp{'iframe'} = ' checked="checked"';
                   5243:             }
1.298     raeburn  5244:             foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5245:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   5246:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5247:             }
                   5248:             $datatable .= ('&nbsp;'x4);
                   5249:             foreach my $dimen ('width','height') {
                   5250:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5251:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   5252:                               ('&nbsp;'x2);
                   5253:             }
1.334     raeburn  5254:             $datatable .= '</span><br />'.
1.296     raeburn  5255:                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5256:                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296     raeburn  5257:                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   5258:                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   5259:                           '</textarea></div><div style=""></div><br />';
1.319     raeburn  5260:             my %units = (
                   5261:                           'passback' => 'days',
                   5262:                           'roster'   => 'seconds',
                   5263:                         );
1.267     raeburn  5264:             foreach my $extra ('passback','roster') {
1.319     raeburn  5265:                 my $validsty = 'none';
                   5266:                 my $currvalid;
1.267     raeburn  5267:                 my $checkedon = '';
                   5268:                 my $checkedoff = ' checked="checked"';
                   5269:                 if ($settings->{$item}->{$extra}) {
                   5270:                     $checkedon = $checkedoff;
                   5271:                     $checkedoff = '';
1.319     raeburn  5272:                     $validsty = 'inline-block';
                   5273:                     if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
                   5274:                         $currvalid = $settings->{$item}->{$extra.'valid'};
                   5275:                     }
                   5276:                 }
                   5277:                 my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
                   5278:                 $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5279:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
                   5280:                               &mt('No').'</label>'.('&nbsp;'x2).
                   5281:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
                   5282:                               &mt('Yes').'</label></span></div>'.
                   5283:                               '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
                   5284:                               '<span class="LC_nobreak">'.
                   5285:                               &mt("at least [_1] $units{$extra} after launch",
                   5286:                                   '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
                   5287:                               '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5288:             }
1.319     raeburn  5289:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
1.267     raeburn  5290:             if ($imgsrc) {
                   5291:                 $datatable .= $imgsrc.
                   5292:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   5293:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   5294:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   5295:             } else {
                   5296:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5297:             }
                   5298:             if ($switchserver) {
                   5299:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5300:             } else {
                   5301:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   5302:             }
                   5303:             $datatable .= '</span></fieldset>';
1.324     raeburn  5304:             my (%checkedfields,%rolemaps,$userincdom);
1.267     raeburn  5305:             if (ref($settings->{$item}) eq 'HASH') {
                   5306:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   5307:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   5308:                 }
1.324     raeburn  5309:                 $userincdom = $settings->{$item}->{'incdom'};
1.267     raeburn  5310:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   5311:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   5312:                     $checkedfields{'roles'} = 1;
                   5313:                 }
                   5314:             }
                   5315:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5316:                           '<span class="LC_nobreak">';
1.324     raeburn  5317:             my $userfieldstyle = 'display:none;';
                   5318:             my $seluserdom = '';
                   5319:             my $unseluserdom = ' selected="selected"';
1.267     raeburn  5320:             foreach my $field (@fields) {
1.324     raeburn  5321:                 my ($checked,$onclick,$id,$spacer);
1.267     raeburn  5322:                 if ($checkedfields{$field}) {
                   5323:                     $checked = ' checked="checked"';
                   5324:                 }
1.324     raeburn  5325:                 if ($field eq 'user') {
                   5326:                     $id = ' id="ltitools_user_field_'.$i.'"';
                   5327:                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   5328:                     if ($checked) {
                   5329:                         $userfieldstyle = 'display:inline-block';
                   5330:                         if ($userincdom) {
                   5331:                             $seluserdom = $unseluserdom;
                   5332:                             $unseluserdom = '';
                   5333:                         }
                   5334:                     }
                   5335:                 } else {
                   5336:                     $spacer = ('&nbsp;' x2);
                   5337:                 }
1.267     raeburn  5338:                 $datatable .= '<label>'.
1.324     raeburn  5339:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   5340:                               $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5341:             }
1.324     raeburn  5342:             $datatable .= '</span>';
                   5343:             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   5344:                           '<span class="LC_nobreak"> : '.
                   5345:                           '<select name="ltitools_userincdom_'.$i.'">'.
                   5346:                           '<option value="">'.&mt('Select').'</option>'.
                   5347:                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   5348:                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   5349:                           '</select></span></div>';
                   5350:             $datatable .= '</fieldset>'.
1.267     raeburn  5351:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   5352:             foreach my $role (@courseroles) {
                   5353:                 my ($selected,$selectnone);
                   5354:                 if (!$rolemaps{$role}) {
                   5355:                     $selectnone = ' selected="selected"';
                   5356:                 }
1.306     raeburn  5357:                 $datatable .= '<td style="text-align: center">'. 
1.267     raeburn  5358:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5359:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   5360:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5361:                 foreach my $ltirole (@ltiroles) {
                   5362:                     unless ($selectnone) {
                   5363:                         if ($rolemaps{$role} eq $ltirole) {
                   5364:                             $selected = ' selected="selected"';
                   5365:                         } else {
                   5366:                             $selected = '';
                   5367:                         }
                   5368:                     }
                   5369:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   5370:                 }
                   5371:                 $datatable .= '</select></td>';
                   5372:             }
1.273     raeburn  5373:             $datatable .= '</tr></table></fieldset>';
                   5374:             my %courseconfig;
                   5375:             if (ref($settings->{$item}) eq 'HASH') {
                   5376:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   5377:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   5378:                 }
                   5379:             }
                   5380:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5381:             foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  5382:                 my $checked;
                   5383:                 if ($courseconfig{$item}) {
                   5384:                     $checked = ' checked="checked"';
                   5385:                 }
                   5386:                 $datatable .= '<label>'.
                   5387:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372     raeburn  5388:                        $lt{'crs'.$item}.'</label>&nbsp; '."\n";
1.273     raeburn  5389:             }
                   5390:             $datatable .= '</span></fieldset>'.
1.267     raeburn  5391:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5392:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   5393:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   5394:                 my %custom = %{$settings->{$item}->{'custom'}};
                   5395:                 if (keys(%custom) > 0) {
                   5396:                     foreach my $key (sort(keys(%custom))) {
                   5397:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5398:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   5399:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   5400:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   5401:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   5402:                     }
                   5403:                 }
                   5404:             }
                   5405:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5406:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   5407:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   5408:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   5409:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   5410:             $itemcount ++;
                   5411:         }
                   5412:     }
                   5413:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319     raeburn  5414:     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267     raeburn  5415:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   5416:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   5417:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   5418:     for (my $k=0; $k<$maxnum+1; $k++) {
                   5419:         my $vpos = $k+1;
                   5420:         my $selstr;
                   5421:         if ($k == $maxnum) {
                   5422:             $selstr = ' selected="selected" ';
                   5423:         }
                   5424:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5425:     }
                   5426:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  5427:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267     raeburn  5428:                   '<td colspan="2">'.
                   5429:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  5430:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267     raeburn  5431:                   ('&nbsp;'x2).
                   5432:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   5433:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   5434:                   ('&nbsp;'x2).
                   5435:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   5436:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  5437:                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   5438:                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5439:                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267     raeburn  5440:                   '<br />'.
1.323     raeburn  5441:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267     raeburn  5442:                   ('&nbsp;'x2).
                   5443:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   5444:                   ('&nbsp;'x2).
1.322     raeburn  5445:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   5446:                   ('&nbsp;'x2).
1.267     raeburn  5447:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   5448:                   '<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".
                   5449:                   '</fieldset>'.
                   5450:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5451:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   5452:     my %defaultdisp;
                   5453:     $defaultdisp{'iframe'} = ' checked="checked"';
1.298     raeburn  5454:     foreach my $disp ('iframe','tab','window') {
1.267     raeburn  5455:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   5456:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5457:     }
                   5458:     $datatable .= ('&nbsp;'x4);
                   5459:     foreach my $dimen ('width','height') {
                   5460:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5461:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   5462:                       ('&nbsp;'x2);
                   5463:     }
1.334     raeburn  5464:     $datatable .= '</span><br />'.
1.296     raeburn  5465:                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  5466:                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296     raeburn  5467:                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334     raeburn  5468:                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296     raeburn  5469:                   '</div><div style=""></div><br />';
1.319     raeburn  5470:     my %units = (
                   5471:                   'passback' => 'days',
                   5472:                   'roster'   => 'seconds',
                   5473:                 );
                   5474:     my %defaulttimes = (
                   5475:                      'passback' => '7',
1.322     raeburn  5476:                      'roster'   => '300',
1.319     raeburn  5477:                    );
1.267     raeburn  5478:     foreach my $extra ('passback','roster') {
1.319     raeburn  5479:         my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
                   5480:         $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   5481:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
                   5482:                       &mt('No').'</label></span>'.('&nbsp;'x2).'<span class="LC_nobreak">'.
                   5483:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
                   5484:                       &mt('Yes').'</label></span></div>'.
                   5485:                       '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
                   5486:                       '<span class="LC_nobreak">'.
                   5487:                       &mt("at least [_1] $units{$extra} after launch",
                   5488:                           '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
                   5489:                       '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  5490:     }
1.319     raeburn  5491:     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
1.267     raeburn  5492:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5493:     if ($switchserver) {
                   5494:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5495:     } else {
                   5496:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   5497:     }
                   5498:     $datatable .= '</span></fieldset>'.
                   5499:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5500:                   '<span class="LC_nobreak">';
                   5501:     foreach my $field (@fields) {
1.324     raeburn  5502:         my ($id,$onclick,$spacer);
                   5503:         if ($field eq 'user') {
                   5504:             $id = ' id="ltitools_user_field_add"';
                   5505:             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   5506:         } else {
                   5507:             $spacer = ('&nbsp;' x2);
                   5508:         }
1.267     raeburn  5509:         $datatable .= '<label>'.
1.324     raeburn  5510:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   5511:                       $lt{$field}.'</label>'.$spacer;
1.267     raeburn  5512:     }
1.324     raeburn  5513:     $datatable .= '</span>'.
                   5514:                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   5515:                   '<span class="LC_nobreak"> : '.
                   5516:                   '<select name="ltitools_userincdom_add">'.
                   5517:                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   5518:                   '<option value="0">'.&mt('username').'</option>'.
                   5519:                   '<option value="1">'.&mt('username:domain').'</option>'.
                   5520:                   '</select></span></div></fieldset>';
                   5521:     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267     raeburn  5522:     foreach my $role (@courseroles) {
                   5523:         my ($checked,$checkednone);
1.306     raeburn  5524:         $datatable .= '<td style="text-align: center">'.
1.267     raeburn  5525:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5526:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   5527:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   5528:         foreach my $ltirole (@ltiroles) {
                   5529:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   5530:         }
                   5531:         $datatable .= '</select></td>';
                   5532:     }
                   5533:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  5534:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  5535:     foreach my $item ('label','title','target','linktext','explanation','append') {
1.296     raeburn  5536:         $datatable .= '<label>'.
                   5537:                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   5538:                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
1.273     raeburn  5539:     }
                   5540:     $datatable .= '</span></fieldset>'.
1.267     raeburn  5541:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5542:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   5543:                   '<tr><td><span class="LC_nobreak">'.
                   5544:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   5545:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   5546:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334     raeburn  5547:                   '</table></fieldset>'."\n".
1.267     raeburn  5548:                   '</td>'."\n".
                   5549:                   '</tr>'."\n";
                   5550:     $itemcount ++;
                   5551:     return $datatable;
                   5552: }
                   5553: 
                   5554: sub ltitools_names {
                   5555:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  5556:                                           'title'          => 'Title',
                   5557:                                           'version'        => 'Version',
                   5558:                                           'msgtype'        => 'Message Type',
1.323     raeburn  5559:                                           'sigmethod'      => 'Signature Method',
1.296     raeburn  5560:                                           'url'            => 'URL',
                   5561:                                           'key'            => 'Key',
1.322     raeburn  5562:                                           'lifetime'       => 'Nonce lifetime (s)',
1.296     raeburn  5563:                                           'secret'         => 'Secret',
                   5564:                                           'icon'           => 'Icon',   
1.324     raeburn  5565:                                           'user'           => 'User',
1.296     raeburn  5566:                                           'fullname'       => 'Full Name',
                   5567:                                           'firstname'      => 'First Name',
                   5568:                                           'lastname'       => 'Last Name',
                   5569:                                           'email'          => 'E-mail',
                   5570:                                           'roles'          => 'Role',
1.298     raeburn  5571:                                           'window'         => 'Window',
                   5572:                                           'tab'            => 'Tab',
1.296     raeburn  5573:                                           'iframe'         => 'iFrame',
                   5574:                                           'height'         => 'Height',
                   5575:                                           'width'          => 'Width',
                   5576:                                           'linktext'       => 'Default Link Text',
                   5577:                                           'explanation'    => 'Default Explanation',
                   5578:                                           'passback'       => 'Tool can return grades:',
                   5579:                                           'roster'         => 'Tool can retrieve roster:',
                   5580:                                           'crstarget'      => 'Display target',
                   5581:                                           'crslabel'       => 'Course label',
                   5582:                                           'crstitle'       => 'Course title', 
                   5583:                                           'crslinktext'    => 'Link Text',
                   5584:                                           'crsexplanation' => 'Explanation',
1.318     raeburn  5585:                                           'crsappend'      => 'Provider URL',
1.267     raeburn  5586:                                         );
                   5587:     return %lt;
                   5588: }
                   5589: 
1.372     raeburn  5590: sub print_proctoring {
                   5591:     my ($dom,$settings,$rowtotal) = @_;
                   5592:     my $itemcount = 1;
                   5593:     my (%ordered,%providernames,%current,%currentdef);
                   5594:     my $confname = $dom.'-domainconfig';
                   5595:     my $switchserver = &check_switchserver($dom,$confname);
                   5596:     if (ref($settings) eq 'HASH') {
                   5597:         foreach my $item (keys(%{$settings})) {
                   5598:             if (ref($settings->{$item}) eq 'HASH') {
                   5599:                 my $num = $settings->{$item}{'order'};
                   5600:                 $ordered{$num} = $item;
                   5601:             }
                   5602:         }
                   5603:     } else {
                   5604:         %ordered = (
                   5605:                      1 => 'proctorio',
                   5606:                      2 => 'examity',
                   5607:                    );
                   5608:     }
                   5609:     %providernames = &proctoring_providernames();
                   5610:     my $maxnum = scalar(keys(%ordered));
                   5611:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   5612:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   5613:     if (ref($requref) eq 'HASH') {
                   5614:         %requserfields = %{$requref};
                   5615:     }
                   5616:     if (ref($opturef) eq 'HASH') {
                   5617:         %optuserfields = %{$opturef};
                   5618:     }
                   5619:     if (ref($defref) eq 'HASH') {
                   5620:         %defaults = %{$defref};
                   5621:     }
                   5622:     if (ref($extref) eq 'HASH') {
                   5623:         %extended = %{$extref};
                   5624:     }
                   5625:     if (ref($crsref) eq 'HASH') {
                   5626:         %crsconf = %{$crsref};
                   5627:     }
                   5628:     if (ref($rolesref) eq 'ARRAY') {
                   5629:         @courseroles = @{$rolesref};
                   5630:     }
                   5631:     if (ref($ltiref) eq 'ARRAY') {
                   5632:         @ltiroles = @{$ltiref};
                   5633:     }
                   5634:     my $datatable;
                   5635:     my $css_class;
                   5636:     if (keys(%ordered)) {
                   5637:         my @items = sort { $a <=> $b } keys(%ordered);
                   5638:         for (my $i=0; $i<@items; $i++) {
                   5639:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5640:             my $provider = $ordered{$items[$i]};
                   5641:             my $optionsty = 'none';
                   5642:             my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
                   5643:                 %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
                   5644:             if (ref($settings) eq 'HASH') {
                   5645:                 if (ref($settings->{$provider}) eq 'HASH') {
                   5646:                     %current = %{$settings->{$provider}};
                   5647:                     if ($current{'available'}) {
                   5648:                         $optionsty = 'block';
                   5649:                         $available = 1;
                   5650:                     }
                   5651:                     if ($current{'lifetime'} =~ /^\d+$/) {
                   5652:                         $lifetime = $current{'lifetime'};
                   5653:                     }
                   5654:                     if ($current{'version'} =~ /^\d+\.\d+$/) {
                   5655:                         $version = $current{'version'};
                   5656:                     }
                   5657:                     if ($current{'image'} ne '') {
                   5658:                         $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
                   5659:                     }
                   5660:                     if (ref($current{'fields'}) eq 'ARRAY') {
                   5661:                         map { $checkedfields{$_} = 1; } @{$current{'fields'}};
                   5662:                     }
                   5663:                     $userincdom = $current{'incdom'};
                   5664:                     if (ref($current{'roles'}) eq 'HASH') {
                   5665:                         %rolemaps = %{$current{'roles'}};
                   5666:                         $checkedfields{'roles'} = 1;
                   5667:                     }
                   5668:                     if (ref($current{'defaults'}) eq 'ARRAY') {
                   5669:                         foreach my $val (@{$current{'defaults'}}) {
                   5670:                             if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
                   5671:                                 $inuse{$val} = 1;
                   5672:                             } else {
                   5673:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5674:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5675:                                         if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
                   5676:                                             $inuse{$poss} = $val;
                   5677:                                             last;
                   5678:                                         }
                   5679:                                     }
                   5680:                                 }
                   5681:                             }
                   5682:                         }
                   5683:                     } elsif (ref($current{'defaults'}) eq 'HASH') {
                   5684:                         foreach my $key (keys(%{$current{'defaults'}})) {
                   5685:                             my $currval = $current{'defaults'}{$key}; 
                   5686:                             if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
                   5687:                                 $inuse{$key} = 1;
                   5688:                             } else {
                   5689:                                 my $match;
                   5690:                                 foreach my $poss (keys(%{$extended{$provider}})) {
                   5691:                                     if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
                   5692:                                         if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
                   5693:                                             $inuse{$poss} = $key;
                   5694:                                             last;
                   5695:                                         }
                   5696:                                     } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
                   5697:                                         foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
                   5698:                                             if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
                   5699:                                                 if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
                   5700:                                                     $currentdef{$inner} = $currval;
                   5701:                                                     $match = 1;
                   5702:                                                     last;
                   5703:                                                 }
                   5704:                                             } elsif ($inner eq $key) {
                   5705:                                                 $currentdef{$key} = $currval;
                   5706:                                                 $match = 1;
                   5707:                                                 last;
                   5708:                                             }
                   5709:                                         }
                   5710:                                     }
                   5711:                                     last if ($match);
                   5712:                                 }
                   5713:                             }
                   5714:                         }
                   5715:                     }
                   5716:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   5717:                         map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
                   5718:                     }
                   5719:                 }
                   5720:             }
                   5721:             my %lt = &proctoring_titles($provider);
                   5722:             my %fieldtitles = &proctoring_fieldtitles($provider);
                   5723:             my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
                   5724:             my %checkedavailable = (
                   5725:                                    yes => '',
                   5726:                                    no  => ' checked="checked"',
                   5727:                                  );
                   5728:             if ($available) {
                   5729:                 $checkedavailable{'yes'} = $checkedavailable{'no'};
                   5730:                 $checkedavailable{'no'} = '';
                   5731:             }
                   5732:             my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
                   5733:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5734:                          .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
                   5735:             for (my $k=0; $k<$maxnum; $k++) {
                   5736:                 my $vpos = $k+1;
                   5737:                 my $selstr;
                   5738:                 if ($k == $i) {
                   5739:                     $selstr = ' selected="selected" ';
                   5740:                 }
                   5741:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5742:             }
                   5743:             if ($version eq '') {
                   5744:                 if ($provider eq 'proctorio') {
                   5745:                     $version = '1.0';
                   5746:                 } elsif ($provider eq 'examity') {
                   5747:                     $version = '1.1';
                   5748:                 }
                   5749:             }
                   5750:             if ($lifetime eq '') {
                   5751:                 $lifetime = '300';
                   5752:             }
                   5753:             $datatable .=
                   5754:                 '</select>'.('&nbsp;'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
                   5755:                 '<span class="LC_nobreak">'.$lt{'avai'}.'&nbsp;'.
                   5756:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   5757:                 '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
                   5758:                 '</td>'.
                   5759:                 '<td colspan="2">'.
                   5760:                 '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
                   5761:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
                   5762:                 '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
                   5763:                 ('&nbsp;'x2).
                   5764:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
                   5765:                 '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5766:                 '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
                   5767:                 ('&nbsp;'x2).
                   5768:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
                   5769:                 '<br />'.
                   5770:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
                   5771:                 '<br />'.
                   5772:                 '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
                   5773:                 ('&nbsp;'x2).
                   5774:                 '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
                   5775:                 '<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";
                   5776:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   5777:             if ($imgsrc) {
                   5778:                 $datatable .= $imgsrc.
                   5779:                               '<label><input type="checkbox" name="proctoring_image_del"'.
                   5780:                               ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
                   5781:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:');
                   5782:             }
                   5783:             $datatable .= '&nbsp;';
                   5784:             if ($switchserver) {
                   5785:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5786:             } else {
                   5787:                 $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
                   5788:             }
                   5789:             unless ($imgsrc) {
                   5790:                 $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
                   5791:             }
                   5792:             $datatable .= '</fieldset>'."\n";
                   5793:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   5794:                 if (@{$requserfields{$provider}} > 0) {
                   5795:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
                   5796:                     foreach my $field (@{$requserfields{$provider}}) {
                   5797:                         $datatable .= '<span class="LC_nobreak">'.
                   5798:                                       '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
                   5799:                                       $lt{$field}.'</label>';
                   5800:                         if ($field eq 'user') {
                   5801:                             my $seluserdom = '';
                   5802:                             my $unseluserdom = ' selected="selected"';
                   5803:                             if ($userincdom) {
                   5804:                                 $seluserdom = $unseluserdom;
                   5805:                                 $unseluserdom = '';
                   5806:                             }
                   5807:                             $datatable .= ':&nbsp;'.
                   5808:                                 '<select name="proctoring_userincdom_'.$provider.'">'.
                   5809:                                 '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
                   5810:                                 '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
                   5811:                                 '</select>&nbsp;';
                   5812:                         } else {
                   5813:                             $datatable .= '&nbsp;';
                   5814:                             if ($field eq 'roles') {
                   5815:                                 $showroles = 1; 
                   5816:                             } 
                   5817:                         }
                   5818:                         $datatable .= '</span> ';
                   5819:                     }
                   5820:                 }
                   5821:                 $datatable .= '</fieldset>'."\n";
                   5822:             }
                   5823:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   5824:                 if (@{$optuserfields{$provider}} > 0) {
                   5825:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>'; 
                   5826:                     foreach my $field (@{$optuserfields{$provider}}) {
                   5827:                         my $checked;
                   5828:                         if ($checkedfields{$field}) {
                   5829:                             $checked = ' checked="checked"';
                   5830:                         }
                   5831:                         $datatable .= '<span class="LC_nobreak">'.
                   5832:                                       '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span>&nbsp; ';
                   5833:                     }
                   5834:                     $datatable .= '</fieldset>'."\n";
                   5835:                 }
                   5836:             }
                   5837:             if (ref($defaults{$provider}) eq 'ARRAY') {
                   5838:                 if (@{$defaults{$provider}}) {
                   5839:                     my (%options,@selectboxes);
                   5840:                     if (ref($extended{$provider}) eq 'HASH') {
                   5841:                         %options = %{$extended{$provider}};
                   5842:                     }
                   5843:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
                   5844:                     my ($rem,$numinrow,$dropdowns);
                   5845:                     if ($provider eq 'proctorio') { 
                   5846:                         $datatable .= '<table>';
                   5847:                         $numinrow = 4;
                   5848:                     }
                   5849:                     my $i = 0;
                   5850:                     foreach my $field (@{$defaults{$provider}}) {
                   5851:                         my $checked;
                   5852:                         if ($inuse{$field}) {
                   5853:                             $checked = ' checked="checked"';
                   5854:                         }
                   5855:                         if ($provider eq 'examity') {
                   5856:                             if ($field eq 'display') {
                   5857:                                 $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
                   5858:                                 foreach my $option ('iframe','tab','window') {
                   5859:                                     my $checkdisp;
                   5860:                                     if ($currentdef{'target'} eq $option) {
                   5861:                                         $checkdisp = ' checked="checked"';
                   5862:                                     }
                   5863:                                     $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
                   5864:                                     $fieldtitles{$option}.'</label>'.('&nbsp;'x2);
                   5865:                                 }
                   5866:                                 $datatable .= ('&nbsp;'x4);
                   5867:                                 foreach my $dimen ('width','height') {
                   5868:                                     $datatable .= '<label>'.$fieldtitles{$dimen}.'&nbsp;'.
                   5869:                                                   '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
                   5870:                                                   'value="'.$currentdef{$dimen}.'" /></label>'.
                   5871:                                                   ('&nbsp;'x2);
                   5872:                                 }
                   5873:                                 $datatable .= '</span><br />'.
                   5874:                                               '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
                   5875:                                               '<input type="text" name="proctoring_linktext_'.$provider.'" '.
                   5876:                                               'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
                   5877:                                               '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
                   5878:                                               '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
                   5879:                                               $currentdef{'explanation'}.
                   5880:                                               '</textarea></div><div style=""></div><br />';
                   5881:                             }
                   5882:                         } else {
                   5883:                             if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   5884:                                 my ($output,$selnone);
                   5885:                                 unless ($checked) {
                   5886:                                     $selnone = ' selected="selected"';
                   5887:                                 }
                   5888:                                 $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
                   5889:                                            '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
                   5890:                                            '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>'; 
                   5891:                                 foreach my $option (@{$options{$field}}) {
                   5892:                                     my $sel; 
                   5893:                                     if ($inuse{$field} eq $option) {
                   5894:                                         $sel = ' selected="selected"';
                   5895:                                     }
                   5896:                                     $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
                   5897:                                 }
                   5898:                                 $output .= '</select></span>';
                   5899:                                 push(@selectboxes,$output);
                   5900:                             } else {
                   5901:                                 $rem = $i%($numinrow);
                   5902:                                 if ($rem == 0) {
                   5903:                                     if ($i > 0) {
                   5904:                                         $datatable .= '</tr>';
                   5905:                                     }
                   5906:                                     $datatable .= '<tr>';
                   5907:                                 }
                   5908:                                 $datatable .= '<td class="LC_left_item">'.
                   5909:                                               '<span class="LC_nobreak">'.
                   5910:                                               '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
                   5911:                                               $fieldtitles{$field}.'</label></span></td>';
                   5912:                                 $i++;
                   5913:                             }
                   5914:                         }
                   5915:                     }
                   5916:                     if ($provider eq 'proctorio') {
                   5917:                         if ($numinrow) {
                   5918:                             $rem = $i%$numinrow;
                   5919:                         }
                   5920:                         my $colsleft = $numinrow - $rem;
                   5921:                         if ($colsleft > 1) {
                   5922:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   5923:                         } else {
                   5924:                             $datatable .= '<td class="LC_left_item">';
                   5925:                         }
                   5926:                         $datatable .= '&nbsp;'.
                   5927:                                       '</td></tr></table>';
                   5928:                         if (@selectboxes) {
                   5929:                             $datatable .= '<hr /><table>';
                   5930:                             $numinrow = 2;
                   5931:                             for (my $i=0; $i<@selectboxes; $i++) {
                   5932:                                 $rem = $i%($numinrow);
                   5933:                                 if ($rem == 0) {
                   5934:                                     if ($i > 0) {
                   5935:                                         $datatable .= '</tr>';
                   5936:                                     }
                   5937:                                     $datatable .= '<tr>';
                   5938:                                 }
                   5939:                                 $datatable .= '<td class="LC_left_item">'.
                   5940:                                               $selectboxes[$i].'</td>';
                   5941:                             }
                   5942:                             if ($numinrow) {
                   5943:                                 $rem = $i%$numinrow;
                   5944:                             }
                   5945:                             $colsleft = $numinrow - $rem;
                   5946:                             if ($colsleft > 1) {
                   5947:                                 $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   5948:                             } else {
                   5949:                                 $datatable .= '<td class="LC_left_item">';
                   5950:                             }
                   5951:                             $datatable .= '&nbsp;'.
                   5952:                                           '</td></tr></table>';
                   5953:                         }
                   5954:                     }
                   5955:                     $datatable .= '</fieldset>';
                   5956:                 }
                   5957:                 if (ref($crsconf{$provider}) eq 'ARRAY') {
                   5958:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   5959:                                   '<legend>'.&mt('Configurable in course').'</legend>';
                   5960:                     my ($rem,$numinrow);
                   5961:                     if ($provider eq 'proctorio') {
                   5962:                         $datatable .= '<table>';
                   5963:                         $numinrow = 4;
                   5964:                     }
                   5965:                     my $i = 0;
                   5966:                     foreach my $item (@{$crsconf{$provider}}) {
                   5967:                         my $name;
                   5968:                         if ($provider eq 'examity') {
                   5969:                             $name = $lt{'crs'.$item};
                   5970:                         } elsif ($provider eq 'proctorio') {
                   5971:                             $name = $fieldtitles{$item};
                   5972:                             $rem = $i%($numinrow);
                   5973:                             if ($rem == 0) {
                   5974:                                 if ($i > 0) {
                   5975:                                     $datatable .= '</tr>';
                   5976:                                 }
                   5977:                                 $datatable .= '<tr>';
                   5978:                             }
                   5979:                             $datatable .= '<td class="LC_left_item>';
                   5980:                         }
                   5981:                         my $checked;
                   5982:                         if ($crsconfig{$item}) {
                   5983:                             $checked = ' checked="checked"';
                   5984:                         }
                   5985:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   5986:                                       '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
                   5987:                                       $name.'</label></span>';
                   5988:                         if ($provider eq 'examity') {
                   5989:                             $datatable .= '&nbsp; ';
                   5990:                         }
                   5991:                         $datatable .= "\n";
                   5992:                         $i++;
                   5993:                     }
                   5994:                     if ($provider eq 'proctorio') {
                   5995:                         if ($numinrow) {
                   5996:                             $rem = $i%$numinrow;
                   5997:                         }
                   5998:                         my $colsleft = $numinrow - $rem;
                   5999:                         if ($colsleft > 1) {
                   6000:                             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   6001:                         } else {
                   6002:                             $datatable .= '<td class="LC_left_item">';
                   6003:                         }
                   6004:                         $datatable .= '&nbsp;'.
                   6005:                                       '</td></tr></table>';
                   6006:                     }
                   6007:                     $datatable .= '</fieldset>';
                   6008:                 }
                   6009:                 if ($showroles) {
                   6010:                     $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6011:                                   '<legend>'.&mt('Role mapping').'</legend><table><tr>';
                   6012:                     foreach my $role (@courseroles) {
                   6013:                         my ($selected,$selectnone);
                   6014:                         if (!$rolemaps{$role}) {
                   6015:                             $selectnone = ' selected="selected"';
                   6016:                         }
                   6017:                         $datatable .= '<td style="text-align: center">'.
                   6018:                                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   6019:                                       '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
                   6020:                                       '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6021:                         foreach my $ltirole (@ltiroles) {
                   6022:                             unless ($selectnone) {
                   6023:                                 if ($rolemaps{$role} eq $ltirole) {
                   6024:                                     $selected = ' selected="selected"';
                   6025:                                 } else {
                   6026:                                     $selected = '';
                   6027:                                 }
                   6028:                             }
                   6029:                             $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   6030:                         }
                   6031:                         $datatable .= '</select></td>';
                   6032:                     }
                   6033:                     $datatable .= '</tr></table></fieldset>'.
                   6034:                                   '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
                   6035:                                   '<legend>'.&mt('Custom items sent on launch').'</legend>'.
                   6036:                                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   6037:                                   '<tr><td></td><td>lms</td>'.
                   6038:                                   '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
                   6039:                                   ' value="Loncapa" disabled="disabled"/></td></tr>';
                   6040:                     if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
                   6041:                         (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
                   6042:                         my %custom = %{$settings->{$provider}->{'custom'}};
                   6043:                         if (keys(%custom) > 0) {
                   6044:                             foreach my $key (sort(keys(%custom))) {
                   6045:                                 next if ($key eq 'lms');
                   6046:                                 $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6047:                                               '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
                   6048:                                               $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   6049:                                               '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
                   6050:                                               ' value="'.$custom{$key}.'" /></td></tr>';
                   6051:                             }
                   6052:                         }
                   6053:                     }
                   6054:                     $datatable .= '<tr><td><span class="LC_nobreak">'.
                   6055:                                   '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
                   6056:                                   &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
                   6057:                                   '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
                   6058:                                   '</table></fieldset></td></tr>'."\n";
                   6059:                 }
                   6060:                 $datatable .= '</td></tr>';
                   6061:             }
                   6062:             $itemcount ++;
                   6063:         }
                   6064:     }
                   6065:     return $datatable;
                   6066: }
                   6067: 
                   6068: sub proctoring_data {
                   6069:     my $requserfields = {
                   6070:                       proctorio => ['user'],
                   6071:                       examity   => ['roles','user'],
                   6072:                      };
                   6073:     my $optuserfields = {
                   6074:                         proctorio => ['fullname'],
                   6075:                         examity   => ['fullname','firstname','lastname','email'],
                   6076:                      };
                   6077:     my $defaults = {
                   6078:                   proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6079:                                 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6080:                                 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6081:                                 'closetabs','onescreen','print','downloads','cache','rightclick',
                   6082:                                 'reentry','calculator','whiteboard'],
                   6083:                   examity   => ['display'],
                   6084:                 };
                   6085:     my $extended = { 
                   6086:                   proctorio => {
                   6087:                                  verifyid => ['verifyidauto','verifyidlive'],
                   6088:                                  fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
                   6089:                                  tabslinks => ['notabs','linksonly'],
                   6090:                                  reentry => ['noreentry','agentreentry'],
                   6091:                                  calculator => ['calculatorbasic','calculatorsci'],
                   6092:                                },
                   6093:                   examity => {
                   6094:                                display => {
                   6095:                                            target      => ['iframe','tab','window'],
                   6096:                                            width       => '',
                   6097:                                            height      => '',
                   6098:                                            linktext    => '',
                   6099:                                            explanation => '',
                   6100:                                           },
                   6101:                              },
                   6102:                 };
                   6103:     my $crsconf = {
                   6104:                  proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
                   6105:                                'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
                   6106:                                'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
                   6107:                                'closetabs','onescreen','print','downloads','cache','rightclick',
                   6108:                                'reentry','calculator','whiteboard'],
                   6109:                  examity => ['label','title','target','linktext','explanation','append'],
                   6110:                };
                   6111:     my $courseroles = ['cc','in','ta','ep','st'];
                   6112:     my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
                   6113:     return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
                   6114: }
                   6115: 
                   6116: sub proctoring_titles {
                   6117:     my ($item) = @_;
                   6118:     my (%common_lt,%custom_lt);
                   6119:     %common_lt = &Apache::lonlocal::texthash (
                   6120:                      'avai'      => 'Available?',
                   6121:                      'base'      => 'Basic Settings',
                   6122:                      'requ'      => 'User data required to be sent on launch',
                   6123:                      'optu'      => 'User data optionally sent on launch',
                   6124:                      'udsl'      => 'User data sent on launch',
                   6125:                      'defa'      => 'Defaults for items configurable in course',
                   6126:                      'sigmethod' => 'Signature Method',
                   6127:                      'key'       => 'Key',
                   6128:                      'lifetime'  => 'Nonce lifetime (s)',
                   6129:                      'secret'    => 'Secret',
                   6130:                      'icon'      => 'Icon',
                   6131:                      'fullname'  => 'Full Name',
                   6132:                      'visible'   => 'Visible input',
                   6133:                      'username'  => 'username',
                   6134:                      'user'      => 'User',
                   6135:                  );
                   6136:     if ($item eq 'proctorio') {
                   6137:         %custom_lt = &Apache::lonlocal::texthash (
                   6138:                          'version'        => 'OAuth version',
                   6139:                          'url'            => 'API URL',
                   6140:                          'uname:dom'      => 'username-domain',
                   6141:         );
                   6142:     } elsif ($item eq 'examity') {
                   6143:         %custom_lt = &Apache::lonlocal::texthash (
                   6144:                          'version'        => 'LTI Version',
                   6145:                          'url'            => 'URL',
                   6146:                          'uname:dom'      => 'username:domain',
                   6147:                          'msgtype'        => 'Message Type',
                   6148:                          'firstname'      => 'First Name',
                   6149:                          'lastname'       => 'Last Name',
                   6150:                          'email'          => 'E-mail',
                   6151:                          'roles'          => 'Role',
                   6152:                          'crstarget'      => 'Display target',
                   6153:                          'crslabel'       => 'Course label',
                   6154:                          'crstitle'       => 'Course title', 
                   6155:                          'crslinktext'    => 'Link Text',
                   6156:                          'crsexplanation' => 'Explanation',
                   6157:                          'crsappend'      => 'Provider URL',
                   6158:         );
                   6159:     }
                   6160:     my %lt = (%common_lt,%custom_lt);
                   6161:     return %lt;
                   6162: }
                   6163: 
                   6164: sub proctoring_fieldtitles {
                   6165:     my ($item) = @_;
                   6166:     if ($item eq 'proctorio') {
                   6167:         return &Apache::lonlocal::texthash (
                   6168:                   'recordvideo' => 'Record video',
                   6169:                   'recordaudio' => 'Record audio',
                   6170:                   'recordscreen' => 'Record screen',
                   6171:                   'recordwebtraffic' => 'Record web traffic',
                   6172:                   'recordroomstart' => 'Record room scan',
                   6173:                   'verifyvideo' => 'Verify webcam',
                   6174:                   'verifyaudio' => 'Verify microphone',
                   6175:                   'verifydesktop' => 'Verify desktop recording',
                   6176:                   'verifyid' => 'Photo ID verification',
                   6177:                   'verifysignature' => 'Require signature',
                   6178:                   'fullscreen' => 'Fullscreen',
                   6179:                   'clipboard' => 'Disable copy/paste',
                   6180:                   'tabslinks' => 'New tabs/windows',
                   6181:                   'closetabs' => 'Close other tabs',
                   6182:                   'onescreen' => 'Limit to single screen',
                   6183:                   'print' => 'Disable Printing',
                   6184:                   'downloads' => 'Disable Downloads',
                   6185:                   'cache' => 'Empty cache after exam',
                   6186:                   'rightclick' => 'Disable right click',
                   6187:                   'reentry' => 'Re-entry to exam',
                   6188:                   'calculator' => 'Onscreen calculator',
                   6189:                   'whiteboard' => 'Onscreen whiteboard',
                   6190:                   'verifyidauto' => 'Automated verification',
                   6191:                   'verifyidlive' => 'Live agent verification',
                   6192:                   'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
                   6193:                   'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
                   6194:                   'fullscreensever' => 'Forced, navigation away ends exam',
                   6195:                   'notabs' => 'Disaallowed',
                   6196:                   'linksonly' => 'Allowed from links in exam',
                   6197:                   'noreentry' => 'Disallowed',
                   6198:                   'agentreentry' => 'Agent required for re-entry',
                   6199:                   'calculatorbasic' => 'Basic',
                   6200:                   'calculatorsci' => 'Scientific',
                   6201:         );
                   6202:     } elsif ($item eq 'examity') {
                   6203:         return &Apache::lonlocal::texthash (
                   6204:                 'target'         => 'Display target',   
                   6205:                 'window'         => 'Window',
                   6206:                 'tab'            => 'Tab',
                   6207:                 'iframe'         => 'iFrame',
                   6208:                 'height'         => 'Height (pixels)',
                   6209:                 'width'          => 'Width (pixels)',
                   6210:                 'linktext'       => 'Default Link Text',
                   6211:                 'explanation'    => 'Default Explanation',
                   6212:                 'append'         => 'Provider URL',
                   6213:         );
                   6214:     }
                   6215: }
                   6216: 
                   6217: sub proctoring_providernames {
                   6218:     return (
                   6219:              proctorio => 'Proctorio',
                   6220:              examity   => 'Examity',
                   6221:            );
                   6222: }
                   6223: 
1.320     raeburn  6224: sub print_lti {
                   6225:     my ($dom,$settings,$rowtotal) = @_;
                   6226:     my $itemcount = 1;
                   6227:     my $maxnum = 0;
                   6228:     my $css_class;
                   6229:     my %ordered;
                   6230:     if (ref($settings) eq 'HASH') {
                   6231:         foreach my $item (keys(%{$settings})) {
                   6232:             if (ref($settings->{$item}) eq 'HASH') {
                   6233:                 my $num = $settings->{$item}{'order'};
1.390     raeburn  6234:                 if ($num eq '') {
                   6235:                     $num = scalar(keys(%{$settings}));
                   6236:                 }
1.320     raeburn  6237:                 $ordered{$num} = $item;
                   6238:             }
                   6239:         }
                   6240:     }
                   6241:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  6242:     my $datatable;
1.320     raeburn  6243:     my %lt = &lti_names();
                   6244:     if (keys(%ordered)) {
                   6245:         my @items = sort { $a <=> $b } keys(%ordered);
                   6246:         for (my $i=0; $i<@items; $i++) {
                   6247:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6248:             my $item = $ordered{$items[$i]};
1.391     raeburn  6249:             my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
1.320     raeburn  6250:             if (ref($settings->{$item}) eq 'HASH') {
                   6251:                 $key = $settings->{$item}->{'key'};
                   6252:                 $secret = $settings->{$item}->{'secret'};
                   6253:                 $lifetime = $settings->{$item}->{'lifetime'};
                   6254:                 $consumer = $settings->{$item}->{'consumer'};
1.345     raeburn  6255:                 $requser = $settings->{$item}->{'requser'};
1.391     raeburn  6256:                 $crsinc = $settings->{$item}->{'crsinc'};
1.320     raeburn  6257:                 $current = $settings->{$item};
                   6258:             }
1.345     raeburn  6259:             my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
                   6260:             my %checkedrequser = (
                   6261:                                    yes => ' checked="checked"',
                   6262:                                    no  => '',
                   6263:                                  );
                   6264:             if (!$requser) {
                   6265:                 $checkedrequser{'no'} = $checkedrequser{'yes'};
                   6266:                 $checkedrequser{'yes'} = '';
1.352     raeburn  6267:             }
1.391     raeburn  6268:             my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
                   6269:             my %checkedcrsinc = (
                   6270:                                       yes => ' checked="checked"',
                   6271:                                       no  => '',
                   6272:                                    );
                   6273:             if (!$crsinc) {
                   6274:                 $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
                   6275:                 $checkedcrsinc{'yes'} = '';
                   6276:             }
1.320     raeburn  6277:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
                   6278:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6279:                          .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
                   6280:             for (my $k=0; $k<=$maxnum; $k++) {
                   6281:                 my $vpos = $k+1;
                   6282:                 my $selstr;
                   6283:                 if ($k == $i) {
                   6284:                     $selstr = ' selected="selected" ';
                   6285:                 }
                   6286:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6287:             }
                   6288:             $datatable .= '</select>'.('&nbsp;'x2).
                   6289:                 '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
                   6290:                 &mt('Delete?').'</label></span></td>'.
                   6291:                 '<td colspan="2">'.
                   6292:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6293:                 '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  6294:                 ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320     raeburn  6295:                 ('&nbsp;'x2).
                   6296:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                   6297:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   6298:                 ('&nbsp;'x2).
                   6299:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345     raeburn  6300:                 'value="'.$lifetime.'" size="3" /></span>'.
                   6301:                 ('&nbsp;'x2).
                   6302:                  '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6303:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6304:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  6305:                 '<br /><br />'.
1.391     raeburn  6306:                 '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6307:                 '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6308:                 '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
                   6309:                 ('&nbsp;'x4).
1.320     raeburn  6310:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   6311:                 ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
                   6312:                 ('&nbsp;'x2).
                   6313:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   6314:                 '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
                   6315:                 '<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>'.
                   6316:                 '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325     raeburn  6317:                 '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320     raeburn  6318:             $itemcount ++;
                   6319:         }
                   6320:     }
                   6321:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6322:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
                   6323:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   6324:                   '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
                   6325:                   '<select name="lti_pos_add"'.$chgstr.'>';
                   6326:     for (my $k=0; $k<$maxnum+1; $k++) {
                   6327:         my $vpos = $k+1;
                   6328:         my $selstr;
                   6329:         if ($k == $maxnum) {
                   6330:             $selstr = ' selected="selected" ';
                   6331:         }
                   6332:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6333:     }
                   6334:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  6335:                   '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320     raeburn  6336:                   '<td colspan="2">'.
                   6337:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   6338:                   '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  6339:                   ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320     raeburn  6340:                   ('&nbsp;'x2).
                   6341:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   6342:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   6343:                   ('&nbsp;'x2).
1.345     raeburn  6344:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
                   6345:                   ('&nbsp;'x2).
                   6346:                   '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   6347:                   '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6348:                   '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  6349:                   '<br /><br />'.
1.391     raeburn  6350:                   '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
                   6351:                   '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   6352:                   '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
                   6353:                   ('&nbsp;'x4).
1.320     raeburn  6354:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
                   6355:                   ('&nbsp;'x2).
                   6356:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
                   6357:                   '<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  6358:                   '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
1.320     raeburn  6359:                   '</td>'."\n".
                   6360:                   '</tr>'."\n";
                   6361:     $$rowtotal ++;
                   6362:     return $datatable;;
                   6363: }
                   6364: 
                   6365: sub lti_names {
                   6366:     my %lt = &Apache::lonlocal::texthash(
                   6367:                                           'version'   => 'LTI Version',
                   6368:                                           'url'       => 'URL',
                   6369:                                           'key'       => 'Key',
1.322     raeburn  6370:                                           'lifetime'  => 'Nonce lifetime (s)',
1.345     raeburn  6371:                                           'consumer'  => 'Consumer',
1.320     raeburn  6372:                                           'secret'    => 'Secret',
1.345     raeburn  6373:                                           'requser'   => "User's identity sent",
1.391     raeburn  6374:                                           'crsinc'    => "Course's identity sent",
1.320     raeburn  6375:                                           'email'     => 'Email address',
                   6376:                                           'sourcedid' => 'User ID',
                   6377:                                           'other'     => 'Other',
                   6378:                                           'passback'  => 'Can return grades to Consumer:',
                   6379:                                           'roster'    => 'Can retrieve roster from Consumer:',
1.326     raeburn  6380:                                           'topmenu'   => 'Display LON-CAPA page header',
1.345     raeburn  6381:                                           'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320     raeburn  6382:                                         );
                   6383:     return %lt;
                   6384: }
                   6385: 
                   6386: sub lti_options {
1.325     raeburn  6387:     my ($num,$current,$itemcount,%lt) = @_;
1.363     raeburn  6388:     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320     raeburn  6389:     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
                   6390:     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392     raeburn  6391:     $checked{'storecrs'}{'Y'} = ' checked="checked"';
                   6392:     $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320     raeburn  6393:     $checked{'mapcrstype'} = {};
                   6394:     $checked{'makeuser'} = {};
                   6395:     $checked{'selfenroll'} = {};
                   6396:     $checked{'crssec'} = {};
                   6397:     $checked{'crssecsrc'} = {};
1.325     raeburn  6398:     $checked{'lcauth'} = {};
1.326     raeburn  6399:     $checked{'menuitem'} = {};
1.325     raeburn  6400:     if ($num eq 'add') {
                   6401:         $checked{'lcauth'}{'lti'} = ' checked="checked"';
                   6402:     }
1.320     raeburn  6403:     my $userfieldsty = 'none';
                   6404:     my $crsfieldsty = 'none';
                   6405:     my $crssecfieldsty = 'none';
                   6406:     my $secsrcfieldsty = 'none';
1.363     raeburn  6407:     my $callbacksty = 'none';
1.337     raeburn  6408:     my $passbacksty = 'none';
1.345     raeburn  6409:     my $optionsty = 'block';
1.391     raeburn  6410:     my $crssty = 'block';
1.325     raeburn  6411:     my $lcauthparm;
                   6412:     my $lcauthparmstyle = 'display:none';
                   6413:     my $lcauthparmtext;
1.326     raeburn  6414:     my $menusty;
1.325     raeburn  6415:     my $numinrow = 4;
1.326     raeburn  6416:     my %menutitles = &ltimenu_titles();
1.320     raeburn  6417: 
                   6418:     if (ref($current) eq 'HASH') {
1.345     raeburn  6419:         if (!$current->{'requser'}) {
                   6420:             $optionsty = 'none';
1.391     raeburn  6421:             $crssty = 'none';
                   6422:         } elsif (!$current->{'crsinc'}) {
                   6423:             $crssty = 'none';
1.345     raeburn  6424:         }
1.320     raeburn  6425:         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
                   6426:             $checked{'mapuser'}{'sourcedid'} = '';
                   6427:             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
                   6428:                 $checked{'mapuser'}{'email'} = ' checked="checked"'; 
                   6429:             } else {
                   6430:                 $checked{'mapuser'}{'other'} = ' checked="checked"';
                   6431:                 $userfield = $current->{'mapuser'};
                   6432:                 $userfieldsty = 'inline-block';
                   6433:             }
                   6434:         }
                   6435:         if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
                   6436:             $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
                   6437:             if ($current->{'mapcrs'} eq 'context_id') {
                   6438:                 $checked{'mapcrs'}{'context_id'} = ' checked="checked"'; 
                   6439:             } else {
                   6440:                 $checked{'mapcrs'}{'other'} = ' checked="checked"';
                   6441:                 $cidfield = $current->{'mapcrs'};
                   6442:                 $crsfieldsty = 'inline-block';
                   6443:             }
                   6444:         }
                   6445:         if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
                   6446:             foreach my $type (@{$current->{'mapcrstype'}}) {
                   6447:                 $checked{'mapcrstype'}{$type} = ' checked="checked"';
                   6448:             }
                   6449:         }
1.392     raeburn  6450:         if (!$current->{'storecrs'}) {
                   6451:             $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
                   6452:             $checked{'storecrs'}{'Y'} = '';
                   6453:         }
1.345     raeburn  6454:         if ($current->{'makecrs'}) {
1.320     raeburn  6455:             $checked{'makecrs'}{'Y'} = '  checked="checked"';
1.326     raeburn  6456:         }
1.320     raeburn  6457:         if (ref($current->{'makeuser'}) eq 'ARRAY') {
                   6458:             foreach my $role (@{$current->{'makeuser'}}) {
                   6459:                 $checked{'makeuser'}{$role} = ' checked="checked"';
                   6460:             }
                   6461:         }
1.325     raeburn  6462:         if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
                   6463:             $checked{'lcauth'}{$1} = ' checked="checked"';
                   6464:             unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   6465:                 $lcauthparm = $current->{'lcauthparm'};
                   6466:                 $lcauthparmstyle = 'display:table-row'; 
                   6467:                 if ($current->{'lcauth'} eq 'localauth') {
                   6468:                     $lcauthparmtext = &mt('Local auth argument');
                   6469:                 } else {
                   6470:                     $lcauthparmtext = &mt('Kerberos domain');
                   6471:                 }
                   6472:             }
                   6473:         }
1.320     raeburn  6474:         if (ref($current->{'selfenroll'}) eq 'ARRAY') {
                   6475:             foreach my $role (@{$current->{'selfenroll'}}) {
                   6476:                 $checked{'selfenroll'}{$role} = ' checked="checked"';
                   6477:             }
                   6478:         }
                   6479:         if (ref($current->{'maproles'}) eq 'HASH') {
                   6480:             %rolemaps = %{$current->{'maproles'}};
                   6481:         }
                   6482:         if ($current->{'section'} ne '') {
                   6483:             $checked{'crssec'}{'Y'} = '  checked="checked"'; 
                   6484:             $crssecfieldsty = 'inline-block';
                   6485:             if ($current->{'section'} eq 'course_section_sourcedid') {
                   6486:                 $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
                   6487:             } else {
                   6488:                 $checked{'crssecsrc'}{'other'} = ' checked="checked"';
                   6489:                 $crssecsrc = $current->{'section'};
                   6490:                 $secsrcfieldsty = 'inline-block';
                   6491:             }
                   6492:         } else {
                   6493:             $checked{'crssec'}{'N'} = ' checked="checked"';
                   6494:         }
1.363     raeburn  6495:         if ($current->{'callback'} ne '') {
                   6496:             $callback = $current->{'callback'};
                   6497:             $checked{'callback'}{'Y'} = ' checked="checked"';
                   6498:             $callbacksty = 'inline-block';
                   6499:         } else {
                   6500:             $checked{'callback'}{'N'} = ' checked="checked"';
                   6501:         }
1.326     raeburn  6502:         if ($current->{'topmenu'}) {
                   6503:             $checked{'topmenu'}{'Y'} = ' checked="checked"';
                   6504:         } else {
                   6505:             $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6506:         }
                   6507:         if ($current->{'inlinemenu'}) {
                   6508:             $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
                   6509:         } else {
                   6510:             $checked{'inlinemenu'}{'N'} = ' checked="checked"';
                   6511:         }
                   6512:         if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
                   6513:             $menusty = 'inline-block';
                   6514:             if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   6515:                 foreach my $item (@{$current->{'lcmenu'}}) {
                   6516:                     if (exists($menutitles{$item})) {
                   6517:                         $checked{'menuitem'}{$item} = ' checked="checked"';
                   6518:                     }
                   6519:                 }
                   6520:             }
                   6521:         } else {
                   6522:             $menusty = 'none';
                   6523:         }
1.320     raeburn  6524:     } else {
                   6525:         $checked{'makecrs'}{'N'} = ' checked="checked"';
                   6526:         $checked{'crssec'}{'N'} = ' checked="checked"';
1.363     raeburn  6527:         $checked{'callback'}{'N'} = ' checked="checked"';
1.326     raeburn  6528:         $checked{'topmenu'}{'N'} = ' checked="checked"';
                   6529:         $checked{'inlinemenu'}{'Y'} = ' checked="checked"'; 
                   6530:         $checked{'menuitem'}{'grades'} = ' checked="checked"';
                   6531:         $menusty = 'inline-block'; 
1.320     raeburn  6532:     }
1.325     raeburn  6533:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  6534:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   6535:                                official   => 'Official',
                   6536:                                unofficial => 'Unofficial',
                   6537:                                community  => 'Community',
                   6538:                                textbook   => 'Textbook',
                   6539:                                placement  => 'Placement Test',
1.325     raeburn  6540:                                lti        => 'LTI Provider',
1.320     raeburn  6541:     );
1.325     raeburn  6542:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6543:     my %shortauth = (
                   6544:                      internal => 'int',
                   6545:                      krb4 => 'krb4',
                   6546:                      krb5 => 'krb5',
                   6547:                      localauth  => 'loc'
                   6548:                     );
                   6549:     my %authnames = &authtype_names();
1.320     raeburn  6550:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   6551:     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
                   6552:     my @courseroles = ('cc','in','ta','ep','st');
                   6553:     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
                   6554:     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
                   6555:     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363     raeburn  6556:     my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320     raeburn  6557:     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325     raeburn  6558:     my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326     raeburn  6559:     my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391     raeburn  6560:     my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392     raeburn  6561:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').':&nbsp;'.
1.391     raeburn  6562:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
                   6563:                  $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6564:                  '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
                   6565:                  $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
                   6566:                  '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
                   6567:                  '<span class="LC_nobreak">'.&mt('Parameter').': '.
                   6568:                  '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
                   6569:                  '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
                   6570:                  '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320     raeburn  6571:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
                   6572:     foreach my $option ('sourcedid','email','other') {
                   6573:         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
                   6574:                    $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
                   6575:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6576:     }
                   6577:     $output .= '</span></div>'.
                   6578:                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                   6579:                '<input type="text" name="lti_customuser_'.$num.'" '.
1.372     raeburn  6580:                'value="'.$userfield.'" /></div></fieldset>'.
1.391     raeburn  6581:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320     raeburn  6582:     foreach my $ltirole (@ltiroles) {
                   6583:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
                   6584:                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';     
                   6585:     }
                   6586:     $output .= '</fieldset>'.
1.391     raeburn  6587:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325     raeburn  6588:                '<table>'.
                   6589:                &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                   6590:                '</table>'.
                   6591:                '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                   6592:                '<td class="LC_left_item">';
                   6593:     foreach my $auth ('lti',@authtypes) {
                   6594:         my $authtext;
                   6595:         if ($auth eq 'lti') {
                   6596:             $authtext = &mt('None');
                   6597:         } else {
                   6598:             $authtext = $authnames{$shortauth{$auth}};
                   6599:         }
                   6600:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                   6601:                    '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                   6602:                    $authtext.'</label></span> &nbsp;';
                   6603:     }
                   6604:     $output .= '</td></tr>'.
                   6605:                '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                   6606:                '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                   6607:                '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                   6608:                '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                   6609:                '</table></fieldset>'.
1.391     raeburn  6610:                '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
                   6611:                &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
                   6612:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                   6613:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                   6614:                $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6615:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
                   6616:                $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
                   6617:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6618:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                   6619:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                   6620:                $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6621:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
                   6622:                $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
                   6623:      $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6624:                '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                   6625:                '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
                   6626:     foreach my $type ('fullname','coursetitle','role','logout','grades') {
                   6627:         $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                   6628:                    $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                   6629:                    ('&nbsp;'x2);
                   6630:     }
                   6631:     $output .= '</span></div></fieldset>'.
                   6632:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320     raeburn  6633:                '<div class="LC_floatleft"><span class="LC_nobreak">'.
                   6634:                &mt('Unique course identifier').':&nbsp;';
                   6635:     foreach my $option ('course_offering_sourcedid','context_id','other') {
                   6636:         $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
                   6637:                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                   6638:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   6639:     }
1.334     raeburn  6640:     $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320     raeburn  6641:                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                   6642:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   6643:                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
                   6644:     foreach my $type (@coursetypes) {
                   6645:         $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
                   6646:                    $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
                   6647:                    ('&nbsp;'x2);
                   6648:     }
1.392     raeburn  6649:     $output .= '</span><br /><br />'.
                   6650:                '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').':&nbsp;'.
                   6651:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
                   6652:                $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6653:                '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
                   6654:                $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6655:                '</fieldset>'.
1.391     raeburn  6656:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
                   6657:     foreach my $ltirole (@lticourseroles) {
                   6658:         my ($selected,$selectnone);
                   6659:         if ($rolemaps{$ltirole} eq '') {
                   6660:             $selectnone = ' selected="selected"';
                   6661:         }
                   6662:         $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
                   6663:                    '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
                   6664:                    '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   6665:         foreach my $role (@courseroles) {
                   6666:             unless ($selectnone) {
                   6667:                 if ($rolemaps{$ltirole} eq $role) {
                   6668:                     $selected = ' selected="selected"';
                   6669:                 } else {
                   6670:                     $selected = '';
                   6671:                 }
                   6672:             }
                   6673:             $output .= '<option value="'.$role.'"'.$selected.'>'.
                   6674:                        &Apache::lonnet::plaintext($role,'Course').
                   6675:                        '</option>';
                   6676:         }
                   6677:         $output .= '</select></td>';
                   6678:     }
                   6679:     $output .= '</tr></table></fieldset>'.
                   6680:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320     raeburn  6681:                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                   6682:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                   6683:                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6684:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                   6685:                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   6686:                '</fieldset>'.
1.391     raeburn  6687:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320     raeburn  6688:     foreach my $lticrsrole (@lticourseroles) {
                   6689:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                   6690:                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
                   6691:     }
                   6692:     $output .= '</fieldset>'.
1.391     raeburn  6693:                '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320     raeburn  6694:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                   6695:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                   6696:                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   6697:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334     raeburn  6698:                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320     raeburn  6699:                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                   6700:                '<span class="LC_nobreak">'.&mt('From').':<label>'.
                   6701:                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
                   6702:                $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
                   6703:                &mt('Standard field').'</label>'.('&nbsp;'x2).
                   6704:                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                   6705:                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334     raeburn  6706:                '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320     raeburn  6707:                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337     raeburn  6708:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
                   6709:     my ($pb1p1chk,$pb1p0chk,$onclickpb);
                   6710:     foreach my $extra ('roster','passback') {
1.320     raeburn  6711:         my $checkedon = '';
                   6712:         my $checkedoff = ' checked="checked"';
1.337     raeburn  6713:         if ($extra eq 'passback') {
                   6714:             $pb1p1chk = ' checked="checked"';
                   6715:             $pb1p0chk = '';
                   6716:             $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"'; 
                   6717:         } else {
                   6718:             $onclickpb = ''; 
                   6719:         }
1.320     raeburn  6720:         if (ref($current) eq 'HASH') {
                   6721:             if (($current->{$extra})) {
                   6722:                 $checkedon = $checkedoff;
                   6723:                 $checkedoff = '';
1.337     raeburn  6724:                 if ($extra eq 'passback') {
                   6725:                     $passbacksty = 'inline-block';
                   6726:                 }
                   6727:                 if ($current->{'passbackformat'} eq '1.0') {
                   6728:                     $pb1p0chk =  ' checked="checked"';
                   6729:                     $pb1p1chk = '';
                   6730:                 }
1.320     raeburn  6731:             }
                   6732:         }
                   6733:         $output .= $lt{$extra}.'&nbsp;'.
1.337     raeburn  6734:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320     raeburn  6735:                    &mt('No').'</label>'.('&nbsp;'x2).
1.339     raeburn  6736:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320     raeburn  6737:                    &mt('Yes').'</label><br />';
                   6738:     }
1.337     raeburn  6739:     $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                   6740:                '<span class="LC_nobreak">'.&mt('Grade format').
                   6741:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                   6742:                &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                   6743:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363     raeburn  6744:                &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391     raeburn  6745:                '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334     raeburn  6746:     $output .= '</span></div></fieldset>';
1.320     raeburn  6747: #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
                   6748: #
                   6749: #    $output .= '</fieldset>'.
                   6750: #        '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
                   6751:     return $output;
                   6752: }
                   6753: 
1.326     raeburn  6754: sub ltimenu_titles {
                   6755:     return &Apache::lonlocal::texthash(
                   6756:                                         fullname    => 'Full name',
                   6757:                                         coursetitle => 'Course title',
                   6758:                                         role        => 'Role',
                   6759:                                         logout      => 'Logout',
                   6760:                                         grades      => 'Grades',
                   6761:     );
                   6762: }
                   6763: 
1.121     raeburn  6764: sub print_coursedefaults {
1.139     raeburn  6765:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  6766:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  6767:     my $itemcount = 1;
1.192     raeburn  6768:     my %choices =  &Apache::lonlocal::texthash (
                   6769:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  6770:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  6771:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   6772:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  6773:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   6774:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314     raeburn  6775:         texengine            => 'Default method to display mathematics',
1.257     raeburn  6776:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  6777:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   6778:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192     raeburn  6779:     );
1.198     raeburn  6780:     my %staticdefaults = (
                   6781:                            anonsurvey_threshold => 10,
                   6782:                            uploadquota          => 500,
1.257     raeburn  6783:                            postsubmit           => 60,
1.276     raeburn  6784:                            mysqltables          => 172800,
1.198     raeburn  6785:                          );
1.139     raeburn  6786:     if ($position eq 'top') {
1.257     raeburn  6787:         %defaultchecked = (
                   6788:                             'canuse_pdfforms' => 'off',
                   6789:                             'uselcmath'       => 'on',
                   6790:                             'usejsme'         => 'on',
1.289     raeburn  6791:                             'canclone'        => 'none',
1.257     raeburn  6792:                           );
                   6793:         @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349     raeburn  6794:         my $deftex = $Apache::lonnet::deftex;
1.314     raeburn  6795:         if (ref($settings) eq 'HASH') {
                   6796:             if ($settings->{'texengine'}) {
                   6797:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   6798:                     $deftex = $settings->{'texengine'};
                   6799:                 }
                   6800:             }
                   6801:         }
                   6802:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6803:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   6804:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   6805:                        '</span></td><td class="LC_right_item">'.
                   6806:                        '<select name="texengine">'."\n";
                   6807:         my %texoptions = (
                   6808:                             MathJax  => 'MathJax',
                   6809:                             mimetex  => &mt('Convert to Images'),
                   6810:                             tth      => &mt('TeX to HTML'),
                   6811:                          );
                   6812:         foreach my $renderer ('MathJax','mimetex','tth') {
                   6813:             my $selected = '';
                   6814:             if ($renderer eq $deftex) {
                   6815:                 $selected = ' selected="selected"';
                   6816:             }
                   6817:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   6818:         }
                   6819:         $mathdisp .= '</select></td></tr>'."\n";
                   6820:         $itemcount ++;
1.139     raeburn  6821:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  6822:                                                      \%choices,$itemcount);
1.314     raeburn  6823:         $datatable = $mathdisp.$datatable;
1.264     raeburn  6824:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6825:         $datatable .=
1.306     raeburn  6826:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  6827:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   6828:             '</span></td><td class="LC_left_item">';
                   6829:         my $currcanclone = 'none';
                   6830:         my $onclick;
                   6831:         my @cloneoptions = ('none','domain');
1.380     raeburn  6832:         my %clonetitles = &Apache::lonlocal::texthash (
1.264     raeburn  6833:                              none     => 'No additional course requesters',
                   6834:                              domain   => "Any course requester in course's domain",
                   6835:                              instcode => 'Course requests for official courses ...',
                   6836:                           );
                   6837:         my (%codedefaults,@code_order,@posscodes);
                   6838:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   6839:                                                     \@code_order) eq 'ok') {
                   6840:             if (@code_order > 0) {
                   6841:                 push(@cloneoptions,'instcode');
                   6842:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   6843:             }
                   6844:         }
                   6845:         if (ref($settings) eq 'HASH') {
                   6846:             if ($settings->{'canclone'}) {
                   6847:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   6848:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   6849:                         if (@code_order > 0) {
                   6850:                             $currcanclone = 'instcode';
                   6851:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   6852:                         }
                   6853:                     }
                   6854:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   6855:                     $currcanclone = $settings->{'canclone'};
                   6856:                 }
                   6857:             }
1.289     raeburn  6858:         }
1.264     raeburn  6859:         foreach my $option (@cloneoptions) {
                   6860:             my ($checked,$additional);
                   6861:             if ($currcanclone eq $option) {
                   6862:                 $checked = ' checked="checked"';
                   6863:             }
                   6864:             if ($option eq 'instcode') {
                   6865:                 if (@code_order) {
                   6866:                     my $show = 'none';
                   6867:                     if ($checked) {
                   6868:                         $show = 'block';
                   6869:                     }
1.317     raeburn  6870:                     $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264     raeburn  6871:                                   &mt('Institutional codes for new and cloned course have identical:').
                   6872:                                   '<br />';
                   6873:                     foreach my $item (@code_order) {
                   6874:                         my $codechk;
                   6875:                         if ($checked) {
                   6876:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   6877:                                 $codechk = ' checked="checked"';
                   6878:                             }
                   6879:                         }
                   6880:                         $additional .= '<label>'.
                   6881:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   6882:                                        $item.'</label>';
                   6883:                     }
                   6884:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   6885:                 }
                   6886:             }
                   6887:             $datatable .=
                   6888:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   6889:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   6890:                 '</label>&nbsp;'.$additional.'</span><br />';
                   6891:         }
                   6892:         $datatable .= '</td>'.
                   6893:                       '</tr>';
                   6894:         $itemcount ++;
1.139     raeburn  6895:     } else {
                   6896:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  6897:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  6898:         my $currusecredits = 0;
1.257     raeburn  6899:         my $postsubmitclient = 1;
1.271     raeburn  6900:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  6901:         if (ref($settings) eq 'HASH') {
                   6902:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  6903:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   6904:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   6905:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   6906:                 }
                   6907:             }
1.192     raeburn  6908:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  6909:                 foreach my $type (@types) {
                   6910:                     next if ($type eq 'community');
                   6911:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   6912:                     if ($defcredits{$type} ne '') {
                   6913:                         $currusecredits = 1;
                   6914:                     }
                   6915:                 }
                   6916:             }
                   6917:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   6918:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   6919:                     $postsubmitclient = 0;
                   6920:                     foreach my $type (@types) {
                   6921:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   6922:                     }
                   6923:                 } else {
                   6924:                     foreach my $type (@types) {
                   6925:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   6926:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  6927:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  6928:                             } else {
                   6929:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   6930:                             }
                   6931:                         } else {
                   6932:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   6933:                         }
                   6934:                     }
                   6935:                 }
                   6936:             } else {
                   6937:                 foreach my $type (@types) {
                   6938:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  6939:                 }
                   6940:             }
1.276     raeburn  6941:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   6942:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   6943:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   6944:                 }
                   6945:             } else {
                   6946:                 foreach my $type (@types) {
                   6947:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   6948:                 }
                   6949:             }
1.258     raeburn  6950:         } else {
                   6951:             foreach my $type (@types) {
                   6952:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   6953:             }
1.139     raeburn  6954:         }
                   6955:         if (!$currdefresponder) {
1.198     raeburn  6956:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  6957:         } elsif ($currdefresponder < 1) {
                   6958:             $currdefresponder = 1;
                   6959:         }
1.198     raeburn  6960:         foreach my $type (@types) {
                   6961:             if ($curruploadquota{$type} eq '') {
                   6962:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   6963:             }
                   6964:         }
1.139     raeburn  6965:         $datatable .=
1.192     raeburn  6966:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   6967:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  6968:                 '</span></td>'.
                   6969:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6970:                 '<input type="text" name="anonsurvey_threshold"'.
                   6971:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  6972:                 '</td></tr>'."\n";
                   6973:         $itemcount ++;
                   6974:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6975:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   6976:                       $choices{'uploadquota'}.
                   6977:                       '</span></td>'.
1.306     raeburn  6978:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  6979:                       '<table><tr>';
1.198     raeburn  6980:         foreach my $type (@types) {
1.306     raeburn  6981:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  6982:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   6983:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   6984:         }
                   6985:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  6986:         $itemcount ++;
1.236     raeburn  6987:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  6988:         my $display = 'none';
1.192     raeburn  6989:         if ($currusecredits) {
                   6990:             $display = 'block';
                   6991:         }
                   6992:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  6993:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   6994:         foreach my $type (@types) {
                   6995:             next if ($type eq 'community');
1.306     raeburn  6996:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  6997:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  6998:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  6999:         }
                   7000:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  7001:         %defaultchecked = ('coursecredits' => 'off');
                   7002:         @toggles = ('coursecredits');
                   7003:         my $current = {
                   7004:                         'coursecredits' => $currusecredits,
                   7005:                       };
                   7006:         (my $table,$itemcount) =
                   7007:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  7008:                                \%choices,$itemcount,$onclick,$additional,'left');
                   7009:         $datatable .= $table;
                   7010:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   7011:         my $display = 'none';
                   7012:         if ($postsubmitclient) {
                   7013:             $display = 'block';
                   7014:         }
                   7015:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  7016:                       &mt('Number of seconds submit is disabled').'<br />'.
                   7017:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   7018:                       '<table><tr>';
1.257     raeburn  7019:         foreach my $type (@types) {
1.306     raeburn  7020:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  7021:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   7022:                            $deftimeout{$type}.'" size="5" /></td>';
                   7023:         }
                   7024:         $additional .= '</tr></table></div>'."\n";
                   7025:         %defaultchecked = ('postsubmit' => 'on');
                   7026:         @toggles = ('postsubmit');
1.280     raeburn  7027:         $current = {
                   7028:                        'postsubmit' => $postsubmitclient,
                   7029:                    };
1.257     raeburn  7030:         ($table,$itemcount) =
                   7031:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   7032:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  7033:         $datatable .= $table;
1.276     raeburn  7034:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7035:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7036:                       $choices{'mysqltables'}.
                   7037:                       '</span></td>'.
1.306     raeburn  7038:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  7039:                       '<table><tr>';
                   7040:         foreach my $type (@types) {
1.306     raeburn  7041:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  7042:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  7043:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  7044:         }
                   7045:         $datatable .= '</tr></table></td></tr>'."\n";
                   7046:         $itemcount ++;
                   7047: 
1.139     raeburn  7048:     }
1.192     raeburn  7049:     $$rowtotal += $itemcount;
1.121     raeburn  7050:     return $datatable;
1.118     jms      7051: }
                   7052: 
1.231     raeburn  7053: sub print_selfenrollment {
                   7054:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7055:     my ($css_class,$datatable);
                   7056:     my $itemcount = 1;
1.271     raeburn  7057:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  7058:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  7059:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   7060:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  7061:         my @rows;
                   7062:         my $key;
                   7063:         if ($position eq 'top') {
                   7064:             $key = 'admin'; 
                   7065:             if (ref($rowsref) eq 'ARRAY') {
                   7066:                 @rows = @{$rowsref};
                   7067:             }
                   7068:         } elsif ($position eq 'middle') {
                   7069:             $key = 'default';
                   7070:             @rows = ('types','registered','approval','limit');
                   7071:         }
                   7072:         foreach my $row (@rows) {
                   7073:             if (defined($titlesref->{$row})) {
                   7074:                 $itemcount ++;
                   7075:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7076:                 $datatable .= '<tr'.$css_class.'>'.
                   7077:                               '<td>'.$titlesref->{$row}.'</td>'.
                   7078:                               '<td class="LC_left_item">'.
                   7079:                               '<table><tr>';
                   7080:                 my (%current,%currentcap);
                   7081:                 if (ref($settings) eq 'HASH') {
                   7082:                     if (ref($settings->{$key}) eq 'HASH') {
                   7083:                         foreach my $type (@types) {
                   7084:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7085:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   7086:                             }
                   7087:                             if (($row eq 'limit') && ($key eq 'default')) {
                   7088:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   7089:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   7090:                                 }
                   7091:                             }
                   7092:                         }
                   7093:                     }
                   7094:                 }
                   7095:                 my %roles = (
                   7096:                              '0' => &Apache::lonnet::plaintext('dc'),
                   7097:                             ); 
                   7098:             
                   7099:                 foreach my $type (@types) {
                   7100:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   7101:                         $datatable .= '<th>'.&mt($type).'</th>';
                   7102:                     }
                   7103:                 }
                   7104:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   7105:                     $datatable .= '</tr><tr>';
                   7106:                 }
                   7107:                 foreach my $type (@types) {
                   7108:                     if ($type eq 'community') {
                   7109:                         $roles{'1'} = &mt('Community personnel');
                   7110:                     } else {
                   7111:                         $roles{'1'} = &mt('Course personnel');
                   7112:                     }
                   7113:                     $datatable .= '<td style="vertical-align: top">';
                   7114:                     if ($position eq 'top') {
                   7115:                         my %checked;
                   7116:                         if ($current{$type} eq '0') {
                   7117:                             $checked{'0'} = ' checked="checked"';
                   7118:                         } else {
                   7119:                             $checked{'1'} = ' checked="checked"';
                   7120:                         }
                   7121:                         foreach my $role ('1','0') {
                   7122:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7123:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   7124:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   7125:                                           $roles{$role}.'</label></span> ';
                   7126:                         }
                   7127:                     } else {
                   7128:                         if ($row eq 'types') {
                   7129:                             my %checked;
                   7130:                             if ($current{$type} =~ /^(all|dom)$/) {
                   7131:                                 $checked{$1} = ' checked="checked"';
                   7132:                             } else {
                   7133:                                 $checked{''} = ' checked="checked"';
                   7134:                             }
                   7135:                             foreach my $val ('','dom','all') {
                   7136:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7137:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7138:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7139:                             }
                   7140:                         } elsif ($row eq 'registered') {
                   7141:                             my %checked;
                   7142:                             if ($current{$type} eq '1') {
                   7143:                                 $checked{'1'} = ' checked="checked"';
                   7144:                             } else {
                   7145:                                 $checked{'0'} = ' checked="checked"';
                   7146:                             }
                   7147:                             foreach my $val ('0','1') {
                   7148:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7149:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7150:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7151:                             }
                   7152:                         } elsif ($row eq 'approval') {
                   7153:                             my %checked;
                   7154:                             if ($current{$type} =~ /^([12])$/) {
                   7155:                                 $checked{$1} = ' checked="checked"';
                   7156:                             } else {
                   7157:                                 $checked{'0'} = ' checked="checked"';
                   7158:                             }
                   7159:                             for my $val (0..2) {
                   7160:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7161:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7162:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7163:                             }
                   7164:                         } elsif ($row eq 'limit') {
                   7165:                             my %checked;
                   7166:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   7167:                                 $checked{$1} = ' checked="checked"';
                   7168:                             } else {
                   7169:                                 $checked{'none'} = ' checked="checked"';
                   7170:                             }
                   7171:                             my $cap;
                   7172:                             if ($currentcap{$type} =~ /^\d+$/) {
                   7173:                                 $cap = $currentcap{$type};
                   7174:                             }
                   7175:                             foreach my $val ('none','allstudents','selfenrolled') {
                   7176:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7177:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   7178:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   7179:                             }
                   7180:                             $datatable .= '<br />'.
                   7181:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   7182:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   7183:                                           '</span>'; 
                   7184:                         }
                   7185:                     }
                   7186:                     $datatable .= '</td>';
                   7187:                 }
                   7188:                 $datatable .= '</tr>';
                   7189:             }
                   7190:             $datatable .= '</table></td></tr>';
                   7191:         }
                   7192:     } elsif ($position eq 'bottom') {
1.235     raeburn  7193:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   7194:     }
                   7195:     $$rowtotal += $itemcount;
                   7196:     return $datatable;
                   7197: }
                   7198: 
                   7199: sub print_validation_rows {
                   7200:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   7201:     my ($itemsref,$namesref,$fieldsref);
                   7202:     if ($caller eq 'selfenroll') { 
                   7203:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   7204:     } elsif ($caller eq 'requestcourses') {
                   7205:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   7206:     }
                   7207:     my %currvalidation;
                   7208:     if (ref($settings) eq 'HASH') {
                   7209:         if (ref($settings->{'validation'}) eq 'HASH') {
                   7210:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  7211:         }
1.235     raeburn  7212:     }
                   7213:     my $datatable;
                   7214:     my $itemcount = 0;
                   7215:     foreach my $item (@{$itemsref}) {
                   7216:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7217:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   7218:                       $namesref->{$item}.
                   7219:                       '</span></td>'.
                   7220:                       '<td class="LC_left_item">';
                   7221:         if (($item eq 'url') || ($item eq 'button')) {
                   7222:             $datatable .= '<span class="LC_nobreak">'.
                   7223:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   7224:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   7225:         } elsif ($item eq 'fields') {
                   7226:             my @currfields;
                   7227:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   7228:                 @currfields = @{$currvalidation{$item}};
                   7229:             }
                   7230:             foreach my $field (@{$fieldsref}) {
                   7231:                 my $check = '';
                   7232:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   7233:                     $check = ' checked="checked"';
                   7234:                 }
                   7235:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7236:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   7237:                               ' value="'.$field.'"'.$check.' />'.$field.
                   7238:                               '</label></span> ';
                   7239:             }
                   7240:         } elsif ($item eq 'markup') {
1.334     raeburn  7241:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235     raeburn  7242:                            $currvalidation{$item}.
1.231     raeburn  7243:                               '</textarea>';
1.235     raeburn  7244:         }
                   7245:         $datatable .= '</td></tr>'."\n";
                   7246:         if (ref($rowtotal)) {
1.231     raeburn  7247:             $itemcount ++;
                   7248:         }
                   7249:     }
1.235     raeburn  7250:     if ($caller eq 'requestcourses') {
                   7251:         my %currhash;
1.248     raeburn  7252:         if (ref($settings) eq 'HASH') {
                   7253:             if (ref($settings->{'validation'}) eq 'HASH') {
                   7254:                 if ($settings->{'validation'}{'dc'} ne '') {
                   7255:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   7256:                 }
1.235     raeburn  7257:             }
                   7258:         }
                   7259:         my $numinrow = 2;
                   7260:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   7261:                                                        'validationdc',%currhash);
1.247     raeburn  7262:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334     raeburn  7263:         $datatable .= '<tr'.$css_class.'><td>';
1.235     raeburn  7264:         if ($numdc > 1) {
1.247     raeburn  7265:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  7266:         } else {
1.247     raeburn  7267:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  7268:         }
1.247     raeburn  7269:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  7270:         $itemcount ++;
                   7271:     }
                   7272:     if (ref($rowtotal)) {
                   7273:         $$rowtotal += $itemcount;
                   7274:     }
1.231     raeburn  7275:     return $datatable;
                   7276: }
                   7277: 
1.357     raeburn  7278: sub print_privacy {
                   7279:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7280:     my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
                   7281:     my $itemcount = 0;
                   7282:     unless ($position eq 'top') {
                   7283:         @items = ('domain','author','course','community');
                   7284:         %names = &Apache::lonlocal::texthash (
                   7285:                      domain => 'Assigned domain role(s)',
                   7286:                      author => 'Assigned co-author role(s)',
                   7287:                      course => 'Assigned course role(s)',
                   7288:                      community => 'Assigned community role',
                   7289:                  );
                   7290:         $numinrow = 4;
                   7291:         ($othertitle,$usertypes,$types) =
                   7292:             &Apache::loncommon::sorted_inst_types($dom);
                   7293:     }
                   7294:     if (($position eq 'top') || ($position eq 'middle')) {
                   7295:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   7296:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   7297:         if ($position eq 'top') {
                   7298:             my %curr;
                   7299:             my @options = ('none','user','domain','auto');
                   7300:             my %titles = &Apache::lonlocal::texthash (
                   7301:                 none   => 'Not allowed',
                   7302:                 user   => 'User authorizes',
                   7303:                 domain => 'DC authorizes',
                   7304:                 auto   => 'Unrestricted',
                   7305:                 instdom => 'Other domain shares institution/provider',
                   7306:                 extdom => 'Other domain has different institution/provider',
                   7307:             );
                   7308:             my %names = &Apache::lonlocal::texthash (
                   7309:                 domain => 'Domain role',
                   7310:                 author => 'Co-author role',
                   7311:                 course => 'Course role',
                   7312:                 community => 'Community role',
                   7313:             );
                   7314:             my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7315:             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7316:             foreach my $domtype ('instdom','extdom') {
                   7317:                 my (%checked,$skip);
                   7318:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7319:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                   7320:                               '<td class="LC_left_item">';
                   7321:                 if ($domtype eq 'instdom') {
                   7322:                     unless (@instdoms > 1) {
                   7323:                         $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                   7324:                         $skip = 1;
                   7325:                     }
                   7326:                 } elsif ($domtype eq 'extdom') {
                   7327:                     if (keys(%by_location) == 0) {
                   7328:                         $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                   7329:                         $skip = 1;
                   7330:                     }
                   7331:                 }
                   7332:                 unless ($skip) {
                   7333:                     foreach my $roletype ('domain','author','course','community') {
                   7334:                         $checked{'auto'} = ' checked="checked"';
                   7335:                         if (ref($settings) eq 'HASH') {
                   7336:                             if (ref($settings->{approval}) eq 'HASH') {
                   7337:                                 if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                   7338:                                     if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                   7339:                                         $checked{$1} = ' checked="checked"';
                   7340:                                         $checked{'auto'} = '';
                   7341:                                     }
                   7342:                                 }
                   7343:                             }
                   7344:                         }
                   7345:                         $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                   7346:                         foreach my $option (@options) {
                   7347:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   7348:                                           '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                   7349:                                           'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   7350:                                           '</label></span>&nbsp; ';
                   7351:                         }
                   7352:                         $datatable .= '</fieldset>';
                   7353:                     }
                   7354:                 }
                   7355:                 $datatable .= '</td></tr>';
                   7356:                 $itemcount ++;
                   7357:             }
                   7358:         } elsif ($position eq 'middle') {
                   7359:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   7360:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7361:                     foreach my $item (@{$types}) {
                   7362:                         $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                   7363:                                                                $numinrow,$itemcount,'','','','','',
                   7364:                                                                '',$usertypes->{$item});
                   7365:                         $itemcount ++;
                   7366:                     }
                   7367:                 }
                   7368:                 $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                   7369:                                                        $numinrow,$itemcount,'','','','','',
                   7370:                                                        '',$othertitle);
                   7371:                 $itemcount ++;
                   7372:             } else {
1.360     raeburn  7373:                 my (@insttypes,%insttitles);
                   7374:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7375:                     @insttypes = @{$types};
                   7376:                     %insttitles = %{$usertypes};
                   7377:                 }
                   7378:                 foreach my $item (@insttypes,'default') {
                   7379:                     my $title;
                   7380:                     if ($item eq 'default') {
                   7381:                         $title = $othertitle;
                   7382:                     } else {
                   7383:                         $title = $insttitles{$item};
                   7384:                     }
                   7385:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7386:                     $datatable .= '<tr'.$css_class.'>'.
                   7387:                                   '<td class="LC_left_item">'.$title.'</td>'.
                   7388:                                   '<td class="LC_left_item">'.
                   7389:                                   &mt('Nothing to set here, as there are no other domains').
                   7390:                                   '</td></tr>';
                   7391:                     $itemcount ++;
                   7392:                 }
1.357     raeburn  7393:             }
                   7394:         }
                   7395:     } else {
                   7396:         my $prefix;
                   7397:         if ($position eq 'lower') {
                   7398:             $prefix = 'priv';
                   7399:         } else {
                   7400:             $prefix = 'unpriv';
                   7401:         }
                   7402:         foreach my $item (@items) {
                   7403:             $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                   7404:                                                    $numinrow,$itemcount,'','','','','',
                   7405:                                                    '',$names{$item});
                   7406:             $itemcount ++;
                   7407:         }
                   7408:     }
                   7409:     if (ref($rowtotal)) {
                   7410:         $$rowtotal += $itemcount;
                   7411:     }
                   7412:     return $datatable;
                   7413: }
                   7414: 
1.354     raeburn  7415: sub print_passwords {
                   7416:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   7417:     my ($datatable,$css_class);
                   7418:     my $itemcount = 0;
                   7419:     my %titles = &Apache::lonlocal::texthash (
                   7420:         captcha        => '"Forgot Password" CAPTCHA validation',
                   7421:         link           => 'Reset link expiration (hours)',
                   7422:         case           => 'Case-sensitive usernames/e-mail',
                   7423:         prelink        => 'Information required (form 1)',
                   7424:         postlink       => 'Information required (form 2)',
                   7425:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   7426:         customtext     => 'Domain specific text (HTML)',
                   7427:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   7428:         intauth_check  => 'Check bcrypt cost if authenticated',
                   7429:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   7430:         permanent      => 'Permanent e-mail address',
                   7431:         critical       => 'Critical notification address',
                   7432:         notify         => 'Notification address',
                   7433:         min            => 'Minimum password length',
                   7434:         max            => 'Maximum password length',
                   7435:         chars          => 'Required characters',
                   7436:         expire         => 'Password expiration (days)',
1.356     raeburn  7437:         numsaved       => 'Number of previous passwords to save and disallow reuse',
1.354     raeburn  7438:     );
                   7439:     if ($position eq 'top') {
                   7440:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7441:         my $shownlinklife = 2;
                   7442:         my $prelink = 'both';
                   7443:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   7444:         if (ref($settings) eq 'HASH') {
                   7445:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   7446:                 $shownlinklife = $settings->{resetlink};
                   7447:             }
                   7448:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   7449:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   7450:             }
                   7451:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   7452:                 $prelink = $settings->{resetprelink};
                   7453:             }
                   7454:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   7455:                 %postlink = %{$settings->{resetpostlink}};
                   7456:             }
                   7457:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   7458:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   7459:             }
                   7460:             if ($settings->{resetremove}) {
                   7461:                 $nostdtext = 1;
                   7462:             }
                   7463:             if ($settings->{resetcustom}) {
                   7464:                 $customurl = $settings->{resetcustom};
                   7465:             }
                   7466:         } else {
                   7467:             if (ref($types) eq 'ARRAY') {
                   7468:                 foreach my $item (@{$types}) {
                   7469:                     $casesens{$item} = 1;
                   7470:                     $postlink{$item} = ['username','email'];
                   7471:                 }
                   7472:             }
                   7473:             $casesens{'default'} = 1;
                   7474:             $postlink{'default'} = ['username','email'];
                   7475:             $prelink = 'both';
                   7476:             %emailsrc = (
                   7477:                           permanent => 1,
                   7478:                           critical  => 1,
                   7479:                           notify    => 1,
                   7480:             );
                   7481:         }
                   7482:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   7483:         $itemcount ++;
                   7484:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7485:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   7486:                       '<td class="LC_left_item">'.
                   7487:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   7488:                       'name="passwords_link" size="3" /></td></tr>';
                   7489:         $itemcount ++;
                   7490:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7491:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   7492:                       '<td class="LC_left_item">';
                   7493:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7494:             foreach my $item (@{$types}) {
                   7495:                 my $checkedcase;
                   7496:                 if ($casesens{$item}) {
                   7497:                     $checkedcase = ' checked="checked"';
                   7498:                 }
                   7499:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7500:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   7501:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369     raeburn  7502:                               '</span>&nbsp;&nbsp; ';
1.354     raeburn  7503:             }
                   7504:         }
                   7505:         my $checkedcase;
                   7506:         if ($casesens{'default'}) {
                   7507:             $checkedcase = ' checked="checked"';
                   7508:         }
                   7509:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   7510:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   7511:                       $othertitle.'</label></span></td>';
                   7512:         $itemcount ++;
                   7513:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7514:         my %checkedpre = (
                   7515:                              both => ' checked="checked"',
                   7516:                              either => '',
                   7517:                          );
                   7518:         if ($prelink eq 'either') {
                   7519:             $checkedpre{either} = ' checked="checked"';
                   7520:             $checkedpre{both} = '';
                   7521:         }
                   7522:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   7523:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   7524:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   7525:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   7526:                       '<span class="LC_nobreak"><label>'.
                   7527:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   7528:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   7529:         $itemcount ++;
                   7530:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7531:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   7532:                       '<td class="LC_left_item">';
                   7533:         my %postlinked;
                   7534:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7535:             foreach my $item (@{$types}) {
                   7536:                 undef(%postlinked);
                   7537:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   7538:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   7539:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   7540:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   7541:                 }
                   7542:                 foreach my $field ('email','username') {
                   7543:                     my $checked;
                   7544:                     if ($postlinked{$field}) {
                   7545:                         $checked = ' checked="checked"';
                   7546:                     }
                   7547:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   7548:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   7549:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   7550:                                   '<span>&nbsp;&nbsp; ';
                   7551:                 }
                   7552:                 $datatable .= '</fieldset>';
                   7553:             }
                   7554:         }
                   7555:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   7556:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   7557:         }
                   7558:         $datatable .= '<fieldset style="display: inline-block;">'.
                   7559:                       '<legend>'.$othertitle.'</legend>';
                   7560:         foreach my $field ('email','username') {
                   7561:             my $checked;
                   7562:             if ($postlinked{$field}) {
                   7563:                 $checked = ' checked="checked"';
                   7564:             }
                   7565:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7566:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   7567:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   7568:                           '<span>&nbsp;&nbsp; ';
                   7569:         }
                   7570:         $datatable .= '</fieldset></td></tr>';
                   7571:         $itemcount ++;
                   7572:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7573:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   7574:                       '<td class="LC_left_item">';
                   7575:         foreach my $type ('permanent','critical','notify') {
                   7576:             my $checkedemail;
                   7577:             if ($emailsrc{$type}) {
                   7578:                 $checkedemail = ' checked="checked"';
                   7579:             }
                   7580:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7581:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   7582:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   7583:                           '<span>&nbsp;&nbsp; ';
                   7584:         }
                   7585:         $datatable .= '</td></tr>';
                   7586:         $itemcount ++;
                   7587:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7588:         my $switchserver = &check_switchserver($dom,$confname);
                   7589:         my ($showstd,$noshowstd);
                   7590:         if ($nostdtext) {
                   7591:             $noshowstd = ' checked="checked"';
                   7592:         } else {
                   7593:             $showstd = ' checked="checked"';
                   7594:         }
                   7595:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   7596:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   7597:                       &mt('Retain standard text:').
                   7598:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   7599:                       &mt('Yes').'</label>'.'&nbsp;'.
                   7600:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   7601:                       &mt('No').'</label></span><br />'.
                   7602:                       '<span class="LC_fontsize_small">'.
                   7603:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   7604:                       &mt('Include custom text:');
                   7605:         if ($customurl) {
1.369     raeburn  7606:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354     raeburn  7607:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   7608:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   7609:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   7610:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   7611:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   7612:         }
                   7613:         if ($switchserver) {
                   7614:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   7615:         } else {
                   7616:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   7617:                          '<input type="file" name="passwords_customfile" /></span>';
                   7618:         }
                   7619:         $datatable .= '</td></tr>';
                   7620:     } elsif ($position eq 'middle') {
                   7621:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   7622:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   7623:         my %defaults;
                   7624:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   7625:             %defaults = %{$domconf{'defaults'}};
                   7626:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   7627:                 $defaults{'intauth_cost'} = 10;
                   7628:             }
                   7629:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   7630:                 $defaults{'intauth_check'} = 0;
                   7631:             }
                   7632:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   7633:                 $defaults{'intauth_switch'} = 0;
                   7634:             }
                   7635:         } else {
                   7636:             %defaults = (
                   7637:                           'intauth_cost'   => 10,
                   7638:                           'intauth_check'  => 0,
                   7639:                           'intauth_switch' => 0,
                   7640:                         );
                   7641:         }
                   7642:         foreach my $item (@items) {
                   7643:             if ($itemcount%2) {
                   7644:                 $css_class = '';
                   7645:             } else {
                   7646:                 $css_class = ' class="LC_odd_row" ';
                   7647:             }
                   7648:             $datatable .= '<tr'.$css_class.'>'.
                   7649:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   7650:                           '</span></td><td class="LC_left_item" colspan="3">';
                   7651:             if ($item eq 'intauth_switch') {
                   7652:                 my @options = (0,1,2);
                   7653:                 my %optiondesc = &Apache::lonlocal::texthash (
                   7654:                                    0 => 'No',
                   7655:                                    1 => 'Yes',
                   7656:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   7657:                                  );
                   7658:                 $datatable .= '<table width="100%">';
                   7659:                 foreach my $option (@options) {
                   7660:                     my $checked = ' ';
                   7661:                     if ($defaults{$item} eq $option) {
                   7662:                         $checked = ' checked="checked"';
                   7663:                     }
                   7664:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   7665:                                   '<label><input type="radio" name="'.$item.
                   7666:                                   '" value="'.$option.'"'.$checked.' />'.
                   7667:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   7668:                 }
                   7669:                 $datatable .= '</table>';
                   7670:             } elsif ($item eq 'intauth_check') {
                   7671:                 my @options = (0,1,2);
                   7672:                 my %optiondesc = &Apache::lonlocal::texthash (
                   7673:                                    0 => 'No',
                   7674:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   7675:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   7676:                                  );
                   7677:                 $datatable .= '<table width="100%">';
                   7678:                 foreach my $option (@options) {
                   7679:                     my $checked = ' ';
                   7680:                     my $onclick;
                   7681:                     if ($defaults{$item} eq $option) {
                   7682:                         $checked = ' checked="checked"';
                   7683:                     }
                   7684:                     if ($option == 2) {
                   7685:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   7686:                     }
                   7687:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   7688:                                   '<label><input type="radio" name="'.$item.
                   7689:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   7690:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   7691:                 }
                   7692:                 $datatable .= '</table>';
                   7693:             } else {
                   7694:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   7695:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   7696:             }
                   7697:             $datatable .= '</td></tr>';
                   7698:             $itemcount ++;
                   7699:         }
                   7700:     } elsif ($position eq 'lower') {
1.356     raeburn  7701:         my ($min,$max,%chars,$expire,$numsaved);
1.365     raeburn  7702:         $min = $Apache::lonnet::passwdmin;
1.354     raeburn  7703:         if (ref($settings) eq 'HASH') {
                   7704:             if ($settings->{min}) {
                   7705:                 $min = $settings->{min};
                   7706:             }
                   7707:             if ($settings->{max}) {
                   7708:                 $max = $settings->{max};
                   7709:             }
                   7710:             if (ref($settings->{chars}) eq 'ARRAY') {
                   7711:                 map { $chars{$_} = 1; } (@{$settings->{chars}});
                   7712:             }
                   7713:             if ($settings->{expire}) {
                   7714:                 $expire = $settings->{expire};
                   7715:             }
1.358     raeburn  7716:             if ($settings->{numsaved}) {
                   7717:                 $numsaved = $settings->{numsaved};
1.356     raeburn  7718:             }
1.354     raeburn  7719:         }
                   7720:         my %rulenames = &Apache::lonlocal::texthash(
                   7721:                                                      uc => 'At least one upper case letter',
                   7722:                                                      lc => 'At least one lower case letter',
                   7723:                                                      num => 'At least one number',
                   7724:                                                      spec => 'At least one non-alphanumeric',
                   7725:                                                    );
                   7726:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7727:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   7728:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7729:                       '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
                   7730:                       'onblur="javascript:warnIntPass(this);" />'.
                   7731:                       '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354     raeburn  7732:                       '</span></td></tr>';
                   7733:         $itemcount ++;
                   7734:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7735:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   7736:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7737:                       '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
                   7738:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  7739:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   7740:                       '</span></td></tr>';
                   7741:         $itemcount ++;
                   7742:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7743:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   7744:                       '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   7745:                       '</span></td>';
                   7746:         my $numinrow = 2;
                   7747:         my @possrules = ('uc','lc','num','spec');
                   7748:         $datatable .= '<td class="LC_left_item"><table>';
                   7749:         for (my $i=0; $i<@possrules; $i++) {
                   7750:             my ($rem,$checked);
                   7751:             if ($chars{$possrules[$i]}) {
                   7752:                 $checked = ' checked="checked"';
                   7753:             }
                   7754:             $rem = $i%($numinrow);
                   7755:             if ($rem == 0) {
                   7756:                 if ($i > 0) {
                   7757:                     $datatable .= '</tr>';
                   7758:                 }
                   7759:                 $datatable .= '<tr>';
                   7760:             }
                   7761:             $datatable .= '<td><span class="LC_nobreak"><label>'.
                   7762:                           '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   7763:                           $rulenames{$possrules[$i]}.'</label></span></td>';
                   7764:         }
                   7765:         my $rem = @possrules%($numinrow);
                   7766:         my $colsleft = $numinrow - $rem;
                   7767:         if ($colsleft > 1 ) {
                   7768:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7769:                           '&nbsp;</td>';
                   7770:         } elsif ($colsleft == 1) {
                   7771:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   7772:         }
                   7773:         $datatable .='</table></td></tr>';
                   7774:         $itemcount ++;
                   7775:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7776:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                   7777:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  7778:                       '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
                   7779:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  7780:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                   7781:                       '</span></td></tr>';
1.356     raeburn  7782:         $itemcount ++;
                   7783:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7784:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   7785:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367     raeburn  7786:                       '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
                   7787:                       'onblur="javascript:warnIntPass(this);" />'. 
1.356     raeburn  7788:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   7789:                       '</span></td></tr>';
1.354     raeburn  7790:     } else {
1.359     raeburn  7791:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7792:         my %ownerchg = (
                   7793:                           by  => {},
                   7794:                           for => {},
                   7795:                        );
                   7796:         my %ownertitles = &Apache::lonlocal::texthash (
                   7797:                             by  => 'Course owner status(es) allowed',
                   7798:                             for => 'Student status(es) allowed',
                   7799:                           );
1.354     raeburn  7800:         if (ref($settings) eq 'HASH') {
1.359     raeburn  7801:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   7802:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   7803:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   7804:                 }
                   7805:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   7806:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   7807:                 }
1.354     raeburn  7808:             }
                   7809:         }
                   7810:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7811:         $datatable .= '<tr '.$css_class.'>'.
                   7812:                       '<td>'.
                   7813:                       &mt('Requirements').'<ul>'.
1.359     raeburn  7814:                       '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354     raeburn  7815:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   7816:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359     raeburn  7817:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354     raeburn  7818:                       '</ul>'.
                   7819:                       '</td>'.
1.359     raeburn  7820:                       '<td class="LC_left_item">';
                   7821:         foreach my $item ('by','for') {
                   7822:             $datatable .= '<fieldset style="display: inline-block;">'.
                   7823:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   7824:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   7825:                 foreach my $type (@{$types}) {
                   7826:                     my $checked;
                   7827:                     if ($ownerchg{$item}{$type}) {
                   7828:                         $checked = ' checked="checked"';
                   7829:                     }
                   7830:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   7831:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   7832:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369     raeburn  7833:                                   '</span>&nbsp;&nbsp; ';
1.359     raeburn  7834:                 }
                   7835:             }
                   7836:             my $checked;
                   7837:             if ($ownerchg{$item}{'default'}) {
                   7838:                 $checked = ' checked="checked"';
                   7839:             }
                   7840:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   7841:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   7842:                           $othertitle.'</label></span></fieldset>';
                   7843:         }
                   7844:         $datatable .= '</td></tr>';
1.354     raeburn  7845:     }
                   7846:     return $datatable;
                   7847: }
                   7848: 
1.373     raeburn  7849: sub print_wafproxy {
                   7850:     my ($position,$dom,$settings,$rowtotal) = @_;
                   7851:     my $css_class;
                   7852:     my $itemcount = 0;
                   7853:     my $datatable;
                   7854:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  7855:     my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374     raeburn  7856:     my %lt = &wafproxy_titles();
1.373     raeburn  7857:     foreach my $server (sort(keys(%servers))) {
                   7858:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381     raeburn  7859:         next if ($serverhome eq '');
1.373     raeburn  7860:         my $serverdom;
                   7861:         if ($serverhome ne $server) {
                   7862:             $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381     raeburn  7863:             if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
                   7864:                 $othercontrol{$server} = $serverdom;
                   7865:             }
1.373     raeburn  7866:         } else {
                   7867:             $serverdom = &Apache::lonnet::host_domain($server);
1.381     raeburn  7868:             next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373     raeburn  7869:             if ($serverdom ne $dom) {
                   7870:                 $othercontrol{$server} = $serverdom;
                   7871:             } else {
                   7872:                 $setdom = 1;
                   7873:                 if (ref($settings) eq 'HASH') {
                   7874:                     if (ref($settings->{'alias'}) eq 'HASH') {
                   7875:                         $aliases{$dom} = $settings->{'alias'};
1.381     raeburn  7876:                         if ($aliases{$dom} ne '') {
                   7877:                             $showdom = 1;
                   7878:                         }
1.373     raeburn  7879:                     }
1.388     raeburn  7880:                     if (ref($settings->{'saml'}) eq 'HASH') {
                   7881:                         $saml{$dom} = $settings->{'saml'};
                   7882:                     }
1.373     raeburn  7883:                 }
                   7884:             }
                   7885:         }
                   7886:     }
1.381     raeburn  7887:     if ($setdom) {
                   7888:         %{$values{$dom}} = ();
                   7889:         if (ref($settings) eq 'HASH') {
                   7890:             foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   7891:                 $values{$dom}{$item} = $settings->{$item};
                   7892:             }
                   7893:         }
                   7894:     }
1.373     raeburn  7895:     if (keys(%othercontrol)) {
                   7896:         %otherdoms = reverse(%othercontrol);
                   7897:         foreach my $domain (keys(%otherdoms)) {
                   7898:             %{$values{$domain}} = ();
                   7899:             my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383     raeburn  7900:             if (ref($config{'wafproxy'}) eq 'HASH') {
                   7901:                 $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388     raeburn  7902:                 if (exists($config{'wafproxy'}{'saml'})) { 
                   7903:                     $saml{$domain} = $config{'wafproxy'}{'saml'};
                   7904:                 }
1.383     raeburn  7905:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   7906:                     $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373     raeburn  7907:                 }
                   7908:             }
                   7909:         }
                   7910:     }
                   7911:     if ($position eq 'top') {
                   7912:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381     raeburn  7913:         my %aliasinfo;
1.373     raeburn  7914:         foreach my $server (sort(keys(%servers))) {
1.381     raeburn  7915:             $itemcount ++;
                   7916:             my $dom_in_effect;
                   7917:             my $aliasrows = '<tr>'.
1.383     raeburn  7918:                             '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   7919:                             &mt('Hostname').':&nbsp;'.
                   7920:                             '<i>'.&Apache::lonnet::hostname($server).'</i></td><td>&nbsp;</td>';
1.373     raeburn  7921:             if ($othercontrol{$server}) {
1.381     raeburn  7922:                 $dom_in_effect = $othercontrol{$server};
1.388     raeburn  7923:                 my ($current,$forsaml);
1.383     raeburn  7924:                 if (ref($aliases{$dom_in_effect}) eq 'HASH') {
                   7925:                     $current = $aliases{$dom_in_effect}{$server};
1.373     raeburn  7926:                 }
1.388     raeburn  7927:                 if (ref($saml{$dom_in_effect}) eq 'HASH') {
                   7928:                     if ($saml{$dom_in_effect}{$server}) {
                   7929:                         $forsaml = 1;
                   7930:                     }
                   7931:                 }
1.383     raeburn  7932:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   7933:                               &mt('Alias').':&nbsp';
1.373     raeburn  7934:                 if ($current) {
1.381     raeburn  7935:                     $aliasrows .= $current;
1.388     raeburn  7936:                     if ($forsaml) {
                   7937:                          $aliasrows .= '&nbsp;('.&mt('also for Shibboleth').')';
                   7938:                     }
1.373     raeburn  7939:                 } else {
1.383     raeburn  7940:                     $aliasrows .= &mt('None');
1.373     raeburn  7941:                 }
1.383     raeburn  7942:                 $aliasrows .= '&nbsp;<span class="LC_small">('.
                   7943:                               &mt('controlled by domain: [_1]',
                   7944:                                   '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373     raeburn  7945:             } else {
1.381     raeburn  7946:                 $dom_in_effect = $dom;
1.388     raeburn  7947:                 my ($current,$samlon,$samloff);
                   7948:                 $samloff = ' checked="checked"';
1.373     raeburn  7949:                 if (ref($aliases{$dom}) eq 'HASH') {
                   7950:                     if ($aliases{$dom}{$server}) {
                   7951:                         $current = $aliases{$dom}{$server};
                   7952:                     }
                   7953:                 }
1.388     raeburn  7954:                 if (ref($saml{$dom}) eq 'HASH') {
                   7955:                     if ($saml{$dom}{$server}) {
                   7956:                         $samlon = $samloff;
                   7957:                         undef($samloff);
                   7958:                     }
                   7959:                 }
1.383     raeburn  7960:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   7961:                               &mt('Alias').':&nbsp;'.
1.381     raeburn  7962:                               '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388     raeburn  7963:                               'value="'.$current.'" size="30" />'.
                   7964:                               ('&nbsp;'x2).'<span class="LC_nobreak">'.
                   7965:                               &mt('Alias used for Shibboleth').':&nbsp;<label>'.
                   7966:                               '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
                   7967:                               &mt('No').'</label>&nbsp;<label>'. 
                   7968:                               '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
                   7969:                               &mt('Yes').'</label></span>'.
                   7970:                               '</td>'; 
1.381     raeburn  7971:             }
                   7972:             $aliasrows .= '</tr>';
                   7973:             $aliasinfo{$dom_in_effect} .= $aliasrows;
                   7974:         }
                   7975:         if ($aliasinfo{$dom}) {
                   7976:             my ($onclick,$wafon,$wafoff,$showtable);
                   7977:             $onclick = ' onclick="javascript:toggleWAF();"';
                   7978:             $wafoff = ' checked="checked"';
                   7979:             $showtable = ' style="display:none";';
                   7980:             if ($showdom) {
                   7981:                 $wafon = $wafoff;
                   7982:                 $wafoff = '';
                   7983:                 $showtable = ' style="display:inline;"';
                   7984:             }
                   7985:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   7986:             $datatable = '<tr'.$css_class.'>'.
                   7987:                          '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
                   7988:                          '<span class="LC_nobreak">'.&mt('WAF in use?').'&nbsp;<label>'.
                   7989:                          '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
                   7990:                          &mt('Yes').'</label>'.('&nbsp;'x2).'<label>'.
                   7991:                          '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
                   7992:                          &mt('No').'</label></span></td>'.
                   7993:                          '<td class="LC_left_item">'.
                   7994:                          '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
                   7995:                          '</table></td></tr>';
                   7996:             $itemcount++;
                   7997:         }
1.383     raeburn  7998:         if (keys(%otherdoms)) {
                   7999:             foreach my $key (sort(keys(%otherdoms))) {
1.381     raeburn  8000:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383     raeburn  8001:                 $datatable .= '<tr'.$css_class.'>'.
                   8002:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
                   8003:                               '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
                   8004:                               '</table></td></tr>';
1.381     raeburn  8005:                 $itemcount++;
1.373     raeburn  8006:             }
                   8007:         }
                   8008:     } else {
1.383     raeburn  8009:         my %ip_methods = &remoteip_methods();
1.373     raeburn  8010:         if ($setdom) {
                   8011:             $itemcount ++;
                   8012:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381     raeburn  8013:             my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382     raeburn  8014:                 $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381     raeburn  8015:             $wafstyle = ' style="display:none;"';
                   8016:             $nowafstyle = ' style="display:table-row;"';
                   8017:             $currwafdisplay = ' style="display: none"';
                   8018:             $wafrangestyle = ' style="display: none"';
                   8019:             $curr_remotip = 'n';
1.382     raeburn  8020:             $ssltossl = ' checked="checked"';
1.381     raeburn  8021:             if ($showdom) {
                   8022:                 $wafstyle = ' style="display:table-row;"';
                   8023:                 $nowafstyle =  ' style="display:none;"';
                   8024:                 if (keys(%{$values{$dom}})) {
                   8025:                     if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
                   8026:                         $curr_remotip = $values{$dom}{remoteip};
                   8027:                     }
                   8028:                     if ($curr_remotip eq 'h') {
                   8029:                         $currwafdisplay = ' style="display:table-row"';
                   8030:                         $wafrangestyle = ' style="display:inline-block;"';
                   8031:                     }
1.382     raeburn  8032:                     if ($values{$dom}{'sslopt'}) {
                   8033:                         $alltossl = ' checked="checked"';
                   8034:                         $ssltossl = '';
                   8035:                     }
1.381     raeburn  8036:                 }
                   8037:                 if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
                   8038:                     $vpndircheck = ' checked="checked"';
                   8039:                     $currwafvpn = ' style="display:table-row;"';
                   8040:                     $wafrangestyle = ' style="display:inline-block;"';
                   8041:                 } else {
                   8042:                     $vpnaliascheck = ' checked="checked"';
                   8043:                     $currwafvpn = ' style="display:none;"';
                   8044:                 }
                   8045:             }
                   8046:             $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                   8047:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
                   8048:                           '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
                   8049:                           '</tr>'.
                   8050:                           '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374     raeburn  8051:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381     raeburn  8052:                           '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393     raeburn  8053:                           &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   8054:                           &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381     raeburn  8055:                           '<td class="LC_left_item"><table>'.
                   8056:                           '<tr>'.
                   8057:                           '<td valign="top">'.$lt{'remoteip'}.':&nbsp;'.
                   8058:                           '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
                   8059:             foreach my $option ('m','h','n') {
                   8060:                 my $sel;
                   8061:                 if ($option eq $curr_remotip) {
                   8062:                    $sel = ' selected="selected"';
                   8063:                 }
                   8064:                 $datatable .= '<option value="'.$option.'"'.$sel.'>'.
                   8065:                               $ip_methods{$option}.'</option>';
                   8066:             }
                   8067:             $datatable .= '</select></td></tr>'."\n".
                   8068:                           '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
                   8069:                           $lt{'ipheader'}.':&nbsp;'.
                   8070:                           '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
                   8071:                           'name="wafproxy_ipheader" />'.
                   8072:                           '</td></tr>'."\n".
                   8073:                           '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382     raeburn  8074:                           $lt{'trusted'}.':<br />'.
1.381     raeburn  8075:                           '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
                   8076:                           $values{$dom}{'trusted'}.'</textarea>'.
                   8077:                           '</td></tr>'."\n".
                   8078:                           '<tr><td><hr /></td></tr>'."\n".
                   8079:                           '<tr>'.
                   8080:                           '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
                   8081:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
                   8082:                           $lt{'vpndirect'}.'</label>'.('&nbsp;'x2).
                   8083:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
                   8084:                           $lt{'vpnaliased'}.'</label></span></td></tr>';
                   8085:             foreach my $item ('vpnint','vpnext') {
                   8086:                 $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382     raeburn  8087:                               '<td valign="top">'.$lt{$item}.':<br />'.
1.381     raeburn  8088:                               '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
                   8089:                               $values{$dom}{$item}.'</textarea>'.
                   8090:                               '</td></tr>'."\n";
1.373     raeburn  8091:             }
1.382     raeburn  8092:             $datatable .= '<tr><td><hr /></td></tr>'."\n".
                   8093:                           '<tr>'.
                   8094:                           '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
                   8095:                           '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
                   8096:                           $lt{'alltossl'}.'</label>'.('&nbsp;'x2).
                   8097:                           '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
                   8098:                           $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
                   8099:                           '</table></td></tr>';
1.373     raeburn  8100:         }
                   8101:         if (keys(%otherdoms)) {
                   8102:             foreach my $domain (sort(keys(%otherdoms))) {
                   8103:                 $itemcount ++;
                   8104:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8105:                 $datatable .= '<tr'.$css_class.'>'.
1.383     raeburn  8106:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374     raeburn  8107:                               '<td class="LC_left_item"><table>';
1.382     raeburn  8108:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  8109:                     my $showval = &mt('None');
1.382     raeburn  8110:                     if ($item eq 'ssl') {
                   8111:                         $showval = $lt{'ssltossl'};
                   8112:                     }
1.373     raeburn  8113:                     if ($values{$domain}{$item}) {
1.381     raeburn  8114:                         $showval = $values{$domain}{$item};
1.382     raeburn  8115:                         if ($item eq 'ssl') {
                   8116:                             $showval = $lt{'alltossl'};
1.383     raeburn  8117:                         } elsif ($item eq 'remoteip') {
                   8118:                             $showval = $ip_methods{$values{$domain}{$item}};
1.382     raeburn  8119:                         }
1.373     raeburn  8120:                     }
                   8121:                     $datatable .= '<tr>'.
                   8122:                                   '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';
                   8123:                 }
1.381     raeburn  8124:                 $datatable .= '</table></td></tr>';
1.373     raeburn  8125:             }
                   8126:         }
                   8127:     }
                   8128:     $$rowtotal += $itemcount;
                   8129:     return $datatable;
                   8130: }
                   8131: 
                   8132: sub wafproxy_titles {
                   8133:     return &Apache::lonlocal::texthash(
1.381     raeburn  8134:                remoteip   => "Method for determining user's IP",
                   8135:                ipheader   => 'Request header containing remote IP',
                   8136:                trusted    => 'Trusted IP range(s)',
                   8137:                vpnaccess  => 'Access from institutional VPN',
                   8138:                vpndirect  => 'via regular hostname (no WAF)',
                   8139:                vpnaliased => 'via aliased hostname (WAF)',
                   8140:                vpnint     => 'Internal IP Range(s) for VPN sessions',
                   8141:                vpnext     => 'IP Range(s) for backend WAF connections',
1.382     raeburn  8142:                sslopt     => 'Forwarding http/https',
1.381     raeburn  8143:                alltossl   => 'WAF forwards both http and https requests to https',
                   8144:                ssltossl   => 'WAF forwards http requests to http and https to https',
                   8145:            );
                   8146: }
                   8147: 
                   8148: sub remoteip_methods {
                   8149:     return &Apache::lonlocal::texthash(
                   8150:               m => 'Use Apache mod_remoteip',
                   8151:               h => 'Use headers parsed by LON-CAPA',
                   8152:               n => 'Not in use',
1.373     raeburn  8153:            );
                   8154: }
                   8155: 
1.137     raeburn  8156: sub print_usersessions {
                   8157:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  8158:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  8159:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8160:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  8161: 
                   8162:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  8163:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  8164:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  8165:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  8166:     if ($position eq 'top') {
1.152     raeburn  8167:         if (keys(%serverhomes) > 1) {
1.145     raeburn  8168:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.371     raeburn  8169:             my ($curroffloadnow,$curroffloadoth);
1.261     raeburn  8170:             if (ref($settings) eq 'HASH') {
                   8171:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   8172:                     $curroffloadnow = $settings->{'offloadnow'};
                   8173:                 }
1.371     raeburn  8174:                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   8175:                     $curroffloadoth = $settings->{'offloadoth'};
                   8176:                 }
1.261     raeburn  8177:             }
1.371     raeburn  8178:             my $other_insts = scalar(keys(%by_location));
                   8179:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   8180:                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  8181:         } else {
1.140     raeburn  8182:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  8183:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   8184:                           '</td></tr>';
1.140     raeburn  8185:         }
1.137     raeburn  8186:     } else {
1.279     raeburn  8187:         my %titles = &usersession_titles();
                   8188:         my ($prefix,@types);
                   8189:         if ($position eq 'bottom') {
                   8190:             $prefix = 'remote';
                   8191:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  8192:         } else {
1.279     raeburn  8193:             $prefix = 'hosted';
                   8194:             @types = ('excludedomain','includedomain');
                   8195:         }
                   8196:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8197:     }
                   8198:     $$rowtotal += $itemcount;
                   8199:     return $datatable;
                   8200: }
                   8201: 
                   8202: sub rules_by_location {
                   8203:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   8204:     my ($datatable,$itemcount,$css_class);
                   8205:     if (keys(%{$by_location}) == 0) {
                   8206:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8207:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   8208:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   8209:                      '</td></tr>';
                   8210:         $itemcount = 1;
                   8211:     } else {
                   8212:         $itemcount = 0;
                   8213:         my $numinrow = 5;
                   8214:         my (%current,%checkedon,%checkedoff);
                   8215:         my @locations = sort(keys(%{$by_location}));
                   8216:         foreach my $type (@{$types}) {
                   8217:             $checkedon{$type} = '';
                   8218:             $checkedoff{$type} = ' checked="checked"';
                   8219:         }
                   8220:         if (ref($settings) eq 'HASH') {
                   8221:             if (ref($settings->{$prefix}) eq 'HASH') {
                   8222:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   8223:                     $current{$key} = $settings->{$prefix}{$key};
                   8224:                     if ($key eq 'version') {
                   8225:                         if ($current{$key} ne '') {
1.145     raeburn  8226:                             $checkedon{$key} = ' checked="checked"';
                   8227:                             $checkedoff{$key} = '';
                   8228:                         }
1.279     raeburn  8229:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   8230:                         $checkedon{$key} = ' checked="checked"';
                   8231:                         $checkedoff{$key} = '';
1.137     raeburn  8232:                     }
                   8233:                 }
                   8234:             }
1.279     raeburn  8235:         }
                   8236:         foreach my $type (@{$types}) {
                   8237:             next if ($type ne 'version' && !@locations);
                   8238:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8239:             $datatable .= '<tr'.$css_class.'>
                   8240:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   8241:                            <span class="LC_nobreak">&nbsp;
                   8242:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   8243:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   8244:             if ($type eq 'version') {
                   8245:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   8246:                 my $selector = '<select name="'.$prefix.'_version">';
                   8247:                 foreach my $version (@lcversions) {
                   8248:                     my $selected = '';
                   8249:                     if ($current{'version'} eq $version) {
                   8250:                         $selected = ' selected="selected"';
1.145     raeburn  8251:                     }
1.279     raeburn  8252:                     $selector .= ' <option value="'.$version.'"'.
                   8253:                                  $selected.'>'.$version.'</option>';
                   8254:                 }
                   8255:                 $selector .= '</select> ';
                   8256:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   8257:             } else {
                   8258:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   8259:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   8260:                              ' />'.('&nbsp;'x2).
                   8261:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   8262:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   8263:                              "\n".
                   8264:                              '</div><div><table>';
                   8265:                 my $rem;
                   8266:                 for (my $i=0; $i<@locations; $i++) {
                   8267:                     my ($showloc,$value,$checkedtype);
                   8268:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   8269:                         my $ip = $by_location->{$locations[$i]}->[0];
                   8270:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8271:                             $value = join(':',@{$by_ip->{$ip}});
                   8272:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   8273:                             if (ref($current{$type}) eq 'ARRAY') {
                   8274:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   8275:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   8276:                                         $checkedtype = ' checked="checked"';
                   8277:                                         last;
1.145     raeburn  8278:                                     }
1.138     raeburn  8279:                                 }
                   8280:                             }
                   8281:                         }
1.137     raeburn  8282:                     }
1.279     raeburn  8283:                     $rem = $i%($numinrow);
                   8284:                     if ($rem == 0) {
                   8285:                         if ($i > 0) {
                   8286:                             $datatable .= '</tr>';
                   8287:                         }
                   8288:                         $datatable .= '<tr>';
                   8289:                     }
                   8290:                     $datatable .= '<td class="LC_left_item">'.
                   8291:                                   '<span class="LC_nobreak"><label>'.
                   8292:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   8293:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   8294:                                   '</label></span></td>';
                   8295:                 }
                   8296:                 $rem = @locations%($numinrow);
                   8297:                 my $colsleft = $numinrow - $rem;
                   8298:                 if ($colsleft > 1 ) {
                   8299:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8300:                                   '&nbsp;</td>';
                   8301:                 } elsif ($colsleft == 1) {
                   8302:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  8303:                 }
1.279     raeburn  8304:                 $datatable .= '</tr></table>';
1.137     raeburn  8305:             }
1.279     raeburn  8306:             $datatable .= '</td></tr>';
                   8307:             $itemcount ++;
1.137     raeburn  8308:         }
                   8309:     }
1.279     raeburn  8310:     return ($datatable,$itemcount);
1.137     raeburn  8311: }
                   8312: 
1.275     raeburn  8313: sub print_ssl {
                   8314:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8315:     my ($css_class,$datatable);
                   8316:     my $itemcount = 1;
                   8317:     if ($position eq 'top') {
1.281     raeburn  8318:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8319:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8320:         my $same_institution;
                   8321:         if ($intdom ne '') {
                   8322:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   8323:             if (ref($internet_names) eq 'ARRAY') {
                   8324:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   8325:                     $same_institution = 1;
                   8326:                 }
                   8327:             }
                   8328:         }
1.275     raeburn  8329:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  8330:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   8331:         if ($same_institution) {
                   8332:             my %domservers = &Apache::lonnet::get_servers($dom);
                   8333:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   8334:         } else {
                   8335:             $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.");
                   8336:         }
                   8337:         $datatable .= '</td></tr>';
1.275     raeburn  8338:         $itemcount ++;
                   8339:     } else {
                   8340:         my %titles = &ssl_titles();
                   8341:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   8342:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8343:         my @alldoms = &Apache::lonnet::all_domains();
                   8344:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   8345:         my @domservers = &Apache::lonnet::get_servers($dom);
                   8346:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8347:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  8348:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   8349:             my $legacy;
                   8350:             unless (ref($settings) eq 'HASH') {
                   8351:                 my $name;
                   8352:                 if ($position eq 'connto') {
                   8353:                     $name = 'loncAllowInsecure';
                   8354:                 } else {
                   8355:                     $name = 'londAllowInsecure';
                   8356:                 }
                   8357:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   8358:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8359:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   8360:                     my %what = (
                   8361:                                    $name => 1,
                   8362:                                );
                   8363:                     my ($result,$returnhash) =
                   8364:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   8365:                     if ($result eq 'ok') {
                   8366:                         if (ref($returnhash) eq 'HASH') {
                   8367:                             $legacy = $returnhash->{$name};
                   8368:                         }
                   8369:                     }
                   8370:                 } else {
                   8371:                     $legacy = $Apache::lonnet::perlvar{$name};
                   8372:                 }
                   8373:             }
1.275     raeburn  8374:             foreach my $type ('dom','intdom','other') {
                   8375:                 my %checked;
                   8376:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8377:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   8378:                               '<td class="LC_right_item">';
                   8379:                 my $skip; 
                   8380:                 if ($type eq 'dom') {
                   8381:                     unless (keys(%servers) > 1) {
                   8382:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   8383:                         $skip = 1;
                   8384:                     }
                   8385:                 }
                   8386:                 if ($type eq 'intdom') {
                   8387:                     unless (@instdoms > 1) {
                   8388:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   8389:                         $skip = 1;
                   8390:                     } 
                   8391:                 } elsif ($type eq 'other') {
                   8392:                     if (keys(%by_location) == 0) {
                   8393:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   8394:                         $skip = 1;
                   8395:                     }
                   8396:                 }
                   8397:                 unless ($skip) {
                   8398:                     $checked{'yes'} = ' checked="checked"'; 
                   8399:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  8400:                         if (ref($settings->{$position}) eq 'HASH') {
                   8401:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  8402:                                 $checked{$1} = $checked{'yes'};
                   8403:                                 delete($checked{'yes'}); 
                   8404:                             }
                   8405:                         }
1.293     raeburn  8406:                     } else {
                   8407:                         if ($legacy == 0) {
                   8408:                             $checked{'req'} = $checked{'yes'};
                   8409:                             delete($checked{'yes'});    
                   8410:                         }
1.275     raeburn  8411:                     }
                   8412:                     foreach my $option ('no','yes','req') {
                   8413:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  8414:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  8415:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   8416:                                       '</label></span>'.('&nbsp;'x2);
                   8417:                     }
                   8418:                 }
                   8419:                 $datatable .= '</td></tr>';
                   8420:                 $itemcount ++; 
                   8421:             }
                   8422:         } else {
                   8423:             my $prefix = 'replication';
                   8424:             my @types = ('certreq','nocertreq');
1.279     raeburn  8425:             if (keys(%by_location) == 0) {
                   8426:                 $datatable .= '<tr'.$css_class.'><td>'.
                   8427:                               &mt('Nothing to set here, as there are no other institutions').
                   8428:                               '</td></tr>';
                   8429:                 $itemcount ++;
1.275     raeburn  8430:             } else {
1.279     raeburn  8431:                 ($datatable,$itemcount) = 
                   8432:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  8433:             }
                   8434:         }
                   8435:     }
                   8436:     $$rowtotal += $itemcount;
                   8437:     return $datatable;
                   8438: }
                   8439: 
                   8440: sub ssl_titles {
                   8441:     return &Apache::lonlocal::texthash (
                   8442:                dom           => 'LON-CAPA servers/VMs from same domain',
                   8443:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   8444:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  8445:                connto        => 'Connections to other servers',
                   8446:                connfrom      => 'Connections from other servers',
1.275     raeburn  8447:                replication   => 'Replicating content to other institutions',
                   8448:                certreq       => 'Client certificate required, but specific domains exempt',
                   8449:                nocertreq     => 'No client certificate required, except for specific domains',
                   8450:                no            => 'SSL not used',
                   8451:                yes           => 'SSL Optional (used if available)',
                   8452:                req           => 'SSL Required',
                   8453:     );
1.279     raeburn  8454: }
                   8455: 
                   8456: sub print_trust {
                   8457:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   8458:     my ($css_class,$datatable,%checked,%choices);
                   8459:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   8460:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   8461:     my $itemcount = 1;
                   8462:     my %titles = &trust_titles();
                   8463:     my @types = ('exc','inc');
                   8464:     if ($prefix eq 'top') {
                   8465:         $prefix = 'content';
                   8466:     } elsif ($prefix eq 'bottom') {
                   8467:         $prefix = 'msg';
                   8468:     }
                   8469:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   8470:     $$rowtotal += $itemcount;
                   8471:     return $datatable;
                   8472: }
                   8473: 
                   8474: sub trust_titles {
                   8475:     return &Apache::lonlocal::texthash(
                   8476:                content  => "Access to this domain's content by others",
                   8477:                shared   => "Access to other domain's content by this domain",
                   8478:                enroll   => "Enrollment in this domain's courses by others", 
                   8479:                othcoau  => "Co-author roles in this domain for others",
                   8480:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   8481:                domroles => "Domain roles in this domain assignable to others",
                   8482:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   8483:                reqcrs   => "Requests for creation of courses in this domain by others",
                   8484:                msg      => "Users in other domains can send messages to this domain",
                   8485:                exc      => "Allow all, but exclude specific domains",
                   8486:                inc      => "Deny all, but include specific domains",
                   8487:            );
1.275     raeburn  8488: } 
                   8489: 
1.138     raeburn  8490: sub build_location_hashes {
1.275     raeburn  8491:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  8492:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  8493:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  8494:     my %iphost = &Apache::lonnet::get_iphost();
                   8495:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   8496:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   8497:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   8498:         foreach my $id (@{$iphost{$primary_ip}}) {
                   8499:             my $intdom = &Apache::lonnet::internet_dom($id);
                   8500:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   8501:                 push(@{$intdoms},$intdom);
                   8502:             }
                   8503:         }
                   8504:     }
                   8505:     foreach my $ip (keys(%iphost)) {
                   8506:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   8507:             foreach my $id (@{$iphost{$ip}}) {
                   8508:                 my $location = &Apache::lonnet::internet_dom($id);
                   8509:                 if ($location) {
1.275     raeburn  8510:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   8511:                         my $dom = &Apache::lonnet::host_domain($id);
                   8512:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   8513:                             push(@{$instdoms},$dom);
                   8514:                         }
                   8515:                         next;
                   8516:                     }
1.138     raeburn  8517:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8518:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   8519:                             push(@{$by_ip->{$ip}},$location);
                   8520:                         }
                   8521:                     } else {
                   8522:                         $by_ip->{$ip} = [$location];
                   8523:                     }
                   8524:                 }
                   8525:             }
                   8526:         }
                   8527:     }
                   8528:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   8529:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   8530:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   8531:             my $first = $by_ip->{$ip}->[0];
                   8532:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   8533:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   8534:                     push(@{$by_location->{$first}},$ip);
                   8535:                 }
                   8536:             } else {
                   8537:                 $by_location->{$first} = [$ip];
                   8538:             }
                   8539:         }
                   8540:     }
                   8541:     return;
                   8542: }
                   8543: 
1.145     raeburn  8544: sub current_offloads_to {
                   8545:     my ($dom,$settings,$servers) = @_;
                   8546:     my (%spareid,%otherdomconfigs);
1.152     raeburn  8547:     if (ref($servers) eq 'HASH') {
1.145     raeburn  8548:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   8549:             my $gotspares;
1.152     raeburn  8550:             if (ref($settings) eq 'HASH') {
                   8551:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   8552:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   8553:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   8554:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   8555:                         $gotspares = 1;
                   8556:                     }
1.145     raeburn  8557:                 }
                   8558:             }
                   8559:             unless ($gotspares) {
                   8560:                 my $gotspares;
                   8561:                 my $serverhomeID =
                   8562:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   8563:                 my $serverhomedom =
                   8564:                     &Apache::lonnet::host_domain($serverhomeID);
                   8565:                 if ($serverhomedom ne $dom) {
                   8566:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   8567:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   8568:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   8569:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   8570:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   8571:                                 $gotspares = 1;
                   8572:                             }
                   8573:                         }
                   8574:                     } else {
                   8575:                         $otherdomconfigs{$serverhomedom} =
                   8576:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   8577:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   8578:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   8579:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   8580:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   8581:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   8582:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   8583:                                         $gotspares = 1;
                   8584:                                     }
                   8585:                                 }
                   8586:                             }
                   8587:                         }
                   8588:                     }
                   8589:                 }
                   8590:             }
                   8591:             unless ($gotspares) {
                   8592:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   8593:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   8594:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   8595:                } else {
                   8596:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   8597:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   8598:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   8599:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   8600:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   8601:                     } else {
1.150     raeburn  8602:                         my %what = (
                   8603:                              spareid => 1,
                   8604:                         );
                   8605:                         my ($result,$returnhash) = 
                   8606:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   8607:                         if ($result eq 'ok') { 
                   8608:                             if (ref($returnhash) eq 'HASH') {
                   8609:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   8610:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   8611:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   8612:                                 }
                   8613:                             }
1.145     raeburn  8614:                         }
                   8615:                     }
                   8616:                 }
                   8617:             }
                   8618:         }
                   8619:     }
                   8620:     return %spareid;
                   8621: }
                   8622: 
                   8623: sub spares_row {
1.371     raeburn  8624:     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   8625:         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  8626:     my $css_class;
                   8627:     my $numinrow = 4;
                   8628:     my $itemcount = 1;
                   8629:     my $datatable;
1.152     raeburn  8630:     my %typetitles = &sparestype_titles();
                   8631:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  8632:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  8633:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   8634:             my ($othercontrol,$serverdom);
                   8635:             if ($serverhome ne $server) {
                   8636:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   8637:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   8638:             } else {
                   8639:                 $serverdom = &Apache::lonnet::host_domain($server);
                   8640:                 if ($serverdom ne $dom) {
                   8641:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   8642:                 }
                   8643:             }
                   8644:             next unless (ref($spareid->{$server}) eq 'HASH');
1.371     raeburn  8645:             my ($checkednow,$checkedoth);
1.261     raeburn  8646:             if (ref($curroffloadnow) eq 'HASH') {
                   8647:                 if ($curroffloadnow->{$server}) {
                   8648:                     $checkednow = ' checked="checked"';
                   8649:                 }
                   8650:             }
1.371     raeburn  8651:             if (ref($curroffloadoth) eq 'HASH') {
                   8652:                 if ($curroffloadoth->{$server}) {
                   8653:                     $checkedoth = ' checked="checked"';
                   8654:                 }
                   8655:             }
1.145     raeburn  8656:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   8657:             $datatable .= '<tr'.$css_class.'>
                   8658:                            <td rowspan="2">
1.183     bisitz   8659:                             <span class="LC_nobreak">'.
                   8660:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  8661:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  8662:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  8663:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371     raeburn  8664:                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.183     bisitz   8665:                           "\n";
1.371     raeburn  8666:             if ($other_insts) {
                   8667:                 $datatable .= '<br />'.
                   8668:                               '<span class="LC_nobreak">'."\n".
                   8669:                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   8670:                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   8671:                           "\n";
                   8672:             }
1.145     raeburn  8673:             my (%current,%canselect);
1.152     raeburn  8674:             my @choices = 
                   8675:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   8676:             foreach my $type ('primary','default') {
                   8677:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  8678:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   8679:                         my @spares = @{$spareid->{$server}{$type}};
                   8680:                         if (@spares > 0) {
1.152     raeburn  8681:                             if ($othercontrol) {
                   8682:                                 $current{$type} = join(', ',@spares);
                   8683:                             } else {
                   8684:                                 $current{$type} .= '<table>';
                   8685:                                 my $numspares = scalar(@spares);
                   8686:                                 for (my $i=0;  $i<@spares; $i++) {
                   8687:                                     my $rem = $i%($numinrow);
                   8688:                                     if ($rem == 0) {
                   8689:                                         if ($i > 0) {
                   8690:                                             $current{$type} .= '</tr>';
                   8691:                                         }
                   8692:                                         $current{$type} .= '<tr>';
1.145     raeburn  8693:                                     }
1.152     raeburn  8694:                                     $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;'.
                   8695:                                                        $spareid->{$server}{$type}[$i].
                   8696:                                                        '</label></td>'."\n";
                   8697:                                 }
                   8698:                                 my $rem = @spares%($numinrow);
                   8699:                                 my $colsleft = $numinrow - $rem;
                   8700:                                 if ($colsleft > 1 ) {
                   8701:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   8702:                                                        '" class="LC_left_item">'.
                   8703:                                                        '&nbsp;</td>';
                   8704:                                 } elsif ($colsleft == 1) {
                   8705:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  8706:                                 }
1.152     raeburn  8707:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  8708:                             }
1.145     raeburn  8709:                         }
                   8710:                     }
                   8711:                     if ($current{$type} eq '') {
                   8712:                         $current{$type} = &mt('None specified');
                   8713:                     }
1.152     raeburn  8714:                     if ($othercontrol) {
                   8715:                         if ($type eq 'primary') {
                   8716:                             $canselect{$type} = $othercontrol;
                   8717:                         }
                   8718:                     } else {
                   8719:                         $canselect{$type} = 
                   8720:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   8721:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   8722:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   8723:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   8724:                         if (@choices > 0) {
                   8725:                             foreach my $lonhost (@choices) {
                   8726:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   8727:                             }
                   8728:                         }
                   8729:                         $canselect{$type} .= '</select>'."\n";
                   8730:                     }
                   8731:                 } else {
                   8732:                     $current{$type} = &mt('Could not be determined');
                   8733:                     if ($type eq 'primary') {
                   8734:                         $canselect{$type} =  $othercontrol;
                   8735:                     }
1.145     raeburn  8736:                 }
1.152     raeburn  8737:                 if ($type eq 'default') {
                   8738:                     $datatable .= '<tr'.$css_class.'>';
                   8739:                 }
                   8740:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   8741:                               '<td>'.$current{$type}.'</td>'."\n".
                   8742:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  8743:             }
                   8744:             $itemcount ++;
                   8745:         }
                   8746:     }
                   8747:     $$rowtotal += $itemcount;
                   8748:     return $datatable;
                   8749: }
                   8750: 
1.152     raeburn  8751: sub possible_newspares {
                   8752:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   8753:     my $serverhostname = &Apache::lonnet::hostname($server);
                   8754:     my %excluded;
                   8755:     if ($serverhostname ne '') {
                   8756:         %excluded = (
                   8757:                        $serverhostname => 1,
                   8758:                     );
                   8759:     }
                   8760:     if (ref($currspares) eq 'HASH') {
                   8761:         foreach my $type (keys(%{$currspares})) {
                   8762:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   8763:                 if (@{$currspares->{$type}} > 0) {
                   8764:                     foreach my $curr (@{$currspares->{$type}}) {
                   8765:                         my $hostname = &Apache::lonnet::hostname($curr);
                   8766:                         $excluded{$hostname} = 1;
                   8767:                     }
                   8768:                 }
                   8769:             }
                   8770:         }
                   8771:     }
                   8772:     my @choices;
                   8773:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   8774:         if (keys(%{$serverhomes}) > 1) {
                   8775:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   8776:                 unless ($excluded{$name}) {
                   8777:                     if (exists($altids->{$serverhomes->{$name}})) {
                   8778:                         push(@choices,$altids->{$serverhomes->{$name}});
                   8779:                     } else {
                   8780:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  8781:                     }
                   8782:                 }
                   8783:             }
                   8784:         }
                   8785:     }
1.152     raeburn  8786:     return sort(@choices);
1.145     raeburn  8787: }
                   8788: 
1.150     raeburn  8789: sub print_loadbalancing {
                   8790:     my ($dom,$settings,$rowtotal) = @_;
                   8791:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8792:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8793:     my $numinrow = 1;
                   8794:     my $datatable;
                   8795:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342     raeburn  8796:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  8797:     if (ref($settings) eq 'HASH') {
                   8798:         %existing = %{$settings};
                   8799:     }
                   8800:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   8801:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  8802:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  8803:     } else {
                   8804:         return;
                   8805:     }
                   8806:     my ($othertitle,$usertypes,$types) =
                   8807:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  8808:     my $rownum = 8;
1.150     raeburn  8809:     if (ref($types) eq 'ARRAY') {
                   8810:         $rownum += scalar(@{$types});
                   8811:     }
1.171     raeburn  8812:     my @css_class = ('LC_odd_row','LC_even_row');
                   8813:     my $balnum = 0;
                   8814:     my $islast;
                   8815:     my (@toshow,$disabledtext);
                   8816:     if (keys(%currbalancer) > 0) {
                   8817:         @toshow = sort(keys(%currbalancer));
                   8818:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   8819:             push(@toshow,'');
                   8820:         }
                   8821:     } else {
                   8822:         @toshow = ('');
                   8823:         $disabledtext = &mt('No existing load balancer');
                   8824:     }
                   8825:     foreach my $lonhost (@toshow) {
                   8826:         if ($balnum == scalar(@toshow)-1) {
                   8827:             $islast = 1;
                   8828:         } else {
                   8829:             $islast = 0;
                   8830:         }
                   8831:         my $cssidx = $balnum%2;
                   8832:         my $targets_div_style = 'display: none';
                   8833:         my $disabled_div_style = 'display: block';
                   8834:         my $homedom_div_style = 'display: none';
                   8835:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  8836:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  8837:                       '<p>';
                   8838:         if ($lonhost eq '') {
1.210     raeburn  8839:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  8840:             if (keys(%currbalancer) > 0) {
                   8841:                 $datatable .= &mt('Add balancer:');
                   8842:             } else {
                   8843:                 $datatable .= &mt('Enable balancer:');
                   8844:             }
                   8845:             $datatable .= '&nbsp;'.
                   8846:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   8847:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   8848:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   8849:                           '<option value="" selected="selected">'.&mt('None').
                   8850:                           '</option>'."\n";
                   8851:             foreach my $server (sort(keys(%servers))) {
                   8852:                 next if ($currbalancer{$server});
                   8853:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   8854:             }
1.210     raeburn  8855:             $datatable .=
1.171     raeburn  8856:                 '</select>'."\n".
                   8857:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   8858:         } else {
                   8859:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   8860:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   8861:                            &mt('Stop balancing').'</label>'.
                   8862:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   8863:             $targets_div_style = 'display: block';
                   8864:             $disabled_div_style = 'display: none';
                   8865:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   8866:                 $homedom_div_style = 'display: block';
                   8867:             }
                   8868:         }
1.306     raeburn  8869:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  8870:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   8871:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   8872:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   8873:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   8874:         my @sparestypes = ('primary','default');
                   8875:         my %typetitles = &sparestype_titles();
1.284     raeburn  8876:         my %hostherechecked = (
                   8877:                                   no => ' checked="checked"',
                   8878:                               );
1.342     raeburn  8879:         my %balcookiechecked = (
                   8880:                                   no => ' checked="checked"', 
                   8881:                                );
1.171     raeburn  8882:         foreach my $sparetype (@sparestypes) {
                   8883:             my $targettable;
                   8884:             for (my $i=0; $i<$numspares; $i++) {
                   8885:                 my $checked;
                   8886:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   8887:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   8888:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   8889:                             $checked = ' checked="checked"';
                   8890:                         }
                   8891:                     }
                   8892:                 }
                   8893:                 my ($chkboxval,$disabled);
                   8894:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   8895:                     $chkboxval = $spares[$i];
                   8896:                 }
                   8897:                 if (exists($currbalancer{$spares[$i]})) {
                   8898:                     $disabled = ' disabled="disabled"';
                   8899:                 }
1.210     raeburn  8900:                 $targettable .=
1.253     raeburn  8901:                     '<td><span class="LC_nobreak"><label>'.
                   8902:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  8903:                     $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  8904:                     '</span></label></span></td>';
1.171     raeburn  8905:                 my $rem = $i%($numinrow);
                   8906:                 if ($rem == 0) {
                   8907:                     if (($i > 0) && ($i < $numspares-1)) {
                   8908:                         $targettable .= '</tr>';
                   8909:                     }
                   8910:                     if ($i < $numspares-1) {
                   8911:                         $targettable .= '<tr>';
1.150     raeburn  8912:                     }
                   8913:                 }
                   8914:             }
1.171     raeburn  8915:             if ($targettable ne '') {
                   8916:                 my $rem = $numspares%($numinrow);
                   8917:                 my $colsleft = $numinrow - $rem;
                   8918:                 if ($colsleft > 1 ) {
                   8919:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8920:                                     '&nbsp;</td>';
                   8921:                 } elsif ($colsleft == 1) {
                   8922:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   8923:                 }
                   8924:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   8925:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   8926:             }
1.284     raeburn  8927:             $hostherechecked{$sparetype} = '';
                   8928:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   8929:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   8930:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   8931:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   8932:                         $hostherechecked{'no'} = '';
                   8933:                     }
                   8934:                 }
                   8935:             }
                   8936:         }
1.342     raeburn  8937:         if ($currcookies{$lonhost}) {
                   8938:             %balcookiechecked = (
                   8939:                                     yes => ' checked="checked"',
                   8940:                                 );
                   8941:         }
1.284     raeburn  8942:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   8943:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   8944:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   8945:         foreach my $sparetype (@sparestypes) {
                   8946:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   8947:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   8948:                           '</i></label><br />';
1.171     raeburn  8949:         }
1.342     raeburn  8950:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   8951:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   8952:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   8953:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   8954:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   8955:                       '</div></td></tr>'.
1.171     raeburn  8956:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   8957:                                            $othertitle,$usertypes,$types,\%servers,
                   8958:                                            \%currbalancer,$lonhost,
                   8959:                                            $targets_div_style,$homedom_div_style,
                   8960:                                            $css_class[$cssidx],$balnum,$islast);
                   8961:         $$rowtotal += $rownum;
                   8962:         $balnum ++;
                   8963:     }
                   8964:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   8965:     return $datatable;
                   8966: }
                   8967: 
                   8968: sub get_loadbalancers_config {
1.342     raeburn  8969:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171     raeburn  8970:     return unless ((ref($servers) eq 'HASH') &&
                   8971:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342     raeburn  8972:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   8973:                    (ref($currcookies) eq 'HASH'));
1.171     raeburn  8974:     if (keys(%{$existing}) > 0) {
                   8975:         my $oldlonhost;
                   8976:         foreach my $key (sort(keys(%{$existing}))) {
                   8977:             if ($key eq 'lonhost') {
                   8978:                 $oldlonhost = $existing->{'lonhost'};
                   8979:                 $currbalancer->{$oldlonhost} = 1;
                   8980:             } elsif ($key eq 'targets') {
                   8981:                 if ($oldlonhost) {
                   8982:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   8983:                 }
                   8984:             } elsif ($key eq 'rules') {
                   8985:                 if ($oldlonhost) {
                   8986:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   8987:                 }
                   8988:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   8989:                 $currbalancer->{$key} = 1;
                   8990:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   8991:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.342     raeburn  8992:                 if ($existing->{$key}{'cookie'}) {
                   8993:                     $currcookies->{$key} = 1;
                   8994:                 }
1.150     raeburn  8995:             }
                   8996:         }
1.171     raeburn  8997:     } else {
                   8998:         my ($balancerref,$targetsref) =
                   8999:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   9000:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   9001:             foreach my $server (sort(keys(%{$balancerref}))) {
                   9002:                 $currbalancer->{$server} = 1;
                   9003:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  9004:             }
                   9005:         }
                   9006:     }
1.171     raeburn  9007:     return;
1.150     raeburn  9008: }
                   9009: 
                   9010: sub loadbalancing_rules {
                   9011:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  9012:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   9013:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  9014:     my $output;
1.171     raeburn  9015:     my $num = 0;
1.210     raeburn  9016:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  9017:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   9018:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   9019:         foreach my $type (@{$alltypes}) {
1.171     raeburn  9020:             $num ++;
1.150     raeburn  9021:             my $current;
                   9022:             if (ref($currrules) eq 'HASH') {
                   9023:                 $current = $currrules->{$type};
                   9024:             }
1.253     raeburn  9025:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  9026:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  9027:                     $current = '';
                   9028:                 }
                   9029:             }
                   9030:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  9031:                                              $servers,$currbalancer,$lonhost,$dom,
                   9032:                                              $targets_div_style,$homedom_div_style,
                   9033:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  9034:         }
                   9035:     }
                   9036:     return $output;
                   9037: }
                   9038: 
                   9039: sub loadbalancing_titles {
                   9040:     my ($dom,$intdom,$usertypes,$types) = @_;
                   9041:     my %othertypes = (
                   9042:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   9043:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   9044:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   9045:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  9046:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   9047:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  9048:                      );
1.209     raeburn  9049:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  9050:     my @available;
1.150     raeburn  9051:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  9052:         @available = @{$types};
1.150     raeburn  9053:     }
1.302     raeburn  9054:     unless (grep(/^default$/,@available)) {
                   9055:         push(@available,'default');
                   9056:     }
                   9057:     unshift(@alltypes,@available);
1.150     raeburn  9058:     my %titles;
                   9059:     foreach my $type (@alltypes) {
                   9060:         if ($type =~ /^_LC_/) {
                   9061:             $titles{$type} = $othertypes{$type};
                   9062:         } elsif ($type eq 'default') {
                   9063:             $titles{$type} = &mt('All users from [_1]',$dom);
                   9064:             if (ref($types) eq 'ARRAY') {
                   9065:                 if (@{$types} > 0) {
                   9066:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   9067:                 }
                   9068:             }
                   9069:         } elsif (ref($usertypes) eq 'HASH') {
                   9070:             $titles{$type} = $usertypes->{$type};
                   9071:         }
                   9072:     }
                   9073:     return (\@alltypes,\%othertypes,\%titles);
                   9074: }
                   9075: 
                   9076: sub loadbalance_rule_row {
1.171     raeburn  9077:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   9078:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  9079:     my @rulenames;
1.150     raeburn  9080:     my %ruletitles = &offloadtype_text();
1.209     raeburn  9081:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  9082:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  9083:     } else {
1.209     raeburn  9084:         @rulenames = ('default','homeserver');
                   9085:         if ($type eq '_LC_external') {
                   9086:             push(@rulenames,'externalbalancer');
                   9087:         } else {
                   9088:             push(@rulenames,'specific');
                   9089:         }
                   9090:         push(@rulenames,'none');
1.150     raeburn  9091:     }
                   9092:     my $style = $targets_div_style;
1.253     raeburn  9093:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  9094:         $style = $homedom_div_style;
                   9095:     }
1.171     raeburn  9096:     my $space;
                   9097:     if ($islast && $num == 1) {
1.317     raeburn  9098:         $space = '<div style="display:inline-block;">&nbsp;</div>';
1.171     raeburn  9099:     }
1.210     raeburn  9100:     my $output =
1.306     raeburn  9101:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  9102:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   9103:         '<td valaign="top">'.$space.
                   9104:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  9105:     for (my $i=0; $i<@rulenames; $i++) {
                   9106:         my $rule = $rulenames[$i];
                   9107:         my ($checked,$extra);
                   9108:         if ($rulenames[$i] eq 'default') {
                   9109:             $rule = '';
                   9110:         }
                   9111:         if ($rulenames[$i] eq 'specific') {
                   9112:             if (ref($servers) eq 'HASH') {
                   9113:                 my $default;
                   9114:                 if (($current ne '') && (exists($servers->{$current}))) {
                   9115:                     $checked = ' checked="checked"';
                   9116:                 }
                   9117:                 unless ($checked) {
                   9118:                     $default = ' selected="selected"';
                   9119:                 }
1.210     raeburn  9120:                 $extra =
1.171     raeburn  9121:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9122:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   9123:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   9124:                     '<option value=""'.$default.'></option>'."\n";
                   9125:                 foreach my $server (sort(keys(%{$servers}))) {
                   9126:                     if (ref($currbalancer) eq 'HASH') {
                   9127:                         next if (exists($currbalancer->{$server}));
                   9128:                     }
1.150     raeburn  9129:                     my $selected;
1.171     raeburn  9130:                     if ($server eq $current) {
1.150     raeburn  9131:                         $selected = ' selected="selected"';
                   9132:                     }
1.171     raeburn  9133:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  9134:                 }
                   9135:                 $extra .= '</select>';
                   9136:             }
                   9137:         } elsif ($rule eq $current) {
                   9138:             $checked = ' checked="checked"';
                   9139:         }
                   9140:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  9141:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   9142:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   9143:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  9144:                    ')"'.$checked.' />&nbsp;';
                   9145:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   9146:             $output .= $ruletitles{'particular'};
                   9147:         } else {
                   9148:             $output .= $ruletitles{$rulenames[$i]};
                   9149:         }
                   9150:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  9151:     }
                   9152:     $output .= '</div></td></tr>'."\n";
                   9153:     return $output;
                   9154: }
                   9155: 
                   9156: sub offloadtype_text {
                   9157:     my %ruletitles = &Apache::lonlocal::texthash (
                   9158:            'default'          => 'Offloads to default destinations',
                   9159:            'homeserver'       => "Offloads to user's home server",
                   9160:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   9161:            'specific'         => 'Offloads to specific server',
1.161     raeburn  9162:            'none'             => 'No offload',
1.209     raeburn  9163:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   9164:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  9165:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  9166:     );
                   9167:     return %ruletitles;
                   9168: }
                   9169: 
                   9170: sub sparestype_titles {
                   9171:     my %typestitles = &Apache::lonlocal::texthash (
                   9172:                           'primary' => 'primary',
                   9173:                           'default' => 'default',
                   9174:                       );
                   9175:     return %typestitles;
                   9176: }
                   9177: 
1.28      raeburn  9178: sub contact_titles {
                   9179:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  9180:                    'supportemail'    => 'Support E-mail address',
                   9181:                    'adminemail'      => 'Default Server Admin E-mail address',
                   9182:                    'errormail'       => 'Error reports to be e-mailed to',
                   9183:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  9184:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   9185:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  9186:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   9187:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   9188:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  9189:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350     raeburn  9190:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.378     raeburn  9191:                    'errorthreshold'  => 'Error count threshold for status e-mail to admin(s)',
                   9192:                    'errorsysmail'    => 'Error count threshold for e-mail to developer group',
1.340     raeburn  9193:                    'errorweights'    => 'Weights used to compute error count',
                   9194:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  9195:                  );
                   9196:     my %short_titles = &Apache::lonlocal::texthash (
                   9197:                            adminemail   => 'Admin E-mail address',
                   9198:                            supportemail => 'Support E-mail',
                   9199:                        );   
                   9200:     return (\%titles,\%short_titles);
                   9201: }
                   9202: 
1.286     raeburn  9203: sub helpform_fields {
                   9204:     my %titles =  &Apache::lonlocal::texthash (
                   9205:                        'username'   => 'Name',
                   9206:                        'user'       => 'Username/domain',
                   9207:                        'phone'      => 'Phone',
                   9208:                        'cc'         => 'Cc e-mail',
                   9209:                        'course'     => 'Course Details',
                   9210:                        'section'    => 'Sections',
1.289     raeburn  9211:                        'screenshot' => 'File upload',
1.286     raeburn  9212:     );
                   9213:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   9214:     my %possoptions = (
                   9215:                         username     => ['yes','no','req'],
1.289     raeburn  9216:                         phone        => ['yes','no','req'],
1.286     raeburn  9217:                         user         => ['yes','no'],
1.289     raeburn  9218:                         cc           => ['yes','no'],
1.286     raeburn  9219:                         course       => ['yes','no'],
                   9220:                         section      => ['yes','no'],
                   9221:                         screenshot   => ['yes','no'],
                   9222:                       );
                   9223:     my %fieldoptions = &Apache::lonlocal::texthash (
                   9224:                          'yes'  => 'Optional',
                   9225:                          'req'  => 'Required',
                   9226:                          'no'   => "Not shown",
                   9227:     );
                   9228:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   9229: }
                   9230: 
1.72      raeburn  9231: sub tool_titles {
                   9232:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  9233:                      aboutme    => 'Personal web page',
1.86      raeburn  9234:                      blog       => 'Blog',
1.162     raeburn  9235:                      webdav     => 'WebDAV',
1.86      raeburn  9236:                      portfolio  => 'Portfolio',
1.88      bisitz   9237:                      official   => 'Official courses (with institutional codes)',
                   9238:                      unofficial => 'Unofficial courses',
1.98      raeburn  9239:                      community  => 'Communities',
1.216     raeburn  9240:                      textbook   => 'Textbook courses',
1.271     raeburn  9241:                      placement  => 'Placement tests',
1.86      raeburn  9242:                  );
1.72      raeburn  9243:     return %titles;
                   9244: }
                   9245: 
1.101     raeburn  9246: sub courserequest_titles {
                   9247:     my %titles = &Apache::lonlocal::texthash (
                   9248:                                    official   => 'Official',
                   9249:                                    unofficial => 'Unofficial',
                   9250:                                    community  => 'Communities',
1.216     raeburn  9251:                                    textbook   => 'Textbook',
1.271     raeburn  9252:                                    placement  => 'Placement tests',
1.325     raeburn  9253:                                    lti        => 'LTI Provider',
1.101     raeburn  9254:                                    norequest  => 'Not allowed',
1.325     raeburn  9255:                                    approval   => 'Approval by DC',
1.101     raeburn  9256:                                    validate   => 'With validation',
                   9257:                                    autolimit  => 'Numerical limit',
1.103     raeburn  9258:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  9259:                  );
                   9260:     return %titles;
                   9261: }
                   9262: 
1.163     raeburn  9263: sub authorrequest_titles {
                   9264:     my %titles = &Apache::lonlocal::texthash (
                   9265:                                    norequest  => 'Not allowed',
                   9266:                                    approval   => 'Approval by Dom. Coord.',
                   9267:                                    automatic  => 'Automatic approval',
                   9268:                  );
                   9269:     return %titles;
1.210     raeburn  9270: }
1.163     raeburn  9271: 
1.101     raeburn  9272: sub courserequest_conditions {
                   9273:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  9274:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   9275:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  9276:                  );
                   9277:     return %conditions;
                   9278: }
                   9279: 
                   9280: 
1.27      raeburn  9281: sub print_usercreation {
1.30      raeburn  9282:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  9283:     my $numinrow = 4;
1.28      raeburn  9284:     my $datatable;
                   9285:     if ($position eq 'top') {
1.30      raeburn  9286:         $$rowtotal ++;
1.34      raeburn  9287:         my $rowcount = 0;
1.32      raeburn  9288:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  9289:         if (ref($rules) eq 'HASH') {
                   9290:             if (keys(%{$rules}) > 0) {
1.32      raeburn  9291:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   9292:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  9293:                 $$rowtotal ++;
1.32      raeburn  9294:                 $rowcount ++;
                   9295:             }
                   9296:         }
                   9297:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   9298:         if (ref($idrules) eq 'HASH') {
                   9299:             if (keys(%{$idrules}) > 0) {
                   9300:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   9301:                                                 $idruleorder,$numinrow,$rowcount);
                   9302:                 $$rowtotal ++;
                   9303:                 $rowcount ++;
1.28      raeburn  9304:             }
                   9305:         }
1.39      raeburn  9306:         if ($rowcount == 0) {
                   9307:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   9308:             $$rowtotal ++;
                   9309:             $rowcount ++;
                   9310:         }
1.34      raeburn  9311:     } elsif ($position eq 'middle') {
1.224     raeburn  9312:         my @creators = ('author','course','requestcrs');
1.37      raeburn  9313:         my ($rules,$ruleorder) =
                   9314:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  9315:         my %lt = &usercreation_types();
                   9316:         my %checked;
                   9317:         if (ref($settings) eq 'HASH') {
                   9318:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9319:                 foreach my $item (@creators) {
                   9320:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   9321:                 }
                   9322:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   9323:                 foreach my $item (@creators) {
                   9324:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   9325:                         $checked{$item} = 'none';
                   9326:                     }
                   9327:                 }
                   9328:             }
                   9329:         }
                   9330:         my $rownum = 0;
                   9331:         foreach my $item (@creators) {
                   9332:             $rownum ++;
1.224     raeburn  9333:             if ($checked{$item} eq '') {
                   9334:                 $checked{$item} = 'any';
1.34      raeburn  9335:             }
                   9336:             my $css_class;
                   9337:             if ($rownum%2) {
                   9338:                 $css_class = '';
                   9339:             } else {
                   9340:                 $css_class = ' class="LC_odd_row" ';
                   9341:             }
                   9342:             $datatable .= '<tr'.$css_class.'>'.
                   9343:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  9344:                          '</span></td><td style="text-align: right">';
1.224     raeburn  9345:             my @options = ('any');
                   9346:             if (ref($rules) eq 'HASH') {
                   9347:                 if (keys(%{$rules}) > 0) {
                   9348:                     push(@options,('official','unofficial'));
1.37      raeburn  9349:                 }
                   9350:             }
1.224     raeburn  9351:             push(@options,'none');
1.37      raeburn  9352:             foreach my $option (@options) {
1.50      raeburn  9353:                 my $type = 'radio';
1.34      raeburn  9354:                 my $check = ' ';
1.224     raeburn  9355:                 if ($checked{$item} eq $option) {
                   9356:                     $check = ' checked="checked" ';
1.34      raeburn  9357:                 } 
                   9358:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  9359:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  9360:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   9361:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   9362:             }
                   9363:             $datatable .= '</td></tr>';
                   9364:         }
1.28      raeburn  9365:     } else {
                   9366:         my @contexts = ('author','course','domain');
1.325     raeburn  9367:         my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  9368:         my %checked;
                   9369:         if (ref($settings) eq 'HASH') {
                   9370:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   9371:                 foreach my $item (@contexts) {
                   9372:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   9373:                         foreach my $auth (@authtypes) {
                   9374:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   9375:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   9376:                             }
                   9377:                         }
                   9378:                     }
                   9379:                 }
1.27      raeburn  9380:             }
1.35      raeburn  9381:         } else {
                   9382:             foreach my $item (@contexts) {
1.36      raeburn  9383:                 foreach my $auth (@authtypes) {
1.35      raeburn  9384:                     $checked{$item}{$auth} = ' checked="checked" ';
                   9385:                 }
                   9386:             }
1.27      raeburn  9387:         }
1.28      raeburn  9388:         my %title = &context_names();
                   9389:         my %authname = &authtype_names();
                   9390:         my $rownum = 0;
                   9391:         my $css_class; 
                   9392:         foreach my $item (@contexts) {
                   9393:             if ($rownum%2) {
                   9394:                 $css_class = '';
                   9395:             } else {
                   9396:                 $css_class = ' class="LC_odd_row" ';
                   9397:             }
1.30      raeburn  9398:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  9399:                             '<td>'.$title{$item}.
                   9400:                             '</td><td class="LC_left_item">'.
                   9401:                             '<span class="LC_nobreak">';
                   9402:             foreach my $auth (@authtypes) {
                   9403:                 $datatable .= '<label>'. 
                   9404:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   9405:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   9406:                               $authname{$auth}.'</label>&nbsp;';
                   9407:             }
                   9408:             $datatable .= '</span></td></tr>';
                   9409:             $rownum ++;
1.27      raeburn  9410:         }
1.30      raeburn  9411:         $$rowtotal += $rownum;
1.27      raeburn  9412:     }
                   9413:     return $datatable;
                   9414: }
                   9415: 
1.224     raeburn  9416: sub print_selfcreation {
                   9417:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  9418:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   9419:         $emaildomain,$datatable);
1.224     raeburn  9420:     if (ref($settings) eq 'HASH') {
                   9421:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   9422:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  9423:             if (ref($createsettings) eq 'HASH') {
                   9424:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   9425:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   9426:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   9427:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   9428:                         @selfcreate = ('email','login','sso');
                   9429:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   9430:                         @selfcreate = ($createsettings->{'selfcreate'});
                   9431:                     }
                   9432:                 }
                   9433:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   9434:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  9435:                 }
1.305     raeburn  9436:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   9437:                     $emailoptions = $createsettings->{'emailoptions'};
                   9438:                 }
1.303     raeburn  9439:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   9440:                     $emailverified = $createsettings->{'emailverified'};
                   9441:                 }
                   9442:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   9443:                     $emaildomain = $createsettings->{'emaildomain'};
                   9444:                 }
1.224     raeburn  9445:             }
                   9446:         }
                   9447:     }
                   9448:     my %radiohash;
                   9449:     my $numinrow = 4;
                   9450:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  9451:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  9452:     if ($position eq 'top') {
                   9453:         my %choices = &Apache::lonlocal::texthash (
                   9454:                                                       cancreate_login      => 'Institutional Login',
                   9455:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   9456:                                                   );
                   9457:         my @toggles = sort(keys(%choices));
                   9458:         my %defaultchecked = (
                   9459:                                'cancreate_login' => 'off',
                   9460:                                'cancreate_sso'   => 'off',
                   9461:                              );
1.228     raeburn  9462:         my ($onclick,$itemcount);
1.224     raeburn  9463:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   9464:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  9465:         $$rowtotal += $itemcount;
                   9466:         
1.224     raeburn  9467:         if (ref($usertypes) eq 'HASH') {
                   9468:             if (keys(%{$usertypes}) > 0) {
                   9469:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   9470:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  9471:                                              'statustocreate',$rowtotal);
1.224     raeburn  9472:                 $$rowtotal ++;
                   9473:             }
                   9474:         }
1.240     raeburn  9475:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   9476:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9477:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   9478:         my $rem;
                   9479:         my $numperrow = 2;
                   9480:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   9481:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  9482:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  9483:                      '<td class="LC_left_item">'."\n".
1.334     raeburn  9484:                      '<table>'."\n";
1.240     raeburn  9485:         for (my $i=0; $i<@fields; $i++) {
                   9486:             $rem = $i%($numperrow);
                   9487:             if ($rem == 0) {
                   9488:                 if ($i > 0) {
                   9489:                     $datatable .= '</tr>';
                   9490:                 }
                   9491:                 $datatable .= '<tr>';
                   9492:             }
                   9493:             my $currval;
1.248     raeburn  9494:             if (ref($createsettings) eq 'HASH') {
                   9495:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   9496:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   9497:                 }
1.240     raeburn  9498:             }
                   9499:             $datatable .= '<td class="LC_left_item">'.
                   9500:                           '<span class="LC_nobreak">'.
                   9501:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   9502:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   9503:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   9504:         }
                   9505:         my $colsleft = $numperrow - $rem;
                   9506:         if ($colsleft > 1 ) {
                   9507:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9508:                          '&nbsp;</td>';
                   9509:         } elsif ($colsleft == 1) {
                   9510:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   9511:         }
                   9512:         $datatable .= '</tr></table></td></tr>';
                   9513:         $$rowtotal ++;
1.224     raeburn  9514:     } elsif ($position eq 'middle') {
                   9515:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  9516:         my @posstypes;
1.224     raeburn  9517:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  9518:             @posstypes = @{$types};
                   9519:         }
                   9520:         unless (grep(/^default$/,@posstypes)) {
                   9521:             push(@posstypes,'default');
                   9522:         }
                   9523:         my %usertypeshash;
                   9524:         if (ref($usertypes) eq 'HASH') {
                   9525:             %usertypeshash = %{$usertypes};
                   9526:         }
                   9527:         $usertypeshash{'default'} = $othertitle;
                   9528:         foreach my $status (@posstypes) {
                   9529:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   9530:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   9531:             $$rowtotal ++;
1.224     raeburn  9532:         }
                   9533:     } else {
1.236     raeburn  9534:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  9535:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  9536:                                                   );
                   9537:         my @toggles = sort(keys(%choices));
                   9538:         my %defaultchecked = (
                   9539:                                'cancreate_email' => 'off',
                   9540:                              );
1.305     raeburn  9541:         my $customclass = 'LC_selfcreate_email';
                   9542:         my $classprefix = 'LC_canmodify_emailusername_';
                   9543:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  9544:         my $display = 'none';
1.305     raeburn  9545:         my $rowstyle = 'display:none';
1.236     raeburn  9546:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   9547:             $display = 'block';
1.305     raeburn  9548:             $rowstyle = 'display:table-row';
1.236     raeburn  9549:         }
1.305     raeburn  9550:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   9551:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   9552:                                                      \%choices,$$rowtotal,$onclick);
                   9553:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   9554:                                          $rowstyle);
                   9555:         $$rowtotal ++;
                   9556:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   9557:                                       $rowstyle);
                   9558:         $$rowtotal ++;
                   9559:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  9560:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  9561:         my ($emailrules,$emailruleorder) =
                   9562:             &Apache::lonnet::inst_userrules($dom,'email');
                   9563:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9564:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9565:         if (ref($types) eq 'ARRAY') {
                   9566:             @posstypes = @{$types};
                   9567:         }
                   9568:         if (@posstypes) {
                   9569:             unless (grep(/^default$/,@posstypes)) {
                   9570:                 push(@posstypes,'default');
1.302     raeburn  9571:             }
                   9572:             if (ref($usertypes) eq 'HASH') {
                   9573:                 %usertypeshash = %{$usertypes};
                   9574:             }
1.305     raeburn  9575:             my $currassign;
                   9576:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   9577:                 $currassign = {
                   9578:                                   selfassign => $domdefaults{'inststatusguest'},
                   9579:                               };
                   9580:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   9581:             } else {
                   9582:                 $currassign = { selfassign => [] };
                   9583:             }
                   9584:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   9585:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   9586:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   9587:                                          $numinrow,$othertitle,'selfassign',
                   9588:                                          $rowtotal,$onclicktypes,$customclass,
                   9589:                                          $rowstyle);
                   9590:             $$rowtotal ++;
1.302     raeburn  9591:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  9592:             foreach my $status (@posstypes) {
                   9593:                 my $css_class;
                   9594:                 if ($$rowtotal%2) {
                   9595:                     $css_class = 'LC_odd_row ';
                   9596:                 }
                   9597:                 $css_class .= $customclass;
                   9598:                 my $rowid = $optionsprefix.$status;
                   9599:                 my $hidden = 1;
                   9600:                 my $currstyle = 'display:none';
                   9601:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   9602:                     $currstyle = $rowstyle;
                   9603:                     $hidden = 0; 
                   9604:                 }
                   9605:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   9606:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   9607:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   9608:                 unless ($hidden) {
                   9609:                     $$rowtotal ++;
                   9610:                 }
1.224     raeburn  9611:             }
1.302     raeburn  9612:         } else {
1.305     raeburn  9613:             my $css_class;
                   9614:             if ($$rowtotal%2) {
                   9615:                 $css_class = 'LC_odd_row ';
                   9616:             }
                   9617:             $css_class .= $customclass;
1.302     raeburn  9618:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  9619:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   9620:                                          $emailrules,$emailruleorder,$settings,'default','',
                   9621:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   9622:             $$rowtotal ++;
1.224     raeburn  9623:         }
                   9624:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  9625:         $numinrow = 1;
1.305     raeburn  9626:         if (@posstypes) {
                   9627:             foreach my $status (@posstypes) {
                   9628:                 my $rowid = $classprefix.$status;
                   9629:                 my $datarowstyle = 'display:none';
                   9630:                 if (grep(/^\Q$status\E$/,@ordered)) { 
                   9631:                     $datarowstyle = $rowstyle; 
                   9632:                 }
                   9633:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   9634:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   9635:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   9636:                 unless ($datarowstyle eq 'display:none') {
                   9637:                     $$rowtotal ++;
                   9638:                 }
1.224     raeburn  9639:             }
1.305     raeburn  9640:         } else {
                   9641:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   9642:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   9643:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  9644:         }
                   9645:     }
                   9646:     return $datatable;
                   9647: }
                   9648: 
1.305     raeburn  9649: sub selfcreate_javascript {
                   9650:     return <<"ENDSCRIPT";
                   9651: 
                   9652: <script type="text/javascript">
                   9653: // <![CDATA[
                   9654: 
                   9655: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   9656:     var x = document.getElementsByClassName(target);
                   9657:     var insttypes = 0;
                   9658:     var insttypeRegExp = new RegExp(prefix);
                   9659:     if ((x.length != undefined) && (x.length > 0)) {
                   9660:         if (form.elements[radio].length != undefined) {
                   9661:             for (var i=0; i<form.elements[radio].length; i++) {
                   9662:                 if (form.elements[radio][i].checked) {
                   9663:                     if (form.elements[radio][i].value == 1) {
                   9664:                         for (var j=0; j<x.length; j++) {
                   9665:                             if (x[j].id == 'undefined') {
                   9666:                                 x[j].style.display = 'table-row';
                   9667:                             } else if (insttypeRegExp.test(x[j].id)) {
                   9668:                                 insttypes ++;
                   9669:                             } else {
                   9670:                                 x[j].style.display = 'table-row';
                   9671:                             }
                   9672:                         }
                   9673:                     } else {
                   9674:                         for (var j=0; j<x.length; j++) {
                   9675:                             x[j].style.display = 'none';
                   9676:                         }
1.236     raeburn  9677:                     }
1.305     raeburn  9678:                     break;
                   9679:                 }
                   9680:             }
                   9681:             if (insttypes > 0) {
                   9682:                 toggleDataRow(form,checkbox,target,altprefix);
                   9683:                 toggleDataRow(form,checkbox,target,prefix,1);
                   9684:             }
                   9685:         }
                   9686:     }
                   9687:     return;
                   9688: }
                   9689: 
                   9690: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   9691:     if (form.elements[checkbox].length != undefined) {
                   9692:         var count = 0;
                   9693:         if (docount) {
                   9694:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   9695:                 if (form.elements[checkbox][i].checked) {
                   9696:                     count ++;
1.236     raeburn  9697:                 }
1.305     raeburn  9698:             }
                   9699:         }
                   9700:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   9701:             var type = form.elements[checkbox][i].value;
                   9702:             if (document.getElementById(prefix+type)) {
                   9703:                 if (form.elements[checkbox][i].checked) {
                   9704:                     document.getElementById(prefix+type).style.display = 'table-row';
                   9705:                     if (count % 2 == 1) {
                   9706:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   9707:                     } else {
                   9708:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  9709:                     }
1.305     raeburn  9710:                     count ++;
1.236     raeburn  9711:                 } else {
1.305     raeburn  9712:                     document.getElementById(prefix+type).style.display = 'none';
                   9713:                 }
                   9714:             }
                   9715:         }
                   9716:     }
                   9717:     return;
                   9718: }
                   9719: 
                   9720: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   9721:     var caller = radio+'_'+status;
                   9722:     if (form.elements[caller].length != undefined) {
                   9723:         for (var i=0; i<form.elements[caller].length; i++) {
                   9724:             if (form.elements[caller][i].checked) {
                   9725:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   9726:                     var curr = form.elements[caller][i].value;
                   9727:                     if (prefix) {
                   9728:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   9729:                     }
                   9730:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   9731:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   9732:                     if (curr == 'custom') {
                   9733:                         if (prefix) { 
                   9734:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   9735:                         }
                   9736:                     } else if (curr == 'inst') {
                   9737:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   9738:                     } else if (curr == 'noninst') {
                   9739:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  9740:                     }
1.305     raeburn  9741:                     break;
1.236     raeburn  9742:                 }
                   9743:             }
                   9744:         }
                   9745:     }
                   9746: }
                   9747: 
1.305     raeburn  9748: // ]]>
                   9749: </script>
                   9750: 
                   9751: ENDSCRIPT
                   9752: }
                   9753: 
                   9754: sub noninst_users {
                   9755:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   9756:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                   9757:     my $class = 'LC_left_item';
                   9758:     if ($css_class) {
                   9759:         $css_class = ' class="'.$css_class.'"'; 
                   9760:     }
                   9761:     if ($rowid) {
                   9762:         $rowid = ' id="'.$rowid.'"';
                   9763:     }
                   9764:     if ($rowstyle) {
                   9765:         $rowstyle = ' style="'.$rowstyle.'"';
                   9766:     }
                   9767:     my ($output,$description);
                   9768:     if ($type eq 'default') {
                   9769:         $description = &mt('Requests for: [_1]',$typetitle);
                   9770:     } else {
                   9771:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   9772:     }
                   9773:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   9774:               "<td>$description</td>\n".           
                   9775:               '<td class="'.$class.'" colspan="2">'.
                   9776:               '<table><tr>';
                   9777:     my %headers = &Apache::lonlocal::texthash( 
                   9778:               approve  => 'Processing',
                   9779:               email    => 'E-mail',
                   9780:               username => 'Username',
                   9781:     );
                   9782:     foreach my $item ('approve','email','username') {
                   9783:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  9784:     }
1.305     raeburn  9785:     $output .= '</tr><tr>';
                   9786:     foreach my $item ('approve','email','username') {
1.306     raeburn  9787:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  9788:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   9789:         if ($item eq 'approve') {
                   9790:             %choices = &Apache::lonlocal::texthash (
                   9791:                                                      automatic => 'Automatically approved',
                   9792:                                                      approval  => 'Queued for approval',
                   9793:                                                    );
                   9794:             @options = ('automatic','approval');
                   9795:             $hashref = $processing;
                   9796:             $defoption = 'automatic';
                   9797:             $name = 'cancreate_emailprocess_'.$type;
                   9798:         } elsif ($item eq 'email') {
                   9799:             %choices = &Apache::lonlocal::texthash (
                   9800:                                                      any     => 'Any e-mail',
                   9801:                                                      inst    => 'Institutional only',
                   9802:                                                      noninst => 'Non-institutional only',
                   9803:                                                      custom  => 'Custom restrictions',
                   9804:                                                    );
                   9805:             @options = ('any','inst','noninst');
                   9806:             my $showcustom;
                   9807:             if (ref($emailrules) eq 'HASH') {
                   9808:                 if (keys(%{$emailrules}) > 0) {
                   9809:                     push(@options,'custom');
                   9810:                     $showcustom = 'cancreate_emailrule';
                   9811:                     if (ref($settings) eq 'HASH') {
                   9812:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   9813:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   9814:                                 if (exists($emailrules->{$rule})) {
                   9815:                                     $hascustom ++;
                   9816:                                 }
                   9817:                             }
                   9818:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   9819:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   9820:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   9821:                                     if (exists($emailrules->{$rule})) {
                   9822:                                         $hascustom ++;
                   9823:                                     }
                   9824:                                 }
                   9825:                             }
                   9826:                         }
                   9827:                     }
                   9828:                 }
                   9829:             }
                   9830:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   9831:                                                      "'cancreate_emaildomain','$type'".');"';
                   9832:             $hashref = $emailoptions;
                   9833:             $defoption = 'any';
                   9834:             $name = 'cancreate_emailoptions_'.$type;
                   9835:         } elsif ($item eq 'username') {
                   9836:             %choices = &Apache::lonlocal::texthash (
                   9837:                                                      all    => 'Same as e-mail',
                   9838:                                                      first  => 'Omit @domain',
                   9839:                                                      free   => 'Free to choose',
                   9840:                                                    );
                   9841:             @options = ('all','first','free');
                   9842:             $hashref = $emailverified;
                   9843:             $defoption = 'all';
                   9844:             $name = 'cancreate_usernameoptions_'.$type;
                   9845:         }
                   9846:         foreach my $option (@options) {
                   9847:             my $checked;
                   9848:             if (ref($hashref) eq 'HASH') {
                   9849:                 if ($type eq '') {
                   9850:                     if (!exists($hashref->{'default'})) {
                   9851:                         if ($option eq $defoption) {
                   9852:                             $checked = ' checked="checked"';
                   9853:                         }
                   9854:                     } else {
                   9855:                         if ($hashref->{'default'} eq $option) {
                   9856:                             $checked = ' checked="checked"';
                   9857:                         }
1.303     raeburn  9858:                     }
                   9859:                 } else {
1.305     raeburn  9860:                     if (!exists($hashref->{$type})) {
                   9861:                         if ($option eq $defoption) {
                   9862:                             $checked = ' checked="checked"';
                   9863:                         }
                   9864:                     } else {
                   9865:                         if ($hashref->{$type} eq $option) {
                   9866:                             $checked = ' checked="checked"';
                   9867:                         }
1.303     raeburn  9868:                     }
                   9869:                 }
1.305     raeburn  9870:             } elsif (($item eq 'email') && ($hascustom)) {
                   9871:                 if ($option eq 'custom') {
                   9872:                     $checked = ' checked="checked"';
                   9873:                 }
                   9874:             } elsif ($option eq $defoption) {
                   9875:                 $checked = ' checked="checked"';
                   9876:             }
                   9877:             $output .= '<span class="LC_nobreak"><label>'.
                   9878:                        '<input type="radio" name="'.$name.'"'.
                   9879:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   9880:                        $choices{$option}.'</label></span><br />';
                   9881:             if ($item eq 'email') {
                   9882:                 if ($option eq 'custom') {
                   9883:                     my $id = 'cancreate_emailrule_'.$type;
                   9884:                     my $display = 'none';
                   9885:                     if ($checked) {
                   9886:                         $display = 'inline';
1.303     raeburn  9887:                     }
1.305     raeburn  9888:                     my $numinrow = 2;
                   9889:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   9890:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   9891:                                &user_formats_row('email',$settings,$emailrules,
                   9892:                                                  $emailruleorder,$numinrow,'',$type);
                   9893:                               '</table></fieldset>';
                   9894:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   9895:                     my %text = &Apache::lonlocal::texthash (
                   9896:                                                              inst    => 'must end:',
                   9897:                                                              noninst => 'cannot end:',
                   9898:                                                            );
                   9899:                     my $value;
                   9900:                     if (ref($emaildomain) eq 'HASH') {
                   9901:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   9902:                             $value = $emaildomain->{$type}->{$option}; 
1.303     raeburn  9903:                         }
                   9904:                     }
1.305     raeburn  9905:                     if ($value eq '') {
                   9906:                         $value = '@'.$intdom;
                   9907:                     }
                   9908:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   9909:                     my $display = 'none';
                   9910:                     if ($checked) {
                   9911:                         $display = 'inline';
                   9912:                     }
                   9913:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   9914:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   9915:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   9916:                                '</div>';
1.303     raeburn  9917:                 }
                   9918:             }
                   9919:         }
1.305     raeburn  9920:         $output .= '</td>'."\n";
1.303     raeburn  9921:     }
1.305     raeburn  9922:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  9923:     return $output;
                   9924: }
                   9925: 
1.165     raeburn  9926: sub captcha_choice {
1.305     raeburn  9927:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  9928:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   9929:         $vertext,$currver);
1.165     raeburn  9930:     my %lt = &captcha_phrases();
                   9931:     $keyentry = 'hidden';
1.354     raeburn  9932:     my $colspan=2;
1.165     raeburn  9933:     if ($context eq 'cancreate') {
1.224     raeburn  9934:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  9935:     } elsif ($context eq 'login') {
                   9936:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.354     raeburn  9937:     } elsif ($context eq 'passwords') {
                   9938:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   9939:         $colspan=1;
1.165     raeburn  9940:     }
                   9941:     if (ref($settings) eq 'HASH') {
                   9942:         if ($settings->{'captcha'}) {
                   9943:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   9944:         } else {
                   9945:             $checked{'original'} = ' checked="checked"';
                   9946:         }
                   9947:         if ($settings->{'captcha'} eq 'recaptcha') {
                   9948:             $pubtext = $lt{'pub'};
                   9949:             $privtext = $lt{'priv'};
                   9950:             $keyentry = 'text';
1.269     raeburn  9951:             $vertext = $lt{'ver'};
                   9952:             $currver = $settings->{'recaptchaversion'};
                   9953:             if ($currver ne '2') {
                   9954:                 $currver = 1;
                   9955:             }
1.165     raeburn  9956:         }
                   9957:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   9958:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   9959:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   9960:         }
                   9961:     } else {
                   9962:         $checked{'original'} = ' checked="checked"';
                   9963:     }
1.305     raeburn  9964:     my $css_class;
                   9965:     if ($itemcount%2) {
                   9966:         $css_class = 'LC_odd_row';
                   9967:     }
                   9968:     if ($customcss) {
                   9969:         $css_class .= " $customcss";
                   9970:     }
                   9971:     $css_class =~ s/^\s+//;
                   9972:     if ($css_class) {
                   9973:         $css_class = ' class="'.$css_class.'"';
                   9974:     }
                   9975:     if ($rowstyle) {
                   9976:         $css_class .= ' style="'.$rowstyle.'"';
                   9977:     }
1.169     raeburn  9978:     my $output = '<tr'.$css_class.'>'.
1.354     raeburn  9979:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165     raeburn  9980:                  '<table><tr><td>'."\n";
                   9981:     foreach my $option ('original','recaptcha','notused') {
                   9982:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   9983:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   9984:                    $lt{$option}.'</label></span>';
                   9985:         unless ($option eq 'notused') {
                   9986:             $output .= ('&nbsp;'x2)."\n";
                   9987:         }
                   9988:     }
                   9989: #
                   9990: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   9991: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  9992: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  9993: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  9994: #
1.165     raeburn  9995:     $output .= '</td></tr>'."\n".
1.305     raeburn  9996:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  9997:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   9998:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   9999:                $currpub.'" size="40" /></span><br />'."\n".
                   10000:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   10001:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  10002:                $currpriv.'" size="40" /></span><br />'.
                   10003:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   10004:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   10005:                $currver.'" size="3" /></span><br />'.
                   10006:                '</td></tr></table>'."\n".
1.165     raeburn  10007:                '</td></tr>';
                   10008:     return $output;
                   10009: }
                   10010: 
1.32      raeburn  10011: sub user_formats_row {
1.305     raeburn  10012:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  10013:     my $output;
                   10014:     my %text = (
                   10015:                    'username' => 'new usernames',
                   10016:                    'id'       => 'IDs',
                   10017:                );
1.305     raeburn  10018:     unless ($type eq 'email') {
                   10019:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   10020:         $output = '<tr '.$css_class.'>'.
                   10021:                   '<td><span class="LC_nobreak">'.
                   10022:                   &mt("Format rules to check for $text{$type}: ").
                   10023:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  10024:     }
1.27      raeburn  10025:     my $rem;
                   10026:     if (ref($ruleorder) eq 'ARRAY') {
                   10027:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   10028:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   10029:                 my $rem = $i%($numinrow);
                   10030:                 if ($rem == 0) {
                   10031:                     if ($i > 0) {
                   10032:                         $output .= '</tr>';
                   10033:                     }
                   10034:                     $output .= '<tr>';
                   10035:                 }
                   10036:                 my $check = ' ';
1.39      raeburn  10037:                 if (ref($settings) eq 'HASH') {
                   10038:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   10039:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   10040:                             $check = ' checked="checked" ';
                   10041:                         }
1.305     raeburn  10042:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   10043:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   10044:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   10045:                                 $check = ' checked="checked" ';
                   10046:                             }
                   10047:                         }
1.27      raeburn  10048:                     }
                   10049:                 }
1.305     raeburn  10050:                 my $name = $type.'_rule';
                   10051:                 if ($type eq 'email') {
                   10052:                     $name .= '_'.$status;
                   10053:                 }
1.27      raeburn  10054:                 $output .= '<td class="LC_left_item">'.
                   10055:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  10056:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  10057:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   10058:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   10059:             }
                   10060:         }
                   10061:         $rem = @{$ruleorder}%($numinrow);
                   10062:     }
1.305     raeburn  10063:     my $colsleft;
                   10064:     if ($rem) {
                   10065:         $colsleft = $numinrow - $rem;
                   10066:     }
1.27      raeburn  10067:     if ($colsleft > 1 ) {
                   10068:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   10069:                    '&nbsp;</td>';
                   10070:     } elsif ($colsleft == 1) {
                   10071:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   10072:     }
1.305     raeburn  10073:     $output .= '</tr></table>';
                   10074:     unless ($type eq 'email') {
                   10075:         $output .= '</td></tr>';
                   10076:     }
1.27      raeburn  10077:     return $output;
                   10078: }
                   10079: 
1.34      raeburn  10080: sub usercreation_types {
                   10081:     my %lt = &Apache::lonlocal::texthash (
                   10082:                     author     => 'When adding a co-author',
                   10083:                     course     => 'When adding a user to a course',
1.100     raeburn  10084:                     requestcrs => 'When requesting a course',
1.34      raeburn  10085:                     any        => 'Any',
                   10086:                     official   => 'Institutional only ',
                   10087:                     unofficial => 'Non-institutional only',
                   10088:                     none       => 'None',
                   10089:     );
                   10090:     return %lt;
1.48      raeburn  10091: }
1.34      raeburn  10092: 
1.224     raeburn  10093: sub selfcreation_types {
                   10094:     my %lt = &Apache::lonlocal::texthash (
                   10095:                     selfcreate => 'User creates own account',
                   10096:                     any        => 'Any',
                   10097:                     official   => 'Institutional only ',
                   10098:                     unofficial => 'Non-institutional only',
                   10099:                     email      => 'E-mail address',
                   10100:                     login      => 'Institutional Login',
                   10101:                     sso        => 'SSO',
                   10102:              );
                   10103: }
                   10104: 
1.28      raeburn  10105: sub authtype_names {
                   10106:     my %lt = &Apache::lonlocal::texthash(
                   10107:                       int    => 'Internal',
                   10108:                       krb4   => 'Kerberos 4',
                   10109:                       krb5   => 'Kerberos 5',
                   10110:                       loc    => 'Local',
1.325     raeburn  10111:                       lti    => 'LTI',
1.28      raeburn  10112:                   );
                   10113:     return %lt;
                   10114: }
                   10115: 
                   10116: sub context_names {
                   10117:     my %context_title = &Apache::lonlocal::texthash(
                   10118:        author => 'Creating users when an Author',
                   10119:        course => 'Creating users when in a course',
                   10120:        domain => 'Creating users when a Domain Coordinator',
                   10121:     );
                   10122:     return %context_title;
                   10123: }
                   10124: 
1.33      raeburn  10125: sub print_usermodification {
                   10126:     my ($position,$dom,$settings,$rowtotal) = @_;
                   10127:     my $numinrow = 4;
                   10128:     my ($context,$datatable,$rowcount);
                   10129:     if ($position eq 'top') {
                   10130:         $rowcount = 0;
                   10131:         $context = 'author'; 
                   10132:         foreach my $role ('ca','aa') {
                   10133:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10134:                                                    $numinrow,$rowcount);
                   10135:             $$rowtotal ++;
                   10136:             $rowcount ++;
                   10137:         }
1.230     raeburn  10138:     } elsif ($position eq 'bottom') {
1.33      raeburn  10139:         $context = 'course';
                   10140:         $rowcount = 0;
                   10141:         foreach my $role ('st','ep','ta','in','cr') {
                   10142:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   10143:                                                    $numinrow,$rowcount);
                   10144:             $$rowtotal ++;
                   10145:             $rowcount ++;
                   10146:         }
                   10147:     }
                   10148:     return $datatable;
                   10149: }
                   10150: 
1.43      raeburn  10151: sub print_defaults {
1.236     raeburn  10152:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  10153:     my $rownum = 0;
1.294     raeburn  10154:     my ($datatable,$css_class,$titles);
                   10155:     unless ($position eq 'bottom') {
                   10156:         $titles = &defaults_titles($dom);
                   10157:     }
1.236     raeburn  10158:     if ($position eq 'top') {
                   10159:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   10160:                      'datelocale_def','portal_def');
                   10161:         my %defaults;
                   10162:         if (ref($settings) eq 'HASH') {
                   10163:             %defaults = %{$settings};
1.43      raeburn  10164:         } else {
1.236     raeburn  10165:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10166:             foreach my $item (@items) {
                   10167:                 $defaults{$item} = $domdefaults{$item};
                   10168:             }
1.43      raeburn  10169:         }
1.236     raeburn  10170:         foreach my $item (@items) {
                   10171:             if ($rownum%2) {
                   10172:                 $css_class = '';
                   10173:             } else {
                   10174:                 $css_class = ' class="LC_odd_row" ';
                   10175:             }
                   10176:             $datatable .= '<tr'.$css_class.'>'.
                   10177:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   10178:                           '</span></td><td class="LC_right_item" colspan="3">';
                   10179:             if ($item eq 'auth_def') {
1.325     raeburn  10180:                 my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236     raeburn  10181:                 my %shortauth = (
                   10182:                                  internal => 'int',
                   10183:                                  krb4 => 'krb4',
                   10184:                                  krb5 => 'krb5',
1.325     raeburn  10185:                                  localauth  => 'loc',
                   10186:                                  lti => 'lti',
1.236     raeburn  10187:                                 );
                   10188:                 my %authnames = &authtype_names();
                   10189:                 foreach my $auth (@authtypes) {
                   10190:                     my $checked = ' ';
                   10191:                     if ($defaults{$item} eq $auth) {
                   10192:                         $checked = ' checked="checked" ';
                   10193:                     }
                   10194:                     $datatable .= '<label><input type="radio" name="'.$item.
                   10195:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   10196:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   10197:                 }
                   10198:             } elsif ($item eq 'timezone_def') {
                   10199:                 my $includeempty = 1;
                   10200:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   10201:             } elsif ($item eq 'datelocale_def') {
                   10202:                 my $includeempty = 1;
                   10203:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   10204:             } elsif ($item eq 'lang_def') {
1.263     raeburn  10205:                 my $includeempty = 1;
                   10206:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  10207:             } else {
                   10208:                 my $size;
                   10209:                 if ($item eq 'portal_def') {
                   10210:                     $size = ' size="25"';
                   10211:                 }
                   10212:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   10213:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  10214:             }
1.236     raeburn  10215:             $datatable .= '</td></tr>';
                   10216:             $rownum ++;
                   10217:         }
1.354     raeburn  10218:     } else {
1.294     raeburn  10219:         my %defaults;
                   10220:         if (ref($settings) eq 'HASH') {
1.354     raeburn  10221:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   10222:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   10223:                 for (my $i=0; $i<$maxnum; $i++) {
                   10224:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10225:                     my $item = $settings->{'inststatusorder'}->[$i];
                   10226:                     my $title = $settings->{'inststatustypes'}->{$item};
                   10227:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   10228:                     $datatable .= '<tr'.$css_class.'>'.
                   10229:                                   '<td><span class="LC_nobreak">'.
                   10230:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   10231:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10232:                         my $vpos = $k+1;
                   10233:                         my $selstr;
                   10234:                         if ($k == $i) {
                   10235:                             $selstr = ' selected="selected" ';
                   10236:                         }
                   10237:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10238:                     }
                   10239:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   10240:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   10241:                                   &mt('delete').'</span></td>'.
1.380     raeburn  10242:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354     raeburn  10243:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   10244:                                   '</span></td></tr>';
                   10245:                 }
                   10246:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10247:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   10248:                 $datatable .= '<tr '.$css_class.'>'.
                   10249:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   10250:                 for (my $k=0; $k<=$maxnum; $k++) {
                   10251:                     my $vpos = $k+1;
                   10252:                     my $selstr;
                   10253:                     if ($k == $maxnum) {
                   10254:                         $selstr = ' selected="selected" ';
                   10255:                     }
                   10256:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10257:                 }
                   10258:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                   10259:                               '<input type="text" size="10" name="addinststatus" value="" />'.
                   10260:                               '&nbsp;'.&mt('(new)').
                   10261:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380     raeburn  10262:                               &mt('Name displayed').':'.
1.354     raeburn  10263:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   10264:                               '</tr>'."\n";
                   10265:                 $rownum ++;
1.294     raeburn  10266:             }
1.354     raeburn  10267:         }
                   10268:     }
                   10269:     $$rowtotal += $rownum;
1.43      raeburn  10270:     return $datatable;
                   10271: }
                   10272: 
1.168     raeburn  10273: sub get_languages_hash {
                   10274:     my %langchoices;
                   10275:     foreach my $id (&Apache::loncommon::languageids()) {
                   10276:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   10277:         if ($code ne '') {
                   10278:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   10279:         }
                   10280:     }
                   10281:     return %langchoices;
                   10282: }
                   10283: 
1.43      raeburn  10284: sub defaults_titles {
1.141     raeburn  10285:     my ($dom) = @_;
1.43      raeburn  10286:     my %titles = &Apache::lonlocal::texthash (
                   10287:                    'auth_def'      => 'Default authentication type',
                   10288:                    'auth_arg_def'  => 'Default authentication argument',
                   10289:                    'lang_def'      => 'Default language',
1.54      raeburn  10290:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  10291:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  10292:                    'portal_def'     => 'Portal/Default URL',
1.294     raeburn  10293:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   10294:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   10295:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  10296:                  );
1.141     raeburn  10297:     if ($dom) {
                   10298:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   10299:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   10300:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   10301:         $protocol = 'http' if ($protocol ne 'https');
                   10302:         if ($uint_dom) {
                   10303:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   10304:                                          $uint_dom);
                   10305:         }
                   10306:     }
1.43      raeburn  10307:     return (\%titles);
                   10308: }
                   10309: 
1.346     raeburn  10310: sub print_scantron {
                   10311:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   10312:     if ($position eq 'top') {
                   10313:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   10314:     } else {
                   10315:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   10316:     }
                   10317: }
                   10318: 
                   10319: sub scantron_javascript {
                   10320:     return <<"ENDSCRIPT";
                   10321: 
                   10322: <script type="text/javascript">
                   10323: // <![CDATA[
                   10324: 
                   10325: function toggleScantron(form) {
1.347     raeburn  10326:     var csvfieldset = new Array();
1.346     raeburn  10327:     if (document.getElementById('scantroncsv_cols')) {
1.347     raeburn  10328:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   10329:     }
                   10330:     if (document.getElementById('scantroncsv_options')) {
                   10331:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   10332:     }
                   10333:     if (csvfieldset.length) {
1.346     raeburn  10334:         if (document.getElementById('scantronconfcsv')) {
1.347     raeburn  10335:             var scantroncsv = document.getElementById('scantronconfcsv');
1.346     raeburn  10336:             if (scantroncsv.checked) {
1.347     raeburn  10337:                 for (var i=0; i<csvfieldset.length; i++) {
                   10338:                     csvfieldset[i].style.display = 'block';
                   10339:                 }
1.346     raeburn  10340:             } else {
1.347     raeburn  10341:                 for (var i=0; i<csvfieldset.length; i++) {
                   10342:                     csvfieldset[i].style.display = 'none';
                   10343:                 }
1.346     raeburn  10344:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   10345:                 if (csvselects.length) {
                   10346:                     for (var j=0; j<csvselects.length; j++) {
                   10347:                         csvselects[j].selectedIndex = 0;
                   10348:                     }
                   10349:                 }
                   10350:             }
                   10351:         }
                   10352:     }
                   10353:     return;
                   10354: }
                   10355: // ]]>
                   10356: </script>
                   10357: 
                   10358: ENDSCRIPT
                   10359: 
                   10360: }
                   10361: 
1.46      raeburn  10362: sub print_scantronformat {
                   10363:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   10364:     my $itemcount = 1;
1.60      raeburn  10365:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   10366:         %confhash);
1.46      raeburn  10367:     my $switchserver = &check_switchserver($dom,$confname);
                   10368:     my %lt = &Apache::lonlocal::texthash (
1.95      www      10369:                 default => 'Default bubblesheet format file error',
                   10370:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  10371:              );
                   10372:     my %scantronfiles = (
                   10373:         default => 'default.tab',
                   10374:         custom => 'custom.tab',
                   10375:     );
                   10376:     foreach my $key (keys(%scantronfiles)) {
                   10377:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   10378:                               .$scantronfiles{$key};
                   10379:     }
                   10380:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   10381:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   10382:         if (!$switchserver) {
                   10383:             my $servadm = $r->dir_config('lonAdmEMail');
                   10384:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   10385:             if ($configuserok eq 'ok') {
                   10386:                 if ($author_ok eq 'ok') {
                   10387:                     my %legacyfile = (
1.346     raeburn  10388:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   10389:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  10390:                     );
                   10391:                     my %md5chk;
                   10392:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  10393:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   10394:                         chomp($md5chk{$type});
1.46      raeburn  10395:                     }
                   10396:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   10397:                         foreach my $type (keys(%legacyfile)) {
1.346     raeburn  10398:                             ($scantronurls{$type},my $error) =
1.46      raeburn  10399:                                 &legacy_scantronformat($r,$dom,$confname,
                   10400:                                                  $type,$legacyfile{$type},
                   10401:                                                  $scantronurls{$type},
                   10402:                                                  $scantronfiles{$type});
1.60      raeburn  10403:                             if ($error ne '') {
                   10404:                                 $error{$type} = $error;
                   10405:                             }
                   10406:                         }
                   10407:                         if (keys(%error) == 0) {
                   10408:                             $is_custom = 1;
1.346     raeburn  10409:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  10410:                                 $scantronurls{'custom'};
1.346     raeburn  10411:                             my $putresult =
1.60      raeburn  10412:                                 &Apache::lonnet::put_dom('configuration',
                   10413:                                                          \%confhash,$dom);
                   10414:                             if ($putresult ne 'ok') {
1.346     raeburn  10415:                                 $error{'custom'} =
1.60      raeburn  10416:                                     '<span class="LC_error">'.
                   10417:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10418:                             }
1.46      raeburn  10419:                         }
                   10420:                     } else {
1.60      raeburn  10421:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  10422:                             &legacy_scantronformat($r,$dom,$confname,
                   10423:                                           'default',$legacyfile{'default'},
                   10424:                                           $scantronurls{'default'},
                   10425:                                           $scantronfiles{'default'});
1.60      raeburn  10426:                         if ($error eq '') {
                   10427:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   10428:                             my $putresult =
                   10429:                                 &Apache::lonnet::put_dom('configuration',
                   10430:                                                          \%confhash,$dom);
                   10431:                             if ($putresult ne 'ok') {
                   10432:                                 $error{'default'} =
                   10433:                                     '<span class="LC_error">'.
                   10434:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   10435:                             }
                   10436:                         } else {
                   10437:                             $error{'default'} = $error;
                   10438:                         }
1.46      raeburn  10439:                     }
                   10440:                 }
                   10441:             }
                   10442:         } else {
1.95      www      10443:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  10444:         }
                   10445:     }
                   10446:     if (ref($settings) eq 'HASH') {
                   10447:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   10448:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   10449:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   10450:                 $scantronurl = '';
                   10451:             } else {
                   10452:                 $scantronurl = $settings->{'scantronformat'};
                   10453:             }
                   10454:             $is_custom = 1;
                   10455:         } else {
                   10456:             $scantronurl = $scantronurls{'default'};
                   10457:         }
                   10458:     } else {
1.60      raeburn  10459:         if ($is_custom) {
                   10460:             $scantronurl = $scantronurls{'custom'};
                   10461:         } else {
                   10462:             $scantronurl = $scantronurls{'default'};
                   10463:         }
1.46      raeburn  10464:     }
                   10465:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10466:     $datatable .= '<tr'.$css_class.'>';
                   10467:     if (!$is_custom) {
1.65      raeburn  10468:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   10469:                       '<span class="LC_nobreak">';
1.46      raeburn  10470:         if ($scantronurl) {
1.199     raeburn  10471:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   10472:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  10473:         } else {
                   10474:             $datatable = &mt('File unavailable for display');
                   10475:         }
1.65      raeburn  10476:         $datatable .= '</span></td>';
1.60      raeburn  10477:         if (keys(%error) == 0) { 
1.306     raeburn  10478:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  10479:             if (!$switchserver) {
                   10480:                 $datatable .= &mt('Upload:').'<br />';
                   10481:             }
                   10482:         } else {
                   10483:             my $errorstr;
                   10484:             foreach my $key (sort(keys(%error))) {
                   10485:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   10486:             }
                   10487:             $datatable .= '<td>'.$errorstr;
                   10488:         }
1.46      raeburn  10489:     } else {
                   10490:         if (keys(%error) > 0) {
                   10491:             my $errorstr;
                   10492:             foreach my $key (sort(keys(%error))) {
                   10493:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   10494:             } 
1.60      raeburn  10495:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  10496:         } elsif ($scantronurl) {
1.199     raeburn  10497:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   10498:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  10499:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  10500:                           $link.
                   10501:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   10502:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  10503:                           '<td><span class="LC_nobreak">&nbsp;'.
                   10504:                           &mt('Replace:').'</span><br />';
1.46      raeburn  10505:         }
                   10506:     }
                   10507:     if (keys(%error) == 0) {
                   10508:         if ($switchserver) {
                   10509:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   10510:         } else {
1.65      raeburn  10511:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   10512:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  10513:         }
                   10514:     }
                   10515:     $datatable .= '</td></tr>';
                   10516:     $$rowtotal ++;
                   10517:     return $datatable;
                   10518: }
                   10519: 
                   10520: sub legacy_scantronformat {
                   10521:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   10522:     my ($url,$error);
                   10523:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   10524:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   10525:         (my $result,$url) =
                   10526:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   10527:                          '','',$newfile);
                   10528:         if ($result ne 'ok') {
1.130     raeburn  10529:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  10530:         }
                   10531:     }
                   10532:     return ($url,$error);
                   10533: }
1.43      raeburn  10534: 
1.346     raeburn  10535: sub print_scantronconfig {
                   10536:     my ($dom,$settings,$rowtotal) = @_;
                   10537:     my $itemcount = 2;
                   10538:     my $is_checked = ' checked="checked"';
1.347     raeburn  10539:     my %optionson = (
                   10540:                      hdr => ' checked="checked"',
                   10541:                      pad => ' checked="checked"',
                   10542:                      rem => ' checked="checked"',
                   10543:                     );
                   10544:     my %optionsoff = (
                   10545:                       hdr => '',
                   10546:                       pad => '',
                   10547:                       rem => '',
                   10548:                      );
1.346     raeburn  10549:     my $currcsvsty = 'none';
1.347     raeburn  10550:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346     raeburn  10551:     my @fields = &scantroncsv_fields();
                   10552:     my %titles = &scantronconfig_titles();
                   10553:     if (ref($settings) eq 'HASH') {
                   10554:         if (ref($settings->{config}) eq 'HASH') {
                   10555:             if ($settings->{config}->{dat}) {
                   10556:                 $checked{'dat'} = $is_checked;
                   10557:             }
                   10558:             if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347     raeburn  10559:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   10560:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   10561:                     if (keys(%csvfields) > 0) {
                   10562:                         $checked{'csv'} = $is_checked;
                   10563:                         $currcsvsty = 'block';
                   10564:                     }
                   10565:                 }
                   10566:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   10567:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   10568:                     foreach my $option (keys(%optionson)) {
                   10569:                         unless ($csvoptions{$option}) {
                   10570:                             $optionsoff{$option} = $optionson{$option};
                   10571:                             $optionson{$option} = '';
                   10572:                         }
                   10573:                     }
1.346     raeburn  10574:                 }
                   10575:             }
                   10576:         } else {
                   10577:             $checked{'dat'} = $is_checked;
                   10578:         }
                   10579:     } else {
                   10580:         $checked{'dat'} = $is_checked;
                   10581:     }
                   10582:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   10583:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   10584:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   10585:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   10586:     foreach my $item ('dat','csv') {
                   10587:         my $id;
                   10588:         if ($item eq 'csv') {
                   10589:             $id = 'id="scantronconfcsv" ';
1.347     raeburn  10590:         }
1.346     raeburn  10591:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   10592:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   10593:         if ($item eq 'csv') {
                   10594:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   10595:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   10596:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   10597:             foreach my $col (@fields) {
                   10598:                 my $selnone;
                   10599:                 if ($csvfields{$col} eq '') {
                   10600:                     $selnone = ' selected="selected"';
                   10601:                 }
                   10602:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   10603:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   10604:                               '<option value=""'.$selnone.'></option>';
                   10605:                 for (my $i=0; $i<20; $i++) {
                   10606:                     my $shown = $i+1;
                   10607:                     my $sel;
                   10608:                     unless ($selnone) {
                   10609:                         if (exists($csvfields{$col})) {
                   10610:                             if ($csvfields{$col} == $i) {
                   10611:                                 $sel = ' selected="selected"';
                   10612:                             }
                   10613:                         }
                   10614:                     }
                   10615:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   10616:                 }
                   10617:                 $datatable .= '</select></td></tr>';
                   10618:            }
1.347     raeburn  10619:            $datatable .= '</table></fieldset>'.
                   10620:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   10621:                          '<legend>'.&mt('CSV Options').'</legend>';
                   10622:            foreach my $option ('hdr','pad','rem') {
                   10623:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   10624:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   10625:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   10626:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   10627:            }
                   10628:            $datatable .= '</fieldset>';
1.346     raeburn  10629:            $itemcount ++;
                   10630:         }
                   10631:     }
                   10632:     $datatable .= '</td></tr>';
                   10633:     $$rowtotal ++;
                   10634:     return $datatable;
                   10635: }
                   10636: 
                   10637: sub scantronconfig_titles {
                   10638:     return &Apache::lonlocal::texthash(
                   10639:                                           dat => 'Standard format (.dat)',
                   10640:                                           csv => 'Comma separated values (.csv)',
1.347     raeburn  10641:                                           hdr => 'Remove first line in file (contains column titles)',
                   10642:                                           pad => 'Prepend 0s to PaperID',
1.348     raeburn  10643:                                           rem => 'Remove leading spaces (except Question Response columns)',
1.346     raeburn  10644:                                           CODE => 'CODE',
                   10645:                                           ID   => 'Student ID',
                   10646:                                           PaperID => 'Paper ID',
                   10647:                                           FirstName => 'First Name',
                   10648:                                           LastName => 'Last Name',
                   10649:                                           FirstQuestion => 'First Question Response',
                   10650:                                           Section => 'Section',
                   10651:     );
                   10652: }
                   10653: 
                   10654: sub scantroncsv_fields {
                   10655:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   10656: }
                   10657: 
1.49      raeburn  10658: sub print_coursecategories {
1.57      raeburn  10659:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   10660:     my $datatable;
                   10661:     if ($position eq 'top') {
1.238     raeburn  10662:         my (%checked);
                   10663:         my @catitems = ('unauth','auth');
                   10664:         my @cattypes = ('std','domonly','codesrch','none');
                   10665:         $checked{'unauth'} = 'std';
                   10666:         $checked{'auth'} = 'std';
                   10667:         if (ref($settings) eq 'HASH') {
                   10668:             foreach my $type (@cattypes) {
                   10669:                 if ($type eq $settings->{'unauth'}) {
                   10670:                     $checked{'unauth'} = $type;
                   10671:                 }
                   10672:                 if ($type eq $settings->{'auth'}) {
                   10673:                     $checked{'auth'} = $type;
                   10674:                 }
                   10675:             }
                   10676:         }
                   10677:         my %lt = &Apache::lonlocal::texthash (
                   10678:                                                unauth   => 'Catalog type for unauthenticated users',
                   10679:                                                auth     => 'Catalog type for authenticated users',
                   10680:                                                none     => 'No catalog',
                   10681:                                                std      => 'Standard catalog',
                   10682:                                                domonly  => 'Domain-only catalog',
                   10683:                                                codesrch => "Code search form",
                   10684:                                              );
                   10685:        my $itemcount = 0;
                   10686:        foreach my $item (@catitems) {
                   10687:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   10688:            $datatable .= '<tr '.$css_class.'>'.
                   10689:                          '<td>'.$lt{$item}.'</td>'.
                   10690:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   10691:            foreach my $type (@cattypes) {
                   10692:                my $ischecked;
                   10693:                if ($checked{$item} eq $type) {
                   10694:                    $ischecked=' checked="checked"';
                   10695:                }
                   10696:                $datatable .= '<label>'.
                   10697:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   10698:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   10699:            }
1.327     raeburn  10700:            $datatable .= '</span></td></tr>';
1.238     raeburn  10701:            $itemcount ++;
                   10702:         }
                   10703:         $$rowtotal += $itemcount;
                   10704:     } elsif ($position eq 'middle') {
1.57      raeburn  10705:         my $toggle_cats_crs = ' ';
                   10706:         my $toggle_cats_dom = ' checked="checked" ';
                   10707:         my $can_cat_crs = ' ';
                   10708:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  10709:         my $toggle_catscomm_comm = ' ';
                   10710:         my $toggle_catscomm_dom = ' checked="checked" ';
                   10711:         my $can_catcomm_comm = ' ';
                   10712:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  10713:         my $toggle_catsplace_place = ' ';
                   10714:         my $toggle_catsplace_dom = ' checked="checked" ';
                   10715:         my $can_catplace_place = ' ';
                   10716:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  10717: 
1.57      raeburn  10718:         if (ref($settings) eq 'HASH') {
                   10719:             if ($settings->{'togglecats'} eq 'crs') {
                   10720:                 $toggle_cats_crs = $toggle_cats_dom;
                   10721:                 $toggle_cats_dom = ' ';
                   10722:             }
                   10723:             if ($settings->{'categorize'} eq 'crs') {
                   10724:                 $can_cat_crs = $can_cat_dom;
                   10725:                 $can_cat_dom = ' ';
                   10726:             }
1.120     raeburn  10727:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   10728:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   10729:                 $toggle_catscomm_dom = ' ';
                   10730:             }
                   10731:             if ($settings->{'categorizecomm'} eq 'comm') {
                   10732:                 $can_catcomm_comm = $can_catcomm_dom;
                   10733:                 $can_catcomm_dom = ' ';
                   10734:             }
1.272     raeburn  10735:             if ($settings->{'togglecatsplace'} eq 'place') {
                   10736:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   10737:                 $toggle_catsplace_dom = ' ';
                   10738:             }
                   10739:             if ($settings->{'categorizeplace'} eq 'place') {
                   10740:                 $can_catplace_place = $can_catplace_dom;
                   10741:                 $can_catplace_dom = ' ';
                   10742:             }
1.57      raeburn  10743:         }
                   10744:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  10745:                      togglecats      => 'Show/Hide a course in catalog',
                   10746:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   10747:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   10748:                      categorize      => 'Assign a category to a course',
                   10749:                      categorizecomm  => 'Assign a category to a community',
                   10750:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  10751:                     );
                   10752:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  10753:                      dom   => 'Set in Domain',
                   10754:                      crs   => 'Set in Course',
                   10755:                      comm  => 'Set in Community',
                   10756:                      place => 'Set in Placement Test',
1.57      raeburn  10757:                     );
                   10758:         $datatable = '<tr class="LC_odd_row">'.
                   10759:                   '<td>'.$title{'togglecats'}.'</td>'.
                   10760:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10761:                   '<input type="radio" name="togglecats"'.
                   10762:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10763:                   '<label><input type="radio" name="togglecats"'.
                   10764:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   10765:                   '</tr><tr>'.
                   10766:                   '<td>'.$title{'categorize'}.'</td>'.
                   10767:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10768:                   '<label><input type="radio" name="categorize"'.
                   10769:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10770:                   '<label><input type="radio" name="categorize"'.
                   10771:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  10772:                   '</tr><tr class="LC_odd_row">'.
                   10773:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   10774:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10775:                   '<input type="radio" name="togglecatscomm"'.
                   10776:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10777:                   '<label><input type="radio" name="togglecatscomm"'.
                   10778:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   10779:                   '</tr><tr>'.
                   10780:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   10781:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10782:                   '<label><input type="radio" name="categorizecomm"'.
                   10783:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10784:                   '<label><input type="radio" name="categorizecomm"'.
                   10785:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327     raeburn  10786:                   '</tr><tr class="LC_odd_row">'.
1.272     raeburn  10787:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   10788:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   10789:                   '<input type="radio" name="togglecatsplace"'.
                   10790:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10791:                   '<label><input type="radio" name="togglecatscomm"'.
                   10792:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   10793:                   '</tr><tr>'.
                   10794:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   10795:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   10796:                   '<label><input type="radio" name="categorizeplace"'.
                   10797:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   10798:                   '<label><input type="radio" name="categorizeplace"'.
                   10799:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  10800:                   '</tr>';
1.272     raeburn  10801:         $$rowtotal += 6;
1.57      raeburn  10802:     } else {
                   10803:         my $css_class;
                   10804:         my $itemcount = 1;
                   10805:         my $cathash; 
                   10806:         if (ref($settings) eq 'HASH') {
                   10807:             $cathash = $settings->{'cats'};
                   10808:         }
                   10809:         if (ref($cathash) eq 'HASH') {
                   10810:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   10811:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   10812:                                                    \%allitems,\%idx,\@jsarray);
                   10813:             my $maxdepth = scalar(@cats);
                   10814:             my $colattrib = '';
                   10815:             if ($maxdepth > 2) {
                   10816:                 $colattrib = ' colspan="2" ';
                   10817:             }
                   10818:             my @path;
                   10819:             if (@cats > 0) {
                   10820:                 if (ref($cats[0]) eq 'ARRAY') {
                   10821:                     my $numtop = @{$cats[0]};
                   10822:                     my $maxnum = $numtop;
1.120     raeburn  10823:                     my %default_names = (
                   10824:                           instcode    => &mt('Official courses'),
                   10825:                           communities => &mt('Communities'),
1.272     raeburn  10826:                           placement   => &mt('Placement Tests'),
1.120     raeburn  10827:                     );
                   10828: 
                   10829:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   10830:                         ($cathash->{'instcode::0'} eq '') ||
                   10831:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  10832:                         ($cathash->{'communities::0'} eq '') ||
                   10833:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   10834:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  10835:                         $maxnum ++;
                   10836:                     }
                   10837:                     my $lastidx;
                   10838:                     for (my $i=0; $i<$numtop; $i++) {
                   10839:                         my $parent = $cats[0][$i];
                   10840:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10841:                         my $item = &escape($parent).'::0';
                   10842:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   10843:                         $lastidx = $idx{$item};
                   10844:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   10845:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   10846:                         for (my $k=0; $k<=$maxnum; $k++) {
                   10847:                             my $vpos = $k+1;
                   10848:                             my $selstr;
                   10849:                             if ($k == $i) {
                   10850:                                 $selstr = ' selected="selected" ';
                   10851:                             }
                   10852:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10853:                         }
1.214     raeburn  10854:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  10855:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  10856:                             $datatable .=  '<span class="LC_nobreak">'
                   10857:                                            .$default_names{$parent}.'</span>';
                   10858:                             if ($parent eq 'instcode') {
                   10859:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   10860:                                               .&mt('with institutional codes')
                   10861:                                               .')</span></td><td'.$colattrib.'>';
                   10862:                             } else {
                   10863:                                 $datatable .= '<table><tr><td>';
                   10864:                             }
                   10865:                             $datatable .= '<span class="LC_nobreak">'
                   10866:                                           .'<label><input type="radio" name="'
                   10867:                                           .$parent.'" value="1" checked="checked" />'
                   10868:                                           .&mt('Display').'</label>';
                   10869:                             if ($parent eq 'instcode') {
                   10870:                                 $datatable .= '&nbsp;';
                   10871:                             } else {
                   10872:                                 $datatable .= '</span></td></tr><tr><td>'
                   10873:                                               .'<span class="LC_nobreak">';
                   10874:                             }
                   10875:                             $datatable .= '<label><input type="radio" name="'
                   10876:                                           .$parent.'" value="0" />'
                   10877:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  10878:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  10879:                                 $datatable .= '</td></tr></table>';
                   10880:                             }
                   10881:                             $datatable .= '</td>';
1.57      raeburn  10882:                         } else {
                   10883:                             $datatable .= $parent
1.214     raeburn  10884:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   10885:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  10886:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   10887:                         }
                   10888:                         my $depth = 1;
                   10889:                         push(@path,$parent);
                   10890:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   10891:                         pop(@path);
                   10892:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   10893:                         $itemcount ++;
                   10894:                     }
1.48      raeburn  10895:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  10896:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   10897:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  10898:                     for (my $k=0; $k<=$maxnum; $k++) {
                   10899:                         my $vpos = $k+1;
                   10900:                         my $selstr;
1.57      raeburn  10901:                         if ($k == $numtop) {
1.48      raeburn  10902:                             $selstr = ' selected="selected" ';
                   10903:                         }
                   10904:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   10905:                     }
1.59      bisitz   10906:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  10907:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   10908:                                   .'</tr>'."\n";
1.48      raeburn  10909:                     $itemcount ++;
1.272     raeburn  10910:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  10911:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   10912:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10913:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   10914:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   10915:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   10916:                             for (my $k=0; $k<=$maxnum; $k++) {
                   10917:                                 my $vpos = $k+1;
                   10918:                                 my $selstr;
                   10919:                                 if ($k == $maxnum) {
                   10920:                                     $selstr = ' selected="selected" ';
                   10921:                                 }
                   10922:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  10923:                             }
1.120     raeburn  10924:                             $datatable .= '</select></span></td>'.
                   10925:                                           '<td><span class="LC_nobreak">'.
                   10926:                                           $default_names{$default}.'</span>';
                   10927:                             if ($default eq 'instcode') {
                   10928:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   10929:                                               .&mt('with institutional codes').')</span>';
                   10930:                             }
                   10931:                             $datatable .= '</td>'
                   10932:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   10933:                                           .&mt('Display').'</label>&nbsp;'
                   10934:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   10935:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  10936:                         }
                   10937:                     }
                   10938:                 }
1.57      raeburn  10939:             } else {
                   10940:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  10941:             }
                   10942:         } else {
1.327     raeburn  10943:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  10944:                           .&initialize_categories($itemcount);
1.48      raeburn  10945:         }
1.57      raeburn  10946:         $$rowtotal += $itemcount;
1.48      raeburn  10947:     }
                   10948:     return $datatable;
                   10949: }
                   10950: 
1.69      raeburn  10951: sub print_serverstatuses {
                   10952:     my ($dom,$settings,$rowtotal) = @_;
                   10953:     my $datatable;
                   10954:     my @pages = &serverstatus_pages();
                   10955:     my (%namedaccess,%machineaccess);
                   10956:     foreach my $type (@pages) {
                   10957:         $namedaccess{$type} = '';
                   10958:         $machineaccess{$type}= '';
                   10959:     }
                   10960:     if (ref($settings) eq 'HASH') {
                   10961:         foreach my $type (@pages) {
                   10962:             if (exists($settings->{$type})) {
                   10963:                 if (ref($settings->{$type}) eq 'HASH') {
                   10964:                     foreach my $key (keys(%{$settings->{$type}})) {
                   10965:                         if ($key eq 'namedusers') {
                   10966:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   10967:                         } elsif ($key eq 'machines') {
                   10968:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   10969:                         }
                   10970:                     }
                   10971:                 }
                   10972:             }
                   10973:         }
                   10974:     }
1.81      raeburn  10975:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  10976:     my $rownum = 0;
                   10977:     my $css_class;
                   10978:     foreach my $type (@pages) {
                   10979:         $rownum ++;
                   10980:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   10981:         $datatable .= '<tr'.$css_class.'>'.
                   10982:                       '<td><span class="LC_nobreak">'.
                   10983:                       $titles->{$type}.'</span></td>'.
                   10984:                       '<td class="LC_left_item">'.
                   10985:                       '<input type="text" name="'.$type.'_namedusers" '.
                   10986:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   10987:                       '<td class="LC_right_item">'.
                   10988:                       '<span class="LC_nobreak">'.
                   10989:                       '<input type="text" name="'.$type.'_machines" '.
                   10990:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.334     raeburn  10991:                       '</span></td></tr>'."\n";
1.69      raeburn  10992:     }
                   10993:     $$rowtotal += $rownum;
                   10994:     return $datatable;
                   10995: }
                   10996: 
                   10997: sub serverstatus_pages {
                   10998:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  10999:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   11000:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   11001:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  11002: }
                   11003: 
1.236     raeburn  11004: sub defaults_javascript {
                   11005:     my ($settings) = @_;
1.354     raeburn  11006:     return unless (ref($settings) eq 'HASH');
1.236     raeburn  11007:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   11008:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   11009:         if ($maxnum eq '') {
                   11010:             $maxnum = 0;
                   11011:         }
                   11012:         $maxnum ++;
1.249     raeburn  11013:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  11014:         return <<"ENDSCRIPT";
                   11015: <script type="text/javascript">
                   11016: // <![CDATA[
                   11017: function reorderTypes(form,caller) {
                   11018:     var changedVal;
                   11019: $jstext 
                   11020:     var newpos = 'addinststatus_pos';
                   11021:     var current = new Array;
                   11022:     var maxh = $maxnum;
                   11023:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11024:     var oldVal;
                   11025:     if (caller == newpos) {
                   11026:         changedVal = newitemVal;
                   11027:     } else {
                   11028:         var curritem = 'inststatus_pos_'+caller;
                   11029:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   11030:         current[newitemVal] = newpos;
                   11031:     }
                   11032:     for (var i=0; i<inststatuses.length; i++) {
                   11033:         if (inststatuses[i] != caller) {
                   11034:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   11035:             if (form.elements[elementName]) {
                   11036:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11037:                 current[currVal] = elementName;
                   11038:             }
                   11039:         }
                   11040:     }
                   11041:     for (var j=0; j<maxh; j++) {
                   11042:         if (current[j] == undefined) {
                   11043:             oldVal = j;
                   11044:         }
                   11045:     }
                   11046:     if (oldVal < changedVal) {
                   11047:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11048:            var elementName = current[k];
                   11049:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11050:         }
                   11051:     } else {
                   11052:         for (var k=changedVal; k<oldVal; k++) {
                   11053:             var elementName = current[k];
                   11054:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11055:         }
                   11056:     }
                   11057:     return;
                   11058: }
                   11059: 
                   11060: // ]]>
                   11061: </script>
                   11062: 
                   11063: ENDSCRIPT
                   11064:     }
1.354     raeburn  11065:     return;
                   11066: }
                   11067: 
                   11068: sub passwords_javascript {
1.365     raeburn  11069:     my %intalert = &Apache::lonlocal::texthash (
                   11070:         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.',
                   11071:         authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   11072:         passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   11073:         passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   11074:         passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   11075:         passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   11076:     );
                   11077:     &js_escape(\%intalert);
                   11078:     my $defmin = $Apache::lonnet::passwdmin;
1.354     raeburn  11079:     my $intauthjs = <<"ENDSCRIPT";
                   11080: 
                   11081: function warnIntAuth(field) {
                   11082:     if (field.name == 'intauth_check') {
                   11083:         if (field.value == '2') {
1.365     raeburn  11084:             alert('$intalert{authcheck}');
1.354     raeburn  11085:         }
                   11086:     }
                   11087:     if (field.name == 'intauth_cost') {
                   11088:         field.value.replace(/\s/g,'');
                   11089:         if (field.value != '') {
                   11090:             var regexdigit=/^\\d+\$/;
                   11091:             if (!regexdigit.test(field.value)) {
1.365     raeburn  11092:                 alert('$intalert{authcost}');
                   11093:             }
                   11094:         }
                   11095:     }
                   11096:     return;
                   11097: }
                   11098: 
                   11099: function warnIntPass(field) {
                   11100:     field.value.replace(/^\s+/,'');
                   11101:     field.value.replace(/\s+\$/,'');
                   11102:     var regexdigit=/^\\d+\$/;
                   11103:     if (field.name == 'passwords_min') {
                   11104:         if (field.value == '') {
                   11105:             alert('$intalert{passmin}');
                   11106:             field.value = '$defmin';
                   11107:         } else {
                   11108:             if (!regexdigit.test(field.value)) {
                   11109:                 alert('$intalert{passmin}');
                   11110:                 field.value = '$defmin';
                   11111:             }
1.366     raeburn  11112:             var minval = parseInt(field.value,10);
1.365     raeburn  11113:             if (minval < $defmin) {
                   11114:                 alert('$intalert{passmin}');
                   11115:                 field.value = '$defmin';
                   11116:             }
                   11117:         }
                   11118:     } else {
                   11119:         if (field.value == '0') {
                   11120:             field.value = '';
                   11121:         }
                   11122:         if (field.value != '') {
                   11123:             if (field.name == 'passwords_expire') {
                   11124:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/; 
                   11125:                 if (!regexpposnum.test(field.value)) {
                   11126:                     alert('$intalert{passexp}');
                   11127:                     field.value = '';
                   11128:                 } else {
                   11129:                     var expval = parseFloat(field.value);
                   11130:                     if (expval == 0) {
                   11131:                         alert('$intalert{passexp}');
                   11132:                         field.value = '';
                   11133:                     }
                   11134:                 }
                   11135:             } else {
                   11136:                 if (!regexdigit.test(field.value)) {
                   11137:                     if (field.name == 'passwords_max') {
                   11138:                         alert('$intalert{passmax}');
                   11139:                     } else {
                   11140:                         if (field.name == 'passwords_numsaved') {
                   11141:                             alert('$intalert{passnum}');
                   11142:                         }
                   11143:                     }
1.370     raeburn  11144:                     field.value = '';
1.365     raeburn  11145:                 }
1.354     raeburn  11146:             }
                   11147:         }
                   11148:     }
                   11149:     return;
                   11150: }
                   11151: 
                   11152: ENDSCRIPT
                   11153:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  11154: }
                   11155: 
1.49      raeburn  11156: sub coursecategories_javascript {
                   11157:     my ($settings) = @_;
1.57      raeburn  11158:     my ($output,$jstext,$cathash);
1.49      raeburn  11159:     if (ref($settings) eq 'HASH') {
1.57      raeburn  11160:         $cathash = $settings->{'cats'};
                   11161:     }
                   11162:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  11163:         my (@cats,@jsarray,%idx);
1.57      raeburn  11164:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  11165:         if (@jsarray > 0) {
                   11166:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   11167:             for (my $i=0; $i<@jsarray; $i++) {
                   11168:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   11169:                     my $catstr = join('","',@{$jsarray[$i]});
                   11170:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   11171:                 }
                   11172:             }
                   11173:         }
                   11174:     } else {
                   11175:         $jstext  = '    var categories = Array(1);'."\n".
                   11176:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   11177:     }
1.237     bisitz   11178:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   11179:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  11180:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  11181:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   11182:     &js_escape(\$instcode_reserved);
                   11183:     &js_escape(\$communities_reserved);
1.272     raeburn  11184:     &js_escape(\$placement_reserved);
1.265     damieng  11185:     &js_escape(\$choose_again);
1.49      raeburn  11186:     $output = <<"ENDSCRIPT";
                   11187: <script type="text/javascript">
1.109     raeburn  11188: // <![CDATA[
1.49      raeburn  11189: function reorderCats(form,parent,item,idx) {
                   11190:     var changedVal;
                   11191: $jstext
                   11192:     var newpos = 'addcategory_pos';
                   11193:     if (parent == '') {
                   11194:         var has_instcode = 0;
                   11195:         var maxtop = categories[idx].length;
                   11196:         for (var j=0; j<maxtop; j++) {
                   11197:             if (categories[idx][j] == 'instcode::0') {
                   11198:                 has_instcode == 1;
                   11199:             }
                   11200:         }
                   11201:         if (has_instcode == 0) {
                   11202:             categories[idx][maxtop] = 'instcode_pos';
                   11203:         }
                   11204:     } else {
                   11205:         newpos += '_'+parent;
                   11206:     }
                   11207:     var maxh = 1 + categories[idx].length;
                   11208:     var current = new Array;
                   11209:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   11210:     if (item == newpos) {
                   11211:         changedVal = newitemVal;
                   11212:     } else {
                   11213:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   11214:         current[newitemVal] = newpos;
                   11215:     }
                   11216:     for (var i=0; i<categories[idx].length; i++) {
                   11217:         var elementName = categories[idx][i];
                   11218:         if (elementName != item) {
                   11219:             if (form.elements[elementName]) {
                   11220:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   11221:                 current[currVal] = elementName;
                   11222:             }
                   11223:         }
                   11224:     }
                   11225:     var oldVal;
                   11226:     for (var j=0; j<maxh; j++) {
                   11227:         if (current[j] == undefined) {
                   11228:             oldVal = j;
                   11229:         }
                   11230:     }
                   11231:     if (oldVal < changedVal) {
                   11232:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   11233:            var elementName = current[k];
                   11234:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   11235:         }
                   11236:     } else {
                   11237:         for (var k=changedVal; k<oldVal; k++) {
                   11238:             var elementName = current[k];
                   11239:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   11240:         }
                   11241:     }
                   11242:     return;
                   11243: }
1.120     raeburn  11244: 
                   11245: function categoryCheck(form) {
                   11246:     if (form.elements['addcategory_name'].value == 'instcode') {
                   11247:         alert('$instcode_reserved\\n$choose_again');
                   11248:         return false;
                   11249:     }
                   11250:     if (form.elements['addcategory_name'].value == 'communities') {
                   11251:         alert('$communities_reserved\\n$choose_again');
                   11252:         return false;
                   11253:     }
1.272     raeburn  11254:     if (form.elements['addcategory_name'].value == 'placement') {
                   11255:         alert('$placement_reserved\\n$choose_again');
                   11256:         return false;
                   11257:     }
1.120     raeburn  11258:     return true;
                   11259: }
                   11260: 
1.109     raeburn  11261: // ]]>
1.49      raeburn  11262: </script>
                   11263: 
                   11264: ENDSCRIPT
                   11265:     return $output;
                   11266: }
                   11267: 
1.48      raeburn  11268: sub initialize_categories {
                   11269:     my ($itemcount) = @_;
1.120     raeburn  11270:     my ($datatable,$css_class,$chgstr);
1.380     raeburn  11271:     my %default_names = &Apache::lonlocal::texthash (
1.120     raeburn  11272:                       instcode    => 'Official courses (with institutional codes)',
                   11273:                       communities => 'Communities',
1.272     raeburn  11274:                       placement   => 'Placement Tests',
1.120     raeburn  11275:                         );
1.328     raeburn  11276:     my %selnum = (
                   11277:                    instcode    => '0',
                   11278:                    communities => '1',
                   11279:                    placement   => '2',
                   11280:                  );
                   11281:     my %selected;
1.272     raeburn  11282:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  11283:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327     raeburn  11284:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328     raeburn  11285:         map { $selected{$selnum{$_}} = '' } keys(%selnum);
                   11286:         $selected{$selnum{$default}} = ' selected="selected"';
1.120     raeburn  11287:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328     raeburn  11288:                      .'<select name="'.$default.'_pos"'.$chgstr.'>'
                   11289:                      .'<option value="0"'.$selected{'0'}.'>1</option>'
                   11290:                      .'<option value="1"'.$selected{'1'}.'>2</option>'
                   11291:                      .'<option value="2"'.$selected{'2'}.'>3</option>'
                   11292:                      .'<option value="3">4</option></select>&nbsp;'
1.120     raeburn  11293:                      .$default_names{$default}
                   11294:                      .'</span></td><td><span class="LC_nobreak">'
                   11295:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   11296:                      .&mt('Display').'</label>&nbsp;<label>'
                   11297:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  11298:                  .'</label></span></td></tr>';
1.120     raeburn  11299:         $itemcount ++;
                   11300:     }
1.48      raeburn  11301:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  11302:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  11303:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  11304:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   11305:                   .'<option value="0">1</option>'
                   11306:                   .'<option value="1">2</option>'
1.328     raeburn  11307:                   .'<option value="2">3</option>'
                   11308:                   .'<option value="3" selected="selected">4</option></select>&nbsp;'
1.327     raeburn  11309:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                   11310:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   11311:                   .'</td></tr>';
1.48      raeburn  11312:     return $datatable;
                   11313: }
                   11314: 
                   11315: sub build_category_rows {
1.49      raeburn  11316:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   11317:     my ($text,$name,$item,$chgstr);
1.48      raeburn  11318:     if (ref($cats) eq 'ARRAY') {
                   11319:         my $maxdepth = scalar(@{$cats});
                   11320:         if (ref($cats->[$depth]) eq 'HASH') {
                   11321:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   11322:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   11323:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  11324:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  11325:                 my ($idxnum,$parent_name,$parent_item);
                   11326:                 my $higher = $depth - 1;
                   11327:                 if ($higher == 0) {
                   11328:                     $parent_name = &escape($parent).'::'.$higher;
                   11329:                 } else {
                   11330:                     if (ref($path) eq 'ARRAY') {
                   11331:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11332:                     }
                   11333:                 }
                   11334:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  11335:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  11336:                     if ($j < $numchildren) {
1.48      raeburn  11337:                         $name = $cats->[$depth]{$parent}[$j];
                   11338:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  11339:                         $idxnum = $idx->{$item};
                   11340:                     } else {
                   11341:                         $name = $parent_name;
                   11342:                         $item = $parent_item;
1.48      raeburn  11343:                     }
1.49      raeburn  11344:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   11345:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  11346:                     for (my $i=0; $i<=$numchildren; $i++) {
                   11347:                         my $vpos = $i+1;
                   11348:                         my $selstr;
                   11349:                         if ($j == $i) {
                   11350:                             $selstr = ' selected="selected" ';
                   11351:                         }
                   11352:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   11353:                     }
                   11354:                     $text .= '</select>&nbsp;';
                   11355:                     if ($j < $numchildren) {
                   11356:                         my $deeper = $depth+1;
                   11357:                         $text .= $name.'&nbsp;'
                   11358:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   11359:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   11360:                         if(ref($path) eq 'ARRAY') {
                   11361:                             push(@{$path},$name);
1.49      raeburn  11362:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  11363:                             pop(@{$path});
                   11364:                         }
                   11365:                     } else {
1.330     raeburn  11366:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  11367:                         if ($j == $numchildren) {
                   11368:                             $text .= $name;
                   11369:                         } else {
                   11370:                             $text .= $item;
                   11371:                         }
                   11372:                         $text .= '" value="" />';
                   11373:                     }
                   11374:                     $text .= '</td></tr>';
                   11375:                 }
                   11376:                 $text .= '</table></td>';
                   11377:             } else {
                   11378:                 my $higher = $depth-1;
                   11379:                 if ($higher == 0) {
                   11380:                     $name = &escape($parent).'::'.$higher;
                   11381:                 } else {
                   11382:                     if (ref($path) eq 'ARRAY') {
                   11383:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   11384:                     }
                   11385:                 }
                   11386:                 my $colspan;
                   11387:                 if ($parent ne 'instcode') {
                   11388:                     $colspan = $maxdepth - $depth - 1;
1.330     raeburn  11389:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  11390:                 }
                   11391:             }
                   11392:         }
                   11393:     }
                   11394:     return $text;
                   11395: }
                   11396: 
1.33      raeburn  11397: sub modifiable_userdata_row {
1.305     raeburn  11398:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357     raeburn  11399:         $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228     raeburn  11400:     my ($role,$rolename,$statustype);
                   11401:     $role = $item;
1.224     raeburn  11402:     if ($context eq 'cancreate') {
1.305     raeburn  11403:         if ($item =~ /^(emailusername)_(.+)$/) {
                   11404:             $role = $1;
                   11405:             $statustype = $2;
1.228     raeburn  11406:             if (ref($usertypes) eq 'HASH') {
                   11407:                 if ($usertypes->{$statustype}) {
                   11408:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   11409:                 } else {
                   11410:                     $rolename = &mt('Data provided by user');
                   11411:                 }
                   11412:             }
1.224     raeburn  11413:         }
                   11414:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  11415:         if (ref($usertypes) eq 'HASH') {
                   11416:             $rolename = $usertypes->{$role};
                   11417:         } else {
                   11418:             $rolename = $role;
                   11419:         }
1.325     raeburn  11420:     } elsif ($context eq 'lti') {
                   11421:         $rolename = &mt('Institutional data used (if available)');
1.357     raeburn  11422:     } elsif ($context eq 'privacy') {
                   11423:         $rolename = $itemdesc;
1.33      raeburn  11424:     } else {
1.63      raeburn  11425:         if ($role eq 'cr') {
                   11426:             $rolename = &mt('Custom role');
                   11427:         } else {
                   11428:             $rolename = &Apache::lonnet::plaintext($role);
                   11429:         }
1.33      raeburn  11430:     }
1.224     raeburn  11431:     my (@fields,%fieldtitles);
                   11432:     if (ref($fieldsref) eq 'ARRAY') {
                   11433:         @fields = @{$fieldsref};
                   11434:     } else {
                   11435:         @fields = ('lastname','firstname','middlename','generation',
                   11436:                    'permanentemail','id');
                   11437:     }
                   11438:     if ((ref($titlesref) eq 'HASH')) {
                   11439:         %fieldtitles = %{$titlesref};
                   11440:     } else {
                   11441:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   11442:     }
1.33      raeburn  11443:     my $output;
1.305     raeburn  11444:     my $css_class;
                   11445:     if ($rowcount%2) {
                   11446:         $css_class = 'LC_odd_row';
                   11447:     }
                   11448:     if ($customcss) {
                   11449:         $css_class .= " $customcss";
                   11450:     }
                   11451:     $css_class =~ s/^\s+//;
                   11452:     if ($css_class) {
                   11453:         $css_class = ' class="'.$css_class.'"';
                   11454:     }
                   11455:     if ($rowstyle) {
                   11456:         $css_class .= ' style="'.$rowstyle.'"';
                   11457:     }
                   11458:     if ($rowid) {
                   11459:         $rowid = ' id="'.$rowid.'"';
                   11460:     }
                   11461:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  11462:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   11463:               '<td class="LC_left_item" colspan="2"><table>';
                   11464:     my $rem;
                   11465:     my %checks;
1.325     raeburn  11466:     my %current;
1.33      raeburn  11467:     if (ref($settings) eq 'HASH') {
1.325     raeburn  11468:         my $hashref;
                   11469:         if ($context eq 'lti') {
                   11470:             if (ref($settings) eq 'HASH') {
                   11471:                 $hashref = $settings->{'instdata'};
                   11472:             }
1.357     raeburn  11473:         } elsif ($context eq 'privacy') {
                   11474:             my ($key,$inner) = split(/_/,$role);
                   11475:             if (ref($settings) eq 'HASH') {
                   11476:                 if (ref($settings->{$key}) eq 'HASH') {
                   11477:                     $hashref = $settings->{$key}->{$inner};
                   11478:                 }
                   11479:             }
1.325     raeburn  11480:         } elsif (ref($settings->{$context}) eq 'HASH') {
1.33      raeburn  11481:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325     raeburn  11482:                 $hashref = $settings->{'lti_instdata'};
                   11483:             }
                   11484:             if ($role eq 'emailusername') {
                   11485:                 if ($statustype) {
                   11486:                     if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   11487:                         $hashref = $settings->{$context}->{$role}->{$statustype};
1.228     raeburn  11488:                     }
1.325     raeburn  11489:                 }
                   11490:             }
                   11491:         }
                   11492:         if (ref($hashref) eq 'HASH') { 
                   11493:             foreach my $field (@fields) {
                   11494:                 if ($hashref->{$field}) {
                   11495:                     if ($role eq 'emailusername') {
                   11496:                         $checks{$field} = $hashref->{$field};
                   11497:                     } else {
                   11498:                         $checks{$field} = ' checked="checked" ';
1.33      raeburn  11499:                     }
                   11500:                 }
                   11501:             }
                   11502:         }
                   11503:     }
1.305     raeburn  11504:  
                   11505:     my $total = scalar(@fields);
                   11506:     for (my $i=0; $i<$total; $i++) {
                   11507:         $rem = $i%($numinrow);
1.33      raeburn  11508:         if ($rem == 0) {
                   11509:             if ($i > 0) {
                   11510:                 $output .= '</tr>';
                   11511:             }
                   11512:             $output .= '<tr>';
                   11513:         }
                   11514:         my $check = ' ';
1.228     raeburn  11515:         unless ($role eq 'emailusername') {
                   11516:             if (exists($checks{$fields[$i]})) {
1.354     raeburn  11517:                 $check = $checks{$fields[$i]};
1.357     raeburn  11518:             } elsif ($context eq 'privacy') {
                   11519:                 if ($role =~ /^priv_(domain|course)$/) {
                   11520:                     if (ref($settings) ne 'HASH') {
                   11521:                         $check = ' checked="checked" ';
                   11522:                     }
                   11523:                 } elsif ($role =~ /^priv_(author|community)$/) {
                   11524:                     if (ref($settings) ne 'HASH') {
                   11525:                         unless ($fields[$i] eq 'id') {
                   11526:                             $check = ' checked="checked" ';
                   11527:                         }
                   11528:                     }
                   11529:                 } elsif ($role =~ /^(unpriv|othdom)_/) {
                   11530:                     if (ref($settings) ne 'HASH') {
                   11531:                         if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                   11532:                             $check = ' checked="checked" ';
                   11533:                         }
                   11534:                     }
                   11535:                 }
1.325     raeburn  11536:             } elsif ($context ne 'lti') {
1.228     raeburn  11537:                 if ($role eq 'st') {
                   11538:                     if (ref($settings) ne 'HASH') {
                   11539:                         $check = ' checked="checked" '; 
                   11540:                     }
1.33      raeburn  11541:                 }
                   11542:             }
                   11543:         }
                   11544:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  11545:                    '<span class="LC_nobreak">';
1.325     raeburn  11546:         my $prefix = 'canmodify';
1.228     raeburn  11547:         if ($role eq 'emailusername') {
                   11548:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   11549:                 $checks{$fields[$i]} = 'omit';
                   11550:             }
                   11551:             foreach my $option ('required','optional','omit') {
                   11552:                 my $checked='';
                   11553:                 if ($checks{$fields[$i]} eq $option) {
                   11554:                     $checked='checked="checked" ';
                   11555:                 }
                   11556:                 $output .= '<label>'.
1.325     raeburn  11557:                            '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228     raeburn  11558:                            &mt($option).'</label>'.('&nbsp;' x2);
                   11559:             }
                   11560:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   11561:         } else {
1.325     raeburn  11562:             if ($context eq 'lti') {
                   11563:                 $prefix = 'lti';
1.357     raeburn  11564:             } elsif ($context eq 'privacy') {
                   11565:                 $prefix = 'privacy';
1.325     raeburn  11566:             }
1.228     raeburn  11567:             $output .= '<label>'.
1.325     raeburn  11568:                        '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228     raeburn  11569:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   11570:                        '</label>';
                   11571:         }
                   11572:         $output .= '</span></td>';
1.33      raeburn  11573:     }
1.305     raeburn  11574:     $rem = $total%$numinrow;
                   11575:     my $colsleft;
                   11576:     if ($rem) {
                   11577:         $colsleft = $numinrow - $rem;
                   11578:     }
                   11579:     if ($colsleft > 1) {
1.33      raeburn  11580:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   11581:                    '&nbsp;</td>';
                   11582:     } elsif ($colsleft == 1) {
                   11583:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   11584:     }
                   11585:     $output .= '</tr></table></td></tr>';
                   11586:     return $output;
                   11587: }
1.28      raeburn  11588: 
1.93      raeburn  11589: sub insttypes_row {
1.305     raeburn  11590:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   11591:         $customcss,$rowstyle) = @_;
1.93      raeburn  11592:     my %lt = &Apache::lonlocal::texthash (
                   11593:                       cansearch => 'Users allowed to search',
                   11594:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  11595:                       lockablenames => 'User preference to lock name',
1.305     raeburn  11596:                       selfassign    => 'Self-reportable affiliations',
1.315     raeburn  11597:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  11598:              );
                   11599:     my $showdom;
                   11600:     if ($context eq 'cansearch') {
                   11601:         $showdom = ' ('.$dom.')';
                   11602:     }
1.165     raeburn  11603:     my $class = 'LC_left_item';
                   11604:     if ($context eq 'statustocreate') {
                   11605:         $class = 'LC_right_item';
                   11606:     }
1.305     raeburn  11607:     my $css_class;
                   11608:     if ($$rowtotal%2) {
                   11609:         $css_class = 'LC_odd_row';
                   11610:     }
                   11611:     if ($customcss) {
                   11612:         $css_class .= ' '.$customcss;
                   11613:     }
                   11614:     $css_class =~ s/^\s+//;
                   11615:     if ($css_class) {
                   11616:         $css_class = ' class="'.$css_class.'"';
                   11617:     }
                   11618:     if ($rowstyle) {
                   11619:         $css_class .= ' style="'.$rowstyle.'"';
                   11620:     }
                   11621:     if ($onclick) {
                   11622:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  11623:     }
                   11624:     my $output = '<tr'.$css_class.'>'.
                   11625:                  '<td>'.$lt{$context}.$showdom.
                   11626:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  11627:     my $rem;
                   11628:     if (ref($types) eq 'ARRAY') {
                   11629:         for (my $i=0; $i<@{$types}; $i++) {
                   11630:             if (defined($usertypes->{$types->[$i]})) {
                   11631:                 my $rem = $i%($numinrow);
                   11632:                 if ($rem == 0) {
                   11633:                     if ($i > 0) {
                   11634:                         $output .= '</tr>';
                   11635:                     }
                   11636:                     $output .= '<tr>';
1.23      raeburn  11637:                 }
1.26      raeburn  11638:                 my $check = ' ';
1.99      raeburn  11639:                 if (ref($settings) eq 'HASH') {
                   11640:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   11641:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   11642:                             $check = ' checked="checked" ';
                   11643:                         }
1.315     raeburn  11644:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   11645:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   11646:                             $check = ' checked="checked" ';
                   11647:                         }
1.99      raeburn  11648:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  11649:                         $check = ' checked="checked" ';
                   11650:                     }
1.23      raeburn  11651:                 }
1.26      raeburn  11652:                 $output .= '<td class="LC_left_item">'.
                   11653:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  11654:                            '<input type="checkbox" name="'.$context.'" '.
1.305     raeburn  11655:                            'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26      raeburn  11656:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  11657:             }
                   11658:         }
1.26      raeburn  11659:         $rem = @{$types}%($numinrow);
1.23      raeburn  11660:     }
                   11661:     my $colsleft = $numinrow - $rem;
1.315     raeburn  11662:     if ($context eq 'overrides') {
                   11663:         if ($colsleft > 1) {
                   11664:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   11665:         } else {
                   11666:             $output .= '<td class="LC_left_item">';
                   11667:         }
                   11668:         $output .= '&nbsp;';  
1.23      raeburn  11669:     } else {
1.334     raeburn  11670:         if ($rem == 0) {
1.315     raeburn  11671:             $output .= '<tr>';
                   11672:         }
                   11673:         if ($colsleft > 1) {
                   11674:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   11675:         } else {
                   11676:             $output .= '<td class="LC_left_item">';
                   11677:         }
                   11678:         my $defcheck = ' ';
                   11679:         if (ref($settings) eq 'HASH') {  
                   11680:             if (ref($settings->{$context}) eq 'ARRAY') {
                   11681:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   11682:                     $defcheck = ' checked="checked" ';
                   11683:                 }
                   11684:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  11685:                 $defcheck = ' checked="checked" ';
                   11686:             }
1.26      raeburn  11687:         }
1.315     raeburn  11688:         $output .= '<span class="LC_nobreak"><label>'.
                   11689:                    '<input type="checkbox" name="'.$context.'" '.
                   11690:                    'value="default"'.$defcheck.$onclick.' />'.
                   11691:                    $othertitle.'</label></span>';
1.23      raeburn  11692:     }
1.315     raeburn  11693:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  11694:     return $output;
1.23      raeburn  11695: }
                   11696: 
                   11697: sub sorted_searchtitles {
                   11698:     my %searchtitles = &Apache::lonlocal::texthash(
                   11699:                          'uname' => 'username',
                   11700:                          'lastname' => 'last name',
                   11701:                          'lastfirst' => 'last name, first name',
                   11702:                      );
                   11703:     my @titleorder = ('uname','lastname','lastfirst');
                   11704:     return (\%searchtitles,\@titleorder);
                   11705: }
                   11706: 
1.25      raeburn  11707: sub sorted_searchtypes {
                   11708:     my %srchtypes_desc = (
                   11709:                            exact    => 'is exact match',
                   11710:                            contains => 'contains ..',
                   11711:                            begins   => 'begins with ..',
                   11712:                          );
                   11713:     my @srchtypeorder = ('exact','begins','contains');
                   11714:     return (\%srchtypes_desc,\@srchtypeorder);
                   11715: }
                   11716: 
1.3       raeburn  11717: sub usertype_update_row {
                   11718:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   11719:     my $datatable;
                   11720:     my $numinrow = 4;
                   11721:     foreach my $type (@{$types}) {
                   11722:         if (defined($usertypes->{$type})) {
                   11723:             $$rownums ++;
                   11724:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   11725:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   11726:                           '</td><td class="LC_left_item"><table>';
                   11727:             for (my $i=0; $i<@{$fields}; $i++) {
                   11728:                 my $rem = $i%($numinrow);
                   11729:                 if ($rem == 0) {
                   11730:                     if ($i > 0) {
                   11731:                         $datatable .= '</tr>';
                   11732:                     }
                   11733:                     $datatable .= '<tr>';
                   11734:                 }
                   11735:                 my $check = ' ';
1.39      raeburn  11736:                 if (ref($settings) eq 'HASH') {
                   11737:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   11738:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   11739:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   11740:                                 $check = ' checked="checked" ';
                   11741:                             }
1.3       raeburn  11742:                         }
                   11743:                     }
                   11744:                 }
                   11745: 
                   11746:                 if ($i == @{$fields}-1) {
                   11747:                     my $colsleft = $numinrow - $rem;
                   11748:                     if ($colsleft > 1) {
                   11749:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   11750:                     } else {
                   11751:                         $datatable .= '<td>';
                   11752:                     }
                   11753:                 } else {
                   11754:                     $datatable .= '<td>';
                   11755:                 }
1.8       raeburn  11756:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   11757:                               '<input type="checkbox" name="updateable_'.$type.
                   11758:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   11759:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  11760:             }
                   11761:             $datatable .= '</tr></table></td></tr>';
                   11762:         }
                   11763:     }
                   11764:     return $datatable;
1.1       raeburn  11765: }
                   11766: 
                   11767: sub modify_login {
1.205     raeburn  11768:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  11769:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386     raeburn  11770:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
                   11771:         %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168     raeburn  11772:     %title = ( coursecatalog => 'Display course catalog',
                   11773:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  11774:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  11775:                newuser => 'Link for visitors to create a user account',
1.386     raeburn  11776:                loginheader => 'Log-in box header',
                   11777:                saml => 'Dual SSO and non-SSO login');
1.168     raeburn  11778:     @offon = ('off','on');
1.112     raeburn  11779:     if (ref($domconfig{login}) eq 'HASH') {
                   11780:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   11781:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   11782:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   11783:             }
                   11784:         }
1.386     raeburn  11785:         if (ref($domconfig{login}{'saml'}) eq 'HASH') {
                   11786:             foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
                   11787:                 if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
                   11788:                     $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
                   11789:                     $saml{$lonhost} = 1;
                   11790:                     $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
                   11791:                     $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
                   11792:                     $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                   11793:                     $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                   11794:                     $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
                   11795:                     $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                   11796:                 }
                   11797:             }
                   11798:         }
1.112     raeburn  11799:     }
1.9       raeburn  11800:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   11801:                                            \%domconfig,\%loginhash);
1.188     raeburn  11802:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  11803:     foreach my $item (@toggles) {
                   11804:         $loginhash{login}{$item} = $env{'form.'.$item};
                   11805:     }
1.41      raeburn  11806:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  11807:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   11808:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   11809:                                          \%loginhash);
                   11810:     }
1.110     raeburn  11811: 
1.149     raeburn  11812:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  11813:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  11814:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  11815:     if (keys(%servers) > 1) {
                   11816:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  11817:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   11818:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   11819:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   11820:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   11821:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   11822:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11823:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   11824:                         $changes{'loginvia'}{$lonhost} = 1;
                   11825:                     } else {
                   11826:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   11827:                         $changes{'loginvia'}{$lonhost} = 1;
                   11828:                     }
                   11829:                 } else {
                   11830:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11831:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   11832:                         $changes{'loginvia'}{$lonhost} = 1;
                   11833:                     }
                   11834:                 }
                   11835:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   11836:                     foreach my $item (@loginvia_attribs) {
                   11837:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   11838:                     }
                   11839:                 } else {
                   11840:                     foreach my $item (@loginvia_attribs) {
                   11841:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   11842:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   11843:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   11844:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   11845:                                 $new = '/';
                   11846:                             }
                   11847:                         }
                   11848:                         if (($item eq 'custompath') && 
                   11849:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   11850:                             $new = '';
                   11851:                         }
                   11852:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   11853:                             $changes{'loginvia'}{$lonhost} = 1;
                   11854:                         }
                   11855:                         if ($item eq 'exempt') {
1.256     raeburn  11856:                             $new = &check_exempt_addresses($new);
1.128     raeburn  11857:                         }
                   11858:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   11859:                     }
                   11860:                 }
1.112     raeburn  11861:             } else {
1.128     raeburn  11862:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   11863:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  11864:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  11865:                     foreach my $item (@loginvia_attribs) {
                   11866:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   11867:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   11868:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   11869:                                 $new = '/';
                   11870:                             }
                   11871:                         }
                   11872:                         if (($item eq 'custompath') && 
                   11873:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   11874:                             $new = '';
                   11875:                         }
                   11876:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   11877:                     }
1.110     raeburn  11878:                 }
                   11879:             }
                   11880:         }
                   11881:     }
1.119     raeburn  11882: 
1.168     raeburn  11883:     my $servadm = $r->dir_config('lonAdmEMail');
                   11884:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   11885:     if (ref($domconfig{'login'}) eq 'HASH') {
                   11886:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   11887:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   11888:                 if ($lang eq 'nolang') {
                   11889:                     push(@currlangs,$lang);
                   11890:                 } elsif (defined($langchoices{$lang})) {
                   11891:                     push(@currlangs,$lang);
                   11892:                 } else {
                   11893:                     next;
                   11894:                 }
                   11895:             }
                   11896:         }
                   11897:     }
                   11898:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   11899:     if (@currlangs > 0) {
                   11900:         foreach my $lang (@currlangs) {
                   11901:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   11902:                 $changes{'helpurl'}{$lang} = 1;
                   11903:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   11904:                 $changes{'helpurl'}{$lang} = 1;
                   11905:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   11906:                 push(@newlangs,$lang);
                   11907:             } else {
                   11908:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   11909:             }
                   11910:         }
                   11911:     }
                   11912:     unless (grep(/^nolang$/,@currlangs)) {
                   11913:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   11914:             $changes{'helpurl'}{'nolang'} = 1;
                   11915:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   11916:             push(@newlangs,'nolang');
                   11917:         }
                   11918:     }
                   11919:     if ($env{'form.loginhelpurl_add_lang'}) {
                   11920:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   11921:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   11922:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   11923:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   11924:         }
                   11925:     }
                   11926:     if ((@newlangs > 0) || ($addedfile)) {
                   11927:         my $error;
                   11928:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   11929:         if ($configuserok eq 'ok') {
                   11930:             if ($switchserver) {
                   11931:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   11932:             } elsif ($author_ok eq 'ok') {
                   11933:                 my @allnew = @newlangs;
                   11934:                 if ($addedfile ne '') {
                   11935:                     push(@allnew,$addedfile);
                   11936:                 }
                   11937:                 foreach my $lang (@allnew) {
                   11938:                     my $formelem = 'loginhelpurl_'.$lang;
                   11939:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   11940:                         $formelem = 'loginhelpurl_add_file';
                   11941:                     }
                   11942:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   11943:                                                                "help/$lang",'','',$newfile{$lang});
                   11944:                     if ($result eq 'ok') {
                   11945:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   11946:                         $changes{'helpurl'}{$lang} = 1;
                   11947:                     } else {
                   11948:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   11949:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  11950:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  11951:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   11952:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   11953:                         }
                   11954:                     }
                   11955:                 }
                   11956:             } else {
                   11957:                 $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);
                   11958:             }
                   11959:         } else {
                   11960:             $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);
                   11961:         }
                   11962:         if ($error) {
                   11963:             &Apache::lonnet::logthis($error);
                   11964:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11965:         }
                   11966:     }
1.256     raeburn  11967: 
                   11968:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   11969:     if (ref($domconfig{'login'}) eq 'HASH') {
                   11970:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   11971:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   11972:                 if ($domservers{$lonhost}) {
                   11973:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   11974:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  11975:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  11976:                     }
                   11977:                 }
                   11978:             }
                   11979:         }
                   11980:     }
                   11981:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   11982:     foreach my $lonhost (sort(keys(%domservers))) {
                   11983:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   11984:             $changes{'headtag'}{$lonhost} = 1;
                   11985:         } else {
                   11986:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   11987:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   11988:             }
                   11989:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   11990:                 push(@newhosts,$lonhost);
                   11991:             } elsif ($currheadtagurls{$lonhost}) {
                   11992:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   11993:                 if ($currexempt{$lonhost}) {
1.289     raeburn  11994:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  11995:                         $changes{'headtag'}{$lonhost} = 1;
                   11996:                     }
                   11997:                 } elsif ($possexempt{$lonhost}) {
                   11998:                     $changes{'headtag'}{$lonhost} = 1;
                   11999:                 }
                   12000:                 if ($possexempt{$lonhost}) {
                   12001:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12002:                 }
                   12003:             }
                   12004:         }
                   12005:     }
                   12006:     if (@newhosts) {
                   12007:         my $error;
                   12008:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12009:         if ($configuserok eq 'ok') {
                   12010:             if ($switchserver) {
                   12011:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   12012:             } elsif ($author_ok eq 'ok') {
                   12013:                 foreach my $lonhost (@newhosts) {
                   12014:                     my $formelem = 'loginheadtag_'.$lonhost;
                   12015:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12016:                                                                           "login/headtag/$lonhost",'','',
                   12017:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   12018:                     if ($result eq 'ok') {
                   12019:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   12020:                         $changes{'headtag'}{$lonhost} = 1;
                   12021:                         if ($possexempt{$lonhost}) {
                   12022:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   12023:                         }
                   12024:                     } else {
                   12025:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   12026:                                            $newheadtagurls{$lonhost},$result);
                   12027:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12028:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   12029:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   12030:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   12031:                         }
                   12032:                     }
                   12033:                 }
                   12034:             } else {
                   12035:                 $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);
                   12036:             }
                   12037:         } else {
                   12038:             $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);
                   12039:         }
                   12040:         if ($error) {
                   12041:             &Apache::lonnet::logthis($error);
                   12042:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12043:         }
                   12044:     }
1.386     raeburn  12045:     my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
                   12046:     my @newsamlimgs;
                   12047:     foreach my $lonhost (keys(%domservers)) {
                   12048:         if ($env{'form.saml_'.$lonhost}) {
                   12049:             if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                   12050:                 push(@newsamlimgs,$lonhost);
                   12051:             }
                   12052:             foreach my $item ('text','alt','url','title','notsso') {
                   12053:                 $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
                   12054:             }
                   12055:             if ($saml{$lonhost}) {
                   12056:                 if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
                   12057: #FIXME Need to obsolete published image
                   12058:                     delete($currsaml{$lonhost}{'img'});
                   12059:                     $changes{'saml'}{$lonhost} = 1;
                   12060:                 }
                   12061:                 if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
                   12062:                     $changes{'saml'}{$lonhost} = 1;
                   12063:                 }
                   12064:                 if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
                   12065:                     $changes{'saml'}{$lonhost} = 1;
                   12066:                 }
                   12067:                 if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
                   12068:                     $changes{'saml'}{$lonhost} = 1;
                   12069:                 }
                   12070:                 if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
                   12071:                     $changes{'saml'}{$lonhost} = 1;
                   12072:                 }
                   12073:                 if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
                   12074:                     $changes{'saml'}{$lonhost} = 1;
                   12075:                 }
                   12076:             } else {
                   12077:                 $changes{'saml'}{$lonhost} = 1;
                   12078:             }
                   12079:             foreach my $item ('text','alt','url','title','notsso') {
                   12080:                 $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
                   12081:             }
                   12082:         } else {
1.389     raeburn  12083:             if ($saml{$lonhost}) {  
                   12084:                 $changes{'saml'}{$lonhost} = 1;
                   12085:                 delete($currsaml{$lonhost});
                   12086:             }
1.386     raeburn  12087:         }
                   12088:     }
                   12089:     foreach my $posshost (keys(%currsaml)) {
                   12090:         unless (exists($domservers{$posshost})) { 
                   12091:             delete($currsaml{$posshost}); 
                   12092:         }
                   12093:     }
                   12094:     %{$loginhash{'login'}{'saml'}} = %currsaml;
                   12095:     if (@newsamlimgs) {
                   12096:         my $error;
                   12097:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12098:         if ($configuserok eq 'ok') {
                   12099:             if ($switchserver) {
                   12100:                 $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
                   12101:             } elsif ($author_ok eq 'ok') {
                   12102:                 foreach my $lonhost (@newsamlimgs) {
                   12103:                     my $formelem = 'saml_img_'.$lonhost;
                   12104:                     my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   12105:                                                         "login/saml/$lonhost",'','',
                   12106:                                                         $env{'form.saml_img_'.$lonhost.'.filename'});
                   12107:                     if ($result eq 'ok') {
                   12108:                         $currsaml{$lonhost}{'img'} = $imgurl;
                   12109:                         $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
                   12110:                         $changes{'saml'}{$lonhost} = 1;
                   12111:                     } else {
                   12112:                         my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
                   12113:                                            $lonhost,$result);
                   12114:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   12115:                     }
                   12116:                 }
                   12117:             } else {
                   12118:                 $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);
                   12119:             }
                   12120:         } else {
                   12121:             $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);
                   12122:         }
                   12123:         if ($error) {
                   12124:             &Apache::lonnet::logthis($error);
                   12125:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12126:         }
                   12127:     }
1.169     raeburn  12128:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  12129: 
                   12130:     my $defaulthelpfile = '/adm/loginproblems.html';
                   12131:     my $defaulttext = &mt('Default in use');
                   12132: 
1.1       raeburn  12133:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   12134:                                              $dom);
                   12135:     if ($putresult eq 'ok') {
1.188     raeburn  12136:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  12137:         my %defaultchecked = (
                   12138:                     'coursecatalog' => 'on',
1.188     raeburn  12139:                     'helpdesk'      => 'on',
1.42      raeburn  12140:                     'adminmail'     => 'off',
1.43      raeburn  12141:                     'newuser'       => 'off',
1.42      raeburn  12142:         );
1.55      raeburn  12143:         if (ref($domconfig{'login'}) eq 'HASH') {
                   12144:             foreach my $item (@toggles) {
                   12145:                 if ($defaultchecked{$item} eq 'on') { 
                   12146:                     if (($domconfig{'login'}{$item} eq '0') &&
                   12147:                         ($env{'form.'.$item} eq '1')) {
                   12148:                         $changes{$item} = 1;
                   12149:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12150:                               $domconfig{'login'}{$item} eq '1') &&
                   12151:                              ($env{'form.'.$item} eq '0')) {
                   12152:                         $changes{$item} = 1;
                   12153:                     }
                   12154:                 } elsif ($defaultchecked{$item} eq 'off') {
                   12155:                     if (($domconfig{'login'}{$item} eq '1') &&
                   12156:                         ($env{'form.'.$item} eq '0')) {
                   12157:                         $changes{$item} = 1;
                   12158:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   12159:                               $domconfig{'login'}{$item} eq '0') &&
                   12160:                              ($env{'form.'.$item} eq '1')) {
                   12161:                         $changes{$item} = 1;
                   12162:                     }
1.42      raeburn  12163:                 }
                   12164:             }
1.41      raeburn  12165:         }
1.6       raeburn  12166:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  12167:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386     raeburn  12168:             if (exists($changes{'saml'})) {
                   12169:                 my $hostid_in_use;
                   12170:                 my @hosts = &Apache::lonnet::current_machine_ids();
                   12171:                 if (@hosts > 1) {
                   12172:                     foreach my $hostid (@hosts) {
                   12173:                         if (&Apache::lonnet::host_domain($hostid) eq $dom) {
                   12174:                             $hostid_in_use = $hostid;
                   12175:                             last;
                   12176:                         }
                   12177:                     }
                   12178:                 } else {
                   12179:                     $hostid_in_use = $r->dir_config('lonHostID');
                   12180:                 }
                   12181:                 if (($hostid_in_use) &&
                   12182:                     (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387     raeburn  12183:                     &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386     raeburn  12184:                 }
                   12185:                 if (ref($lastactref) eq 'HASH') {
                   12186:                     if (ref($changes{'saml'}) eq 'HASH') {
                   12187:                         my %updates;
                   12188:                         map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
                   12189:                         $lastactref->{'samllanding'} = \%updates;
                   12190:                     }
                   12191:                 }
                   12192:             }
1.212     raeburn  12193:             if (ref($lastactref) eq 'HASH') {
                   12194:                 $lastactref->{'domainconfig'} = 1;
                   12195:             }
1.1       raeburn  12196:             $resulttext = &mt('Changes made:').'<ul>';
                   12197:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   12198:                 if ($item eq 'loginvia') {
1.112     raeburn  12199:                     if (ref($changes{$item}) eq 'HASH') {
                   12200:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   12201:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  12202:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   12203:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   12204:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   12205:                                     $protocol = 'http' if ($protocol ne 'https');
                   12206:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   12207: 
                   12208:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   12209:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   12210:                                     } else {
                   12211:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   12212:                                     }
                   12213:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   12214:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   12215:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   12216:                                     }
                   12217:                                     $resulttext .= '</li>';
                   12218:                                 } else {
                   12219:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   12220:                                 }
1.112     raeburn  12221:                             } else {
1.128     raeburn  12222:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  12223:                             }
                   12224:                         }
1.128     raeburn  12225:                         $resulttext .= '</ul></li>';
1.112     raeburn  12226:                     }
1.168     raeburn  12227:                 } elsif ($item eq 'helpurl') {
                   12228:                     if (ref($changes{$item}) eq 'HASH') {
                   12229:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   12230:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   12231:                                 my ($chg,$link);
                   12232:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   12233:                                 if ($lang eq 'nolang') {
                   12234:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   12235:                                 } else {
                   12236:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   12237:                                 }
                   12238:                                 $resulttext .= '<li>'.$chg.'</li>';
                   12239:                             } else {
                   12240:                                 my $chg;
                   12241:                                 if ($lang eq 'nolang') {
                   12242:                                     $chg = &mt('custom log-in help file for no preferred language');
                   12243:                                 } else {
                   12244:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   12245:                                 }
                   12246:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   12247:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   12248:                                                       '?inhibitmenu=yes',$chg,600,500).
                   12249:                                                '</li>';
                   12250:                             }
                   12251:                         }
                   12252:                     }
1.256     raeburn  12253:                 } elsif ($item eq 'headtag') {
                   12254:                     if (ref($changes{$item}) eq 'HASH') {
                   12255:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12256:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   12257:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   12258:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   12259:                                 $resulttext .= '<li><a href="'.
                   12260:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   12261:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   12262:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   12263:                                 if ($possexempt{$lonhost}) {
                   12264:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   12265:                                 } else {
                   12266:                                     $resulttext .= &mt('included for any client IP');
                   12267:                                 }
                   12268:                                 $resulttext .= '</li>';
                   12269:                             }
                   12270:                         }
                   12271:                     }
1.386     raeburn  12272:                 } elsif ($item eq 'saml') {
                   12273:                     if (ref($changes{$item}) eq 'HASH') {
                   12274:                         my %notlt = (
                   12275:                                        text   => 'Text for log-in by SSO',
                   12276:                                        img    => 'SSO button image',
                   12277:                                        alt    => 'Alt text for button image',
                   12278:                                        url    => 'SSO URL',
                   12279:                                        title  => 'Tooltip for SSO link',
                   12280:                                        notsso => 'Text for non-SSO log-in',
                   12281:                                     );
                   12282:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   12283:                             if (ref($currsaml{$lonhost}) eq 'HASH') {
                   12284:                                 $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
                   12285:                                                '<ul>';
                   12286:                                 foreach my $key ('text','img','alt','url','title','notsso') {
                   12287:                                     if ($currsaml{$lonhost}{$key} eq '') {
                   12288:                                         $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
                   12289:                                     } else {
                   12290:                                         my $value = "'$currsaml{$lonhost}{$key}'";
                   12291:                                         if ($key eq 'img') {
                   12292:                                             $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
                   12293:                                         }
                   12294:                                         $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                   12295:                                                                   $value).'</li>';
                   12296:                                     }
                   12297:                                 }
                   12298:                                 $resulttext .= '</ul></li>';
                   12299:                             } else {
                   12300:                                 $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
                   12301:                             }
                   12302:                         }
                   12303:                     }
1.169     raeburn  12304:                 } elsif ($item eq 'captcha') {
                   12305:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  12306:                         my $chgtxt;
1.169     raeburn  12307:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   12308:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   12309:                         } else {
                   12310:                             my %captchas = &captcha_phrases();
                   12311:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   12312:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   12313:                             } else {
                   12314:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   12315:                             }
                   12316:                         }
                   12317:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12318:                     }
                   12319:                 } elsif ($item eq 'recaptchakeys') {
                   12320:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12321:                         my ($privkey,$pubkey);
                   12322:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   12323:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   12324:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   12325:                         }
                   12326:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   12327:                         if (!$pubkey) {
                   12328:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   12329:                         } else {
                   12330:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   12331:                         }
                   12332:                         if (!$privkey) {
                   12333:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   12334:                         } else {
1.251     raeburn  12335:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  12336:                         }
                   12337:                         $chgtxt .= '</ul>';
                   12338:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   12339:                     }
1.269     raeburn  12340:                 } elsif ($item eq 'recaptchaversion') {
                   12341:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   12342:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  12343:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  12344:                                            '</li>';
                   12345:                         }
                   12346:                     }
1.41      raeburn  12347:                 } else {
                   12348:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   12349:                 }
1.1       raeburn  12350:             }
1.6       raeburn  12351:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  12352:         } else {
                   12353:             $resulttext = &mt('No changes made to log-in page settings');
                   12354:         }
                   12355:     } else {
1.11      albertel 12356:         $resulttext = '<span class="LC_error">'.
                   12357: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  12358:     }
1.6       raeburn  12359:     if ($errors) {
1.9       raeburn  12360:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  12361:                        $errors.'</ul>';
                   12362:     }
                   12363:     return $resulttext;
                   12364: }
                   12365: 
1.256     raeburn  12366: sub check_exempt_addresses {
                   12367:     my ($iplist) = @_;
                   12368:     $iplist =~ s/^\s+//;
                   12369:     $iplist =~ s/\s+$//;
                   12370:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   12371:     my (@okips,$new);
                   12372:     foreach my $ip (@poss_ips) {
                   12373:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   12374:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   12375:                 push(@okips,$ip);
                   12376:             }
                   12377:         }
                   12378:     }
                   12379:     if (@okips > 0) {
                   12380:         $new = join(',',@okips);
                   12381:     } else {
                   12382:         $new = '';
                   12383:     }
                   12384:     return $new;
                   12385: }
                   12386: 
1.6       raeburn  12387: sub color_font_choices {
                   12388:     my %choices =
                   12389:         &Apache::lonlocal::texthash (
                   12390:             img => "Header",
                   12391:             bgs => "Background colors",
                   12392:             links => "Link colors",
1.55      raeburn  12393:             images => "Images",
1.6       raeburn  12394:             font => "Font color",
1.201     raeburn  12395:             fontmenu => "Font menu",
1.76      raeburn  12396:             pgbg => "Page",
1.6       raeburn  12397:             tabbg => "Header",
                   12398:             sidebg => "Border",
                   12399:             link => "Link",
                   12400:             alink => "Active link",
                   12401:             vlink => "Visited link",
                   12402:         );
                   12403:     return %choices;
                   12404: }
                   12405: 
1.394     raeburn  12406: sub modify_ipaccess {
                   12407:     my ($dom,$lastactref,%domconfig) = @_;
                   12408:     my (@allpos,%changes,%confhash,$errors,$resulttext);
                   12409:     my (@items,%deletions,%itemids,@warnings);
                   12410:     my ($typeorder,$types) = &commblocktype_text();
                   12411:     if ($env{'form.ipaccess_add'}) {
                   12412:         my $name = $env{'form.ipaccess_name_add'};
                   12413:         my ($newid,$error) = &get_ipaccess_id($dom,$name);
                   12414:         if ($newid) {
                   12415:             $itemids{'add'} = $newid;
                   12416:             push(@items,'add');
                   12417:             $changes{$newid} = 1;
                   12418:         } else {
                   12419:             $error = &mt('Failed to acquire unique ID for new IP access control item');
                   12420:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12421:         }
                   12422:     }
                   12423:     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   12424:         my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
                   12425:         if (@todelete) {
                   12426:             map { $deletions{$_} = 1; } @todelete;
                   12427:         }
                   12428:         my $maxnum = $env{'form.ipaccess_maxnum'};
                   12429:         for (my $i=0; $i<$maxnum; $i++) {
                   12430:             my $itemid = $env{'form.ipaccess_id_'.$i};
                   12431:             $itemid =~ s/\D+//g;
                   12432:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12433:                 if ($deletions{$itemid}) {
                   12434:                     $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
                   12435:                 } else {
                   12436:                     push(@items,$i);
                   12437:                     $itemids{$i} = $itemid;
                   12438:                 }
                   12439:             }
                   12440:         }
                   12441:     }
                   12442:     foreach my $idx (@items) {
                   12443:         my $itemid = $itemids{$idx};
                   12444:         next unless ($itemid);
                   12445:         my %current;
                   12446:         unless ($idx eq 'add') {
                   12447:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12448:                 %current = %{$domconfig{'ipaccess'}{$itemid}};
                   12449:             }
                   12450:         }
                   12451:         my $position = $env{'form.ipaccess_pos_'.$itemid};
                   12452:         $position =~ s/\D+//g;
                   12453:         if ($position ne '') {
                   12454:             $allpos[$position] = $itemid;
                   12455:         }
                   12456:         my $name = $env{'form.ipaccess_name_'.$idx};
                   12457:         $name =~ s/^\s+|\s+$//g;
                   12458:         $confhash{$itemid}{'name'} = $name;
                   12459:         my $possrange = $env{'form.ipaccess_range_'.$idx};
                   12460:         $possrange =~ s/^\s+|\s+$//g;
                   12461:         unless ($possrange eq '') {
                   12462:             $possrange =~ s/[\r\n]+/\s/g;
                   12463:             $possrange =~ s/\s*-\s*/-/g;
                   12464:             $possrange =~ s/\s+/,/g;
                   12465:             $possrange =~ s/,+/,/g;
                   12466:             if ($possrange ne '') {
                   12467:                 my (@ok,$count);
                   12468:                 $count = 0; 
                   12469:                 foreach my $poss (split(/\,/,$possrange)) {
                   12470:                     $count ++;
                   12471:                     $poss = &validate_ip_pattern($poss);
                   12472:                     if ($poss ne '') {
                   12473:                         push(@ok,$poss);
                   12474:                     }
                   12475:                 }
                   12476:                 my $diff = $count - scalar(@ok);
                   12477:                 if ($diff) {
                   12478:                     $errors .= '<li><span class="LC_error">'.
                   12479:                                &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
                   12480:                                    $diff,$name).
                   12481:                                '</span></li>';
                   12482:                 }
                   12483:                 if (@ok) {
                   12484:                     my @cidr_list;
                   12485:                     foreach my $item (@ok) {
                   12486:                         @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   12487:                     }
                   12488:                     $confhash{$itemid}{'ip'} = join(',',@cidr_list);
                   12489:                 }
                   12490:             }
                   12491:         }
                   12492:         foreach my $field ('name','ip') {
                   12493:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   12494:                 if ($current{$field} ne $confhash{$itemid}{$field}) {
                   12495:                     $changes{$itemid} = 1;
                   12496:                     last;
                   12497:                 }
                   12498:             }
                   12499:         }
                   12500:         $confhash{$itemid}{'commblocks'} = {};
                   12501:          
                   12502:         my %commblocks;
                   12503:         map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);  
                   12504:         foreach my $type (@{$typeorder}) {
                   12505:             if ($commblocks{$type}) {
                   12506:                 $confhash{$itemid}{'commblocks'}{$type} = 'on';
                   12507:             }
                   12508:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   12509:                 if (ref($current{'commblocks'}) eq 'HASH') {
                   12510:                     if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
                   12511:                         $changes{$itemid} = 1;
                   12512:                     }
                   12513:                 } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
                   12514:                     $changes{$itemid} = 1;
                   12515:                 }
                   12516:             }
                   12517:         }
                   12518:         $confhash{$itemid}{'courses'} = {};
                   12519:         my %crsdeletions;
                   12520:         my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
                   12521:         if (@delcrs) {
                   12522:             map { $crsdeletions{$_} = 1; } @delcrs;
                   12523:         }
                   12524:         if (ref($current{'courses'}) eq 'HASH') {
                   12525:             foreach my $cid (sort(keys(%{$current{'courses'}}))) {
                   12526:                 if ($crsdeletions{$cid}) {
                   12527:                     $changes{$itemid} = 1;
                   12528:                 } else {
                   12529:                     $confhash{$itemid}{'courses'}{$cid} = 1;
                   12530:                 }
                   12531:             }
                   12532:         }
                   12533:         $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
                   12534:         $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
                   12535:         if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) && 
                   12536:             ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
                   12537:             if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
                   12538:                                             $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
                   12539:                 $errors .= '<li><span class="LC_error">'.
                   12540:                            &mt('Invalid courseID [_1] omitted from list of allowed courses',
                   12541:                                $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
                   12542:                            '</span></li>';
                   12543:             } else {
                   12544:                 $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
                   12545:                 $changes{$itemid} = 1;
                   12546:             }
                   12547:         }
                   12548:     }
                   12549:     if (@allpos > 0) {
                   12550:         my $idx = 0;
                   12551:         foreach my $itemid (@allpos) {
                   12552:             if ($itemid ne '') {
                   12553:                 $confhash{$itemid}{'order'} = $idx;
                   12554:                 unless ($changes{$itemid}) {
                   12555:                     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   12556:                         if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   12557:                             if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
                   12558:                                 $changes{$itemid} = 1;
                   12559:                             }
                   12560:                         }
                   12561:                     }
                   12562:                 }
                   12563:                 $idx ++;
                   12564:             }
                   12565:         }
                   12566:     }
                   12567:     if (keys(%changes)) {
                   12568:         my %defaultshash = (
                   12569:                               ipaccess => \%confhash,
                   12570:                            );
                   12571:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12572:                                                  $dom);
                   12573:         if ($putresult eq 'ok') {
                   12574:             my $cachetime = 1800;
                   12575:             &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
                   12576:             if (ref($lastactref) eq 'HASH') {
                   12577:                 $lastactref->{'ipaccess'} = 1;
                   12578:             }
                   12579:             $resulttext = &mt('Changes made:').'<ul>';
                   12580:             my %bynum;
                   12581:             foreach my $itemid (sort(keys(%changes))) {
                   12582:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   12583:                     my $position = $confhash{$itemid}{'order'};
                   12584:                     if ($position =~ /^\d+$/) {
                   12585:                         $bynum{$position} = $itemid;
                   12586:                     }
                   12587:                 }
                   12588:             }
                   12589:             if (keys(%deletions)) {
                   12590:                 foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
                   12591:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12592:                 }
                   12593:             }
                   12594:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12595:                 my $itemid = $bynum{$pos};
                   12596:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   12597:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
                   12598:                     my $position = $pos + 1;
                   12599:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   12600:                     if ($confhash{$itemid}{'ip'} eq '') {
                   12601:                         $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
                   12602:                     } else {
                   12603:                         $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
                   12604:                     }
                   12605:                     if (keys(%{$confhash{$itemid}{'commblocks'}})) {
                   12606:                         $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
                   12607:                                                   join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
                   12608:                                        '</li>';
                   12609:                     } else {
                   12610:                         $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
                   12611:                     }
                   12612:                     if (keys(%{$confhash{$itemid}{'courses'}})) {
                   12613:                         my @courses;
                   12614:                         foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
                   12615:                             my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1}); 
                   12616:                             push(@courses,$courseinfo{'description'}.' ('.$cid.')');
                   12617:                         }
                   12618:                         $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
                   12619:                                              join('</li><li>',@courses).'</li></ul>';
                   12620:                     } else {
                   12621:                         $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
                   12622:                     }
1.395   ! raeburn  12623:                     $resulttext .= '</ul></li>';
1.394     raeburn  12624:                 }
                   12625:             }
1.395   ! raeburn  12626:             $resulttext .= '</ul>';
1.394     raeburn  12627:         } else {
                   12628:             $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   12629:         }
                   12630:     } else {
                   12631:         $resulttext = &mt('No changes made');
                   12632:     }
                   12633:     if ($errors) {
                   12634:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   12635:                        $errors.'</ul></p>';
                   12636:     }
                   12637:     return $resulttext;
                   12638: }
                   12639: 
                   12640: sub get_ipaccess_id {
                   12641:     my ($domain,$location) = @_;
                   12642:     # get lock on ipaccess db
                   12643:     my $lockhash = {
                   12644:                       lock => $env{'user.name'}.
                   12645:                               ':'.$env{'user.domain'},
                   12646:                    };
                   12647:     my $tries = 0;
                   12648:     my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   12649:     my ($id,$error);
                   12650: 
                   12651:     while (($gotlock ne 'ok') && ($tries<10)) {
                   12652:         $tries ++;
                   12653:         sleep (0.1);
                   12654:         $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   12655:     }
                   12656:     if ($gotlock eq 'ok') {
                   12657:         my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
                   12658:         if ($currids{'lock'}) {
                   12659:             delete($currids{'lock'});
                   12660:             if (keys(%currids)) {
                   12661:                 my @curr = sort { $a <=> $b } keys(%currids);
                   12662:                 if ($curr[-1] =~ /^\d+$/) {
                   12663:                     $id = 1 + $curr[-1];
                   12664:                 }
                   12665:             } else {
                   12666:                 $id = 1;
                   12667:             }
                   12668:             if ($id) {
                   12669:                 unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
                   12670:                     $error = 'nostore';
                   12671:                 }
                   12672:             } else {
                   12673:                 $error = 'nonumber';
                   12674:             }
                   12675:         }
                   12676:         my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
                   12677:     } else {
                   12678:         $error = 'nolock';
                   12679:     }
                   12680:     return ($id,$error);
                   12681: }
                   12682: 
1.6       raeburn  12683: sub modify_rolecolors {
1.205     raeburn  12684:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  12685:     my ($resulttext,%rolehash);
                   12686:     $rolehash{'rolecolors'} = {};
1.55      raeburn  12687:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   12688:         if ($domconfig{'rolecolors'} eq '') {
                   12689:             $domconfig{'rolecolors'} = {};
                   12690:         }
                   12691:     }
1.9       raeburn  12692:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  12693:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   12694:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   12695:                                              $dom);
                   12696:     if ($putresult eq 'ok') {
                   12697:         if (keys(%changes) > 0) {
1.41      raeburn  12698:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  12699:             if (ref($lastactref) eq 'HASH') {
                   12700:                 $lastactref->{'domainconfig'} = 1;
                   12701:             }
1.6       raeburn  12702:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   12703:                                              $rolehash{'rolecolors'});
                   12704:         } else {
                   12705:             $resulttext = &mt('No changes made to default color schemes');
                   12706:         }
                   12707:     } else {
1.11      albertel 12708:         $resulttext = '<span class="LC_error">'.
                   12709: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  12710:     }
                   12711:     if ($errors) {
                   12712:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   12713:                        $errors.'</ul>';
                   12714:     }
                   12715:     return $resulttext;
                   12716: }
                   12717: 
                   12718: sub modify_colors {
1.9       raeburn  12719:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  12720:     my (%changes,%choices);
1.51      raeburn  12721:     my @bgs;
1.6       raeburn  12722:     my @links = ('link','alink','vlink');
1.41      raeburn  12723:     my @logintext;
1.6       raeburn  12724:     my @images;
                   12725:     my $servadm = $r->dir_config('lonAdmEMail');
                   12726:     my $errors;
1.200     raeburn  12727:     my %defaults;
1.6       raeburn  12728:     foreach my $role (@{$roles}) {
                   12729:         if ($role eq 'login') {
1.12      raeburn  12730:             %choices = &login_choices();
1.41      raeburn  12731:             @logintext = ('textcol','bgcol');
1.12      raeburn  12732:         } else {
                   12733:             %choices = &color_font_choices();
                   12734:         }
                   12735:         if ($role eq 'login') {
1.41      raeburn  12736:             @images = ('img','logo','domlogo','login');
1.51      raeburn  12737:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  12738:         } else {
                   12739:             @images = ('img');
1.200     raeburn  12740:             @bgs = ('pgbg','tabbg','sidebg');
                   12741:         }
                   12742:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   12743:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   12744:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   12745:         }
                   12746:         if ($role eq 'login') {
                   12747:             foreach my $item (@logintext) {
1.234     raeburn  12748:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12749:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12750:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12751:                 }
                   12752:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  12753:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12754:                 }
                   12755:             }
                   12756:         } else {
1.234     raeburn  12757:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   12758:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   12759:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   12760:             }
                   12761:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  12762:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   12763:             }
1.6       raeburn  12764:         }
1.200     raeburn  12765:         foreach my $item (@bgs) {
1.234     raeburn  12766:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12767:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12768:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12769:             }
                   12770:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  12771:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12772:             }
                   12773:         }
                   12774:         foreach my $item (@links) {
1.234     raeburn  12775:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   12776:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   12777:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   12778:             }
                   12779:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  12780:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   12781:             }
1.6       raeburn  12782:         }
1.46      raeburn  12783:         my ($configuserok,$author_ok,$switchserver) = 
                   12784:             &config_check($dom,$confname,$servadm);
1.9       raeburn  12785:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  12786:         if (ref($domconfig->{$role}) ne 'HASH') {
                   12787:             $domconfig->{$role} = {};
                   12788:         }
1.8       raeburn  12789:         foreach my $img (@images) {
1.70      raeburn  12790:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   12791:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   12792:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   12793:                 } else { 
                   12794:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   12795:                 }
                   12796:             } 
1.18      albertel 12797: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   12798: 		 && !defined($domconfig->{$role}{$img})
                   12799: 		 && !$env{'form.'.$role.'_del_'.$img}
                   12800: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   12801: 		# import the old configured image from the .tab setting
                   12802: 		# if they haven't provided a new one 
                   12803: 		$domconfig->{$role}{$img} = 
                   12804: 		    $env{'form.'.$role.'_import_'.$img};
                   12805: 	    }
1.6       raeburn  12806:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  12807:                 my $error;
1.6       raeburn  12808:                 if ($configuserok eq 'ok') {
1.9       raeburn  12809:                     if ($switchserver) {
1.12      raeburn  12810:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  12811:                     } else {
                   12812:                         if ($author_ok eq 'ok') {
                   12813:                             my ($result,$logourl) = 
                   12814:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   12815:                                            $dom,$confname,$img,$width,$height);
                   12816:                             if ($result eq 'ok') {
                   12817:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  12818:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  12819:                             } else {
1.12      raeburn  12820:                                 $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  12821:                             }
                   12822:                         } else {
1.46      raeburn  12823:                             $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  12824:                         }
                   12825:                     }
                   12826:                 } else {
1.46      raeburn  12827:                     $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  12828:                 }
                   12829:                 if ($error) {
1.8       raeburn  12830:                     &Apache::lonnet::logthis($error);
1.11      albertel 12831:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  12832:                 }
                   12833:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  12834:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   12835:                     my $error;
                   12836:                     if ($configuserok eq 'ok') {
                   12837: # is confname an author?
                   12838:                         if ($switchserver eq '') {
                   12839:                             if ($author_ok eq 'ok') {
                   12840:                                 my ($result,$logourl) = 
                   12841:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   12842:                                             $dom,$confname,$img,$width,$height);
                   12843:                                 if ($result eq 'ok') {
                   12844:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 12845: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  12846:                                 }
                   12847:                             }
                   12848:                         }
                   12849:                     }
1.6       raeburn  12850:                 }
                   12851:             }
                   12852:         }
                   12853:         if (ref($domconfig) eq 'HASH') {
                   12854:             if (ref($domconfig->{$role}) eq 'HASH') {
                   12855:                 foreach my $img (@images) {
                   12856:                     if ($domconfig->{$role}{$img} ne '') {
                   12857:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   12858:                             $confhash->{$role}{$img} = '';
1.12      raeburn  12859:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  12860:                         } else {
1.9       raeburn  12861:                             if ($confhash->{$role}{$img} eq '') {
                   12862:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   12863:                             }
1.6       raeburn  12864:                         }
                   12865:                     } else {
                   12866:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   12867:                             $confhash->{$role}{$img} = '';
1.12      raeburn  12868:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  12869:                         } 
                   12870:                     }
1.70      raeburn  12871:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   12872:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   12873:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   12874:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   12875:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   12876:                             }
                   12877:                         } else {
                   12878:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   12879:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   12880:                             }
                   12881:                         }
                   12882:                     }
                   12883:                 }
1.6       raeburn  12884:                 if ($domconfig->{$role}{'font'} ne '') {
                   12885:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   12886:                         $changes{$role}{'font'} = 1;
                   12887:                     }
                   12888:                 } else {
                   12889:                     if ($confhash->{$role}{'font'}) {
                   12890:                         $changes{$role}{'font'} = 1;
                   12891:                     }
                   12892:                 }
1.107     raeburn  12893:                 if ($role ne 'login') {
                   12894:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   12895:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   12896:                             $changes{$role}{'fontmenu'} = 1;
                   12897:                         }
                   12898:                     } else {
                   12899:                         if ($confhash->{$role}{'fontmenu'}) {
                   12900:                             $changes{$role}{'fontmenu'} = 1;
                   12901:                         }
1.97      tempelho 12902:                     }
                   12903:                 }
1.6       raeburn  12904:                 foreach my $item (@bgs) {
                   12905:                     if ($domconfig->{$role}{$item} ne '') {
                   12906:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   12907:                             $changes{$role}{'bgs'}{$item} = 1;
                   12908:                         } 
                   12909:                     } else {
                   12910:                         if ($confhash->{$role}{$item}) {
                   12911:                             $changes{$role}{'bgs'}{$item} = 1;
                   12912:                         }
                   12913:                     }
                   12914:                 }
                   12915:                 foreach my $item (@links) {
                   12916:                     if ($domconfig->{$role}{$item} ne '') {
                   12917:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   12918:                             $changes{$role}{'links'}{$item} = 1;
                   12919:                         }
                   12920:                     } else {
                   12921:                         if ($confhash->{$role}{$item}) {
                   12922:                             $changes{$role}{'links'}{$item} = 1;
                   12923:                         }
                   12924:                     }
                   12925:                 }
1.41      raeburn  12926:                 foreach my $item (@logintext) {
                   12927:                     if ($domconfig->{$role}{$item} ne '') {
                   12928:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   12929:                             $changes{$role}{'logintext'}{$item} = 1;
                   12930:                         }
                   12931:                     } else {
                   12932:                         if ($confhash->{$role}{$item}) {
                   12933:                             $changes{$role}{'logintext'}{$item} = 1;
                   12934:                         }
                   12935:                     }
                   12936:                 }
1.6       raeburn  12937:             } else {
                   12938:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  12939:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  12940:             }
                   12941:         } else {
                   12942:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  12943:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  12944:         }
                   12945:     }
                   12946:     return ($errors,%changes);
                   12947: }
                   12948: 
1.46      raeburn  12949: sub config_check {
                   12950:     my ($dom,$confname,$servadm) = @_;
                   12951:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   12952:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   12953:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   12954:                                                    $confname,$servadm);
                   12955:     if ($configuserok eq 'ok') {
                   12956:         $switchserver = &check_switchserver($dom,$confname);
                   12957:         if ($switchserver eq '') {
                   12958:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   12959:         }
                   12960:     }
                   12961:     return ($configuserok,$author_ok,$switchserver);
                   12962: }
                   12963: 
1.6       raeburn  12964: sub default_change_checker {
1.41      raeburn  12965:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  12966:     foreach my $item (@{$links}) {
                   12967:         if ($confhash->{$role}{$item}) {
                   12968:             $changes->{$role}{'links'}{$item} = 1;
                   12969:         }
                   12970:     }
                   12971:     foreach my $item (@{$bgs}) {
                   12972:         if ($confhash->{$role}{$item}) {
                   12973:             $changes->{$role}{'bgs'}{$item} = 1;
                   12974:         }
                   12975:     }
1.41      raeburn  12976:     foreach my $item (@{$logintext}) {
                   12977:         if ($confhash->{$role}{$item}) {
                   12978:             $changes->{$role}{'logintext'}{$item} = 1;
                   12979:         }
                   12980:     }
1.6       raeburn  12981:     foreach my $img (@{$images}) {
                   12982:         if ($env{'form.'.$role.'_del_'.$img}) {
                   12983:             $confhash->{$role}{$img} = '';
1.12      raeburn  12984:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  12985:         }
1.70      raeburn  12986:         if ($role eq 'login') {
                   12987:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   12988:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   12989:             }
                   12990:         }
1.6       raeburn  12991:     }
                   12992:     if ($confhash->{$role}{'font'}) {
                   12993:         $changes->{$role}{'font'} = 1;
                   12994:     }
1.48      raeburn  12995: }
1.6       raeburn  12996: 
                   12997: sub display_colorchgs {
                   12998:     my ($dom,$changes,$roles,$confhash) = @_;
                   12999:     my (%choices,$resulttext);
                   13000:     if (!grep(/^login$/,@{$roles})) {
                   13001:         $resulttext = &mt('Changes made:').'<br />';
                   13002:     }
                   13003:     foreach my $role (@{$roles}) {
                   13004:         if ($role eq 'login') {
                   13005:             %choices = &login_choices();
                   13006:         } else {
                   13007:             %choices = &color_font_choices();
                   13008:         }
                   13009:         if (ref($changes->{$role}) eq 'HASH') {
                   13010:             if ($role ne 'login') {
                   13011:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   13012:             }
                   13013:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   13014:                 if ($role ne 'login') {
                   13015:                     $resulttext .= '<ul>';
                   13016:                 }
                   13017:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   13018:                     if ($role ne 'login') {
                   13019:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   13020:                     }
                   13021:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  13022:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   13023:                             if ($confhash->{$role}{$key}{$item}) {
                   13024:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   13025:                             } else {
                   13026:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   13027:                             }
                   13028:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  13029:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   13030:                         } else {
1.12      raeburn  13031:                             my $newitem = $confhash->{$role}{$item};
                   13032:                             if ($key eq 'images') {
1.306     raeburn  13033:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  13034:                             }
                   13035:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  13036:                         }
                   13037:                     }
                   13038:                     if ($role ne 'login') {
                   13039:                         $resulttext .= '</ul></li>';
                   13040:                     }
                   13041:                 } else {
                   13042:                     if ($confhash->{$role}{$key} eq '') {
                   13043:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   13044:                     } else {
                   13045:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   13046:                     }
                   13047:                 }
                   13048:                 if ($role ne 'login') {
                   13049:                     $resulttext .= '</ul>';
                   13050:                 }
                   13051:             }
                   13052:         }
                   13053:     }
1.3       raeburn  13054:     return $resulttext;
1.1       raeburn  13055: }
                   13056: 
1.9       raeburn  13057: sub thumb_dimensions {
                   13058:     return ('200','50');
                   13059: }
                   13060: 
1.16      raeburn  13061: sub check_dimensions {
                   13062:     my ($inputfile) = @_;
                   13063:     my ($fullwidth,$fullheight);
                   13064:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   13065:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   13066:             my $imageinfo = <PIPE>;
                   13067:             if (!close(PIPE)) {
                   13068:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   13069:             }
                   13070:             chomp($imageinfo);
                   13071:             my ($fullsize) = 
1.21      raeburn  13072:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  13073:             if ($fullsize) {
                   13074:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   13075:             }
                   13076:         }
                   13077:     }
                   13078:     return ($fullwidth,$fullheight);
                   13079: }
                   13080: 
1.9       raeburn  13081: sub check_configuser {
                   13082:     my ($uhome,$dom,$confname,$servadm) = @_;
                   13083:     my ($configuserok,%currroles);
                   13084:     if ($uhome eq 'no_host') {
                   13085:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.361     raeburn  13086:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  13087:         $configuserok = 
                   13088:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   13089:                              $configpass,'','','','','',undef,$servadm);
                   13090:     } else {
                   13091:         $configuserok = 'ok';
                   13092:         %currroles = 
                   13093:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   13094:     }
                   13095:     return ($configuserok,%currroles);
                   13096: }
                   13097: 
                   13098: sub check_authorstatus {
                   13099:     my ($dom,$confname,%currroles) = @_;
                   13100:     my $author_ok;
1.40      raeburn  13101:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  13102:         my $start = time;
                   13103:         my $end = 0;
                   13104:         $author_ok = 
                   13105:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  13106:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  13107:     } else {
                   13108:         $author_ok = 'ok';
                   13109:     }
                   13110:     return $author_ok;
                   13111: }
                   13112: 
                   13113: sub publishlogo {
1.46      raeburn  13114:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  13115:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  13116:     if ($action eq 'upload') {
                   13117:         $fname=$env{'form.'.$formname.'.filename'};
                   13118:         chop($env{'form.'.$formname});
                   13119:     } else {
                   13120:         ($fname) = ($formname =~ /([^\/]+)$/);
                   13121:     }
1.46      raeburn  13122:     if ($savefileas ne '') {
                   13123:         $fname = $savefileas;
                   13124:     }
1.9       raeburn  13125:     $fname=&Apache::lonnet::clean_filename($fname);
                   13126: # See if there is anything left
                   13127:     unless ($fname) { return ('error: no uploaded file'); }
                   13128:     $fname="$subdir/$fname";
1.210     raeburn  13129:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  13130:     my $filepath="$docroot/priv";
                   13131:     my $relpath = "$dom/$confname";
1.9       raeburn  13132:     my ($fnamepath,$file,$fetchthumb);
                   13133:     $file=$fname;
                   13134:     if ($fname=~m|/|) {
                   13135:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   13136:     }
1.164     raeburn  13137:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  13138:     my $count;
1.164     raeburn  13139:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  13140:         $filepath.="/$parts[$count]";
                   13141:         if ((-e $filepath)!=1) {
                   13142:             mkdir($filepath,02770);
                   13143:         }
                   13144:     }
                   13145:     # Check for bad extension and disallow upload
                   13146:     if ($file=~/\.(\w+)$/ &&
                   13147:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   13148:         $output = 
1.207     bisitz   13149:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  13150:     } elsif ($file=~/\.(\w+)$/ &&
                   13151:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   13152:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   13153:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   13154:         $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  13155:     } elsif (-d "$filepath/$file") {
1.195     bisitz   13156:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  13157:     } else {
                   13158:         my $source = $filepath.'/'.$file;
                   13159:         my $logfile;
1.316     raeburn  13160:         if (!open($logfile,">>",$source.'.log')) {
1.196     raeburn  13161:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  13162:         }
                   13163:         print $logfile
                   13164: "\n================= Publish ".localtime()." ================\n".
                   13165: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   13166: # Save the file
1.316     raeburn  13167:         if (!open(FH,">",$source)) {
1.9       raeburn  13168:             &Apache::lonnet::logthis('Failed to create '.$source);
                   13169:             return (&mt('Failed to create file'));
                   13170:         }
                   13171:         if ($action eq 'upload') {
                   13172:             if (!print FH ($env{'form.'.$formname})) {
                   13173:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   13174:                 return (&mt('Failed to write file'));
                   13175:             }
                   13176:         } else {
                   13177:             my $original = &Apache::lonnet::filelocation('',$formname);
                   13178:             if(!copy($original,$source)) {
                   13179:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   13180:                 return (&mt('Failed to write file'));
                   13181:             }
                   13182:         }
                   13183:         close(FH);
                   13184:         chmod(0660, $source); # Permissions to rw-rw---.
                   13185: 
                   13186:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   13187:         my $copyfile=$targetdir.'/'.$file;
                   13188: 
                   13189:         my @parts=split(/\//,$targetdir);
                   13190:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   13191:         for (my $count=5;$count<=$#parts;$count++) {
                   13192:             $path.="/$parts[$count]";
                   13193:             if (!-e $path) {
                   13194:                 print $logfile "\nCreating directory ".$path;
                   13195:                 mkdir($path,02770);
                   13196:             }
                   13197:         }
                   13198:         my $versionresult;
                   13199:         if (-e $copyfile) {
                   13200:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   13201:         } else {
                   13202:             $versionresult = 'ok';
                   13203:         }
                   13204:         if ($versionresult eq 'ok') {
                   13205:             if (copy($source,$copyfile)) {
                   13206:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   13207:                 $output = 'ok';
                   13208:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  13209:                 push(@{$modified_urls},[$copyfile,$source]);
                   13210:                 my $metaoutput = 
                   13211:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   13212:                 unless ($registered_cleanup) {
                   13213:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13214:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13215:                     $registered_cleanup=1;
                   13216:                 }
1.9       raeburn  13217:             } else {
                   13218:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   13219:                 $output = &mt('Failed to copy file to RES space').", $!";
                   13220:             }
                   13221:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   13222:                 my $inputfile = $filepath.'/'.$file;
                   13223:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  13224:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   13225:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   13226:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   13227:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316     raeburn  13228:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   13229:                         system({$args[0]} @args);
1.16      raeburn  13230:                         chmod(0660, $filepath.'/tn-'.$file);
                   13231:                         if (-e $outfile) {
                   13232:                             my $copyfile=$targetdir.'/tn-'.$file;
                   13233:                             if (copy($outfile,$copyfile)) {
                   13234:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  13235:                                 my $thumb_metaoutput = 
                   13236:                                     &write_metadata($dom,$confname,$formname,
                   13237:                                                     $targetdir,'tn-'.$file,$logfile);
                   13238:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   13239:                                 unless ($registered_cleanup) {
                   13240:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   13241:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   13242:                                     $registered_cleanup=1;
                   13243:                                 }
1.267     raeburn  13244:                                 $madethumb = 1;
1.16      raeburn  13245:                             } else {
                   13246:                                 print $logfile "\nUnable to write ".$copyfile.
                   13247:                                                ':'.$!."\n";
                   13248:                             }
                   13249:                         }
1.9       raeburn  13250:                     }
                   13251:                 }
                   13252:             }
                   13253:         } else {
                   13254:             $output = $versionresult;
                   13255:         }
                   13256:     }
1.267     raeburn  13257:     return ($output,$logourl,$madethumb);
1.9       raeburn  13258: }
                   13259: 
                   13260: sub logo_versioning {
                   13261:     my ($targetdir,$file,$logfile) = @_;
                   13262:     my $target = $targetdir.'/'.$file;
                   13263:     my ($maxversion,$fn,$extn,$output);
                   13264:     $maxversion = 0;
                   13265:     if ($file =~ /^(.+)\.(\w+)$/) {
                   13266:         $fn=$1;
                   13267:         $extn=$2;
                   13268:     }
                   13269:     opendir(DIR,$targetdir);
                   13270:     while (my $filename=readdir(DIR)) {
                   13271:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   13272:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   13273:         }
                   13274:     }
                   13275:     $maxversion++;
                   13276:     print $logfile "\nCreating old version ".$maxversion."\n";
                   13277:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   13278:     if (copy($target,$copyfile)) {
                   13279:         print $logfile "Copied old target to ".$copyfile."\n";
                   13280:         $copyfile=$copyfile.'.meta';
                   13281:         if (copy($target.'.meta',$copyfile)) {
                   13282:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   13283:             $output = 'ok';
                   13284:         } else {
                   13285:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   13286:             $output = &mt('Failed to copy old meta').", $!, ";
                   13287:         }
                   13288:     } else {
                   13289:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   13290:         $output = &mt('Failed to copy old target').", $!, ";
                   13291:     }
                   13292:     return $output;
                   13293: }
                   13294: 
                   13295: sub write_metadata {
                   13296:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   13297:     my (%metadatafields,%metadatakeys,$output);
                   13298:     $metadatafields{'title'}=$formname;
                   13299:     $metadatafields{'creationdate'}=time;
                   13300:     $metadatafields{'lastrevisiondate'}=time;
                   13301:     $metadatafields{'copyright'}='public';
                   13302:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   13303:                                          $env{'user.domain'};
                   13304:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   13305:     $metadatafields{'domain'}=$dom;
                   13306:     {
                   13307:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   13308:         my $mfh;
1.316     raeburn  13309:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  13310:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  13311:                 unless ($_=~/\./) {
                   13312:                     my $unikey=$_;
                   13313:                     $unikey=~/^([A-Za-z]+)/;
                   13314:                     my $tag=$1;
                   13315:                     $tag=~tr/A-Z/a-z/;
                   13316:                     print $mfh "\n\<$tag";
                   13317:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   13318:                         my $value=$metadatafields{$unikey.'.'.$_};
                   13319:                         $value=~s/\"/\'\'/g;
                   13320:                         print $mfh ' '.$_.'="'.$value.'"';
                   13321:                     }
                   13322:                     print $mfh '>'.
                   13323:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   13324:                             .'</'.$tag.'>';
                   13325:                 }
                   13326:             }
                   13327:             $output = 'ok';
                   13328:             print $logfile "\nWrote metadata";
                   13329:             close($mfh);
                   13330:         } else {
                   13331:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  13332:             $output = &mt('Could not write metadata');
                   13333:         }
                   13334:     }
1.155     raeburn  13335:     return $output;
                   13336: }
                   13337: 
                   13338: sub notifysubscribed {
                   13339:     foreach my $targetsource (@{$modified_urls}){
                   13340:         next unless (ref($targetsource) eq 'ARRAY');
                   13341:         my ($target,$source)=@{$targetsource};
                   13342:         if ($source ne '') {
1.316     raeburn  13343:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  13344:                 print $logfh "\nCleanup phase: Notifications\n";
                   13345:                 my @subscribed=&subscribed_hosts($target);
                   13346:                 foreach my $subhost (@subscribed) {
                   13347:                     print $logfh "\nNotifying host ".$subhost.':';
                   13348:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   13349:                     print $logfh $reply;
                   13350:                 }
                   13351:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   13352:                 foreach my $subhost (@subscribedmeta) {
                   13353:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   13354:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   13355:                                                         $subhost);
                   13356:                     print $logfh $reply;
                   13357:                 }
                   13358:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  13359:                 close($logfh);
1.155     raeburn  13360:             }
                   13361:         }
                   13362:     }
                   13363:     return OK;
                   13364: }
                   13365: 
                   13366: sub subscribed_hosts {
                   13367:     my ($target) = @_;
                   13368:     my @subscribed;
1.316     raeburn  13369:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  13370:         while (my $subline=<$fh>) {
                   13371:             if ($subline =~ /^($match_lonid):/) {
                   13372:                 my $host = $1;
                   13373:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   13374:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   13375:                         push(@subscribed,$host);
                   13376:                     }
                   13377:                 }
                   13378:             }
                   13379:         }
                   13380:     }
                   13381:     return @subscribed;
1.9       raeburn  13382: }
                   13383: 
                   13384: sub check_switchserver {
                   13385:     my ($dom,$confname) = @_;
                   13386:     my ($allowed,$switchserver);
                   13387:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   13388:     if ($home eq 'no_host') {
                   13389:         $home = &Apache::lonnet::domain($dom,'primary');
                   13390:     }
                   13391:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 13392:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   13393:     if (!$allowed) {
1.180     raeburn  13394: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  13395:     }
                   13396:     return $switchserver;
                   13397: }
                   13398: 
1.1       raeburn  13399: sub modify_quotas {
1.216     raeburn  13400:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  13401:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  13402:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  13403:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   13404:         $validationfieldsref);
1.86      raeburn  13405:     if ($action eq 'quotas') {
                   13406:         $context = 'tools'; 
1.163     raeburn  13407:     } else {
1.86      raeburn  13408:         $context = $action;
                   13409:     }
                   13410:     if ($context eq 'requestcourses') {
1.325     raeburn  13411:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  13412:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  13413:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   13414:         %titles = &courserequest_titles();
                   13415:         $toolregexp = join('|',@usertools);
                   13416:         %conditions = &courserequest_conditions();
1.216     raeburn  13417:         $confname = $dom.'-domainconfig';
                   13418:         my $servadm = $r->dir_config('lonAdmEMail');
                   13419:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  13420:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   13421:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  13422:     } elsif ($context eq 'requestauthor') {
                   13423:         @usertools = ('author');
                   13424:         %titles = &authorrequest_titles();
1.86      raeburn  13425:     } else {
1.162     raeburn  13426:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  13427:         %titles = &tool_titles();
1.86      raeburn  13428:     }
1.212     raeburn  13429:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  13430:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  13431:     foreach my $key (keys(%env)) {
1.101     raeburn  13432:         if ($context eq 'requestcourses') {
                   13433:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   13434:                 my $item = $1;
                   13435:                 my $type = $2;
                   13436:                 if ($type =~ /^limit_(.+)/) {
                   13437:                     $limithash{$item}{$1} = $env{$key};
                   13438:                 } else {
                   13439:                     $confhash{$item}{$type} = $env{$key};
                   13440:                 }
                   13441:             }
1.163     raeburn  13442:         } elsif ($context eq 'requestauthor') {
                   13443:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   13444:                 $confhash{$1} = $env{$key};
                   13445:             }
1.101     raeburn  13446:         } else {
1.86      raeburn  13447:             if ($key =~ /^form\.quota_(.+)$/) {
                   13448:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  13449:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   13450:                 $confhash{'authorquota'}{$1} = $env{$key};
                   13451:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  13452:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   13453:             }
1.72      raeburn  13454:         }
                   13455:     }
1.163     raeburn  13456:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  13457:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  13458:         @approvalnotify = sort(@approvalnotify);
                   13459:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325     raeburn  13460:         my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218     raeburn  13461:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   13462:         foreach my $type (@hasuniquecode) {
                   13463:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   13464:                 $confhash{'uniquecode'}{$type} = 1;
                   13465:             }
1.216     raeburn  13466:         }
1.242     raeburn  13467:         my (%newbook,%allpos);
1.216     raeburn  13468:         if ($context eq 'requestcourses') {
1.242     raeburn  13469:             foreach my $type ('textbooks','templates') {
                   13470:                 @{$allpos{$type}} = (); 
                   13471:                 my $invalid;
                   13472:                 if ($type eq 'textbooks') {
                   13473:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   13474:                 } else {
                   13475:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   13476:                 }
                   13477:                 if ($env{'form.'.$type.'_addbook'}) {
                   13478:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   13479:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   13480:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   13481:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   13482:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   13483:                         } else {
                   13484:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   13485:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   13486:                             $position =~ s/\D+//g;
                   13487:                             if ($position ne '') {
                   13488:                                 $allpos{$type}[$position] = $newbook{$type};
                   13489:                             }
1.216     raeburn  13490:                         }
1.242     raeburn  13491:                     } else {
                   13492:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  13493:                     }
                   13494:                 }
1.242     raeburn  13495:             } 
1.216     raeburn  13496:         }
1.102     raeburn  13497:         if (ref($domconfig{$action}) eq 'HASH') {
                   13498:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   13499:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   13500:                     $changes{'notify'}{'approval'} = 1;
                   13501:                 }
                   13502:             } else {
1.144     raeburn  13503:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  13504:                     $changes{'notify'}{'approval'} = 1;
                   13505:                 }
                   13506:             }
1.218     raeburn  13507:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   13508:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   13509:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   13510:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   13511:                             $changes{'uniquecode'} = 1;
                   13512:                         }
                   13513:                     }
                   13514:                     unless ($changes{'uniquecode'}) {
                   13515:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   13516:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   13517:                                 $changes{'uniquecode'} = 1;
                   13518:                             }
                   13519:                         }
                   13520:                     }
                   13521:                } else {
                   13522:                    $changes{'uniquecode'} = 1;
                   13523:                }
                   13524:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   13525:                 $changes{'uniquecode'} = 1;
1.216     raeburn  13526:             }
                   13527:             if ($context eq 'requestcourses') {
1.242     raeburn  13528:                 foreach my $type ('textbooks','templates') {
                   13529:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   13530:                         my %deletions;
                   13531:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   13532:                         if (@todelete) {
                   13533:                             map { $deletions{$_} = 1; } @todelete;
                   13534:                         }
                   13535:                         my %imgdeletions;
                   13536:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   13537:                         if (@todeleteimages) {
                   13538:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   13539:                         }
                   13540:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   13541:                         for (my $i=0; $i<=$maxnum; $i++) {
                   13542:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   13543:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   13544:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   13545:                                 if ($deletions{$key}) {
                   13546:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   13547:                                         #FIXME need to obsolete item in RES space
                   13548:                                     }
                   13549:                                     next;
                   13550:                                 } else {
                   13551:                                     my $newpos = $env{'form.'.$itemid};
                   13552:                                     $newpos =~ s/\D+//g;
1.243     raeburn  13553:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  13554:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  13555:                                                  ($type eq 'templates'));
1.242     raeburn  13556:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   13557:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   13558:                                             $changes{$type}{$key} = 1;
                   13559:                                         }
                   13560:                                     }
                   13561:                                     $allpos{$type}[$newpos] = $key;
                   13562:                                 }
                   13563:                                 if ($imgdeletions{$key}) {
                   13564:                                     $changes{$type}{$key} = 1;
1.216     raeburn  13565:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  13566:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   13567:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  13568:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   13569:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   13570:                                     } else {
                   13571:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   13572:                                                                                       $cdom,$cnum,$type,$configuserok,
                   13573:                                                                                       $switchserver,$author_ok);
                   13574:                                         if ($imgurl) {
                   13575:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   13576:                                             $changes{$type}{$key} = 1; 
                   13577:                                         }
                   13578:                                         if ($error) {
                   13579:                                             &Apache::lonnet::logthis($error);
                   13580:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13581:                                         }
                   13582:                                     }
1.242     raeburn  13583:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   13584:                                     $confhash{$type}{$key}{'image'} = 
                   13585:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  13586:                                 }
                   13587:                             }
                   13588:                         }
                   13589:                     }
                   13590:                 }
                   13591:             }
1.102     raeburn  13592:         } else {
1.144     raeburn  13593:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  13594:                 $changes{'notify'}{'approval'} = 1;
                   13595:             }
1.218     raeburn  13596:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  13597:                 $changes{'uniquecode'} = 1;
                   13598:             }
                   13599:         }
                   13600:         if ($context eq 'requestcourses') {
1.242     raeburn  13601:             foreach my $type ('textbooks','templates') {
                   13602:                 if ($newbook{$type}) {
                   13603:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  13604:                     foreach my $item ('subject','title','publisher','author') {
                   13605:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   13606:                                  ($type eq 'template'));
1.242     raeburn  13607:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   13608:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   13609:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   13610:                         }
                   13611:                     }
                   13612:                     if ($type eq 'textbooks') {
                   13613:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   13614:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  13615:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   13616:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   13617:                             } else {
                   13618:                                 my ($imageurl,$error) =
                   13619:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   13620:                                                             $configuserok,$switchserver,$author_ok);
                   13621:                                 if ($imageurl) {
                   13622:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   13623:                                 }
                   13624:                                 if ($error) {
                   13625:                                     &Apache::lonnet::logthis($error);
                   13626:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13627:                                 }
1.242     raeburn  13628:                             }
                   13629:                         }
1.216     raeburn  13630:                     }
                   13631:                 }
1.242     raeburn  13632:                 if (@{$allpos{$type}} > 0) {
                   13633:                     my $idx = 0;
                   13634:                     foreach my $item (@{$allpos{$type}}) {
                   13635:                         if ($item ne '') {
                   13636:                             $confhash{$type}{$item}{'order'} = $idx;
                   13637:                             if (ref($domconfig{$action}) eq 'HASH') {
                   13638:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   13639:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   13640:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   13641:                                             $changes{$type}{$item} = 1;
                   13642:                                         }
1.216     raeburn  13643:                                     }
                   13644:                                 }
                   13645:                             }
1.242     raeburn  13646:                             $idx ++;
1.216     raeburn  13647:                         }
                   13648:                     }
                   13649:                 }
                   13650:             }
1.235     raeburn  13651:             if (ref($validationitemsref) eq 'ARRAY') {
                   13652:                 foreach my $item (@{$validationitemsref}) {
                   13653:                     if ($item eq 'fields') {
                   13654:                         my @changed;
                   13655:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   13656:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   13657:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   13658:                         }
1.266     raeburn  13659:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13660:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13661:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   13662:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   13663:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   13664:                                 } else {
                   13665:                                     @changed = @{$confhash{'validation'}{$item}};
                   13666:                                 }
1.235     raeburn  13667:                             } else {
                   13668:                                 @changed = @{$confhash{'validation'}{$item}};
                   13669:                             }
                   13670:                         } else {
                   13671:                             @changed = @{$confhash{'validation'}{$item}};
                   13672:                         }
                   13673:                         if (@changed) {
                   13674:                             if ($confhash{'validation'}{$item}) {
                   13675:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   13676:                             } else {
                   13677:                                 $changes{'validation'}{$item} = &mt('None');
                   13678:                             }
                   13679:                         }
                   13680:                     } else {
                   13681:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   13682:                         if ($item eq 'markup') {
                   13683:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   13684:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   13685:                             }
                   13686:                         }
1.266     raeburn  13687:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13688:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13689:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   13690:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13691:                                 }
                   13692:                             } else {
                   13693:                                 if ($confhash{'validation'}{$item} ne '') {
                   13694:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13695:                                 }
1.235     raeburn  13696:                             }
                   13697:                         } else {
                   13698:                             if ($confhash{'validation'}{$item} ne '') {
                   13699:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   13700:                             }
                   13701:                         }
                   13702:                     }
                   13703:                 }
                   13704:             }
                   13705:             if ($env{'form.validationdc'}) {
                   13706:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  13707:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  13708:                 if (exists($domcoords{$newval})) {
                   13709:                     $confhash{'validation'}{'dc'} = $newval;
                   13710:                 }
                   13711:             }
                   13712:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  13713:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13714:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13715:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13716:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13717:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   13718:                                     $changes{'validation'}{'dc'} = &mt('None');
                   13719:                                 } else {
                   13720:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   13721:                                 }
1.235     raeburn  13722:                             }
1.266     raeburn  13723:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13724:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  13725:                         }
                   13726:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13727:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   13728:                     }
                   13729:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   13730:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  13731:                 }
1.266     raeburn  13732:             } else {
                   13733:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   13734:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   13735:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   13736:                             $changes{'validation'}{'dc'} = &mt('None');
                   13737:                         }
                   13738:                     }
1.235     raeburn  13739:                 }
                   13740:             }
1.102     raeburn  13741:         }
                   13742:     } else {
1.86      raeburn  13743:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  13744:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  13745:     }
1.72      raeburn  13746:     foreach my $item (@usertools) {
                   13747:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  13748:             my $unset; 
1.101     raeburn  13749:             if ($context eq 'requestcourses') {
1.104     raeburn  13750:                 $unset = '0';
                   13751:                 if ($type eq '_LC_adv') {
                   13752:                     $unset = '';
                   13753:                 }
1.101     raeburn  13754:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   13755:                     $confhash{$item}{$type} .= '=';
                   13756:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   13757:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   13758:                     }
                   13759:                 }
1.163     raeburn  13760:             } elsif ($context eq 'requestauthor') {
                   13761:                 $unset = '0';
                   13762:                 if ($type eq '_LC_adv') {
                   13763:                     $unset = '';
                   13764:                 }
1.72      raeburn  13765:             } else {
1.101     raeburn  13766:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   13767:                     $confhash{$item}{$type} = 1;
                   13768:                 } else {
                   13769:                     $confhash{$item}{$type} = 0;
                   13770:                 }
1.72      raeburn  13771:             }
1.86      raeburn  13772:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  13773:                 if ($action eq 'requestauthor') {
                   13774:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   13775:                         $changes{$type} = 1;
                   13776:                     }
                   13777:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  13778:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   13779:                         $changes{$item}{$type} = 1;
                   13780:                     }
                   13781:                 } else {
                   13782:                     if ($context eq 'requestcourses') {
1.104     raeburn  13783:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  13784:                             $changes{$item}{$type} = 1;
                   13785:                         }
                   13786:                     } else {
                   13787:                         if (!$confhash{$item}{$type}) {
                   13788:                             $changes{$item}{$type} = 1;
                   13789:                         }
                   13790:                     }
                   13791:                 }
                   13792:             } else {
                   13793:                 if ($context eq 'requestcourses') {
1.104     raeburn  13794:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  13795:                         $changes{$item}{$type} = 1;
                   13796:                     }
1.163     raeburn  13797:                 } elsif ($context eq 'requestauthor') {
                   13798:                     if ($confhash{$type} ne $unset) {
                   13799:                         $changes{$type} = 1;
                   13800:                     }
1.72      raeburn  13801:                 } else {
                   13802:                     if (!$confhash{$item}{$type}) {
                   13803:                         $changes{$item}{$type} = 1;
                   13804:                     }
                   13805:                 }
                   13806:             }
1.1       raeburn  13807:         }
                   13808:     }
1.163     raeburn  13809:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  13810:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13811:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   13812:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   13813:                     if (exists($confhash{'defaultquota'}{$key})) {
                   13814:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   13815:                             $changes{'defaultquota'}{$key} = 1;
                   13816:                         }
                   13817:                     } else {
                   13818:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  13819:                     }
                   13820:                 }
1.86      raeburn  13821:             } else {
                   13822:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   13823:                     if (exists($confhash{'defaultquota'}{$key})) {
                   13824:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   13825:                             $changes{'defaultquota'}{$key} = 1;
                   13826:                         }
                   13827:                     } else {
                   13828:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  13829:                     }
1.1       raeburn  13830:                 }
                   13831:             }
1.197     raeburn  13832:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   13833:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   13834:                     if (exists($confhash{'authorquota'}{$key})) {
                   13835:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   13836:                             $changes{'authorquota'}{$key} = 1;
                   13837:                         }
                   13838:                     } else {
                   13839:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   13840:                     }
                   13841:                 }
                   13842:             }
1.1       raeburn  13843:         }
1.86      raeburn  13844:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   13845:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   13846:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13847:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   13848:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   13849:                             $changes{'defaultquota'}{$key} = 1;
                   13850:                         }
                   13851:                     } else {
                   13852:                         if (!exists($domconfig{'quotas'}{$key})) {
                   13853:                             $changes{'defaultquota'}{$key} = 1;
                   13854:                         }
1.72      raeburn  13855:                     }
                   13856:                 } else {
1.86      raeburn  13857:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  13858:                 }
1.1       raeburn  13859:             }
                   13860:         }
1.197     raeburn  13861:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   13862:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   13863:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   13864:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   13865:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   13866:                             $changes{'authorquota'}{$key} = 1;
                   13867:                         }
                   13868:                     } else {
                   13869:                         $changes{'authorquota'}{$key} = 1;
                   13870:                     }
                   13871:                 } else {
                   13872:                     $changes{'authorquota'}{$key} = 1;
                   13873:                 }
                   13874:             }
                   13875:         }
1.1       raeburn  13876:     }
1.72      raeburn  13877: 
1.163     raeburn  13878:     if ($context eq 'requestauthor') {
                   13879:         $domdefaults{'requestauthor'} = \%confhash;
                   13880:     } else {
                   13881:         foreach my $key (keys(%confhash)) {
1.242     raeburn  13882:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  13883:                 $domdefaults{$key} = $confhash{$key};
                   13884:             }
1.163     raeburn  13885:         }
1.72      raeburn  13886:     }
1.163     raeburn  13887: 
1.1       raeburn  13888:     my %quotahash = (
1.86      raeburn  13889:                       $action => { %confhash }
1.1       raeburn  13890:                     );
                   13891:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   13892:                                              $dom);
                   13893:     if ($putresult eq 'ok') {
                   13894:         if (keys(%changes) > 0) {
1.72      raeburn  13895:             my $cachetime = 24*60*60;
                   13896:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  13897:             if (ref($lastactref) eq 'HASH') {
                   13898:                 $lastactref->{'domdefaults'} = 1;
                   13899:             }
1.1       raeburn  13900:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  13901:             unless (($context eq 'requestcourses') ||
1.163     raeburn  13902:                     ($context eq 'requestauthor')) {
1.86      raeburn  13903:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   13904:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   13905:                     foreach my $type (@{$types},'default') {
                   13906:                         if (defined($changes{'defaultquota'}{$type})) {
                   13907:                             my $typetitle = $usertypes->{$type};
                   13908:                             if ($type eq 'default') {
                   13909:                                 $typetitle = $othertitle;
                   13910:                             }
1.213     raeburn  13911:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  13912:                         }
                   13913:                     }
1.86      raeburn  13914:                     $resulttext .= '</ul></li>';
1.72      raeburn  13915:                 }
1.197     raeburn  13916:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   13917:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  13918:                     foreach my $type (@{$types},'default') {
                   13919:                         if (defined($changes{'authorquota'}{$type})) {
                   13920:                             my $typetitle = $usertypes->{$type};
                   13921:                             if ($type eq 'default') {
                   13922:                                 $typetitle = $othertitle;
                   13923:                             }
1.213     raeburn  13924:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  13925:                         }
                   13926:                     }
                   13927:                     $resulttext .= '</ul></li>';
                   13928:                 }
1.72      raeburn  13929:             }
1.80      raeburn  13930:             my %newenv;
1.72      raeburn  13931:             foreach my $item (@usertools) {
1.163     raeburn  13932:                 my (%haschgs,%inconf);
                   13933:                 if ($context eq 'requestauthor') {
                   13934:                     %haschgs = %changes;
1.210     raeburn  13935:                     %inconf = %confhash;
1.163     raeburn  13936:                 } else {
                   13937:                     if (ref($changes{$item}) eq 'HASH') {
                   13938:                         %haschgs = %{$changes{$item}};
                   13939:                     }
                   13940:                     if (ref($confhash{$item}) eq 'HASH') {
                   13941:                         %inconf = %{$confhash{$item}};
                   13942:                     }
                   13943:                 }
                   13944:                 if (keys(%haschgs) > 0) {
1.80      raeburn  13945:                     my $newacc = 
                   13946:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   13947:                                                           $env{'user.domain'},
1.86      raeburn  13948:                                                           $item,'reload',$context);
1.210     raeburn  13949:                     if (($context eq 'requestcourses') ||
1.163     raeburn  13950:                         ($context eq 'requestauthor')) {
1.108     raeburn  13951:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   13952:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  13953:                         }
                   13954:                     } else {
                   13955:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   13956:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   13957:                         }
1.80      raeburn  13958:                     }
1.163     raeburn  13959:                     unless ($context eq 'requestauthor') {
                   13960:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   13961:                     }
1.72      raeburn  13962:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  13963:                         if ($haschgs{$type}) {
1.72      raeburn  13964:                             my $typetitle = $usertypes->{$type};
                   13965:                             if ($type eq 'default') {
                   13966:                                 $typetitle = $othertitle;
                   13967:                             } elsif ($type eq '_LC_adv') {
                   13968:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   13969:                             }
1.163     raeburn  13970:                             if ($inconf{$type}) {
1.101     raeburn  13971:                                 if ($context eq 'requestcourses') {
                   13972:                                     my $cond;
1.163     raeburn  13973:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  13974:                                         if ($1 eq '') {
                   13975:                                             $cond = &mt('(Automatic processing of any request).');
                   13976:                                         } else {
                   13977:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   13978:                                         }
                   13979:                                     } else { 
1.163     raeburn  13980:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  13981:                                     }
                   13982:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  13983:                                 } elsif ($context eq 'requestauthor') {
                   13984:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   13985:                                                              $titles{$inconf{$type}},$typetitle);
                   13986: 
1.101     raeburn  13987:                                 } else {
                   13988:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   13989:                                 }
1.72      raeburn  13990:                             } else {
1.104     raeburn  13991:                                 if ($type eq '_LC_adv') {
1.163     raeburn  13992:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  13993:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   13994:                                     } else { 
                   13995:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   13996:                                     }
                   13997:                                 } else {
                   13998:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   13999:                                 }
1.72      raeburn  14000:                             }
                   14001:                         }
1.26      raeburn  14002:                     }
1.163     raeburn  14003:                     unless ($context eq 'requestauthor') {
                   14004:                         $resulttext .= '</ul></li>';
                   14005:                     }
1.26      raeburn  14006:                 }
1.1       raeburn  14007:             }
1.163     raeburn  14008:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  14009:                 if (ref($changes{'notify'}) eq 'HASH') {
                   14010:                     if ($changes{'notify'}{'approval'}) {
                   14011:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   14012:                             if ($confhash{'notify'}{'approval'}) {
                   14013:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   14014:                             } else {
1.163     raeburn  14015:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  14016:                             }
                   14017:                         }
                   14018:                     }
                   14019:                 }
                   14020:             }
1.216     raeburn  14021:             if ($action eq 'requestcourses') {
                   14022:                 my @offon = ('off','on');
                   14023:                 if ($changes{'uniquecode'}) {
1.218     raeburn  14024:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   14025:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   14026:                         $resulttext .= '<li>'.
                   14027:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   14028:                                        '</li>';
                   14029:                     } else {
                   14030:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   14031:                                        '</li>';
                   14032:                     }
1.216     raeburn  14033:                 }
1.242     raeburn  14034:                 foreach my $type ('textbooks','templates') {
                   14035:                     if (ref($changes{$type}) eq 'HASH') {
                   14036:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   14037:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   14038:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   14039:                             my $coursetitle = $coursehash{'description'};
                   14040:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   14041:                             $resulttext .= '<li>';
1.243     raeburn  14042:                             foreach my $item ('subject','title','publisher','author') {
                   14043:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   14044:                                          ($type eq 'templates'));
1.242     raeburn  14045:                                 my $name = $item.':';
                   14046:                                 $name =~ s/^(\w)/\U$1/;
                   14047:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   14048:                             }
                   14049:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   14050:                             if ($type eq 'textbooks') {
                   14051:                                 if ($confhash{$type}{$key}{'image'}) {
                   14052:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   14053:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   14054:                                                    ' alt="Textbook cover" />').'<br />';
                   14055:                                 }
                   14056:                             }
                   14057:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  14058:                         }
1.242     raeburn  14059:                         $resulttext .= '</ul></li>';
1.216     raeburn  14060:                     }
                   14061:                 }
1.235     raeburn  14062:                 if (ref($changes{'validation'}) eq 'HASH') {
                   14063:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   14064:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   14065:                         foreach my $item (@{$validationitemsref}) {
                   14066:                             if (exists($changes{'validation'}{$item})) {
                   14067:                                 if ($item eq 'markup') {
                   14068:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14069:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   14070:                                 } else {
                   14071:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   14072:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   14073:                                 }
                   14074:                             }
                   14075:                         }
                   14076:                         if (exists($changes{'validation'}{'dc'})) {
                   14077:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   14078:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   14079:                         }
                   14080:                     }
                   14081:                 }
1.216     raeburn  14082:             }
1.1       raeburn  14083:             $resulttext .= '</ul>';
1.80      raeburn  14084:             if (keys(%newenv)) {
                   14085:                 &Apache::lonnet::appenv(\%newenv);
                   14086:             }
1.1       raeburn  14087:         } else {
1.86      raeburn  14088:             if ($context eq 'requestcourses') {
                   14089:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  14090:             } elsif ($context eq 'requestauthor') {
                   14091:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  14092:             } else {
1.90      weissno  14093:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  14094:             }
1.1       raeburn  14095:         }
                   14096:     } else {
1.11      albertel 14097:         $resulttext = '<span class="LC_error">'.
                   14098: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  14099:     }
1.216     raeburn  14100:     if ($errors) {
                   14101:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   14102:                        '<ul>'.$errors.'</ul></p>';
                   14103:     }
1.3       raeburn  14104:     return $resulttext;
1.1       raeburn  14105: }
                   14106: 
1.216     raeburn  14107: sub process_textbook_image {
1.242     raeburn  14108:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  14109:     my $filename = $env{'form.'.$caller.'.filename'};
                   14110:     my ($error,$url);
                   14111:     my ($width,$height) = (50,50);
                   14112:     if ($configuserok eq 'ok') {
                   14113:         if ($switchserver) {
                   14114:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   14115:                          $switchserver);
                   14116:         } elsif ($author_ok eq 'ok') {
                   14117:             my ($result,$imageurl) =
                   14118:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.312     raeburn  14119:                              "$type/$cdom/$cnum/cover",$width,$height);
1.216     raeburn  14120:             if ($result eq 'ok') {
                   14121:                 $url = $imageurl;
                   14122:             } else {
                   14123:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14124:             }
                   14125:         } else {
                   14126:             $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);
                   14127:         }
                   14128:     } else {
                   14129:         $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);
                   14130:     }
                   14131:     return ($url,$error);
                   14132: }
                   14133: 
1.267     raeburn  14134: sub modify_ltitools {
                   14135:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   14136:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297     raeburn  14137:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267     raeburn  14138:     my $confname = $dom.'-domainconfig';
                   14139:     my $servadm = $r->dir_config('lonAdmEMail');
                   14140:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   14141:     my (%posslti,%possfield);
                   14142:     my @courseroles = ('cc','in','ta','ep','st');
                   14143:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   14144:     map { $posslti{$_} = 1; } @ltiroles;
                   14145:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   14146:     map { $possfield{$_} = 1; } @allfields;
                   14147:     my %lt = &ltitools_names(); 
                   14148:     if ($env{'form.ltitools_add'}) {
                   14149:         my $title = $env{'form.ltitools_add_title'};
                   14150:         $title =~ s/(`)/'/g;
                   14151:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   14152:         if ($newid) {
                   14153:             my $position = $env{'form.ltitools_add_pos'};
                   14154:             $position =~ s/\D+//g;
                   14155:             if ($position ne '') {
                   14156:                 $allpos[$position] = $newid;
                   14157:             }
                   14158:             $changes{$newid} = 1;
1.322     raeburn  14159:             foreach my $item ('title','url','key','secret','lifetime') {
1.267     raeburn  14160:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322     raeburn  14161:                 if ($item eq 'lifetime') {
                   14162:                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   14163:                 }
1.267     raeburn  14164:                 if ($env{'form.ltitools_add_'.$item}) {
1.297     raeburn  14165:                     if (($item eq 'key') || ($item eq 'secret')) {
                   14166:                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14167:                     } else {
                   14168:                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   14169:                     }
1.267     raeburn  14170:                 }
                   14171:             }
                   14172:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   14173:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   14174:             }
                   14175:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   14176:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   14177:             }
1.323     raeburn  14178:             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   14179:                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   14180:             } else {
                   14181:                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   14182:             }
1.296     raeburn  14183:             foreach my $item ('width','height','linktext','explanation') {
1.267     raeburn  14184:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   14185:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296     raeburn  14186:                 if (($item eq 'width') || ($item eq 'height')) {
                   14187:                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   14188:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   14189:                     }
                   14190:                 } else {
                   14191:                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   14192:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item}; 
                   14193:                     }
1.267     raeburn  14194:                 }
                   14195:             }
                   14196:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   14197:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298     raeburn  14198:             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   14199:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267     raeburn  14200:             } else {
                   14201:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   14202:             }
                   14203:             foreach my $item ('passback','roster') {
1.319     raeburn  14204:                 if ($env{'form.ltitools_'.$item.'_add'}) {
1.267     raeburn  14205:                     $confhash{$newid}{$item} = 1;
1.319     raeburn  14206:                     if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
                   14207:                         my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
                   14208:                         $lifetime =~ s/^\s+|\s+$//g;
                   14209:                         if ($lifetime =~ /^\d+\.?\d*$/) {
                   14210:                             $confhash{$newid}{$item.'valid'} = $lifetime;
                   14211:                         }
                   14212:                     }
1.267     raeburn  14213:                 }
                   14214:             }
                   14215:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   14216:                 my ($imageurl,$error) =
1.307     raeburn  14217:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267     raeburn  14218:                                             $configuserok,$switchserver,$author_ok);
                   14219:                 if ($imageurl) {
                   14220:                     $confhash{$newid}{'image'} = $imageurl;
                   14221:                 }
                   14222:                 if ($error) {
                   14223:                     &Apache::lonnet::logthis($error);
                   14224:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14225:                 }
                   14226:             }
                   14227:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   14228:             foreach my $field (@fields) {
                   14229:                 if ($possfield{$field}) {
                   14230:                     if ($field eq 'roles') {
                   14231:                         foreach my $role (@courseroles) {
                   14232:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   14233:                             if (($choice ne '') && ($posslti{$choice})) {
                   14234:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   14235:                                 if ($role eq 'cc') {
                   14236:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   14237:                                 }
                   14238:                             }
                   14239:                         }
                   14240:                     } else {
                   14241:                         $confhash{$newid}{'fields'}{$field} = 1;
                   14242:                     }
                   14243:                 }
                   14244:             }
1.324     raeburn  14245:             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   14246:                 if ($confhash{$newid}{'fields'}{'user'}) {
                   14247:                     if ($env{'form.ltitools_userincdom_add'}) {
                   14248:                         $confhash{$newid}{'incdom'} = 1;
                   14249:                     }
                   14250:                 }
                   14251:             }
1.273     raeburn  14252:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   14253:             foreach my $item (@courseconfig) {
                   14254:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   14255:             }
1.267     raeburn  14256:             if ($env{'form.ltitools_add_custom'}) {
                   14257:                 my $name = $env{'form.ltitools_add_custom_name'};
                   14258:                 my $value = $env{'form.ltitools_add_custom_value'};
                   14259:                 $value =~ s/(`)/'/g;
                   14260:                 $name =~ s/(`)/'/g;
                   14261:                 $confhash{$newid}{'custom'}{$name} = $value;
                   14262:             }
                   14263:         } else {
                   14264:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   14265:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14266:         }
                   14267:     }
                   14268:     if (ref($domconfig{$action}) eq 'HASH') {
                   14269:         my %deletions;
                   14270:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   14271:         if (@todelete) {
                   14272:             map { $deletions{$_} = 1; } @todelete;
                   14273:         }
                   14274:         my %customadds;
                   14275:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   14276:         if (@newcustom) {
                   14277:             map { $customadds{$_} = 1; } @newcustom;
                   14278:         } 
                   14279:         my %imgdeletions;
                   14280:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   14281:         if (@todeleteimages) {
                   14282:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14283:         }
                   14284:         my $maxnum = $env{'form.ltitools_maxnum'};
                   14285:         for (my $i=0; $i<=$maxnum; $i++) {
                   14286:             my $itemid = $env{'form.ltitools_id_'.$i};
1.308     raeburn  14287:             $itemid =~ s/\D+//g;
1.267     raeburn  14288:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   14289:                 if ($deletions{$itemid}) {
                   14290:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   14291:                         #FIXME need to obsolete item in RES space
                   14292:                     }
                   14293:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   14294:                     next;
                   14295:                 } else {
                   14296:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   14297:                     $newpos =~ s/\D+//g;
1.322     raeburn  14298:                     foreach my $item ('title','url','lifetime') {
1.267     raeburn  14299:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14300:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   14301:                             $changes{$itemid} = 1;
                   14302:                         }
                   14303:                     }
1.297     raeburn  14304:                     foreach my $item ('key','secret') {
                   14305:                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14306:                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   14307:                             $changes{$itemid} = 1;
                   14308:                         }
                   14309:                     }
1.267     raeburn  14310:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   14311:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   14312:                     }
                   14313:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   14314:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   14315:                     }
1.323     raeburn  14316:                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   14317:                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   14318:                     } else {
                   14319:                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1'; 
                   14320:                     }
                   14321:                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   14322:                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   14323:                             $changes{$itemid} = 1;
                   14324:                         }
                   14325:                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   14326:                         $changes{$itemid} = 1;
                   14327:                     }
1.267     raeburn  14328:                     foreach my $size ('width','height') {
                   14329:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   14330:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   14331:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   14332:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   14333:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14334:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   14335:                                     $changes{$itemid} = 1;
                   14336:                                 }
                   14337:                             } else {
                   14338:                                 $changes{$itemid} = 1;
                   14339:                             }
1.296     raeburn  14340:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14341:                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   14342:                                 $changes{$itemid} = 1;
                   14343:                             }
                   14344:                         }
                   14345:                     }
                   14346:                     foreach my $item ('linktext','explanation') {
                   14347:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   14348:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   14349:                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   14350:                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   14351:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14352:                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   14353:                                     $changes{$itemid} = 1;
                   14354:                                 }
                   14355:                             } else {
                   14356:                                 $changes{$itemid} = 1;
                   14357:                             }
                   14358:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14359:                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   14360:                                 $changes{$itemid} = 1;
                   14361:                             }
1.267     raeburn  14362:                         }
                   14363:                     }
                   14364:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   14365:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298     raeburn  14366:                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   14367:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267     raeburn  14368:                     } else {
                   14369:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   14370:                     }
                   14371:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   14372:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   14373:                             $changes{$itemid} = 1;
                   14374:                         }
                   14375:                     } else {
                   14376:                         $changes{$itemid} = 1;
                   14377:                     }
                   14378:                     foreach my $extra ('passback','roster') {
                   14379:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   14380:                             $confhash{$itemid}{$extra} = 1;
1.319     raeburn  14381:                             if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338     raeburn  14382:                                 my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319     raeburn  14383:                                 $lifetime =~ s/^\s+|\s+$//g;
                   14384:                                 if ($lifetime =~ /^\d+\.?\d*$/) {
                   14385:                                     $confhash{$itemid}{$extra.'valid'} = $lifetime;
                   14386:                                 }
                   14387:                             }
1.267     raeburn  14388:                         }
                   14389:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   14390:                             $changes{$itemid} = 1;
                   14391:                         }
1.319     raeburn  14392:                         if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
                   14393:                             $changes{$itemid} = 1;
                   14394:                         }
1.267     raeburn  14395:                     }
1.273     raeburn  14396:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318     raeburn  14397:                     foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  14398:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   14399:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   14400:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   14401:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   14402:                                     $changes{$itemid} = 1;
                   14403:                                 }
                   14404:                             } else {
                   14405:                                 $changes{$itemid} = 1;
                   14406:                             }
                   14407:                         }
                   14408:                     }
1.267     raeburn  14409:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   14410:                     foreach my $field (@fields) {
                   14411:                         if ($possfield{$field}) {
                   14412:                             if ($field eq 'roles') {
                   14413:                                 foreach my $role (@courseroles) {
                   14414:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   14415:                                     if (($choice ne '') && ($posslti{$choice})) {
                   14416:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   14417:                                         if ($role eq 'cc') {
                   14418:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   14419:                                         }
                   14420:                                     }
                   14421:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   14422:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   14423:                                             $changes{$itemid} = 1;
                   14424:                                         }
                   14425:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   14426:                                         $changes{$itemid} = 1;
                   14427:                                     }
                   14428:                                 }
                   14429:                             } else {
                   14430:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   14431:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   14432:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   14433:                                         $changes{$itemid} = 1;
                   14434:                                     }
                   14435:                                 } else {
                   14436:                                     $changes{$itemid} = 1;
                   14437:                                 }
                   14438:                             }
                   14439:                         }
                   14440:                     }
1.324     raeburn  14441:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   14442:                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   14443:                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   14444:                                 $confhash{$itemid}{'incdom'} = 1;
                   14445:                             }
                   14446:                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   14447:                                 $changes{$itemid} = 1;
                   14448:                             }
                   14449:                         }
                   14450:                     }
1.267     raeburn  14451:                     $allpos[$newpos] = $itemid;
                   14452:                 }
                   14453:                 if ($imgdeletions{$itemid}) {
                   14454:                     $changes{$itemid} = 1;
                   14455:                     #FIXME need to obsolete item in RES space
                   14456:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   14457:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   14458:                                                                  $itemid,$configuserok,$switchserver,
                   14459:                                                                  $author_ok);
                   14460:                     if ($imgurl) {
                   14461:                         $confhash{$itemid}{'image'} = $imgurl;
                   14462:                         $changes{$itemid} = 1;
                   14463:                     }
                   14464:                     if ($error) {
                   14465:                         &Apache::lonnet::logthis($error);
                   14466:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14467:                     }
                   14468:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   14469:                     $confhash{$itemid}{'image'} =
                   14470:                        $domconfig{$action}{$itemid}{'image'};
                   14471:                 }
                   14472:                 if ($customadds{$i}) {
                   14473:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   14474:                     $name =~ s/(`)/'/g;
                   14475:                     $name =~ s/^\s+//;
                   14476:                     $name =~ s/\s+$//;
                   14477:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   14478:                     $value =~ s/(`)/'/g;
                   14479:                     $value =~ s/^\s+//;
                   14480:                     $value =~ s/\s+$//;
                   14481:                     if ($name ne '') {
                   14482:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   14483:                         $changes{$itemid} = 1;
                   14484:                     }
                   14485:                 }
                   14486:                 my %customdels;
                   14487:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   14488:                 if (@customdeletions) {
                   14489:                     $changes{$itemid} = 1;
                   14490:                 }
                   14491:                 map { $customdels{$_} = 1; } @customdeletions;
                   14492:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   14493:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   14494:                         unless ($customdels{$key}) {
                   14495:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   14496:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   14497:                             }
                   14498:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   14499:                                 $changes{$itemid} = 1;
                   14500:                             }
                   14501:                         }
                   14502:                     }
                   14503:                 }
                   14504:                 unless ($changes{$itemid}) {
                   14505:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   14506:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   14507:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   14508:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   14509:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   14510:                                         $changes{$itemid} = 1;
                   14511:                                         last;
                   14512:                                     }
                   14513:                                 }
                   14514:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   14515:                                 $changes{$itemid} = 1;
                   14516:                             }
                   14517:                         }
                   14518:                         last if ($changes{$itemid});
                   14519:                     }
                   14520:                 }
                   14521:             }
                   14522:         }
                   14523:     }
                   14524:     if (@allpos > 0) {
                   14525:         my $idx = 0;
                   14526:         foreach my $itemid (@allpos) {
                   14527:             if ($itemid ne '') {
                   14528:                 $confhash{$itemid}{'order'} = $idx;
                   14529:                 if (ref($domconfig{$action}) eq 'HASH') {
                   14530:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   14531:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   14532:                             $changes{$itemid} = 1;
                   14533:                         }
                   14534:                     }
                   14535:                 }
                   14536:                 $idx ++;
                   14537:             }
                   14538:         }
                   14539:     }
                   14540:     my %ltitoolshash = (
                   14541:                           $action => { %confhash }
                   14542:                        );
                   14543:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   14544:                                              $dom);
                   14545:     if ($putresult eq 'ok') {
1.297     raeburn  14546:         my %ltienchash = (
                   14547:                              $action => { %encconfig }
                   14548:                          );
1.384     raeburn  14549:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267     raeburn  14550:         if (keys(%changes) > 0) {
                   14551:             my $cachetime = 24*60*60;
1.297     raeburn  14552:             my %ltiall = %confhash;
                   14553:             foreach my $id (keys(%ltiall)) {
                   14554:                 if (ref($encconfig{$id}) eq 'HASH') {
                   14555:                     foreach my $item ('key','secret') {
                   14556:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   14557:                     }
                   14558:                 }
                   14559:             }
                   14560:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267     raeburn  14561:             if (ref($lastactref) eq 'HASH') {
                   14562:                 $lastactref->{'ltitools'} = 1;
                   14563:             }
                   14564:             $resulttext = &mt('Changes made:').'<ul>';
                   14565:             my %bynum;
                   14566:             foreach my $itemid (sort(keys(%changes))) {
                   14567:                 my $position = $confhash{$itemid}{'order'};
                   14568:                 $bynum{$position} = $itemid;
                   14569:             }
                   14570:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   14571:                 my $itemid = $bynum{$pos}; 
                   14572:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   14573:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   14574:                 } else {
                   14575:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   14576:                     if ($confhash{$itemid}{'image'}) {
                   14577:                         $resulttext .= '&nbsp;'.
                   14578:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   14579:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   14580:                     }
                   14581:                     $resulttext .= '</li><ul>';
                   14582:                     my $position = $pos + 1;
                   14583:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323     raeburn  14584:                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267     raeburn  14585:                         if ($confhash{$itemid}{$item} ne '') {
                   14586:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   14587:                         }
                   14588:                     }
1.297     raeburn  14589:                     if ($encconfig{$itemid}{'key'} ne '') {
                   14590:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   14591:                     }
                   14592:                     if ($encconfig{$itemid}{'secret'} ne '') {
1.267     raeburn  14593:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
1.297     raeburn  14594:                         my $num = length($encconfig{$itemid}{'secret'});
1.267     raeburn  14595:                         $resulttext .= ('*'x$num).'</li>';
                   14596:                     }
1.273     raeburn  14597:                     $resulttext .= '<li>'.&mt('Configurable in course:');
1.318     raeburn  14598:                     my @possconfig = ('label','title','target','linktext','explanation','append');
1.273     raeburn  14599:                     my $numconfig = 0; 
                   14600:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   14601:                         foreach my $item (@possconfig) {
                   14602:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   14603:                                 $numconfig ++;
1.296     raeburn  14604:                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273     raeburn  14605:                             }
                   14606:                         }
                   14607:                     }
                   14608:                     if (!$numconfig) {
1.372     raeburn  14609:                         $resulttext .= '&nbsp;'.&mt('None');
1.273     raeburn  14610:                     }
                   14611:                     $resulttext .= '</li>';
1.267     raeburn  14612:                     foreach my $item ('passback','roster') {
                   14613:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   14614:                         if ($confhash{$itemid}{$item}) {
                   14615:                             $resulttext .= &mt('Yes');
1.319     raeburn  14616:                             if ($confhash{$itemid}{$item.'valid'}) {
                   14617:                                 if ($item eq 'passback') {
                   14618:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
                   14619:                                                            $confhash{$itemid}{$item.'valid'});
                   14620:                                 } else {
                   14621:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
                   14622:                                                            $confhash{$itemid}{$item.'valid'});
                   14623:                                 }
                   14624:                             }
1.267     raeburn  14625:                         } else {
                   14626:                             $resulttext .= &mt('No');
                   14627:                         }
                   14628:                         $resulttext .= '</li>';
                   14629:                     }
                   14630:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   14631:                         my $displaylist;
                   14632:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   14633:                             $displaylist = &mt('Display target').':&nbsp;'.
                   14634:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   14635:                         }
                   14636:                         foreach my $size ('width','height') { 
                   14637:                             if ($confhash{$itemid}{'display'}{$size}) {
                   14638:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   14639:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   14640:                             }
                   14641:                         }
                   14642:                         if ($displaylist) {
                   14643:                             $displaylist =~ s/,$//;
                   14644:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   14645:                         }
1.296     raeburn  14646:                         foreach my $item ('linktext','explanation') {
                   14647:                             if ($confhash{$itemid}{'display'}{$item}) {
                   14648:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   14649:                             }
                   14650:                         }
                   14651:                     }
1.267     raeburn  14652:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   14653:                         my $fieldlist;
                   14654:                         foreach my $field (@allfields) {
                   14655:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   14656:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   14657:                             }
                   14658:                         }
                   14659:                         if ($fieldlist) {
                   14660:                             $fieldlist =~ s/,$//;
1.324     raeburn  14661:                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   14662:                                 if ($confhash{$itemid}{'incdom'}) {
                   14663:                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   14664:                                 } else {
                   14665:                                     $fieldlist .= ' ('.&mt('username').')';
                   14666:                                 }
                   14667:                             }
1.267     raeburn  14668:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   14669:                         }
                   14670:                     }
                   14671:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   14672:                         my $rolemaps;
                   14673:                         foreach my $role (@courseroles) {
                   14674:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   14675:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   14676:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   14677:                             }
                   14678:                         }
                   14679:                         if ($rolemaps) {
                   14680:                             $rolemaps =~ s/,$//; 
                   14681:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   14682:                         }
                   14683:                     }
                   14684:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   14685:                         my $customlist;
                   14686:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   14687:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   14688:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   14689:                             } 
                   14690:                         }
                   14691:                         if ($customlist) {
1.317     raeburn  14692:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267     raeburn  14693:                         }
                   14694:                     } 
                   14695:                     $resulttext .= '</ul></li>';
                   14696:                 }
                   14697:             }
                   14698:             $resulttext .= '</ul>';
                   14699:         } else {
                   14700:             $resulttext = &mt('No changes made.');
                   14701:         }
                   14702:     } else {
                   14703:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   14704:     }
                   14705:     if ($errors) {
                   14706:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   14707:                        $errors.'</ul>';
                   14708:     }
                   14709:     return $resulttext;
                   14710: }
                   14711: 
                   14712: sub process_ltitools_image {
                   14713:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   14714:     my $filename = $env{'form.'.$caller.'.filename'};
                   14715:     my ($error,$url);
                   14716:     my ($width,$height) = (21,21);
                   14717:     if ($configuserok eq 'ok') {
                   14718:         if ($switchserver) {
                   14719:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   14720:                          $switchserver);
                   14721:         } elsif ($author_ok eq 'ok') {
                   14722:             my ($result,$imageurl,$madethumb) =
                   14723:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   14724:                              "ltitools/$itemid/icon",$width,$height);
                   14725:             if ($result eq 'ok') {
                   14726:                 if ($madethumb) {
                   14727:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   14728:                     my $imagethumb = "$path/tn-".$imagefile;
                   14729:                     $url = $imagethumb;
                   14730:                 } else {
                   14731:                     $url = $imageurl;
                   14732:                 }
                   14733:             } else {
                   14734:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   14735:             }
                   14736:         } else {
                   14737:             $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);
                   14738:         }
                   14739:     } else {
                   14740:         $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);
                   14741:     }
                   14742:     return ($url,$error);
                   14743: }
                   14744: 
                   14745: sub get_ltitools_id {
                   14746:     my ($cdom,$title) = @_;
                   14747:     # get lock on ltitools db
                   14748:     my $lockhash = {
                   14749:                       lock => $env{'user.name'}.
                   14750:                               ':'.$env{'user.domain'},
                   14751:                    };
                   14752:     my $tries = 0;
                   14753:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   14754:     my ($id,$error);
                   14755:  
                   14756:     while (($gotlock ne 'ok') && ($tries<10)) {
                   14757:         $tries ++;
                   14758:         sleep (0.1);
                   14759:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   14760:     }
                   14761:     if ($gotlock eq 'ok') {
                   14762:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   14763:         if ($currids{'lock'}) {
                   14764:             delete($currids{'lock'});
                   14765:             if (keys(%currids)) {
                   14766:                 my @curr = sort { $a <=> $b } keys(%currids);
                   14767:                 if ($curr[-1] =~ /^\d+$/) {
                   14768:                     $id = 1 + $curr[-1];
                   14769:                 }
                   14770:             } else {
                   14771:                 $id = 1;
                   14772:             }
                   14773:             if ($id) {
                   14774:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   14775:                     $error = 'nostore';
                   14776:                 }
                   14777:             } else {
                   14778:                 $error = 'nonumber';
                   14779:             }
                   14780:         }
                   14781:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   14782:     } else {
                   14783:         $error = 'nolock';
                   14784:     }
                   14785:     return ($id,$error);
                   14786: }
                   14787: 
1.372     raeburn  14788: sub modify_proctoring {
                   14789:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   14790:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14791:     my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
                   14792:     my $confname = $dom.'-domainconfig';
                   14793:     my $servadm = $r->dir_config('lonAdmEMail');
                   14794:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   14795:     my %providernames = &proctoring_providernames();
                   14796:     my $maxnum = scalar(keys(%providernames));
                   14797: 
                   14798:     my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
                   14799:     my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
                   14800:     if (ref($requref) eq 'HASH') {
                   14801:         %requserfields = %{$requref};
                   14802:     }
                   14803:     if (ref($opturef) eq 'HASH') {
                   14804:         %optuserfields = %{$opturef};
                   14805:     }
                   14806:     if (ref($defref) eq 'HASH') {
                   14807:         %defaults = %{$defref};
                   14808:     }
                   14809:     if (ref($extref) eq 'HASH') {
                   14810:         %extended = %{$extref};
                   14811:     }
                   14812:     if (ref($crsref) eq 'HASH') {
                   14813:         %crsconf = %{$crsref};
                   14814:     }
                   14815:     if (ref($rolesref) eq 'ARRAY') {
                   14816:         @courseroles = @{$rolesref};
                   14817:     }
                   14818:     if (ref($ltiref) eq 'ARRAY') {
                   14819:         @ltiroles = @{$ltiref};
                   14820:     }
                   14821: 
                   14822:     if (ref($domconfig{$action}) eq 'HASH') {
                   14823:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
                   14824:         if (@todeleteimages) {
                   14825:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   14826:         }
                   14827:     }
                   14828:     my %customadds;
                   14829:     my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
                   14830:     if (@newcustom) {
                   14831:         map { $customadds{$_} = 1; } @newcustom;
                   14832:     }
                   14833:     foreach my $provider (sort(keys(%providernames))) {
                   14834:         $confhash{$provider} = {};
                   14835:         my $pos = $env{'form.proctoring_pos_'.$provider};
                   14836:         $pos =~ s/\D+//g;
                   14837:         $allpos[$pos] = $provider;
                   14838:         my (%current,%currentenc);
                   14839:         my $showroles = 0;
                   14840:         if (ref($domconfig{$action}) eq 'HASH') {
                   14841:             if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   14842:                 %current = %{$domconfig{$action}{$provider}};
                   14843:                 foreach my $item ('key','secret') { 
                   14844:                     $currentenc{$item} = $current{$item};
                   14845:                     delete($current{$item});
                   14846:                 }
                   14847:             }
                   14848:         }
                   14849:         if ($env{'form.proctoring_available_'.$provider}) {
                   14850:             $confhash{$provider}{'available'} = 1;
                   14851:             unless ($current{'available'}) {
                   14852:                 $changes{$provider} = 1;
                   14853:             }
                   14854:         } else {
                   14855:             %{$confhash{$provider}} = %current;
                   14856:             %{$encconfhash{$provider}} = %currentenc;
                   14857:             $confhash{$provider}{'available'} = 0;
                   14858:             if ($current{'available'}) {
                   14859:                 $changes{$provider} = 1;
                   14860:             }
                   14861:         }
                   14862:         if ($confhash{$provider}{'available'}) {
                   14863:             foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
                   14864:                 my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
                   14865:                 if ($field eq 'lifetime') {
                   14866:                     if ($possval =~ /^\d+$/) {
                   14867:                         $confhash{$provider}{$field} = $possval;
                   14868:                     }
                   14869:                 } elsif ($field eq 'version') {
                   14870:                     if ($possval =~ /^\d+\.\d+$/) {
                   14871:                         $confhash{$provider}{$field} = $possval;
                   14872:                     }
                   14873:                 } elsif ($field eq 'sigmethod') {
                   14874:                     if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
                   14875:                         $confhash{$provider}{$field} = $possval;
                   14876:                     }
                   14877:                 } elsif ($field eq 'url') {
                   14878:                     $confhash{$provider}{$field} = $possval;
                   14879:                 } elsif (($field eq 'key') || ($field eq 'secret')) {
                   14880:                     $encconfhash{$provider}{$field} = $possval;
                   14881:                     unless ($currentenc{$field} eq $possval) {
                   14882:                         $changes{$provider} = 1;
                   14883:                     }
                   14884:                 }
                   14885:                 unless (($field eq 'key') || ($field eq 'secret')) {
                   14886:                     unless ($current{$field} eq $confhash{$provider}{$field}) {
                   14887:                         $changes{$provider} = 1;
                   14888:                     }
                   14889:                 }
                   14890:             }
                   14891:             if ($imgdeletions{$provider}) {
                   14892:                 $changes{$provider} = 1;
                   14893:             } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
                   14894:                 my ($imageurl,$error) =
                   14895:                     &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
                   14896:                                               $configuserok,$switchserver,$author_ok);
                   14897:                 if ($imageurl) {
                   14898:                     $confhash{$provider}{'image'} = $imageurl;
                   14899:                     $changes{$provider} = 1; 
                   14900:                 }
                   14901:                 if ($error) {
                   14902:                     &Apache::lonnet::logthis($error);
                   14903:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14904:                 }
                   14905:             } elsif (exists($current{'image'})) {
                   14906:                 $confhash{$provider}{'image'} = $current{'image'};
                   14907:             }
                   14908:             if (ref($requserfields{$provider}) eq 'ARRAY') {
                   14909:                 if (@{$requserfields{$provider}} > 0) {
                   14910:                     if (grep(/^user$/,@{$requserfields{$provider}})) {
                   14911:                         if ($env{'form.proctoring_userincdom_'.$provider}) {
                   14912:                             $confhash{$provider}{'incdom'} = 1;
                   14913:                         }
                   14914:                         unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
                   14915:                             $changes{$provider} = 1;
                   14916:                         }
                   14917:                     }
                   14918:                     if (grep(/^roles$/,@{$requserfields{$provider}})) {
                   14919:                         $showroles = 1;
                   14920:                     }
                   14921:                 }
                   14922:             }
                   14923:             $confhash{$provider}{'fields'} = [];
                   14924:             if (ref($optuserfields{$provider}) eq 'ARRAY') {
                   14925:                 if (@{$optuserfields{$provider}} > 0) {
                   14926:                     my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
                   14927:                     foreach my $field (@{$optuserfields{$provider}}) {
                   14928:                         if (grep(/^\Q$field\E$/,@optfields)) {
                   14929:                             push(@{$confhash{$provider}{'fields'}},$field);
                   14930:                         }
                   14931:                     }
                   14932:                 }
                   14933:                 if (ref($current{'fields'}) eq 'ARRAY') {
                   14934:                     unless ($changes{$provider}) {
                   14935:                         my @new = sort(@{$confhash{$provider}{'fields'}});
                   14936:                         my @old = sort(@{$current{'fields'}}); 
                   14937:                         my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   14938:                         if (@diffs) {
                   14939:                             $changes{$provider} = 1;
                   14940:                         }
                   14941:                     }
                   14942:                 } elsif (@{$confhash{$provider}{'fields'}}) {
                   14943:                     $changes{$provider} = 1;
                   14944:                 }
                   14945:             }
                   14946:             if (ref($defaults{$provider}) eq 'ARRAY') {  
                   14947:                 if (@{$defaults{$provider}} > 0) {
                   14948:                     my %options;
                   14949:                     if (ref($extended{$provider}) eq 'HASH') {
                   14950:                         %options = %{$extended{$provider}};
                   14951:                     }
                   14952:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
                   14953:                     foreach my $field (@{$defaults{$provider}}) {
                   14954:                         if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
                   14955:                             my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
                   14956:                             if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
                   14957:                                 push(@{$confhash{$provider}{'defaults'}},$poss); 
                   14958:                             }
                   14959:                         } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
                   14960:                             foreach my $inner (keys(%{$options{$field}})) {
                   14961:                                 if (ref($options{$field}{$inner}) eq 'ARRAY') {
                   14962:                                     my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
                   14963:                                     if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
                   14964:                                         $confhash{$provider}{'defaults'}{$inner} = $poss;
                   14965:                                     }
                   14966:                                 } else {
                   14967:                                     $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
                   14968:                                 }
                   14969:                             }
                   14970:                         } else {
                   14971:                             if (grep(/^\Q$field\E$/,@checked)) {
                   14972:                                 push(@{$confhash{$provider}{'defaults'}},$field);
                   14973:                             }
                   14974:                         }
                   14975:                     }
                   14976:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   14977:                         if (ref($current{'defaults'}) eq 'ARRAY') {
                   14978:                             unless ($changes{$provider}) {
                   14979:                                 my @new = sort(@{$confhash{$provider}{'defaults'}});
                   14980:                                 my @old = sort(@{$current{'defaults'}});
                   14981:                                 my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   14982:                                 if (@diffs) {
                   14983:                                     $changes{$provider} = 1; 
                   14984:                                 }
                   14985:                             }
                   14986:                         } elsif (ref($current{'defaults'}) eq 'ARRAY') {
                   14987:                             if (@{$current{'defaults'}}) {
                   14988:                                 $changes{$provider} = 1;
                   14989:                             }
                   14990:                         }
                   14991:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   14992:                         if (ref($current{'defaults'}) eq 'HASH') {
                   14993:                             unless ($changes{$provider}) {
                   14994:                                 foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
                   14995:                                     unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
                   14996:                                         $changes{$provider} = 1;
                   14997:                                         last;
                   14998:                                     }
                   14999:                                 }
                   15000:                             }
                   15001:                             unless ($changes{$provider}) {
                   15002:                                 foreach my $key (keys(%{$current{'defaults'}})) {
                   15003:                                     unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
                   15004:                                         $changes{$provider} = 1;
                   15005:                                         last;
                   15006:                                     }
                   15007:                                 }
                   15008:                             }
                   15009:                         } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
                   15010:                             $changes{$provider} = 1;
                   15011:                         }
                   15012:                     }
                   15013:                 }
                   15014:             }
                   15015:             if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15016:                 if (@{$crsconf{$provider}} > 0) {
                   15017:                     $confhash{$provider}{'crsconf'} = [];
                   15018:                     my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
                   15019:                     foreach my $crsfield (@{$crsconf{$provider}}) {
                   15020:                         if (grep(/^\Q$crsfield\E$/,@checked)) {
                   15021:                             push(@{$confhash{$provider}{'crsconf'}},$crsfield);
                   15022:                         }
                   15023:                     }
                   15024:                     if (ref($current{'crsconf'}) eq 'ARRAY') {
                   15025:                         unless ($changes{$provider}) {  
                   15026:                             my @new = sort(@{$confhash{$provider}{'crsconf'}});
                   15027:                             my @old = sort(@{$current{'crsconf'}});
                   15028:                             my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
                   15029:                             if (@diffs) {
                   15030:                                 $changes{$provider} = 1;
                   15031:                             }
                   15032:                         }
                   15033:                     } elsif (@{$confhash{$provider}{'crsconf'}}) {
                   15034:                         $changes{$provider} = 1;
                   15035:                     }
                   15036:                 }
                   15037:             }
                   15038:             if ($showroles) {
                   15039:                 $confhash{$provider}{'roles'} = {};
                   15040:                 foreach my $role (@courseroles) {
                   15041:                     my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
                   15042:                     if (grep(/^\Q$poss\E$/,@ltiroles)) {
                   15043:                         $confhash{$provider}{'roles'}{$role} = $poss;
                   15044:                     }
                   15045:                 }
                   15046:                 unless ($changes{$provider}) {
                   15047:                     if (ref($current{'roles'}) eq 'HASH') {
                   15048:                         foreach my $role (keys(%{$current{'roles'}})) {
                   15049:                             unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
                   15050:                                 $changes{$provider} = 1;
                   15051:                                 last
                   15052:                             }
                   15053:                         }
                   15054:                         unless ($changes{$provider}) {
                   15055:                             foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
                   15056:                                 unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
                   15057:                                     $changes{$provider} = 1;
                   15058:                                     last;
                   15059:                                 }
                   15060:                             }
                   15061:                         }
                   15062:                     } elsif (keys(%{$confhash{$provider}{'roles'}})) {
                   15063:                         $changes{$provider} = 1;
                   15064:                     }
                   15065:                 }
                   15066:             }
                   15067:             if (ref($current{'custom'}) eq 'HASH') {
                   15068:                 my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
                   15069:                 foreach my $key (keys(%{$current{'custom'}})) {
                   15070:                     if (grep(/^\Q$key\E$/,@customdels)) {
                   15071:                         $changes{$provider} = 1;
                   15072:                     } else {
                   15073:                         $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
                   15074:                         if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
                   15075:                             $changes{$provider} = 1;
                   15076:                         }
                   15077:                     }
                   15078:                 }
                   15079:             }
                   15080:             if ($customadds{$provider}) {
                   15081:                 my $name = $env{'form.proctoring_custom_name_'.$provider};
                   15082:                 $name =~ s/(`)/'/g;
                   15083:                 $name =~ s/^\s+//;
                   15084:                 $name =~ s/\s+$//;
                   15085:                 my $value = $env{'form.proctoring_custom_value_'.$provider};
                   15086:                 $value =~ s/(`)/'/g;
                   15087:                 $value =~ s/^\s+//;
                   15088:                 $value =~ s/\s+$//;
                   15089:                 if ($name ne '') {
                   15090:                     $confhash{$provider}{'custom'}{$name} = $value;
                   15091:                     $changes{$provider} = 1;
                   15092:                 }
                   15093:             }
                   15094:         }
                   15095:     }
                   15096:     if (@allpos > 0) {
                   15097:         my $idx = 0;
                   15098:         foreach my $provider (@allpos) {
                   15099:             if ($provider ne '') {
                   15100:                 $confhash{$provider}{'order'} = $idx;
                   15101:                 unless ($changes{$provider}) {
                   15102:                     if (ref($domconfig{$action}) eq 'HASH') {
                   15103:                         if (ref($domconfig{$action}{$provider}) eq 'HASH') {
                   15104:                             if ($domconfig{$action}{$provider}{'order'} ne $idx) {
                   15105:                                 $changes{$provider} = 1;
                   15106:                             }
                   15107:                         }
                   15108:                     }
                   15109:                 }
                   15110:                 $idx ++;
                   15111:             }
                   15112:         }
                   15113:     }
                   15114:     my %proc_hash = (
                   15115:                           $action => { %confhash }
                   15116:                        );
                   15117:     my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
                   15118:                                              $dom);
                   15119:     if ($putresult eq 'ok') {
                   15120:         my %proc_enchash = (
                   15121:                              $action => { %encconfhash }
                   15122:                          );
1.384     raeburn  15123:         &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372     raeburn  15124:         if (keys(%changes) > 0) {
                   15125:             my $cachetime = 24*60*60;
                   15126:             my %procall = %confhash;
                   15127:             foreach my $provider (keys(%procall)) {
                   15128:                 if (ref($encconfhash{$provider}) eq 'HASH') {
                   15129:                     foreach my $key ('key','secret') {
                   15130:                         $procall{$provider}{$key} = $encconfhash{$provider}{$key};
                   15131:                     }
                   15132:                 }
                   15133:             }
                   15134:             &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
                   15135:             if (ref($lastactref) eq 'HASH') {
                   15136:                 $lastactref->{'proctoring'} = 1;
                   15137:             }
                   15138:             $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
                   15139:             my %bynum;
                   15140:             foreach my $provider (sort(keys(%changes))) {
                   15141:                 my $position = $confhash{$provider}{'order'};
                   15142:                 $bynum{$position} = $provider;
                   15143:             }
                   15144:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15145:                 my $provider = $bynum{$pos};
                   15146:                 my %lt = &proctoring_titles($provider);
                   15147:                 my %fieldtitles = &proctoring_fieldtitles($provider);
                   15148:                 if (!$confhash{$provider}{'available'}) {
                   15149:                     $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
                   15150:                 } else {
                   15151:                     $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
                   15152:                     if ($confhash{$provider}{'image'}) {
                   15153:                         $resulttext .= '&nbsp;'.
                   15154:                                        '<img src="'.$confhash{$provider}{'image'}.'"'.
                   15155:                                        ' alt="'.&mt('Proctoring icon').'" />';
                   15156:                     }
                   15157:                     $resulttext .= '<ul>';
                   15158:                     my $position = $pos + 1;
                   15159:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15160:                     foreach my $key ('version','sigmethod','url','lifetime') {
                   15161:                         if ($confhash{$provider}{$key} ne '') {
                   15162:                             $resulttext .= '<li>'.$lt{$key}.':&nbsp;'.$confhash{$provider}{$key}.'</li>';
                   15163:                         }
                   15164:                     }
                   15165:                     if ($encconfhash{$provider}{'key'} ne '') {
                   15166:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfhash{$provider}{'key'}.'</li>';
                   15167:                     }
                   15168:                     if ($encconfhash{$provider}{'secret'} ne '') {
                   15169:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15170:                         my $num = length($encconfhash{$provider}{'secret'});
                   15171:                         $resulttext .= ('*'x$num).'</li>';
                   15172:                     }
                   15173:                     my (@fields,$showroles);
                   15174:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15175:                         push(@fields,@{$requserfields{$provider}});
                   15176:                     }
                   15177:                     if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
                   15178:                         push(@fields,@{$confhash{$provider}{'fields'}});
                   15179:                     } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
                   15180:                         push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
                   15181:                     }
                   15182:                     if (@fields) {
                   15183:                         if (grep(/^roles$/,@fields)) {
                   15184:                             $showroles = 1;
                   15185:                         }
                   15186:                         $resulttext .= '<li>'.$lt{'udsl'}.':&nbsp;"'.
                   15187:                                        join('", "', map { $lt{$_}; } @fields).'"</li>';
                   15188:                     }
                   15189:                     if (ref($requserfields{$provider}) eq 'ARRAY') {
                   15190:                         if (grep(/^user$/,@{$requserfields{$provider}})) {
                   15191:                             if ($confhash{$provider}{'incdom'}) {
                   15192:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
                   15193:                             } else { 
                   15194:                                 $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
                   15195:                             }
                   15196:                         }
                   15197:                     }
                   15198:                     if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
                   15199:                         if (@{$confhash{$provider}{'defaults'}} > 0) {
                   15200:                             $resulttext .= '<li>'.$lt{'defa'};
                   15201:                             foreach my $field (@{$confhash{$provider}{'defaults'}}) {
                   15202:                                 $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15203:                             }
                   15204:                             $resulttext =~ s/,$//;
                   15205:                             $resulttext .= '</li>';
                   15206:                         }
                   15207:                     } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
                   15208:                         if (keys(%{$confhash{$provider}{'defaults'}})) {
                   15209:                             $resulttext .= '<li>'.$lt{'defa'}.':&nbsp;<ul>';
                   15210:                             foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
                   15211:                                 if ($confhash{$provider}{'defaults'}{$key} ne '') {
                   15212:                                     $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
                   15213:                                 }
                   15214:                             }
                   15215:                             $resulttext .= '</ul></li>';
                   15216:                         }
                   15217:                     }
                   15218:                     if (ref($crsconf{$provider}) eq 'ARRAY') {
                   15219:                         if (@{$crsconf{$provider}} > 0) {
                   15220:                             $resulttext .= '<li>'.&mt('Configurable in course:');
                   15221:                             my $numconfig = 0;
                   15222:                             if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
                   15223:                                 if (@{$confhash{$provider}{'crsconf'}} > 0) {
                   15224:                                     foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
                   15225:                                         $numconfig ++;
                   15226:                                         if ($provider eq 'examity') {
                   15227:                                             $resulttext .= ' "'.$lt{'crs'.$field}.'",';
                   15228:                                         } else {
                   15229:                                             $resulttext .= ' "'.$fieldtitles{$field}.'",';
                   15230:                                         }
                   15231:                                     }
                   15232:                                     $resulttext =~ s/,$//;
                   15233:                                 }
                   15234:                             }
                   15235:                             if (!$numconfig) {
                   15236:                                 $resulttext .= '&nbsp;'.&mt('None');
                   15237:                             }
                   15238:                             $resulttext .= '</li>';
                   15239:                         }
                   15240:                     }
                   15241:                     if ($showroles) {
                   15242:                         if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
                   15243:                             my $rolemaps;
                   15244:                             foreach my $role (@courseroles) {
                   15245:                                 if ($confhash{$provider}{'roles'}{$role}) {
                   15246:                                     $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   15247:                                                  $confhash{$provider}{'roles'}{$role}.',';
                   15248:                                 }
                   15249:                             }
                   15250:                             if ($rolemaps) {
                   15251:                                 $rolemaps =~ s/,$//;
                   15252:                                 $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15253:                             }
                   15254:                         }
                   15255:                     }
                   15256:                     if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
                   15257:                         my $customlist;
                   15258:                         if (keys(%{$confhash{$provider}{'custom'}})) {
                   15259:                             foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
                   15260:                                 $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
                   15261:                             }
                   15262:                             $customlist =~ s/,$//;
                   15263:                         }
                   15264:                         if ($customlist) {
                   15265:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
                   15266:                         }
                   15267:                     } 
                   15268:                     $resulttext .= '</ul></li>';
                   15269:                 }
                   15270:             }
                   15271:             $resulttext .= '</ul>';
                   15272:         } else {
                   15273:             $resulttext = &mt('No changes made.');
                   15274:         }
                   15275:     } else {
                   15276:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15277:     }
                   15278:     if ($errors) {
                   15279:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15280:                        $errors.'</ul>';
                   15281:     }
                   15282:     return $resulttext;
                   15283: }
                   15284: 
                   15285: sub process_proctoring_image {
                   15286:     my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
                   15287:     my $filename = $env{'form.'.$caller.'.filename'};
                   15288:     my ($error,$url);
                   15289:     my ($width,$height) = (21,21);
                   15290:     if ($configuserok eq 'ok') {
                   15291:         if ($switchserver) {
                   15292:             $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
                   15293:                          $switchserver);
                   15294:         } elsif ($author_ok eq 'ok') {
                   15295:             my ($result,$imageurl,$madethumb) =
                   15296:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   15297:                              "proctoring/$provider/icon",$width,$height);
                   15298:             if ($result eq 'ok') {
                   15299:                 if ($madethumb) {
                   15300:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   15301:                     my $imagethumb = "$path/tn-".$imagefile;
                   15302:                     $url = $imagethumb;
                   15303:                 } else {
                   15304:                     $url = $imageurl;
                   15305:                 }
                   15306:             } else {
                   15307:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   15308:             }
                   15309:         } else {
                   15310:             $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);
                   15311:         }
                   15312:     } else {
                   15313:         $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);
                   15314:     }
                   15315:     return ($url,$error);
                   15316: }
                   15317: 
1.320     raeburn  15318: sub modify_lti {
                   15319:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   15320:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15321:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   15322:     my (%posslti,%posslticrs,%posscrstype);
                   15323:     my @courseroles = ('cc','in','ta','ep','st');
                   15324:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   15325:     my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392     raeburn  15326:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  15327:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   15328:                                official   => 'Official',
                   15329:                                unofficial => 'Unofficial',
                   15330:                                community  => 'Community',
                   15331:                                textbook   => 'Textbook',
                   15332:                                placement  => 'Placement Test',
1.392     raeburn  15333:                                lti        => 'LTI Provider',
1.320     raeburn  15334:     );
1.325     raeburn  15335:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320     raeburn  15336:     my %lt = &lti_names();
                   15337:     map { $posslti{$_} = 1; } @ltiroles;
                   15338:     map { $posslticrs{$_} = 1; } @lticourseroles;
                   15339:     map { $posscrstype{$_} = 1; } @coursetypes;
1.325     raeburn  15340: 
1.326     raeburn  15341:     my %menutitles = &ltimenu_titles();
                   15342: 
1.320     raeburn  15343:     my (@items,%deletions,%itemids);
                   15344:     if ($env{'form.lti_add'}) {
                   15345:         my $consumer = $env{'form.lti_consumer_add'};
                   15346:         $consumer =~ s/(`)/'/g;
                   15347:         ($newid,my $error) = &get_lti_id($dom,$consumer);
                   15348:         if ($newid) {
                   15349:             $itemids{'add'} = $newid;
                   15350:             push(@items,'add');
                   15351:             $changes{$newid} = 1;
                   15352:         } else {
                   15353:             my $error = &mt('Failed to acquire unique ID for new LTI configuration');
                   15354:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   15355:         }
                   15356:     }
                   15357:     if (ref($domconfig{$action}) eq 'HASH') {
                   15358:         my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
                   15359:         if (@todelete) {
                   15360:             map { $deletions{$_} = 1; } @todelete;
                   15361:         }
                   15362:         my $maxnum = $env{'form.lti_maxnum'};
1.390     raeburn  15363:         for (my $i=0; $i<$maxnum; $i++) {
1.320     raeburn  15364:             my $itemid = $env{'form.lti_id_'.$i};
                   15365:             $itemid =~ s/\D+//g;
                   15366:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15367:                 if ($deletions{$itemid}) {
                   15368:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
                   15369:                 } else {
1.390     raeburn  15370:                     push(@items,$i);
                   15371:                     $itemids{$i} = $itemid;
1.320     raeburn  15372:                 }
                   15373:             }
                   15374:         }
                   15375:     }
                   15376:     foreach my $idx (@items) {
                   15377:         my $itemid = $itemids{$idx};
                   15378:         next unless ($itemid);
1.390     raeburn  15379:         my $position = $env{'form.lti_pos_'.$itemid};
1.320     raeburn  15380:         $position =~ s/\D+//g;
                   15381:         if ($position ne '') {
                   15382:             $allpos[$position] = $itemid;
                   15383:         }
1.391     raeburn  15384:         foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320     raeburn  15385:             my $formitem = 'form.lti_'.$item.'_'.$idx;
                   15386:             $env{$formitem} =~ s/(`)/'/g;
                   15387:             if ($item eq 'lifetime') {
                   15388:                 $env{$formitem} =~ s/[^\d.]//g;
                   15389:             }
                   15390:             if ($env{$formitem} ne '') {
                   15391:                 if (($item eq 'key') || ($item eq 'secret')) {
                   15392:                     $encconfig{$itemid}{$item} = $env{$formitem};
                   15393:                 } else {
                   15394:                     $confhash{$itemid}{$item} = $env{$formitem};
                   15395:                     unless (($idx eq 'add') || ($changes{$itemid})) {
                   15396:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   15397:                             $changes{$itemid} = 1;
                   15398:                         }
                   15399:                     }
                   15400:                 }
                   15401:             }
                   15402:         }
                   15403:         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
                   15404:             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
                   15405:         }
1.345     raeburn  15406:         if ($confhash{$itemid}{'requser'}) {
                   15407:             if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
                   15408:                 $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid'; 
                   15409:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
                   15410:                 $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
                   15411:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
                   15412:                 my $mapuser = $env{'form.lti_customuser_'.$idx};
                   15413:                 $mapuser =~ s/(`)/'/g;
                   15414:                 $mapuser =~ s/^\s+|\s+$//g; 
                   15415:                 $confhash{$itemid}{'mapuser'} = $mapuser; 
                   15416:             }
                   15417:             my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
                   15418:             my @makeuser;
                   15419:             foreach my $ltirole (sort(@possmakeuser)) {
                   15420:                 if ($posslti{$ltirole}) {
                   15421:                     push(@makeuser,$ltirole);
                   15422:                 }
                   15423:             }
                   15424:             $confhash{$itemid}{'makeuser'} = \@makeuser;
                   15425:             if (@makeuser) {
                   15426:                 my $lcauth = $env{'form.lti_lcauth_'.$idx};
                   15427:                 if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
                   15428:                     $confhash{$itemid}{'lcauth'} = $lcauth;
                   15429:                     if ($lcauth ne 'internal') {
                   15430:                         my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
                   15431:                         $lcauthparm =~ s/^(\s+|\s+)$//g;
                   15432:                         $lcauthparm =~ s/`//g;
                   15433:                         if ($lcauthparm ne '') {
                   15434:                             $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
                   15435:                         }
                   15436:                     }
                   15437:                 } else {
                   15438:                     $confhash{$itemid}{'lcauth'} = 'lti';
                   15439:                 }
1.320     raeburn  15440:             }
1.345     raeburn  15441:             my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
                   15442:             if (@possinstdata) {
                   15443:                 foreach my $field (@possinstdata) {
                   15444:                     if (exists($fieldtitles{$field})) {
                   15445:                         push(@{$confhash{$itemid}{'instdata'}});
1.325     raeburn  15446:                     }
                   15447:                 }
                   15448:             }
1.363     raeburn  15449:             if ($env{'form.lti_callback_'.$idx}) {
                   15450:                 if ($env{'form.lti_callbackparam_'.$idx}) {
                   15451:                     my $callback = $env{'form.lti_callbackparam_'.$idx};
                   15452:                     $callback =~ s/^\s+|\s+$//g;
                   15453:                     $confhash{$itemid}{'callback'} = $callback;
                   15454:                 }
                   15455:             }
1.391     raeburn  15456:             foreach my $field ('topmenu','inlinemenu') {
1.345     raeburn  15457:                 if ($env{'form.lti_'.$field.'_'.$idx}) {
                   15458:                     $confhash{$itemid}{$field} = 1;
                   15459:                 }
1.320     raeburn  15460:             }
1.345     raeburn  15461:             if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   15462:                 $confhash{$itemid}{lcmenu} = [];
                   15463:                 my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   15464:                 foreach my $field (@possmenu) {
                   15465:                     if (exists($menutitles{$field})) {
                   15466:                         if ($field eq 'grades') {
                   15467:                             next unless ($env{'form.lti_inlinemenu_'.$idx});
                   15468:                         }
                   15469:                         push(@{$confhash{$itemid}{lcmenu}},$field);
1.326     raeburn  15470:                     }
                   15471:                 }
                   15472:             }
1.391     raeburn  15473:             if ($confhash{$itemid}{'crsinc'}) {
                   15474:                 if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
                   15475:                     ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
                   15476:                     $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
                   15477:                 } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                   15478:                     my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
                   15479:                     $mapcrs =~ s/(`)/'/g;
                   15480:                     $mapcrs =~ s/^\s+|\s+$//g;
                   15481:                     $confhash{$itemid}{'mapcrs'} = $mapcrs;
                   15482:                 }
                   15483:                 my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                   15484:                 my @crstypes;
                   15485:                 foreach my $type (sort(@posstypes)) {
                   15486:                     if ($posscrstype{$type}) {
                   15487:                         push(@crstypes,$type);
                   15488:                     }
                   15489:                 }
                   15490:                 $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392     raeburn  15491:                 if ($env{'form.lti_storecrs_'.$idx}) {
                   15492:                     $confhash{$itemid}{'storecrs'} = 1;
                   15493:                 }       
1.391     raeburn  15494:                 if ($env{'form.lti_makecrs_'.$idx}) {
                   15495:                     $confhash{$itemid}{'makecrs'} = 1;
                   15496:                 }
                   15497:                 foreach my $ltirole (@lticourseroles) {
                   15498:                     my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                   15499:                     if (grep(/^\Q$possrole\E$/,@courseroles)) {
                   15500:                         $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
                   15501:                     }
                   15502:                 }
                   15503:                 my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
                   15504:                 my @selfenroll;
                   15505:                 foreach my $type (sort(@possenroll)) {
                   15506:                     if ($posslticrs{$type}) {
                   15507:                         push(@selfenroll,$type);
                   15508:                     }
                   15509:                 }
                   15510:                 $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                   15511:                 if ($env{'form.lti_crssec_'.$idx}) {
                   15512:                     if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                   15513:                         $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                   15514:                     } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                   15515:                         my $section = $env{'form.lti_customsection_'.$idx};
                   15516:                         $section =~ s/(`)/'/g;
                   15517:                         $section =~ s/^\s+|\s+$//g;
                   15518:                         if ($section ne '') {
                   15519:                             $confhash{$itemid}{'section'} = $section;
                   15520:                         }
                   15521:                     }
                   15522:                 }
                   15523:                 foreach my $field ('passback','roster') {
                   15524:                     if ($env{'form.lti_'.$field.'_'.$idx}) {
                   15525:                         $confhash{$itemid}{$field} = 1;
                   15526:                     }
                   15527:                 }
                   15528:                 if ($env{'form.lti_passback_'.$idx}) {
                   15529:                     if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                   15530:                         $confhash{$itemid}{'passbackformat'} = '1.0';
                   15531:                     } else {
                   15532:                         $confhash{$itemid}{'passbackformat'} = '1.1';
1.337     raeburn  15533:                     }
                   15534:                 }
1.391     raeburn  15535:             }
                   15536:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   15537:                 if ($confhash{$itemid}{'crsinc'}) {
1.392     raeburn  15538:                     foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391     raeburn  15539:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320     raeburn  15540:                             $changes{$itemid} = 1;
                   15541:                         }
1.345     raeburn  15542:                     }
                   15543:                     unless ($changes{$itemid}) {
1.391     raeburn  15544:                         if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
                   15545:                             if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320     raeburn  15546:                                 $changes{$itemid} = 1;
                   15547:                             }
                   15548:                         }
1.345     raeburn  15549:                     }
1.391     raeburn  15550:                     foreach my $field ('mapcrstype','selfenroll') {
                   15551:                         unless ($changes{$itemid}) {
                   15552:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   15553:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15554:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   15555:                                                                                    $confhash{$itemid}{$field});
                   15556:                                     if (@diffs) {
                   15557:                                         $changes{$itemid} = 1;
                   15558:                                     }
                   15559:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   15560:                                     $changes{$itemid} = 1;
                   15561:                                 }
                   15562:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15563:                                 if (@{$confhash{$itemid}{$field}} > 0) {
1.320     raeburn  15564:                                     $changes{$itemid} = 1;
                   15565:                                 }
                   15566:                             }
1.391     raeburn  15567:                         }
                   15568:                     }
                   15569:                     unless ($changes{$itemid}) {
                   15570:                         if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
                   15571:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15572:                                 foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
                   15573:                                     if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne 
                   15574:                                         $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345     raeburn  15575:                                         $changes{$itemid} = 1;
                   15576:                                         last;
                   15577:                                     }
                   15578:                                 }
1.391     raeburn  15579:                                 unless ($changes{$itemid}) {
                   15580:                                     foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                   15581:                                         if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
                   15582:                                             $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
                   15583:                                             $changes{$itemid} = 1;
                   15584:                                             last;
                   15585:                                         }
                   15586:                                     }
                   15587:                                 }
                   15588:                             } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
                   15589:                                 $changes{$itemid} = 1;
1.345     raeburn  15590:                             }
1.391     raeburn  15591:                         } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15592:                             unless ($changes{$itemid}) {
                   15593:                                 if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                   15594:                                     $changes{$itemid} = 1;
                   15595:                                 }
                   15596:                             }
                   15597:                         }
                   15598:                     }
                   15599:                 }
                   15600:                 unless ($changes{$itemid}) {
                   15601:                     foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
                   15602:                         if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345     raeburn  15603:                             $changes{$itemid} = 1;
1.320     raeburn  15604:                         }
1.391     raeburn  15605:                     }
                   15606:                     unless ($changes{$itemid}) {
                   15607:                         foreach my $field ('makeuser','lcmenu') {
                   15608:                             if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   15609:                                 if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15610:                                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   15611:                                                                                    $confhash{$itemid}{$field});
                   15612:                                     if (@diffs) {
                   15613:                                         $changes{$itemid} = 1;
                   15614:                                     }
                   15615:                                 } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   15616:                                     $changes{$itemid} = 1;
                   15617:                                 }
                   15618:                             } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   15619:                                 if (@{$confhash{$itemid}{$field}} > 0) {
                   15620:                                     $changes{$itemid} = 1;
                   15621:                                 }
1.345     raeburn  15622:                             }
1.320     raeburn  15623:                         }
                   15624:                     }
                   15625:                 }
                   15626:             }
                   15627:         }
                   15628:     }
                   15629:     if (@allpos > 0) {
                   15630:         my $idx = 0;
                   15631:         foreach my $itemid (@allpos) {
                   15632:             if ($itemid ne '') {
                   15633:                 $confhash{$itemid}{'order'} = $idx;
                   15634:                 if (ref($domconfig{$action}) eq 'HASH') {
                   15635:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   15636:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   15637:                             $changes{$itemid} = 1;
                   15638:                         }
                   15639:                     }
                   15640:                 }
                   15641:                 $idx ++;
                   15642:             }
                   15643:         }
                   15644:     }
                   15645:     my %ltihash = (
                   15646:                           $action => { %confhash }
                   15647:                        );
                   15648:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
                   15649:                                              $dom);
                   15650:     if ($putresult eq 'ok') {
                   15651:         my %ltienchash = (
                   15652:                              $action => { %encconfig }
                   15653:                          );
1.384     raeburn  15654:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320     raeburn  15655:         if (keys(%changes) > 0) {
                   15656:             my $cachetime = 24*60*60;
                   15657:             my %ltiall = %confhash;
                   15658:             foreach my $id (keys(%ltiall)) {
                   15659:                 if (ref($encconfig{$id}) eq 'HASH') {
                   15660:                     foreach my $item ('key','secret') {
                   15661:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   15662:                     }
                   15663:                 }
                   15664:             }
                   15665:             &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
                   15666:             if (ref($lastactref) eq 'HASH') {
                   15667:                 $lastactref->{'lti'} = 1;
                   15668:             }
                   15669:             $resulttext = &mt('Changes made:').'<ul>';
                   15670:             my %bynum;
                   15671:             foreach my $itemid (sort(keys(%changes))) {
                   15672:                 my $position = $confhash{$itemid}{'order'};
                   15673:                 $bynum{$position} = $itemid;
                   15674:             }
                   15675:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   15676:                 my $itemid = $bynum{$pos};
                   15677:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   15678:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   15679:                 } else {
1.390     raeburn  15680:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320     raeburn  15681:                     my $position = $pos + 1;
                   15682:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   15683:                     foreach my $item ('version','lifetime') {
                   15684:                         if ($confhash{$itemid}{$item} ne '') {
                   15685:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   15686:                         }
                   15687:                     }
                   15688:                     if ($encconfig{$itemid}{'key'} ne '') {
                   15689:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   15690:                     }
                   15691:                     if ($encconfig{$itemid}{'secret'} ne '') {
                   15692:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   15693:                         my $num = length($encconfig{$itemid}{'secret'});
                   15694:                         $resulttext .= ('*'x$num).'</li>';
                   15695:                     }
1.345     raeburn  15696:                     if ($confhash{$itemid}{'requser'}) {
1.391     raeburn  15697:                         if ($confhash{$itemid}{'callback'}) {
                   15698:                             $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
                   15699:                         } else {
1.392     raeburn  15700:                             $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391     raeburn  15701:                         }
1.345     raeburn  15702:                         if ($confhash{$itemid}{'mapuser'}) {
                   15703:                             my $shownmapuser;
                   15704:                             if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                   15705:                                 $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                   15706:                             } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                   15707:                                 $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                   15708:                             } else {
                   15709:                                 $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320     raeburn  15710:                             }
1.345     raeburn  15711:                             $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320     raeburn  15712:                         }
1.345     raeburn  15713:                         if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                   15714:                             if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                   15715:                                 $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                   15716:                                                           join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                   15717:                                 if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                   15718:                                     $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                   15719:                                 } else {
                   15720:                                     $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                   15721:                                                        $confhash{$itemid}{'lcauth'});
                   15722:                                     if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                   15723:                                         $resulttext .= '; '.&mt('a randomly generated password will be created');
                   15724:                                     } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                   15725:                                         if ($confhash{$itemid}{'lcauthparm'} ne '') {
                   15726:                                             $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                   15727:                                         }
                   15728:                                     } else {
                   15729:                                         $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                   15730:                                     }
                   15731:                                 }
                   15732:                                 $resulttext .= '</li>';
                   15733:                             } else {
                   15734:                                 $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                   15735:                             }
1.320     raeburn  15736:                         }
1.345     raeburn  15737:                         if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                   15738:                             if (@{$confhash{$itemid}{'instdata'}} > 0) {
                   15739:                                 $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                   15740:                                                           join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325     raeburn  15741:                             } else {
1.345     raeburn  15742:                                 $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325     raeburn  15743:                             }
1.320     raeburn  15744:                         }
1.391     raeburn  15745:                         foreach my $item ('topmenu','inlinemenu') {
1.345     raeburn  15746:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   15747:                             if ($confhash{$itemid}{$item}) {
                   15748:                                 $resulttext .= &mt('Yes');
                   15749:                             } else {
                   15750:                                 $resulttext .= &mt('No');
1.337     raeburn  15751:                             }
1.345     raeburn  15752:                             $resulttext .= '</li>';
1.320     raeburn  15753:                         }
1.345     raeburn  15754:                         if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   15755:                             if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   15756:                                 $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391     raeburn  15757:                                                join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
                   15758:                             } else {
                   15759:                                 $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
                   15760:                             }
                   15761:                         }
                   15762:                         if ($confhash{$itemid}{'crsinc'}) {
                   15763:                             if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   15764:                                 my $rolemaps;
                   15765:                                 foreach my $role (@ltiroles) {
                   15766:                                     if ($confhash{$itemid}{'maproles'}{$role}) {
                   15767:                                         $rolemaps .= ('&nbsp;'x2).$role.'='.
                   15768:                                                      &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                   15769:                                                                                 'Course').',';
                   15770:                                     }
                   15771:                                 }
                   15772:                                 if ($rolemaps) {
                   15773:                                     $rolemaps =~ s/,$//;
                   15774:                                     $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   15775:                                 }
                   15776:                             }
                   15777:                             if ($confhash{$itemid}{'mapcrs'}) {
                   15778:                                 $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                   15779:                             }
                   15780:                             if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                   15781:                                 if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                   15782:                                     $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                   15783:                                                    join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                   15784:                                                    '</li>';
                   15785:                                 } else {
                   15786:                                     $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                   15787:                                 }
                   15788:                             }
1.392     raeburn  15789:                             if ($confhash{$itemid}{'storecrs'}) {
                   15790:                                 $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
                   15791:                             }
1.391     raeburn  15792:                             if ($confhash{$itemid}{'makecrs'}) {
                   15793:                                 $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
                   15794:                             } else {
                   15795:                                 $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
                   15796:                             }
                   15797:                             if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                   15798:                                 if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                   15799:                                     $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                   15800:                                                               join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                   15801:                                                    '</li>';
                   15802:                                 } else {
                   15803:                                     $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                   15804:                                 }
                   15805:                             }
                   15806:                             if ($confhash{$itemid}{'section'}) {
                   15807:                                 if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                   15808:                                     $resulttext .= '<li>'.&mt('User section from standard field:').
                   15809:                                                          ' (course_section_sourcedid)'.'</li>';  
                   15810:                                 } else {
                   15811:                                     $resulttext .= '<li>'.&mt('User section from:').' '.
                   15812:                                                           $confhash{$itemid}{'section'}.'</li>';
                   15813:                                 }
1.345     raeburn  15814:                             } else {
1.391     raeburn  15815:                                 $resulttext .= '<li>'.&mt('No section assignment').'</li>';
                   15816:                             }
                   15817:                             foreach my $item ('passback','roster','topmenu','inlinemenu') {
                   15818:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   15819:                                 if ($confhash{$itemid}{$item}) {
                   15820:                                     $resulttext .= &mt('Yes');
                   15821:                                     if ($item eq 'passback') {
                   15822:                                         if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                   15823:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                   15824:                                         } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                   15825:                                             $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                   15826:                                         }
                   15827:                                     }
                   15828:                                 } else {
                   15829:                                     $resulttext .= &mt('No');
                   15830:                                 }
                   15831:                                 $resulttext .= '</li>';
                   15832:                             }
                   15833:                             if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   15834:                                 if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   15835:                                     $resulttext .= '<li>'.&mt('Menu items:').' '.
                   15836:                                                    join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                   15837:                                 } else {
                   15838:                                     $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                   15839:                                 }
1.345     raeburn  15840:                             }
1.326     raeburn  15841:                         }
                   15842:                     }
1.320     raeburn  15843:                     $resulttext .= '</ul></li>';
                   15844:                 }
                   15845:             }
                   15846:             $resulttext .= '</ul>';
                   15847:         } else {
                   15848:             $resulttext = &mt('No changes made.');
                   15849:         }
                   15850:     } else {
                   15851:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   15852:     }
                   15853:     if ($errors) {
                   15854:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   15855:                        $errors.'</ul>';
                   15856:     }
                   15857:     return $resulttext;
                   15858: }
                   15859: 
                   15860: sub get_lti_id {
                   15861:     my ($domain,$consumer) = @_;
                   15862:     # get lock on lti db
                   15863:     my $lockhash = {
                   15864:                       lock => $env{'user.name'}.
                   15865:                               ':'.$env{'user.domain'},
                   15866:                    };
                   15867:     my $tries = 0;
                   15868:     my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   15869:     my ($id,$error);
                   15870: 
                   15871:     while (($gotlock ne 'ok') && ($tries<10)) {
                   15872:         $tries ++;
                   15873:         sleep (0.1);
                   15874:         $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   15875:     }
                   15876:     if ($gotlock eq 'ok') {
                   15877:         my %currids = &Apache::lonnet::dump_dom('lti',$domain);
                   15878:         if ($currids{'lock'}) {
                   15879:             delete($currids{'lock'});
                   15880:             if (keys(%currids)) {
                   15881:                 my @curr = sort { $a <=> $b } keys(%currids);
                   15882:                 if ($curr[-1] =~ /^\d+$/) {
                   15883:                     $id = 1 + $curr[-1];
                   15884:                 }
                   15885:             } else {
                   15886:                 $id = 1;
                   15887:             }
                   15888:             if ($id) {
                   15889:                 unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
                   15890:                     $error = 'nostore';
                   15891:                 }
                   15892:             } else {
                   15893:                 $error = 'nonumber';
                   15894:             }
                   15895:         }
                   15896:         my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
                   15897:     } else {
                   15898:         $error = 'nolock';
                   15899:     }
                   15900:     return ($id,$error);
                   15901: }
                   15902: 
1.3       raeburn  15903: sub modify_autoenroll {
1.205     raeburn  15904:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  15905:     my ($resulttext,%changes);
                   15906:     my %currautoenroll;
                   15907:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   15908:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   15909:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   15910:         }
                   15911:     }
                   15912:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   15913:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  15914:                   sender => 'Sender for notification messages',
1.274     raeburn  15915:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   15916:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  15917:     my @offon = ('off','on');
1.17      raeburn  15918:     my $sender_uname = $env{'form.sender_uname'};
                   15919:     my $sender_domain = $env{'form.sender_domain'};
                   15920:     if ($sender_domain eq '') {
                   15921:         $sender_uname = '';
                   15922:     } elsif ($sender_uname eq '') {
                   15923:         $sender_domain = '';
                   15924:     }
1.129     raeburn  15925:     my $coowners = $env{'form.autoassign_coowners'};
1.274     raeburn  15926:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   15927:     $failsafe =~ s{^\s+|\s+$}{}g;
                   15928:     if ($failsafe =~ /\D/) {
                   15929:         undef($failsafe);
                   15930:     }
1.1       raeburn  15931:     my %autoenrollhash =  (
1.129     raeburn  15932:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   15933:                                        'sender_uname' => $sender_uname,
                   15934:                                        'sender_domain' => $sender_domain,
                   15935:                                        'co-owners' => $coowners,
1.274     raeburn  15936:                                        'autofailsafe' => $failsafe,
1.1       raeburn  15937:                                 }
                   15938:                      );
1.4       raeburn  15939:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   15940:                                              $dom);
1.1       raeburn  15941:     if ($putresult eq 'ok') {
                   15942:         if (exists($currautoenroll{'run'})) {
                   15943:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   15944:                  $changes{'run'} = 1;
                   15945:              }
                   15946:         } elsif ($autorun) {
                   15947:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  15948:                  $changes{'run'} = 1;
1.1       raeburn  15949:             }
                   15950:         }
1.17      raeburn  15951:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  15952:             $changes{'sender'} = 1;
                   15953:         }
1.17      raeburn  15954:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  15955:             $changes{'sender'} = 1;
                   15956:         }
1.129     raeburn  15957:         if ($currautoenroll{'co-owners'} ne '') {
                   15958:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   15959:                 $changes{'coowners'} = 1;
                   15960:             }
                   15961:         } elsif ($coowners) {
                   15962:             $changes{'coowners'} = 1;
1.274     raeburn  15963:         }
                   15964:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   15965:             $changes{'autofailsafe'} = 1;
                   15966:         }
1.1       raeburn  15967:         if (keys(%changes) > 0) {
                   15968:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  15969:             if ($changes{'run'}) {
1.1       raeburn  15970:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   15971:             }
                   15972:             if ($changes{'sender'}) {
1.17      raeburn  15973:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   15974:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   15975:                 } else {
                   15976:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   15977:                 }
1.1       raeburn  15978:             }
1.129     raeburn  15979:             if ($changes{'coowners'}) {
                   15980:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   15981:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  15982:                 if (ref($lastactref) eq 'HASH') {
                   15983:                     $lastactref->{'domainconfig'} = 1;
                   15984:                 }
1.129     raeburn  15985:             }
1.274     raeburn  15986:             if ($changes{'autofailsafe'}) {
                   15987:                 if ($failsafe ne '') {
1.299     raeburn  15988:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274     raeburn  15989:                 } else {
1.299     raeburn  15990:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274     raeburn  15991:                 }
                   15992:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   15993:                 if (ref($lastactref) eq 'HASH') {
                   15994:                     $lastactref->{'domdefaults'} = 1;
                   15995:                 }
                   15996:             }
1.1       raeburn  15997:             $resulttext .= '</ul>';
                   15998:         } else {
                   15999:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   16000:         }
                   16001:     } else {
1.11      albertel 16002:         $resulttext = '<span class="LC_error">'.
                   16003: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16004:     }
1.3       raeburn  16005:     return $resulttext;
1.1       raeburn  16006: }
                   16007: 
                   16008: sub modify_autoupdate {
1.3       raeburn  16009:     my ($dom,%domconfig) = @_;
1.1       raeburn  16010:     my ($resulttext,%currautoupdate,%fields,%changes);
                   16011:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   16012:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   16013:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   16014:         }
                   16015:     }
                   16016:     my @offon = ('off','on');
                   16017:     my %title = &Apache::lonlocal::texthash (
1.385     raeburn  16018:                     run        => 'Auto-update:',
                   16019:                     classlists => 'Updates to user information in classlists?',
                   16020:                     unexpired  => 'Skip updates for users without active or future roles?',
                   16021:                     lastactive => 'Skip updates for inactive users?',
1.1       raeburn  16022:                 );
1.44      raeburn  16023:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  16024:     my %fieldtitles = &Apache::lonlocal::texthash (
                   16025:                         id => 'Student/Employee ID',
1.20      raeburn  16026:                         permanentemail => 'E-mail address',
1.1       raeburn  16027:                         lastname => 'Last Name',
                   16028:                         firstname => 'First Name',
                   16029:                         middlename => 'Middle Name',
1.132     raeburn  16030:                         generation => 'Generation',
1.1       raeburn  16031:                       );
1.142     raeburn  16032:     $othertitle = &mt('All users');
1.1       raeburn  16033:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  16034:         $othertitle = &mt('Other users');
1.1       raeburn  16035:     }
                   16036:     foreach my $key (keys(%env)) {
                   16037:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  16038:             my ($usertype,$item) = ($1,$2);
                   16039:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   16040:                 if ($usertype eq 'default') {   
                   16041:                     push(@{$fields{$1}},$2);
                   16042:                 } elsif (ref($types) eq 'ARRAY') {
                   16043:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   16044:                         push(@{$fields{$1}},$2);
                   16045:                     }
                   16046:                 }
                   16047:             }
1.1       raeburn  16048:         }
                   16049:     }
1.131     raeburn  16050:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   16051:     @lockablenames = sort(@lockablenames);
                   16052:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   16053:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16054:         if (@changed) {
                   16055:             $changes{'lockablenames'} = 1;
                   16056:         }
                   16057:     } else {
                   16058:         if (@lockablenames) {
                   16059:             $changes{'lockablenames'} = 1;
                   16060:         }
                   16061:     }
1.1       raeburn  16062:     my %updatehash = (
                   16063:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   16064:                                       classlists => $env{'form.classlists'},
1.385     raeburn  16065:                                       unexpired  => $env{'form.unexpired'},
1.1       raeburn  16066:                                       fields => {%fields},
1.131     raeburn  16067:                                       lockablenames => \@lockablenames,
1.1       raeburn  16068:                                     }
                   16069:                      );
1.385     raeburn  16070:     my $lastactivedays;
                   16071:     if ($env{'form.lastactive'}) {
                   16072:         $lastactivedays = $env{'form.lastactivedays'};
                   16073:         $lastactivedays =~ s/^\s+|\s+$//g;
                   16074:         unless ($lastactivedays =~ /^\d+$/) {
                   16075:             undef($lastactivedays);
                   16076:             $env{'form.lastactive'} = 0;
                   16077:         }
                   16078:     }
                   16079:     $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1       raeburn  16080:     foreach my $key (keys(%currautoupdate)) {
1.385     raeburn  16081:         if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1       raeburn  16082:             if (exists($updatehash{autoupdate}{$key})) {
                   16083:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   16084:                     $changes{$key} = 1;
                   16085:                 }
                   16086:             }
                   16087:         } elsif ($key eq 'fields') {
                   16088:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  16089:                 foreach my $item (@{$types},'default') {
1.1       raeburn  16090:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   16091:                         my $change = 0;
                   16092:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   16093:                             if (!exists($fields{$item})) {
                   16094:                                 $change = 1;
1.132     raeburn  16095:                                 last;
1.1       raeburn  16096:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  16097:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  16098:                                     $change = 1;
1.132     raeburn  16099:                                     last;
1.1       raeburn  16100:                                 }
                   16101:                             }
                   16102:                         }
                   16103:                         if ($change) {
                   16104:                             push(@{$changes{$key}},$item);
                   16105:                         }
1.26      raeburn  16106:                     } 
1.1       raeburn  16107:                 }
                   16108:             }
1.131     raeburn  16109:         } elsif ($key eq 'lockablenames') {
                   16110:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   16111:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   16112:                 if (@changed) {
                   16113:                     $changes{'lockablenames'} = 1;
                   16114:                 }
                   16115:             } else {
                   16116:                 if (@lockablenames) {
                   16117:                     $changes{'lockablenames'} = 1;
                   16118:                 }
                   16119:             }
                   16120:         }
                   16121:     }
                   16122:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   16123:         if (@lockablenames) {
                   16124:             $changes{'lockablenames'} = 1;
1.1       raeburn  16125:         }
                   16126:     }
1.385     raeburn  16127:     unless (grep(/^unexpired$/,keys(%currautoupdate))) {
                   16128:         if ($updatehash{'autoupdate'}{'unexpired'}) {
                   16129:             $changes{'unexpired'} = 1;
                   16130:         }
                   16131:     }
                   16132:     unless (grep(/^lastactive$/,keys(%currautoupdate))) {
                   16133:         if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
                   16134:             $changes{'lastactive'} = 1;
                   16135:         }
                   16136:     }
1.26      raeburn  16137:     foreach my $item (@{$types},'default') {
                   16138:         if (defined($fields{$item})) {
                   16139:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  16140:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   16141:                     my $change = 0;
                   16142:                     if (ref($fields{$item}) eq 'ARRAY') {
                   16143:                         foreach my $type (@{$fields{$item}}) {
                   16144:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   16145:                                 $change = 1;
                   16146:                                 last;
                   16147:                             }
                   16148:                         }
                   16149:                     }
                   16150:                     if ($change) {
                   16151:                         push(@{$changes{'fields'}},$item);
                   16152:                     }
                   16153:                 } else {
1.26      raeburn  16154:                     push(@{$changes{'fields'}},$item);
                   16155:                 }
                   16156:             } else {
                   16157:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  16158:             }
                   16159:         }
                   16160:     }
                   16161:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   16162:                                              $dom);
                   16163:     if ($putresult eq 'ok') {
                   16164:         if (keys(%changes) > 0) {
                   16165:             $resulttext = &mt('Changes made:').'<ul>';
                   16166:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  16167:                 if ($key eq 'lockablenames') {
                   16168:                     $resulttext .= '<li>';
                   16169:                     if (@lockablenames) {
                   16170:                         $usertypes->{'default'} = $othertitle;
                   16171:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   16172:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   16173:                     } else {
                   16174:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   16175:                     }
                   16176:                     $resulttext .= '</li>';
                   16177:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  16178:                     foreach my $item (@{$changes{$key}}) {
                   16179:                         my @newvalues;
                   16180:                         foreach my $type (@{$fields{$item}}) {
                   16181:                             push(@newvalues,$fieldtitles{$type});
                   16182:                         }
1.3       raeburn  16183:                         my $newvaluestr;
                   16184:                         if (@newvalues > 0) {
                   16185:                             $newvaluestr = join(', ',@newvalues);
                   16186:                         } else {
                   16187:                             $newvaluestr = &mt('none');
1.6       raeburn  16188:                         }
1.1       raeburn  16189:                         if ($item eq 'default') {
1.26      raeburn  16190:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  16191:                         } else {
1.26      raeburn  16192:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  16193:                         }
                   16194:                     }
                   16195:                 } else {
                   16196:                     my $newvalue;
                   16197:                     if ($key eq 'run') {
                   16198:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385     raeburn  16199:                     } elsif ($key eq 'lastactive') {
                   16200:                         $newvalue = $offon[$env{'form.lastactive'}];
                   16201:                         unless ($lastactivedays eq '') {
                   16202:                             $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
                   16203:                         }
1.1       raeburn  16204:                     } else {
                   16205:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  16206:                     }
1.1       raeburn  16207:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   16208:                 }
                   16209:             }
                   16210:             $resulttext .= '</ul>';
                   16211:         } else {
1.3       raeburn  16212:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  16213:         }
                   16214:     } else {
1.11      albertel 16215:         $resulttext = '<span class="LC_error">'.
                   16216: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  16217:     }
1.3       raeburn  16218:     return $resulttext;
1.1       raeburn  16219: }
                   16220: 
1.125     raeburn  16221: sub modify_autocreate {
                   16222:     my ($dom,%domconfig) = @_;
                   16223:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   16224:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   16225:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   16226:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   16227:         }
                   16228:     }
                   16229:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   16230:                  req => 'Auto-creation of validated requests for official courses',
                   16231:                  xmldc => 'Identity of course creator of courses from XML files',
                   16232:                );
                   16233:     my @types = ('xml','req');
                   16234:     foreach my $item (@types) {
                   16235:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   16236:         $newvals{$item} =~ s/\D//g;
                   16237:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   16238:     }
                   16239:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  16240:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  16241:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   16242:         $newvals{'xmldc'} = '';
                   16243:     } 
                   16244:     %autocreatehash =  (
                   16245:                         autocreate => { xml => $newvals{'xml'},
                   16246:                                         req => $newvals{'req'},
                   16247:                                       }
                   16248:                        );
                   16249:     if ($newvals{'xmldc'} ne '') {
                   16250:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   16251:     }
                   16252:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   16253:                                              $dom);
                   16254:     if ($putresult eq 'ok') {
                   16255:         my @items = @types;
                   16256:         if ($newvals{'xml'}) {
                   16257:             push(@items,'xmldc');
                   16258:         }
                   16259:         foreach my $item (@items) {
                   16260:             if (exists($currautocreate{$item})) {
                   16261:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   16262:                     $changes{$item} = 1;
                   16263:                 }
                   16264:             } elsif ($newvals{$item}) {
                   16265:                 $changes{$item} = 1;
                   16266:             }
                   16267:         }
                   16268:         if (keys(%changes) > 0) {
                   16269:             my @offon = ('off','on'); 
                   16270:             $resulttext = &mt('Changes made:').'<ul>';
                   16271:             foreach my $item (@types) {
                   16272:                 if ($changes{$item}) {
                   16273:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  16274:                     $resulttext .= '<li>'.
                   16275:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   16276:                                        '<b>','</b>').
                   16277:                                    '</li>';
1.125     raeburn  16278:                 }
                   16279:             }
                   16280:             if ($changes{'xmldc'}) {
                   16281:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   16282:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  16283:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  16284:             }
                   16285:             $resulttext .= '</ul>';
                   16286:         } else {
                   16287:             $resulttext = &mt('No changes made to auto-creation settings');
                   16288:         }
                   16289:     } else {
                   16290:         $resulttext = '<span class="LC_error">'.
                   16291:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16292:     }
                   16293:     return $resulttext;
                   16294: }
                   16295: 
1.23      raeburn  16296: sub modify_directorysrch {
1.295     raeburn  16297:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  16298:     my ($resulttext,%changes);
                   16299:     my %currdirsrch;
                   16300:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   16301:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   16302:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   16303:         }
                   16304:     }
1.277     raeburn  16305:     my %title = ( available => 'Institutional directory search available',
                   16306:                   localonly => 'Other domains can search institution',
                   16307:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  16308:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  16309:                   searchby => 'Search types',
                   16310:                   searchtypes => 'Search latitude');
                   16311:     my @offon = ('off','on');
1.24      raeburn  16312:     my @otherdoms = ('Yes','No');
1.23      raeburn  16313: 
1.25      raeburn  16314:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  16315:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   16316:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   16317: 
1.44      raeburn  16318:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  16319:     if (keys(%{$usertypes}) == 0) {
                   16320:         @cansearch = ('default');
                   16321:     } else {
                   16322:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   16323:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   16324:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   16325:                     push(@{$changes{'cansearch'}},$type);
                   16326:                 }
1.23      raeburn  16327:             }
1.26      raeburn  16328:             foreach my $type (@cansearch) {
                   16329:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   16330:                     push(@{$changes{'cansearch'}},$type);
                   16331:                 }
1.23      raeburn  16332:             }
1.26      raeburn  16333:         } else {
                   16334:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  16335:         }
                   16336:     }
                   16337: 
                   16338:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   16339:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   16340:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   16341:                 push(@{$changes{'searchby'}},$by);
                   16342:             }
                   16343:         }
                   16344:         foreach my $by (@searchby) {
                   16345:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   16346:                 push(@{$changes{'searchby'}},$by);
                   16347:             }
                   16348:         }
                   16349:     } else {
                   16350:         push(@{$changes{'searchby'}},@searchby);
                   16351:     }
1.25      raeburn  16352: 
                   16353:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   16354:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   16355:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   16356:                 push(@{$changes{'searchtypes'}},$type);
                   16357:             }
                   16358:         }
                   16359:         foreach my $type (@searchtypes) {
                   16360:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   16361:                 push(@{$changes{'searchtypes'}},$type);
                   16362:             }
                   16363:         }
                   16364:     } else {
                   16365:         if (exists($currdirsrch{'searchtypes'})) {
                   16366:             foreach my $type (@searchtypes) {  
                   16367:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   16368:                     push(@{$changes{'searchtypes'}},$type);
                   16369:                 }
                   16370:             }
                   16371:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   16372:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   16373:             }   
                   16374:         } else {
                   16375:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   16376:         }
                   16377:     }
                   16378: 
1.23      raeburn  16379:     my %dirsrch_hash =  (
                   16380:             directorysrch => { available => $env{'form.dirsrch_available'},
                   16381:                                cansearch => \@cansearch,
1.277     raeburn  16382:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   16383:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   16384:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  16385:                                searchby => \@searchby,
1.25      raeburn  16386:                                searchtypes => \@searchtypes,
1.23      raeburn  16387:                              }
                   16388:             );
                   16389:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   16390:                                              $dom);
                   16391:     if ($putresult eq 'ok') {
                   16392:         if (exists($currdirsrch{'available'})) {
                   16393:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   16394:                  $changes{'available'} = 1;
                   16395:              }
                   16396:         } else {
                   16397:             if ($env{'form.dirsrch_available'} eq '1') {
                   16398:                 $changes{'available'} = 1;
                   16399:             }
                   16400:         }
1.277     raeburn  16401:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  16402:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   16403:                 $changes{'lcavailable'} = 1;
                   16404:             }
1.277     raeburn  16405:         } else {
                   16406:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   16407:                 $changes{'lcavailable'} = 1;
                   16408:             }
                   16409:         }
1.24      raeburn  16410:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  16411:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   16412:                 $changes{'localonly'} = 1;
                   16413:             }
1.24      raeburn  16414:         } else {
1.277     raeburn  16415:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  16416:                 $changes{'localonly'} = 1;
                   16417:             }
                   16418:         }
1.277     raeburn  16419:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  16420:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   16421:                 $changes{'lclocalonly'} = 1;
                   16422:             }
1.277     raeburn  16423:         } else {
                   16424:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   16425:                 $changes{'lclocalonly'} = 1;
                   16426:             }
                   16427:         }
1.23      raeburn  16428:         if (keys(%changes) > 0) {
                   16429:             $resulttext = &mt('Changes made:').'<ul>';
                   16430:             if ($changes{'available'}) {
                   16431:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   16432:             }
1.277     raeburn  16433:             if ($changes{'lcavailable'}) {
                   16434:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   16435:             }
1.24      raeburn  16436:             if ($changes{'localonly'}) {
1.277     raeburn  16437:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  16438:             }
1.277     raeburn  16439:             if ($changes{'lclocalonly'}) {
                   16440:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  16441:             }
1.23      raeburn  16442:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   16443:                 my $chgtext;
1.26      raeburn  16444:                 if (ref($usertypes) eq 'HASH') {
                   16445:                     if (keys(%{$usertypes}) > 0) {
                   16446:                         foreach my $type (@{$types}) {
                   16447:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   16448:                                 $chgtext .= $usertypes->{$type}.'; ';
                   16449:                             }
                   16450:                         }
                   16451:                         if (grep(/^default$/,@cansearch)) {
                   16452:                             $chgtext .= $othertitle;
                   16453:                         } else {
                   16454:                             $chgtext =~ s/\; $//;
                   16455:                         }
1.210     raeburn  16456:                         $resulttext .=
1.178     raeburn  16457:                             '<li>'.
                   16458:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   16459:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   16460:                             '</li>';
1.23      raeburn  16461:                     }
                   16462:                 }
                   16463:             }
                   16464:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   16465:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   16466:                 my $chgtext;
                   16467:                 foreach my $type (@{$titleorder}) {
                   16468:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   16469:                         if (defined($searchtitles->{$type})) {
                   16470:                             $chgtext .= $searchtitles->{$type}.'; ';
                   16471:                         }
                   16472:                     }
                   16473:                 }
                   16474:                 $chgtext =~ s/\; $//;
                   16475:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   16476:             }
1.25      raeburn  16477:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   16478:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   16479:                 my $chgtext;
                   16480:                 foreach my $type (@{$srchtypeorder}) {
                   16481:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   16482:                         if (defined($srchtypes_desc->{$type})) {
                   16483:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   16484:                         }
                   16485:                     }
                   16486:                 }
                   16487:                 $chgtext =~ s/\; $//;
1.178     raeburn  16488:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  16489:             }
                   16490:             $resulttext .= '</ul>';
1.295     raeburn  16491:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   16492:             if (ref($lastactref) eq 'HASH') {
                   16493:                 $lastactref->{'directorysrch'} = 1;
                   16494:             }
1.23      raeburn  16495:         } else {
1.277     raeburn  16496:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  16497:         }
                   16498:     } else {
                   16499:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  16500:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   16501:     }
                   16502:     return $resulttext;
                   16503: }
                   16504: 
1.28      raeburn  16505: sub modify_contacts {
1.205     raeburn  16506:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  16507:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   16508:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   16509:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   16510:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   16511:         }
                   16512:     }
1.286     raeburn  16513:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  16514:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  16515:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350     raeburn  16516:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340     raeburn  16517:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   16518:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286     raeburn  16519:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  16520:     foreach my $type (@mailings) {
                   16521:         @{$newsetting{$type}} = 
                   16522:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   16523:         foreach my $item (@contacts) {
                   16524:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   16525:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   16526:             } else {
                   16527:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   16528:             }
1.289     raeburn  16529:         }
1.28      raeburn  16530:         $others{$type} = $env{'form.'.$type.'_others'};
                   16531:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  16532:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16533:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   16534:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  16535:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   16536:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   16537:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   16538:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   16539:             }
1.134     raeburn  16540:         }
1.28      raeburn  16541:     }
                   16542:     foreach my $item (@contacts) {
                   16543:         $to{$item} = $env{'form.'.$item};
                   16544:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   16545:     }
1.203     raeburn  16546:     foreach my $item (@toggles) {
                   16547:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   16548:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   16549:         }
                   16550:     }
1.340     raeburn  16551:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   16552:     foreach my $item (@lonstatus) {
                   16553:         if ($item eq 'excluded') {
                   16554:             my (%serverhomes,@excluded);
                   16555:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   16556:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   16557:             if (@possexcluded) {
                   16558:                 foreach my $id (sort(@possexcluded)) {
                   16559:                     if ($serverhomes{$id}) {
                   16560:                         push(@excluded,$id);
                   16561:                     }
                   16562:                 }
                   16563:             }
                   16564:             if (@excluded) {
                   16565:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   16566:             }
                   16567:         } elsif ($item eq 'weights') {
1.377     raeburn  16568:             foreach my $type ('E','W','N','U') {
1.340     raeburn  16569:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   16570:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   16571:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   16572:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   16573:                             $env{'form.error'.$item.'_'.$type};
                   16574:                     }
                   16575:                 }
                   16576:             }
                   16577:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   16578:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   16579:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   16580:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   16581:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   16582:                 }
                   16583:             }
                   16584:         }
                   16585:     }
1.286     raeburn  16586:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   16587:         foreach my $field (@{$fields}) {
                   16588:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   16589:                 my $value = $env{'form.helpform_'.$field};
                   16590:                 $value =~ s/^\s+|\s+$//g;
                   16591:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  16592:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  16593:                     if ($field eq 'screenshot') {
                   16594:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   16595:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  16596:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  16597:                         }
                   16598:                     }
                   16599:                 }
                   16600:             }
                   16601:         }
                   16602:     }
1.315     raeburn  16603:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   16604:     my (@statuses,%usertypeshash,@overrides);
                   16605:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   16606:         @statuses = @{$types};
                   16607:         if (ref($usertypes) eq 'HASH') {
                   16608:             %usertypeshash = %{$usertypes};
                   16609:         }
                   16610:     }
                   16611:     if (@statuses) {
                   16612:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   16613:         foreach my $type (@possoverrides) {
                   16614:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   16615:                 push(@overrides,$type);
                   16616:             }
                   16617:         }
                   16618:         if (@overrides) {
                   16619:             foreach my $type (@overrides) {
                   16620:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   16621:                 foreach my $item (@contacts) {
                   16622:                     if (grep(/^\Q$item\E$/,@standard)) {
                   16623:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   16624:                         $newsetting{'override_'.$type}{$item} = 1;
                   16625:                     } else {
                   16626:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   16627:                         $newsetting{'override_'.$type}{$item} = 0;
                   16628:                     }
                   16629:                 }
                   16630:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   16631:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   16632:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   16633:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   16634:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   16635:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   16636:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   16637:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   16638:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   16639:                 }
                   16640:             }     
                   16641:         }
                   16642:     }
1.28      raeburn  16643:     if (keys(%currsetting) > 0) {
                   16644:         foreach my $item (@contacts) {
                   16645:             if ($to{$item} ne $currsetting{$item}) {
                   16646:                 $changes{$item} = 1;
                   16647:             }
                   16648:         }
                   16649:         foreach my $type (@mailings) {
                   16650:             foreach my $item (@contacts) {
                   16651:                 if (ref($currsetting{$type}) eq 'HASH') {
                   16652:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   16653:                         push(@{$changes{$type}},$item);
                   16654:                     }
                   16655:                 } else {
                   16656:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   16657:                 }
                   16658:             }
                   16659:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   16660:                 push(@{$changes{$type}},'others');
                   16661:             }
1.289     raeburn  16662:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16663:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   16664:                     push(@{$changes{$type}},'bcc'); 
                   16665:                 }
1.286     raeburn  16666:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   16667:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   16668:                     push(@{$changes{$type}},'include');
                   16669:                 }
                   16670:             }
                   16671:         }
                   16672:         if (ref($fields) eq 'ARRAY') {
                   16673:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   16674:                 foreach my $field (@{$fields}) {
                   16675:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   16676:                         push(@{$changes{'helpform'}},$field);
                   16677:                     }
                   16678:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16679:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   16680:                             push(@{$changes{'helpform'}},'maxsize');
                   16681:                         }
                   16682:                     }
                   16683:                 }
                   16684:             } else {
                   16685:                 foreach my $field (@{$fields}) {
                   16686:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   16687:                         push(@{$changes{'helpform'}},$field);
                   16688:                     }
                   16689:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16690:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   16691:                             push(@{$changes{'helpform'}},'maxsize');
                   16692:                         }
                   16693:                     }
                   16694:                 }
1.134     raeburn  16695:             }
1.28      raeburn  16696:         }
1.315     raeburn  16697:         if (@statuses) {
                   16698:             if (ref($currsetting{'overrides'}) eq 'HASH') { 
                   16699:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   16700:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   16701:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   16702:                             foreach my $item (@contacts,'bcc','others','include') {
                   16703:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
                   16704:                                     push(@{$changes{'overrides'}},$key);
                   16705:                                     last;
                   16706:                                 }
                   16707:                             }
                   16708:                         } else {
                   16709:                             push(@{$changes{'overrides'}},$key);
                   16710:                         }
                   16711:                     }
                   16712:                 }
                   16713:                 foreach my $key (@overrides) {
                   16714:                     unless (exists($currsetting{'overrides'}{$key})) {
                   16715:                         push(@{$changes{'overrides'}},$key);
                   16716:                     }
                   16717:                 }
                   16718:             } else {
                   16719:                 foreach my $key (@overrides) {
                   16720:                     push(@{$changes{'overrides'}},$key); 
                   16721:                 }
                   16722:             }
                   16723:         }
1.340     raeburn  16724:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   16725:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   16726:                 if ($key eq 'excluded') {
                   16727:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   16728:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   16729:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   16730:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   16731:                             my @diffs =
                   16732:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   16733:                                                                    $currsetting{'lonstatus'}{$key});
                   16734:                             if (@diffs) {
                   16735:                                 push(@{$changes{'lonstatus'}},$key);
                   16736:                             }
                   16737:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   16738:                             push(@{$changes{'lonstatus'}},$key);
                   16739:                         }
                   16740:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   16741:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   16742:                         push(@{$changes{'lonstatus'}},$key);
                   16743:                     }
                   16744:                 } elsif ($key eq 'weights') {
                   16745:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   16746:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   16747:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  16748:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  16749:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   16750:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   16751:                                     push(@{$changes{'lonstatus'}},$key);
                   16752:                                     last;
                   16753:                                 }
                   16754:                             }
                   16755:                         } else {
1.341     raeburn  16756:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  16757:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   16758:                                     push(@{$changes{'lonstatus'}},$key);
                   16759:                                     last;
                   16760:                                 }
                   16761:                             }
                   16762:                         }
                   16763:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  16764:                         foreach my $type ('E','W','N','U') {
1.340     raeburn  16765:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   16766:                                 push(@{$changes{'lonstatus'}},$key);
                   16767:                                 last;
                   16768:                             }
                   16769:                         }
                   16770:                     }
                   16771:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   16772:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16773:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   16774:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   16775:                                 push(@{$changes{'lonstatus'}},$key);
                   16776:                             }
                   16777:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   16778:                             push(@{$changes{'lonstatus'}},$key);
                   16779:                         }
                   16780:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   16781:                         push(@{$changes{'lonstatus'}},$key);
                   16782:                     }
                   16783:                 }
                   16784:             }
                   16785:         } else {
                   16786:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16787:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   16788:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   16789:                         push(@{$changes{'lonstatus'}},$key);
                   16790:                     }
                   16791:                 }
                   16792:             }
                   16793:         }
1.28      raeburn  16794:     } else {
                   16795:         my %default;
                   16796:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   16797:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   16798:         $default{'errormail'} = 'adminemail';
                   16799:         $default{'packagesmail'} = 'adminemail';
                   16800:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  16801:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  16802:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  16803:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  16804:         $default{'updatesmail'} = 'adminemail';
1.350     raeburn  16805:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  16806:         foreach my $item (@contacts) {
                   16807:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  16808:                $changes{$item} = 1;
1.203     raeburn  16809:            }
1.28      raeburn  16810:         }
                   16811:         foreach my $type (@mailings) {
                   16812:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   16813:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   16814:             }
                   16815:             if ($others{$type} ne '') {
                   16816:                 push(@{$changes{$type}},'others');
1.134     raeburn  16817:             }
1.286     raeburn  16818:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16819:                 if ($bcc{$type} ne '') {
                   16820:                     push(@{$changes{$type}},'bcc');
                   16821:                 }
1.286     raeburn  16822:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   16823:                     push(@{$changes{$type}},'include');
                   16824:                 }
1.134     raeburn  16825:             }
1.28      raeburn  16826:         }
1.286     raeburn  16827:         if (ref($fields) eq 'ARRAY') {
                   16828:             foreach my $field (@{$fields}) {
                   16829:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   16830:                     push(@{$changes{'helpform'}},$field);
                   16831:                 }
                   16832:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   16833:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   16834:                         push(@{$changes{'helpform'}},'maxsize');
                   16835:                     }
                   16836:                 }
                   16837:             }
1.289     raeburn  16838:         }
1.340     raeburn  16839:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   16840:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   16841:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   16842:                     push(@{$changes{'lonstatus'}},$key);
                   16843:                 }
                   16844:             }
                   16845:         }
1.28      raeburn  16846:     }
1.203     raeburn  16847:     foreach my $item (@toggles) {
                   16848:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   16849:             $changes{$item} = 1;
                   16850:         } elsif ((!$env{'form.'.$item}) &&
                   16851:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   16852:             $changes{$item} = 1;
                   16853:         }
                   16854:     }
1.28      raeburn  16855:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   16856:                                              $dom);
                   16857:     if ($putresult eq 'ok') {
                   16858:         if (keys(%changes) > 0) {
1.205     raeburn  16859:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16860:             if (ref($lastactref) eq 'HASH') {
                   16861:                 $lastactref->{'domainconfig'} = 1;
                   16862:             }
1.28      raeburn  16863:             my ($titles,$short_titles)  = &contact_titles();
                   16864:             $resulttext = &mt('Changes made:').'<ul>';
                   16865:             foreach my $item (@contacts) {
                   16866:                 if ($changes{$item}) {
                   16867:                     $resulttext .= '<li>'.$titles->{$item}.
                   16868:                                     &mt(' set to: ').
                   16869:                                     '<span class="LC_cusr_emph">'.
                   16870:                                     $to{$item}.'</span></li>';
                   16871:                 }
                   16872:             }
                   16873:             foreach my $type (@mailings) {
                   16874:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  16875:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  16876:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  16877:                     } else {
                   16878:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   16879:                     }
1.28      raeburn  16880:                     my @text;
                   16881:                     foreach my $item (@{$newsetting{$type}}) {
                   16882:                         push(@text,$short_titles->{$item});
                   16883:                     }
                   16884:                     if ($others{$type} ne '') {
                   16885:                         push(@text,$others{$type});
                   16886:                     }
1.286     raeburn  16887:                     if (@text) {
                   16888:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   16889:                                        join(', ',@text).'</span>';
                   16890:                     }
                   16891:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  16892:                         if ($bcc{$type} ne '') {
1.286     raeburn  16893:                             my $bcctext;
                   16894:                             if (@text) {
1.289     raeburn  16895:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  16896:                             } else {
                   16897:                                 $bcctext = '(Bcc)';
                   16898:                             }
                   16899:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   16900:                         } elsif (!@text) {
                   16901:                             $resulttext .= &mt('No one');
                   16902:                         }   
1.289     raeburn  16903:                         if ($includestr{$type} ne '') {
1.286     raeburn  16904:                             if ($includeloc{$type} eq 'b') {
                   16905:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   16906:                             } elsif ($includeloc{$type} eq 's') {
                   16907:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   16908:                             }
1.134     raeburn  16909:                         }
1.286     raeburn  16910:                     } elsif (!@text) {
                   16911:                         $resulttext .= &mt('No recipients');
1.134     raeburn  16912:                     }
                   16913:                     $resulttext .= '</li>';
1.28      raeburn  16914:                 }
                   16915:             }
1.315     raeburn  16916:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   16917:                 my @deletions;
                   16918:                 foreach my $type (@{$changes{'overrides'}}) {
                   16919:                     if ($usertypeshash{$type}) {
                   16920:                         if (grep(/^\Q$type\E/,@overrides)) {
                   16921:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   16922:                                                       $usertypeshash{$type}).'<ul><li>';
                   16923:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   16924:                                 my @text;
                   16925:                                 foreach my $item (@contacts) {
                   16926:                                     if ($newsetting{'override_'.$type}{$item}) { 
                   16927:                                         push(@text,$short_titles->{$item});
                   16928:                                     }
                   16929:                                 }
                   16930:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   16931:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   16932:                                 }
                   16933:   
                   16934:                                 if (@text) {
                   16935:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   16936:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   16937:                                 }
                   16938:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   16939:                                     my $bcctext;
                   16940:                                     if (@text) {
                   16941:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   16942:                                     } else {
                   16943:                                         $bcctext = '(Bcc)';
                   16944:                                     }
                   16945:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   16946:                                 } elsif (!@text) {
                   16947:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   16948:                                 }
                   16949:                                 $resulttext .= '</li>';
                   16950:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   16951:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   16952:                                     if ($loc eq 'b') {
                   16953:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   16954:                                     } elsif ($loc eq 's') {
                   16955:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   16956:                                     }
                   16957:                                 }
                   16958:                             }
                   16959:                             $resulttext .= '</li></ul></li>';
                   16960:                         } else {
                   16961:                             push(@deletions,$usertypeshash{$type});
                   16962:                         }
                   16963:                     }
                   16964:                 }
                   16965:                 if (@deletions) {
                   16966:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   16967:                                               join(', ',@deletions)).'</li>';
                   16968:                 }
                   16969:             }
1.203     raeburn  16970:             my @offon = ('off','on');
1.340     raeburn  16971:             my $corelink = &core_link_msu();
1.203     raeburn  16972:             if ($changes{'reporterrors'}) {
                   16973:                 $resulttext .= '<li>'.
                   16974:                                &mt('E-mail error reports to [_1] set to "'.
                   16975:                                    $offon[$env{'form.reporterrors'}].'".',
1.340     raeburn  16976:                                    $corelink).
1.203     raeburn  16977:                                '</li>';
                   16978:             }
                   16979:             if ($changes{'reportupdates'}) {
                   16980:                 $resulttext .= '<li>'.
                   16981:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   16982:                                     $offon[$env{'form.reportupdates'}].'".',
1.340     raeburn  16983:                                     $corelink).
1.203     raeburn  16984:                                 '</li>';
                   16985:             }
1.340     raeburn  16986:             if ($changes{'reportstatus'}) {
                   16987:                 $resulttext .= '<li>'.
                   16988:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   16989:                                     $offon[$env{'form.reportstatus'}].'".',
                   16990:                                     $corelink).
                   16991:                                 '</li>';
                   16992:             }
                   16993:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   16994:                 $resulttext .= '<li>'.
                   16995:                                &mt('Nightly status check e-mail settings').':<ul>';
                   16996:                 my (%defval,%use_def,%shown);
                   16997:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   16998:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   16999:                 $defval{'weights'} =
1.341     raeburn  17000:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340     raeburn  17001:                 $defval{'excluded'} = &mt('None');
                   17002:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   17003:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   17004:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   17005:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   17006:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   17007:                             } elsif ($item eq 'weights') {
                   17008:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341     raeburn  17009:                                     foreach my $type ('E','W','N','U') {
1.340     raeburn  17010:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   17011:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   17012:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   17013:                                         } else {
                   17014:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   17015:                                         }
                   17016:                                         $shown{$item} .= ', ';
                   17017:                                     }
                   17018:                                     $shown{$item} =~ s/, $//;
                   17019:                                 } else {
                   17020:                                     $shown{$item} = $defval{$item};
                   17021:                                 }
                   17022:                             } elsif ($item eq 'excluded') {
                   17023:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   17024:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   17025:                                 } else {
                   17026:                                     $shown{$item} = $defval{$item};
                   17027:                                 }
                   17028:                             }
                   17029:                         } else {
                   17030:                             $shown{$item} = $defval{$item};
                   17031:                         }
                   17032:                     }
                   17033:                 } else {
                   17034:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   17035:                         $shown{$item} = $defval{$item};
                   17036:                     }
                   17037:                 }
                   17038:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   17039:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   17040:                                           $shown{$item}).'</li>';
                   17041:                 }
                   17042:                 $resulttext .= '</ul></li>';
                   17043:             }
1.286     raeburn  17044:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   17045:                 my (@optional,@required,@unused,$maxsizechg);
                   17046:                 foreach my $field (@{$changes{'helpform'}}) {
                   17047:                     if ($field eq 'maxsize') {
                   17048:                         $maxsizechg = 1;
                   17049:                         next;
                   17050:                     }
                   17051:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  17052:                         push(@optional,$field);
1.286     raeburn  17053:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   17054:                         push(@unused,$field);
                   17055:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  17056:                         push(@required,$field);
1.286     raeburn  17057:                     }
                   17058:                 }
                   17059:                 if (@optional) {
                   17060:                     $resulttext .= '<li>'.
                   17061:                                    &mt('Help form fields changed to "Optional": [_1].',
                   17062:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   17063:                                    '</li>';
                   17064:                 }
                   17065:                 if (@required) {
                   17066:                     $resulttext .= '<li>'.
                   17067:                                    &mt('Help form fields changed to "Required": [_1].',
                   17068:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   17069:                                    '</li>';
                   17070:                 }
                   17071:                 if (@unused) {
                   17072:                     $resulttext .= '<li>'.
                   17073:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   17074:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   17075:                                    '</li>';
                   17076:                 }
                   17077:                 if ($maxsizechg) {
                   17078:                     $resulttext .= '<li>'.
                   17079:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   17080:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   17081:                                    '</li>';
                   17082:                 }
                   17083:             }
1.28      raeburn  17084:             $resulttext .= '</ul>';
                   17085:         } else {
1.288     raeburn  17086:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  17087:         }
                   17088:     } else {
                   17089:         $resulttext = '<span class="LC_error">'.
                   17090:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   17091:     }
                   17092:     return $resulttext;
                   17093: }
                   17094: 
1.357     raeburn  17095: sub modify_privacy {
                   17096:     my ($dom,%domconfig) = @_;
                   17097:     my ($resulttext,%current,%changes);
                   17098:     if (ref($domconfig{'privacy'}) eq 'HASH') {
                   17099:         %current = %{$domconfig{'privacy'}};
                   17100:     }
                   17101:     my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
                   17102:     my @items = ('domain','author','course','community');
                   17103:     my %names = &Apache::lonlocal::texthash (
                   17104:                    domain => 'Assigned domain role(s)',
                   17105:                    author => 'Assigned co-author role(s)',
                   17106:                    course => 'Assigned course role(s)',
                   17107:                    community => 'Assigned community role',
                   17108:                 );
                   17109:     my %roles = &Apache::lonlocal::texthash (
                   17110:                    domain => 'Domain role',
                   17111:                    author => 'Co-author role',
                   17112:                    course => 'Course role',
                   17113:                    community => 'Community role',
                   17114:                 );
                   17115:     my %titles = &Apache::lonlocal::texthash (
                   17116:                   approval => 'Approval for role in different domain',
                   17117:                   othdom   => 'User information available in other domain',
                   17118:                   priv     => 'Information viewable by privileged user in same domain',
                   17119:                   unpriv   => 'Information viewable by unprivileged user in same domain',
                   17120:                   instdom  => 'Other domain shares institution/provider',
                   17121:                   extdom   => 'Other domain has different institution/provider',
                   17122:                   none     => 'Not allowed',
                   17123:                   user     => 'User authorizes',
                   17124:                   domain   => 'Domain Coordinator authorizes',
                   17125:                   auto     => 'Unrestricted',
                   17126:     );
                   17127:     my %fieldnames = &Apache::lonlocal::texthash (
                   17128:                         id => 'Student/Employee ID',
                   17129:                         permanentemail => 'E-mail address',
                   17130:                         lastname => 'Last Name',
                   17131:                         firstname => 'First Name',
                   17132:                         middlename => 'Middle Name',
                   17133:                         generation => 'Generation',
                   17134:     );
                   17135:     my ($othertitle,$usertypes,$types) =
                   17136:         &Apache::loncommon::sorted_inst_types($dom);
                   17137:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   17138:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   17139: 
                   17140:     my %privacyhash = (
                   17141:                        'approval' => {
                   17142:                                        instdom => {},
                   17143:                                        extdom  => {},
                   17144:                                      },
                   17145:                        'othdom'   => {},
                   17146:                        'priv'     => {},
                   17147:                        'unpriv'   => {},
                   17148:                       );
                   17149:     foreach my $item (@items) {
                   17150:         if (@instdoms > 1) {
                   17151:             if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
                   17152:                 $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
                   17153:             }
                   17154:             if (ref($current{'approval'}) eq 'HASH') {
                   17155:                 if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                   17156:                     unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                   17157:                         $changes{'approval'} = 1;
                   17158:                     }
                   17159:                 }
                   17160:             } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   17161:                 $changes{'approval'} = 1;
                   17162:             }
                   17163:         }
                   17164:         if (keys(%by_location) > 0) {
                   17165:             if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   17166:                 $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
                   17167:             }
                   17168:             if (ref($current{'approval'}) eq 'HASH') {
                   17169:                 if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                   17170:                     unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                   17171:                         $changes{'approval'} = 1;
                   17172:                     }
                   17173:                 }
                   17174:             } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   17175:                 $changes{'approval'} = 1;
                   17176:             }
                   17177:         }
                   17178:         foreach my $status ('priv','unpriv') {
                   17179:             my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
                   17180:             my @newvalues;
                   17181:             foreach my $field (@possibles) {
                   17182:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17183:                     $privacyhash{$status}{$item}{$field} = 1;
                   17184:                     push(@newvalues,$field);
                   17185:                 }
                   17186:             }
                   17187:             @newvalues = sort(@newvalues);
                   17188:             if (ref($current{$status}) eq 'HASH') {
                   17189:                 if (ref($current{$status}{$item}) eq 'HASH') {
                   17190:                     my @currvalues = sort(keys(%{$current{$status}{$item}}));
                   17191:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17192:                     if (@diffs > 0) {
                   17193:                         $changes{$status} = 1;
                   17194:                     }
                   17195:                 }
                   17196:             } else {
                   17197:                 my @stdfields;
                   17198:                 foreach my $field (@fields) {
                   17199:                     if ($field eq 'id') {
                   17200:                         next if ($status eq 'unpriv');
                   17201:                         next if (($status eq 'priv') && ($item eq 'community'));
                   17202:                     }
                   17203:                     push(@stdfields,$field);
                   17204:                 }
                   17205:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17206:                 if (@diffs > 0) {
                   17207:                     $changes{$status} = 1;
                   17208:                 }
                   17209:             }
                   17210:         }
                   17211:     }
                   17212:     if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   17213:         my @statuses;
                   17214:         if (ref($types) eq 'ARRAY') {
                   17215:             @statuses = @{$types};
                   17216:         }
                   17217:         foreach my $type (@statuses,'default') {
                   17218:             my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
                   17219:             my @newvalues;
                   17220:             foreach my $field (sort(@possfields)) {
                   17221:                 if (grep(/^\Q$field\E$/,@fields)) {
                   17222:                     $privacyhash{'othdom'}{$type}{$field} = 1;
                   17223:                     push(@newvalues,$field);
                   17224:                 }
                   17225:             }
                   17226:             @newvalues = sort(@newvalues);
                   17227:             if (ref($current{'othdom'}) eq 'HASH') {
                   17228:                 if (ref($current{'othdom'}{$type}) eq 'HASH') {
                   17229:                     my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                   17230:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   17231:                     if (@diffs > 0) {
                   17232:                         $changes{'othdom'} = 1;
                   17233:                     }
                   17234:                 }
                   17235:             } else {
                   17236:                 my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   17237:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   17238:                 if (@diffs > 0) {
                   17239:                     $changes{'othdom'} = 1;
                   17240:                 }
                   17241:             }
                   17242:         }
                   17243:     }
                   17244:     my %confighash = (
                   17245:                         privacy => \%privacyhash,
                   17246:                      );
                   17247:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   17248:     if ($putresult eq 'ok') {
                   17249:         if (keys(%changes) > 0) {
                   17250:             $resulttext = &mt('Changes made: ').'<ul>';
                   17251:             foreach my $key ('approval','othdom','priv','unpriv') {
                   17252:                 if ($changes{$key}) {
                   17253:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   17254:                     if ($key eq 'approval') {
                   17255:                         if (keys(%{$privacyhash{$key}{instdom}})) {
                   17256:                             $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                   17257:                             foreach my $item (@items) {
                   17258:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                   17259:                             }
                   17260:                             $resulttext .= '</ul></li>';
                   17261:                         }
                   17262:                         if (keys(%{$privacyhash{$key}{extdom}})) {
                   17263:                             $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                   17264:                             foreach my $item (@items) {
                   17265:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                   17266:                             }
                   17267:                             $resulttext .= '</ul></li>';
                   17268:                         }
                   17269:                     } elsif ($key eq 'othdom') {
                   17270:                         my @statuses;
                   17271:                         if (ref($types) eq 'ARRAY') {
                   17272:                             @statuses = @{$types};
                   17273:                         }
                   17274:                         if (ref($privacyhash{$key}) eq 'HASH') {
                   17275:                             foreach my $status (@statuses,'default') {
                   17276:                                 if ($status eq 'default') {
                   17277:                                     $resulttext .= '<li>'.$othertitle.': ';
                   17278:                                 } elsif (ref($usertypes) eq 'HASH') {
                   17279:                                     $resulttext .= '<li>'.$usertypes->{$status}.': ';
                   17280:                                 } else {
                   17281:                                     next;
                   17282:                                 }
                   17283:                                 if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                   17284:                                     if (keys(%{$privacyhash{$key}{$status}})) {
                   17285:                                         $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                   17286:                                     } else {
                   17287:                                         $resulttext .= &mt('none');
                   17288:                                     }
                   17289:                                 }
                   17290:                                 $resulttext .= '</li>';
                   17291:                             }
                   17292:                         }
                   17293:                     } else {
                   17294:                         foreach my $item (@items) {
                   17295:                             if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                   17296:                                 $resulttext .= '<li>'.$names{$item}.': ';
                   17297:                                 if (keys(%{$privacyhash{$key}{$item}})) {
                   17298:                                     $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                   17299:                                 } else {
                   17300:                                     $resulttext .= &mt('none');
                   17301:                                 }
                   17302:                                 $resulttext .= '</li>';
                   17303:                             }
                   17304:                         }
                   17305:                     }
                   17306:                     $resulttext .= '</ul></li>';
                   17307:                 }
                   17308:             }
                   17309:         } else {
                   17310:             $resulttext = &mt('No changes made to user information settings');
                   17311:         }
                   17312:     } else {
                   17313:         $resulttext = '<span class="LC_error">'.
                   17314:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17315:     }
                   17316:     return $resulttext;
                   17317: }
                   17318: 
1.354     raeburn  17319: sub modify_passwords {
                   17320:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355     raeburn  17321:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   17322:         $updatedefaults,$updateconf);
1.354     raeburn  17323:     my $customfn = 'resetpw.html';
                   17324:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   17325:         %current = %{$domconfig{'passwords'}};
                   17326:     }
                   17327:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   17328:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   17329:     if (ref($types) eq 'ARRAY') {
                   17330:         @oktypes = @{$types};
                   17331:     }
                   17332:     push(@oktypes,'default');
                   17333: 
                   17334:     my %titles = &Apache::lonlocal::texthash (
                   17335:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   17336:         intauth_check  => 'Check bcrypt cost if authenticated',
                   17337:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   17338:         permanent      => 'Permanent e-mail address',
                   17339:         critical       => 'Critical notification address',
                   17340:         notify         => 'Notification address',
                   17341:         min            => 'Minimum password length',
                   17342:         max            => 'Maximum password length',
                   17343:         chars          => 'Required characters',
                   17344:         expire         => 'Password expiration (days)',
1.356     raeburn  17345:         numsaved       => 'Number of previous passwords to save',
1.354     raeburn  17346:         reset          => 'Resetting Forgotten Password',
                   17347:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   17348:         rules          => 'Rules for LON-CAPA Passwords',
                   17349:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   17350:         username       => 'Username',
                   17351:         email          => 'E-mail address',
                   17352:     );
                   17353: 
                   17354: #
                   17355: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   17356: #
                   17357:     my (%curr_defaults,%save_defaults);
                   17358:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   17359:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   17360:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   17361:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   17362:             } else {
                   17363:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   17364:             }
                   17365:         }
                   17366:     }
                   17367:     my %staticdefaults = (
                   17368:         'resetlink'      => 2,
                   17369:         'resetcase'      => \@oktypes,
                   17370:         'resetprelink'   => 'both',
                   17371:         'resetemail'     => ['critical','notify','permanent'],
                   17372:         'intauth_cost'   => 10,
                   17373:         'intauth_check'  => 0,
                   17374:         'intauth_switch' => 0,
                   17375:     );
1.365     raeburn  17376:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354     raeburn  17377:     foreach my $type (@oktypes) {
                   17378:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   17379:     }
                   17380:     my $linklife = $env{'form.passwords_link'};
                   17381:     $linklife =~ s/^\s+|\s+$//g;
                   17382:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   17383:         $newvalues{'resetlink'} = $linklife;
                   17384:         if ($current{'resetlink'}) {
                   17385:             if ($current{'resetlink'} ne $linklife) {
                   17386:                 $changes{'reset'} = 1;
                   17387:             }
1.368     raeburn  17388:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17389:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   17390:                 $changes{'reset'} = 1;
                   17391:             }
                   17392:         }
                   17393:     } elsif ($current{'resetlink'}) {
                   17394:         $changes{'reset'} = 1;
                   17395:     }
                   17396:     my @casesens;
                   17397:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   17398:     foreach my $case (sort(@posscase)) {
                   17399:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   17400:             push(@casesens,$case);
                   17401:         }
                   17402:     }
                   17403:     $newvalues{'resetcase'} = \@casesens;
                   17404:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   17405:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   17406:         if (@diffs > 0) {
                   17407:             $changes{'reset'} = 1;
                   17408:         }
1.368     raeburn  17409:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17410:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   17411:         if (@diffs > 0) {
                   17412:             $changes{'reset'} = 1;
                   17413:         }
                   17414:     }
                   17415:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   17416:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   17417:         if (exists($current{'resetprelink'})) {
                   17418:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   17419:                 $changes{'reset'} = 1;
                   17420:             }
1.368     raeburn  17421:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17422:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   17423:                 $changes{'reset'} = 1;
                   17424:             }
                   17425:         }
                   17426:     } elsif ($current{'resetprelink'}) {
                   17427:         $changes{'reset'} = 1;
                   17428:     }
                   17429:     foreach my $type (@oktypes) {
                   17430:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   17431:         my @postlink;
                   17432:         foreach my $item (sort(@possplink)) {
                   17433:             if ($item =~ /^(email|username)$/) {
                   17434:                 push(@postlink,$item);
                   17435:             }
                   17436:         }
                   17437:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   17438:         unless ($changes{'reset'}) {
                   17439:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   17440:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   17441:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   17442:                     if (@diffs > 0) {
                   17443:                         $changes{'reset'} = 1;
                   17444:                     }
                   17445:                 } else {
                   17446:                     $changes{'reset'} = 1;
                   17447:                 }
1.368     raeburn  17448:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17449:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   17450:                 if (@diffs > 0) {
                   17451:                     $changes{'reset'} = 1;
                   17452:                 }
                   17453:             }
                   17454:         }
                   17455:     }
                   17456:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   17457:     my @resetemail;
                   17458:     foreach my $item (sort(@possemailsrc)) {
                   17459:         if ($item =~ /^(permanent|critical|notify)$/) {
                   17460:             push(@resetemail,$item);
                   17461:         }
                   17462:     }
                   17463:     $newvalues{'resetemail'} = \@resetemail;
                   17464:     unless ($changes{'reset'}) {
                   17465:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   17466:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   17467:             if (@diffs > 0) {
                   17468:                 $changes{'reset'} = 1;
                   17469:             }
1.368     raeburn  17470:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  17471:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   17472:             if (@diffs > 0) {
                   17473:                 $changes{'reset'} = 1;
                   17474:             }
                   17475:         }
                   17476:     }
                   17477:     if ($env{'form.passwords_stdtext'} == 0) {
                   17478:         $newvalues{'resetremove'} = 1;
                   17479:         unless ($current{'resetremove'}) {
                   17480:             $changes{'reset'} = 1;
                   17481:         }
                   17482:     } elsif ($current{'resetremove'}) {
                   17483:         $changes{'reset'} = 1;
                   17484:     }
                   17485:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   17486:         my $servadm = $r->dir_config('lonAdmEMail');
                   17487:         my ($configuserok,$author_ok,$switchserver) =
                   17488:             &config_check($dom,$confname,$servadm);
                   17489:         my $error;
                   17490:         if ($configuserok eq 'ok') {
                   17491:             if ($switchserver) {
                   17492:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   17493:             } else {
                   17494:                 if ($author_ok eq 'ok') {
                   17495:                     my ($result,$customurl) =
                   17496:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   17497:                                      $confname,'customtext/resetpw','','',$customfn);
                   17498:                     if ($result eq 'ok') {
                   17499:                         $newvalues{'resetcustom'} = $customurl;
                   17500:                         $changes{'reset'} = 1;
                   17501:                     } else {
                   17502:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   17503:                     }
                   17504:                 } else {
                   17505:                     $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);
                   17506:                 }
                   17507:             }
                   17508:         } else {
                   17509:             $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);
                   17510:         }
                   17511:         if ($error) {
                   17512:             &Apache::lonnet::logthis($error);
                   17513:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   17514:         }
                   17515:     } elsif ($current{'resetcustom'}) {
                   17516:         if ($env{'form.passwords_custom_del'}) {
                   17517:             $changes{'reset'} = 1;
                   17518:         } else {
                   17519:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   17520:         }
                   17521:     }
                   17522:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   17523:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   17524:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   17525:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   17526:             $changes{'intauth'} = 1;
                   17527:         }
                   17528:     } else {
                   17529:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   17530:     }
                   17531:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   17532:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   17533:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   17534:             $changes{'intauth'} = 1;
                   17535:         }
                   17536:     } else {
                   17537:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   17538:     }
                   17539:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   17540:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   17541:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   17542:             $changes{'intauth'} = 1;
                   17543:         }
                   17544:     } else {
                   17545:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   17546:     }
                   17547:     foreach my $item ('cost','check','switch') {
                   17548:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   17549:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   17550:             $updatedefaults = 1;
                   17551:         }
                   17552:     }
1.356     raeburn  17553:     foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  17554:         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356     raeburn  17555:         my $ruleok;
                   17556:         if ($rule eq 'expire') {
1.365     raeburn  17557:             if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
                   17558:                 ($env{'form.passwords_'.$rule} ne '0')) {
1.359     raeburn  17559:                 $ruleok = 1;
1.356     raeburn  17560:             }
1.365     raeburn  17561:         } elsif ($rule eq 'min') {
                   17562:             if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   17563:                 if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
                   17564:                     $ruleok = 1;
                   17565:                 }
                   17566:             }
                   17567:         } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
                   17568:                  ($env{'form.passwords_'.$rule} ne '0')) {
1.356     raeburn  17569:             $ruleok = 1;
                   17570:         }
                   17571:         if ($ruleok) {
1.354     raeburn  17572:             $newvalues{$rule} = $env{'form.passwords_'.$rule};
                   17573:             if (exists($current{$rule})) {
                   17574:                 if ($newvalues{$rule} ne $current{$rule}) {
                   17575:                     $changes{'rules'} = 1;
                   17576:                 }
                   17577:             } elsif ($rule eq 'min') {
                   17578:                 if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                   17579:                     $changes{'rules'} = 1;
                   17580:                 }
1.370     raeburn  17581:             } else {
                   17582:                 $changes{'rules'} = 1;
1.354     raeburn  17583:             }
                   17584:         } elsif (exists($current{$rule})) {
                   17585:             $changes{'rules'} = 1;
                   17586:         }
                   17587:     }
                   17588:     my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
                   17589:     my @chars;
                   17590:     foreach my $item (sort(@posschars)) {
                   17591:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   17592:             push(@chars,$item);
                   17593:         }
                   17594:     }
                   17595:     $newvalues{'chars'} = \@chars;
                   17596:     unless ($changes{'rules'}) {
                   17597:         if (ref($current{'chars'}) eq 'ARRAY') {
                   17598:             my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
                   17599:             if (@diffs > 0) {
                   17600:                 $changes{'rules'} = 1;
                   17601:             }
                   17602:         } else {
                   17603:             if (@chars > 0) {
                   17604:                 $changes{'rules'} = 1;
                   17605:             }
                   17606:         }
                   17607:     }
1.359     raeburn  17608:     my %crsownerchg = (
                   17609:                         by => [],
                   17610:                         for => [],
                   17611:                       );
                   17612:     foreach my $item ('by','for') {
                   17613:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   17614:         foreach my $type (sort(@posstypes)) {
                   17615:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   17616:                 push(@{$crsownerchg{$item}},$type);
                   17617:             }
                   17618:         }
                   17619:     }
                   17620:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   17621:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   17622:         foreach my $item ('by','for') {
                   17623:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   17624:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   17625:                 if (@diffs > 0) {
                   17626:                     $changes{'crsownerchg'} = 1;
                   17627:                     last;
                   17628:                 }
                   17629:             }
                   17630:         }
1.368     raeburn  17631:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359     raeburn  17632:         foreach my $item ('by','for') {
                   17633:             if (@{$crsownerchg{$item}} > 0) {
                   17634:                 $changes{'crsownerchg'} = 1;
                   17635:                 last;
                   17636:             }
1.354     raeburn  17637:         }
                   17638:     }
                   17639: 
                   17640:     my %confighash = (
                   17641:                         defaults  => \%save_defaults,
                   17642:                         passwords => \%newvalues,
                   17643:                      );
                   17644:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   17645: 
                   17646:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   17647:     if ($putresult eq 'ok') {
                   17648:         if (keys(%changes) > 0) {
                   17649:             $resulttext = &mt('Changes made: ').'<ul>';
                   17650:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   17651:                 if ($changes{$key}) {
1.355     raeburn  17652:                     unless ($key eq 'intauth') {
                   17653:                         $updateconf = 1;
                   17654:                     }
1.354     raeburn  17655:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   17656:                     if ($key eq 'reset') {
                   17657:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   17658:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   17659:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   17660:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369     raeburn  17661:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   17662:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   17663:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   17664:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   17665:                             }
1.354     raeburn  17666:                         } else {
                   17667:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   17668:                         }
                   17669:                         if ($confighash{'passwords'}{'resetlink'}) {
                   17670:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   17671:                         } else {
                   17672:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   17673:                                                   &mt('Will default to 2 hours').'</li>';
                   17674:                         }
                   17675:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   17676:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   17677:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   17678:                             } else {
                   17679:                                 my $casesens;
                   17680:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   17681:                                     if ($type eq 'default') {
                   17682:                                         $casesens .= $othertitle.', ';
                   17683:                                     } elsif ($usertypes->{$type} ne '') {
                   17684:                                         $casesens .= $usertypes->{$type}.', ';
                   17685:                                     }
                   17686:                                 }
                   17687:                                 $casesens =~ s/\Q, \E$//;
                   17688:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   17689:                             }
                   17690:                         } else {
                   17691:                             $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>';
                   17692:                         }
                   17693:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   17694:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   17695:                         } else {
                   17696:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   17697:                         }
                   17698:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   17699:                             my $output;
                   17700:                             if (ref($types) eq 'ARRAY') {
                   17701:                                 foreach my $type (@{$types}) {
                   17702:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   17703:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   17704:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   17705:                                         } else {
                   17706:                                             $output .= $usertypes->{$type}.' -- '.
                   17707:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   17708:                                         }
                   17709:                                     }
                   17710:                                 }
                   17711:                             }
                   17712:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   17713:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   17714:                                     $output .= $othertitle.' -- '.&mt('none');
                   17715:                                 } else {
                   17716:                                     $output .= $othertitle.' -- '.
                   17717:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   17718:                                 }
                   17719:                             }
                   17720:                             if ($output) {
                   17721:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   17722:                             } else {
                   17723:                                 $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>';
                   17724:                             }
                   17725:                         } else {
                   17726:                             $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>';
                   17727:                         }
                   17728:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   17729:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   17730:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   17731:                             } else {
                   17732:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   17733:                             }
                   17734:                         } else {
1.379     raeburn  17735:                             $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  17736:                         }
                   17737:                         if ($confighash{'passwords'}{'resetremove'}) {
                   17738:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   17739:                         } else {
                   17740:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   17741:                         }
                   17742:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   17743:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369     raeburn  17744:                                                                             &mt('custom text'),600,500,undef,undef,
                   17745:                                                                             undef,undef,'background-color:#ffffff');
                   17746:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354     raeburn  17747:                         } else {
                   17748:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   17749:                         }
                   17750:                     } elsif ($key eq 'intauth') {
                   17751:                         foreach my $item ('cost','switch','check') {
                   17752:                             my $value = $save_defaults{$key.'_'.$item};
                   17753:                             if ($item eq 'switch') {
                   17754:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   17755:                                                      0 => 'No',
                   17756:                                                      1 => 'Yes',
                   17757:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   17758:                                                  );
                   17759:                                 if ($value =~ /^(0|1|2)$/) {
                   17760:                                     $value = $optiondesc{$value};
                   17761:                                 } else {
                   17762:                                     $value = &mt('none -- defaults to No');
                   17763:                                 }
                   17764:                             } elsif ($item eq 'check') {
                   17765:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   17766:                                                      0 => 'No',
                   17767:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   17768:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   17769:                                                  );
                   17770:                                 if ($value =~ /^(0|1|2)$/) {
                   17771:                                     $value = $optiondesc{$value};
                   17772:                                 } else {
                   17773:                                     $value = &mt('none -- defaults to No');
                   17774:                                 }
                   17775:                             }
                   17776:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   17777:                         }
                   17778:                     } elsif ($key eq 'rules') {
1.356     raeburn  17779:                         foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  17780:                             if ($confighash{'passwords'}{$rule} eq '') {
                   17781:                                 if ($rule eq 'min') {
1.356     raeburn  17782:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365     raeburn  17783:                                                    ' '.&mt('Default of [_1] will be used',
                   17784:                                                            $Apache::lonnet::passwdmin).'</li>';
1.356     raeburn  17785:                                 } else {
                   17786:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354     raeburn  17787:                                 }
                   17788:                             } else {
                   17789:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   17790:                             }
                   17791:                         }
1.370     raeburn  17792:                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   17793:                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   17794:                                 my %rulenames = &Apache::lonlocal::texthash(
                   17795:                                                      uc => 'At least one upper case letter',
                   17796:                                                      lc => 'At least one lower case letter',
                   17797:                                                      num => 'At least one number',
                   17798:                                                      spec => 'At least one non-alphanumeric',
                   17799:                                                    );
                   17800:                                 my $needed = '<ul><li>'.
                   17801:                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
                   17802:                                              '</li></ul>'; 
                   17803:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   17804:                             } else {
                   17805:                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   17806:                             }
                   17807:                         } else {
                   17808:                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   17809:                         }
1.354     raeburn  17810:                     } elsif ($key eq 'crsownerchg') {
1.359     raeburn  17811:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   17812:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   17813:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   17814:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   17815:                             } else {
                   17816:                                 my %crsownerstr;
                   17817:                                 foreach my $item ('by','for') {
                   17818:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   17819:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   17820:                                             if ($type eq 'default') {
                   17821:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   17822:                                             } elsif ($usertypes->{$type} ne '') {
                   17823:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   17824:                                             }
                   17825:                                         }
                   17826:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   17827:                                     }
                   17828:                                 }
                   17829:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   17830:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   17831:                             }
1.354     raeburn  17832:                         } else {
1.359     raeburn  17833:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354     raeburn  17834:                         }
                   17835:                     }
                   17836:                     $resulttext .= '</ul></li>';
                   17837:                 }
                   17838:             }
                   17839:             $resulttext .= '</ul>';
                   17840:         } else {
                   17841:             $resulttext = &mt('No changes made to password settings');
                   17842:         }
1.355     raeburn  17843:         my $cachetime = 24*60*60;
1.354     raeburn  17844:         if ($updatedefaults) {
                   17845:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   17846:             if (ref($lastactref) eq 'HASH') {
                   17847:                 $lastactref->{'domdefaults'} = 1;
                   17848:             }
                   17849:         }
1.355     raeburn  17850:         if ($updateconf) {
                   17851:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   17852:             if (ref($lastactref) eq 'HASH') {
                   17853:                 $lastactref->{'passwdconf'} = 1;
                   17854:             }
                   17855:         }
1.354     raeburn  17856:     } else {
                   17857:         $resulttext = '<span class="LC_error">'.
                   17858:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17859:     }
                   17860:     if ($errors) {
                   17861:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   17862:                        $errors.'</ul></p>';
                   17863:     }
                   17864:     return $resulttext;
                   17865: }
                   17866: 
1.28      raeburn  17867: sub modify_usercreation {
1.27      raeburn  17868:     my ($dom,%domconfig) = @_;
1.224     raeburn  17869:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  17870:     my $warningmsg;
1.27      raeburn  17871:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   17872:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  17873:             if ($key eq 'cancreate') {
                   17874:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   17875:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  17876:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   17877:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   17878:                         } else {
1.224     raeburn  17879:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   17880:                         }
                   17881:                     }
                   17882:                 }
                   17883:             } elsif ($key eq 'email_rule') {
                   17884:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   17885:             } else {
                   17886:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   17887:             }
1.27      raeburn  17888:         }
                   17889:     }
                   17890:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  17891:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  17892:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  17893:     foreach my $item(@contexts) {
1.224     raeburn  17894:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  17895:     }
1.34      raeburn  17896:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   17897:         foreach my $item (@contexts) {
1.224     raeburn  17898:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   17899:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  17900:             }
1.27      raeburn  17901:         }
1.34      raeburn  17902:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   17903:         foreach my $item (@contexts) {
1.43      raeburn  17904:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  17905:                 if ($cancreate{$item} ne 'any') {
                   17906:                     push(@{$changes{'cancreate'}},$item);
                   17907:                 }
                   17908:             } else {
                   17909:                 if ($cancreate{$item} ne 'none') {
                   17910:                     push(@{$changes{'cancreate'}},$item);
                   17911:                 }
1.27      raeburn  17912:             }
                   17913:         }
                   17914:     } else {
1.43      raeburn  17915:         foreach my $item (@contexts)  {
1.34      raeburn  17916:             push(@{$changes{'cancreate'}},$item);
                   17917:         }
1.27      raeburn  17918:     }
1.34      raeburn  17919: 
1.27      raeburn  17920:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   17921:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   17922:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   17923:                 push(@{$changes{'username_rule'}},$type);
                   17924:             }
                   17925:         }
                   17926:         foreach my $type (@username_rule) {
                   17927:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   17928:                 push(@{$changes{'username_rule'}},$type);
                   17929:             }
                   17930:         }
                   17931:     } else {
                   17932:         push(@{$changes{'username_rule'}},@username_rule);
                   17933:     }
                   17934: 
1.32      raeburn  17935:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   17936:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   17937:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   17938:                 push(@{$changes{'id_rule'}},$type);
                   17939:             }
                   17940:         }
                   17941:         foreach my $type (@id_rule) {
                   17942:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   17943:                 push(@{$changes{'id_rule'}},$type);
                   17944:             }
                   17945:         }
                   17946:     } else {
                   17947:         push(@{$changes{'id_rule'}},@id_rule);
                   17948:     }
                   17949: 
1.43      raeburn  17950:     my @authen_contexts = ('author','course','domain');
1.325     raeburn  17951:     my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  17952:     my %authhash;
1.43      raeburn  17953:     foreach my $item (@authen_contexts) {
1.28      raeburn  17954:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   17955:         foreach my $auth (@authtypes) {
                   17956:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   17957:                 $authhash{$item}{$auth} = 1;
                   17958:             } else {
                   17959:                 $authhash{$item}{$auth} = 0;
                   17960:             }
                   17961:         }
                   17962:     }
                   17963:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  17964:         foreach my $item (@authen_contexts) {
1.28      raeburn  17965:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   17966:                 foreach my $auth (@authtypes) {
                   17967:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   17968:                         push(@{$changes{'authtypes'}},$item);
                   17969:                         last;
                   17970:                     }
                   17971:                 }
                   17972:             }
                   17973:         }
                   17974:     } else {
1.43      raeburn  17975:         foreach my $item (@authen_contexts) {
1.28      raeburn  17976:             push(@{$changes{'authtypes'}},$item);
                   17977:         }
                   17978:     }
                   17979: 
1.224     raeburn  17980:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   17981:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   17982:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   17983:     $save_usercreate{'id_rule'} = \@id_rule;
                   17984:     $save_usercreate{'username_rule'} = \@username_rule,
                   17985:     $save_usercreate{'authtypes'} = \%authhash;
                   17986: 
1.27      raeburn  17987:     my %usercreation_hash =  (
1.224     raeburn  17988:         usercreation     => \%save_usercreate,
                   17989:     );
1.27      raeburn  17990: 
                   17991:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   17992:                                              $dom);
1.50      raeburn  17993: 
1.224     raeburn  17994:     if ($putresult eq 'ok') {
                   17995:         if (keys(%changes) > 0) {
                   17996:             $resulttext = &mt('Changes made:').'<ul>';
                   17997:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   17998:                 my %lt = &usercreation_types();
                   17999:                 foreach my $type (@{$changes{'cancreate'}}) {
                   18000:                     my $chgtext = $lt{$type}.', ';
                   18001:                     if ($cancreate{$type} eq 'none') {
                   18002:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   18003:                     } elsif ($cancreate{$type} eq 'any') {
                   18004:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   18005:                     } elsif ($cancreate{$type} eq 'official') {
                   18006:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   18007:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   18008:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   18009:                     }
                   18010:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   18011:                 }
                   18012:             }
                   18013:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   18014:                 my ($rules,$ruleorder) = 
                   18015:                     &Apache::lonnet::inst_userrules($dom,'username');
                   18016:                 my $chgtext = '<ul>';
                   18017:                 foreach my $type (@username_rule) {
                   18018:                     if (ref($rules->{$type}) eq 'HASH') {
                   18019:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   18020:                     }
                   18021:                 }
                   18022:                 $chgtext .= '</ul>';
                   18023:                 if (@username_rule > 0) {
                   18024:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   18025:                 } else {
                   18026:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   18027:                 }
                   18028:             }
                   18029:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   18030:                 my ($idrules,$idruleorder) = 
                   18031:                     &Apache::lonnet::inst_userrules($dom,'id');
                   18032:                 my $chgtext = '<ul>';
                   18033:                 foreach my $type (@id_rule) {
                   18034:                     if (ref($idrules->{$type}) eq 'HASH') {
                   18035:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   18036:                     }
                   18037:                 }
                   18038:                 $chgtext .= '</ul>';
                   18039:                 if (@id_rule > 0) {
                   18040:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   18041:                 } else {
                   18042:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   18043:                 }
                   18044:             }
                   18045:             my %authname = &authtype_names();
                   18046:             my %context_title = &context_names();
                   18047:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   18048:                 my $chgtext = '<ul>';
                   18049:                 foreach my $type (@{$changes{'authtypes'}}) {
                   18050:                     my @allowed;
                   18051:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   18052:                     foreach my $auth (@authtypes) {
                   18053:                         if ($authhash{$type}{$auth}) {
                   18054:                             push(@allowed,$authname{$auth});
                   18055:                         }
                   18056:                     }
                   18057:                     if (@allowed > 0) {
                   18058:                         $chgtext .= join(', ',@allowed).'</li>';
                   18059:                     } else {
                   18060:                         $chgtext .= &mt('none').'</li>';
                   18061:                     }
                   18062:                 }
                   18063:                 $chgtext .= '</ul>';
                   18064:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   18065:                 $resulttext .= '</li>';
                   18066:             }
                   18067:             $resulttext .= '</ul>';
                   18068:         } else {
                   18069:             $resulttext = &mt('No changes made to user creation settings');
                   18070:         }
                   18071:     } else {
                   18072:         $resulttext = '<span class="LC_error">'.
                   18073:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18074:     }
                   18075:     if ($warningmsg ne '') {
                   18076:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   18077:     }
                   18078:     return $resulttext;
                   18079: }
                   18080: 
                   18081: sub modify_selfcreation {
1.305     raeburn  18082:     my ($dom,$lastactref,%domconfig) = @_;
                   18083:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   18084:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   18085:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  18086:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   18087:     if (ref($typesref) eq 'ARRAY') {
                   18088:         @types = @{$typesref};
                   18089:     }
                   18090:     if (ref($usertypesref) eq 'HASH') {
                   18091:         %usertypes = %{$usertypesref};
1.228     raeburn  18092:     }
1.303     raeburn  18093:     $usertypes{'default'} = $othertitle;
1.224     raeburn  18094: #
                   18095: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   18096: #
                   18097:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   18098:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   18099:             if ($key eq 'cancreate') {
                   18100:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   18101:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   18102:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  18103:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   18104:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   18105:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   18106:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  18107:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  18108:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18109:                         } else {
                   18110:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   18111:                         }
                   18112:                     }
                   18113:                 }
                   18114:             } elsif ($key eq 'email_rule') {
                   18115:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   18116:             } else {
                   18117:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   18118:             }
                   18119:         }
                   18120:     }
                   18121: #
                   18122: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   18123: #
                   18124:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   18125:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   18126:             if ($key eq 'selfcreate') {
                   18127:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18128:             } else {
                   18129:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   18130:             }
                   18131:         }
                   18132:     }
1.305     raeburn  18133: #
                   18134: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   18135: #
                   18136:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   18137:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   18138:             if ($key eq 'inststatusguest') {
                   18139:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18140:             } else {
                   18141:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   18142:             }
                   18143:         }
                   18144:     }
1.224     raeburn  18145: 
                   18146:     my @contexts = ('selfcreate');
                   18147:     @{$cancreate{'selfcreate'}} = ();
                   18148:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  18149:     if (@types) {
                   18150:         @{$cancreate{'statustocreate'}} = ();
                   18151:     }
1.236     raeburn  18152:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  18153:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  18154:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  18155:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  18156:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  18157:     my %selfcreatetypes = (
                   18158:                              sso   => 'users authenticated by institutional single sign on',
                   18159:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  18160:                              email => 'users verified by e-mail',
1.50      raeburn  18161:                           );
1.224     raeburn  18162: #
                   18163: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   18164: # is permitted.
                   18165: #
1.305     raeburn  18166:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  18167: 
1.305     raeburn  18168:     my (@statuses,%email_rule);
1.228     raeburn  18169:     foreach my $item ('login','sso','email') {
1.224     raeburn  18170:         if ($item eq 'email') {
1.236     raeburn  18171:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  18172:                 if (@types) {
                   18173:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   18174:                     foreach my $status (@poss_statuses) {
                   18175:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   18176:                             push(@statuses,$status);
                   18177:                         }
                   18178:                     }
                   18179:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   18180:                 } else {
                   18181:                     push(@statuses,'default');
                   18182:                 }
                   18183:                 if (@statuses) {
                   18184:                     my %curr_rule;
                   18185:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   18186:                         foreach my $type (@statuses) {
                   18187:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  18188:                         }
1.305     raeburn  18189:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   18190:                         foreach my $type (@statuses) {
                   18191:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   18192:                         }
                   18193:                     }
                   18194:                     push(@{$cancreate{'selfcreate'}},'email');
                   18195:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   18196:                     my %curremaildom;
                   18197:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   18198:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   18199:                     }
                   18200:                     foreach my $type (@statuses) {
                   18201:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   18202:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   18203:                         }
                   18204:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   18205:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   18206:                         }
                   18207:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   18208: #
                   18209: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   18210: #
                   18211:                             my $chosen = $1;
                   18212:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   18213:                                 my $emaildom;
                   18214:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   18215:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                   18216:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   18217:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   18218:                                         if (exists($curremaildom{$type}{$chosen})) {
                   18219:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   18220:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   18221:                                             }
                   18222:                                         } elsif ($emaildom ne '') {
                   18223:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   18224:                                         }
                   18225:                                     } elsif ($emaildom ne '') {
                   18226:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   18227:                                     } 
                   18228:                                 }
                   18229:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   18230:                             } elsif ($chosen eq 'custom') {
                   18231:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   18232:                                 $email_rule{$type} = [];
                   18233:                                 if (ref($emailrules) eq 'HASH') {
                   18234:                                     foreach my $rule (@possemail_rules) {
                   18235:                                         if (exists($emailrules->{$rule})) {
                   18236:                                             push(@{$email_rule{$type}},$rule);
                   18237:                                         }
                   18238:                                     }
                   18239:                                 }
                   18240:                                 if (@{$email_rule{$type}}) {
                   18241:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   18242:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   18243:                                         if (@{$curr_rule{$type}} > 0) {
                   18244:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   18245:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   18246:                                                     push(@{$changes{'email_rule'}},$type);
                   18247:                                                 }
                   18248:                                             }
                   18249:                                         }
                   18250:                                         foreach my $type (@{$email_rule{$type}}) {
                   18251:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   18252:                                                 push(@{$changes{'email_rule'}},$type);
                   18253:                                             }
                   18254:                                         }
                   18255:                                     } else {
                   18256:                                         push(@{$changes{'email_rule'}},$type);
                   18257:                                     }
                   18258:                                 }
                   18259:                             } else {
                   18260:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   18261:                             }
                   18262:                         }
                   18263:                     }
                   18264:                     if (@types) {
                   18265:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18266:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   18267:                             if (@changed) {
                   18268:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   18269:                             }
                   18270:                         } else {
                   18271:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   18272:                         }
                   18273:                     }
                   18274:                 } else {
                   18275:                     delete($env{'form.cancreate_email'});
                   18276:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18277:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   18278:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   18279:                         }
                   18280:                     }
                   18281:                 }
                   18282:             } else {
                   18283:                 $save_inststatus{'inststatusguest'} = [];
                   18284:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18285:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   18286:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  18287:                     }
                   18288:                 }
1.224     raeburn  18289:             }
                   18290:         } else {
                   18291:             if ($env{'form.cancreate_'.$item}) {
                   18292:                 push(@{$cancreate{'selfcreate'}},$item);
                   18293:             }
                   18294:         }
                   18295:     }
1.305     raeburn  18296:     my (%userinfo,%savecaptcha);
1.224     raeburn  18297:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   18298: #
1.228     raeburn  18299: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   18300: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  18301: #
1.236     raeburn  18302: 
1.244     raeburn  18303:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  18304:         push(@contexts,'emailusername');
1.305     raeburn  18305:         if (@statuses) {
                   18306:             foreach my $type (@statuses) {
1.228     raeburn  18307:                 if (ref($infofields) eq 'ARRAY') {
                   18308:                     foreach my $field (@{$infofields}) {
                   18309:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   18310:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   18311:                         }
                   18312:                     }
1.224     raeburn  18313:                 }
                   18314:             }
                   18315:         }
                   18316: #
                   18317: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  18318: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  18319: #
                   18320: 
                   18321:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   18322:         @approvalnotify = sort(@approvalnotify);
                   18323:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   18324:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18325:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   18326:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   18327:                     push(@{$changes{'cancreate'}},'notify');
                   18328:                 }
                   18329:             } else {
                   18330:                 if ($cancreate{'notify'}{'approval'}) {
                   18331:                     push(@{$changes{'cancreate'}},'notify');
                   18332:                 }
                   18333:             }
                   18334:         } elsif ($cancreate{'notify'}{'approval'}) {
                   18335:             push(@{$changes{'cancreate'}},'notify');
                   18336:         }
                   18337: 
                   18338:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   18339:     }
                   18340: #  
1.236     raeburn  18341: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  18342: # institutional log-in.
                   18343: #
                   18344:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   18345:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   18346:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   18347:             $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.').' '.
                   18348:                           &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.');
                   18349:         }
                   18350:     }
                   18351:     my @fields = ('lastname','firstname','middlename','generation',
                   18352:                   'permanentemail','id');
1.240     raeburn  18353:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  18354:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   18355: #
                   18356: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   18357: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   18358: # may self-create accounts 
                   18359: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   18360: # which the user may supply, if institutional data is unavailable.
                   18361: #
                   18362:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  18363:         if (@types) {
1.305     raeburn  18364:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   18365:             push(@contexts,'statustocreate');
1.303     raeburn  18366:             foreach my $type (@types) {
1.224     raeburn  18367:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   18368:                 foreach my $field (@fields) {
                   18369:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   18370:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   18371:                     } else {
                   18372:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   18373:                     }
                   18374:                 }
                   18375:             }
                   18376:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  18377:                 foreach my $type (@types) {
1.224     raeburn  18378:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   18379:                         foreach my $field (@fields) {
                   18380:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   18381:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   18382:                                 push(@{$changes{'selfcreate'}},$type);
                   18383:                                 last;
                   18384:                             }
                   18385:                         }
                   18386:                     }
                   18387:                 }
                   18388:             } else {
1.303     raeburn  18389:                 foreach my $type (@types) {
1.224     raeburn  18390:                     push(@{$changes{'selfcreate'}},$type);
                   18391:                 }
                   18392:             }
                   18393:         }
1.240     raeburn  18394:         foreach my $field (@shibfields) {
                   18395:             if ($env{'form.shibenv_'.$field} ne '') {
                   18396:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   18397:             }
                   18398:         }
                   18399:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   18400:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   18401:                 foreach my $field (@shibfields) {
                   18402:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   18403:                         push(@{$changes{'cancreate'}},'shibenv');
                   18404:                     }
                   18405:                 }
                   18406:             } else {
                   18407:                 foreach my $field (@shibfields) {
                   18408:                     if ($env{'form.shibenv_'.$field}) {
                   18409:                         push(@{$changes{'cancreate'}},'shibenv');
                   18410:                         last;
                   18411:                     }
                   18412:                 }
                   18413:             }
                   18414:         }
1.224     raeburn  18415:     }
                   18416:     foreach my $item (@contexts) {
                   18417:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   18418:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   18419:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   18420:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   18421:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18422:                             push(@{$changes{'cancreate'}},$item);
                   18423:                         }
                   18424:                     }
                   18425:                 }
                   18426:             }
                   18427:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   18428:                 foreach my $type (@{$cancreate{$item}}) {
                   18429:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   18430:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18431:                             push(@{$changes{'cancreate'}},$item);
                   18432:                         }
                   18433:                     }
                   18434:                 }
                   18435:             }
                   18436:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   18437:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  18438:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   18439:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   18440:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   18441:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  18442:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18443:                                     push(@{$changes{'cancreate'}},$item);
                   18444:                                 }
                   18445:                             }
                   18446:                         }
1.305     raeburn  18447:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18448:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  18449:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18450:                                 push(@{$changes{'cancreate'}},$item);
                   18451:                             }
1.224     raeburn  18452:                         }
                   18453:                     }
                   18454:                 }
1.305     raeburn  18455:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   18456:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   18457:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   18458:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   18459:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  18460:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18461:                                         push(@{$changes{'cancreate'}},$item);
                   18462:                                     }
                   18463:                                 }
                   18464:                             } else {
                   18465:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18466:                                     push(@{$changes{'cancreate'}},$item);
                   18467:                                 }
                   18468:                             }
                   18469:                         }
1.305     raeburn  18470:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18471:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  18472:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18473:                                 push(@{$changes{'cancreate'}},$item);
                   18474:                             }
1.224     raeburn  18475:                         }
                   18476:                     }
                   18477:                 }
                   18478:             }
                   18479:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   18480:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   18481:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   18482:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18483:                         push(@{$changes{'cancreate'}},$item);
                   18484:                     }
                   18485:                 }
1.305     raeburn  18486:             }
                   18487:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   18488:             if (ref($cancreate{$item}) eq 'HASH') {
                   18489:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18490:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  18491:                 }
                   18492:             }
                   18493:         } elsif ($item eq 'emailusername') {
1.228     raeburn  18494:             if (ref($cancreate{$item}) eq 'HASH') {
                   18495:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   18496:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   18497:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   18498:                             if ($cancreate{$item}{$type}{$field}) {
                   18499:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   18500:                                     push(@{$changes{'cancreate'}},$item);
                   18501:                                 }
                   18502:                                 last;
                   18503:                             }
                   18504:                         }
                   18505:                     }
                   18506:                 }
1.224     raeburn  18507:             }
                   18508:         }
                   18509:     }
                   18510: #
                   18511: # Populate %save_usercreate hash with updates to self-creation configuration.
                   18512: #
                   18513:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   18514:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  18515:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  18516:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   18517:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   18518:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   18519:     }
1.236     raeburn  18520:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   18521:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   18522:     }
1.303     raeburn  18523:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   18524:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   18525:     }
1.305     raeburn  18526:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   18527:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   18528:     }
1.303     raeburn  18529:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   18530:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   18531:     }
1.224     raeburn  18532:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   18533:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   18534:     }
1.240     raeburn  18535:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   18536:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   18537:     }
1.224     raeburn  18538:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  18539:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  18540: 
                   18541:     my %userconfig_hash = (
                   18542:             usercreation     => \%save_usercreate,
                   18543:             usermodification => \%save_usermodify,
1.305     raeburn  18544:             inststatus       => \%save_inststatus,
1.224     raeburn  18545:     );
1.305     raeburn  18546: 
1.224     raeburn  18547:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   18548:                                              $dom);
                   18549: #
1.305     raeburn  18550: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  18551: #
1.27      raeburn  18552:     if ($putresult eq 'ok') {
                   18553:         if (keys(%changes) > 0) {
                   18554:             $resulttext = &mt('Changes made:').'<ul>';
                   18555:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  18556:                 my %lt = &selfcreation_types();
1.34      raeburn  18557:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  18558:                     my $chgtext = '';
1.45      raeburn  18559:                     if ($type eq 'selfcreate') {
1.50      raeburn  18560:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  18561:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  18562:                         } else {
1.224     raeburn  18563:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   18564:                                         '<ul>';
1.50      raeburn  18565:                             foreach my $case (@{$cancreate{$type}}) {
                   18566:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   18567:                             }
                   18568:                             $chgtext .= '</ul>';
1.100     raeburn  18569:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   18570:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   18571:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   18572:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  18573:                                             $chgtext .= '<span class="LC_warning">'.
                   18574:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   18575:                                                         '</span><br />';
                   18576:                                         }
                   18577:                                     }
                   18578:                                 }
                   18579:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  18580:                                     if (!@statuses) {
                   18581:                                         $chgtext .= '<span class="LC_warning">'.
                   18582:                                                     &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.").
                   18583:                                                     '</span><br />';
1.303     raeburn  18584: 
1.100     raeburn  18585:                                     }
                   18586:                                 }
                   18587:                             }
1.43      raeburn  18588:                         }
1.240     raeburn  18589:                     } elsif ($type eq 'shibenv') {
                   18590:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  18591:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  18592:                         } else {
                   18593:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   18594:                                         '<ul>';
                   18595:                             foreach my $field (@shibfields) {
                   18596:                                 next if ($cancreate{$type}{$field} eq '');
                   18597:                                 if ($field eq 'inststatus') {
                   18598:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   18599:                                 } else {
                   18600:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   18601:                                 }
                   18602:                             }
                   18603:                             $chgtext .= '</ul>';
1.303     raeburn  18604:                         }
1.93      raeburn  18605:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  18606:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   18607:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   18608:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   18609:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  18610:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  18611:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  18612:                                         $chgtext .= '<br />'.
                   18613:                                                     '<span class="LC_warning">'.
                   18614:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   18615:                                                     '</span>';
                   18616:                                     }
1.303     raeburn  18617:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  18618:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  18619:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   18620:                                     } else {
                   18621:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   18622:                                     }
                   18623:                                     $chgtext .= '<ul>';
                   18624:                                     foreach my $case (@{$cancreate{$type}}) {
                   18625:                                         if ($case eq 'default') {
                   18626:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   18627:                                         } else {
1.303     raeburn  18628:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  18629:                                         }
                   18630:                                     }
1.100     raeburn  18631:                                     $chgtext .= '</ul>';
                   18632:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  18633:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  18634:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   18635:                                                     '</span>';
1.100     raeburn  18636:                                     }
                   18637:                                 }
                   18638:                             } else {
                   18639:                                 if (@{$cancreate{$type}} == 0) {
                   18640:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   18641:                                 } else {
                   18642:                                     $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  18643:                                 }
                   18644:                             }
1.303     raeburn  18645:                             $chgtext .= '<br />';
1.93      raeburn  18646:                         }
1.236     raeburn  18647:                     } elsif ($type eq 'selfcreateprocessing') {
                   18648:                         my %choices = &Apache::lonlocal::texthash (
                   18649:                                                                     automatic => 'Automatic approval',
                   18650:                                                                     approval  => 'Queued for approval',
                   18651:                                                                   );
1.305     raeburn  18652:                         if (@types) {
                   18653:                             if (@statuses) {
1.303     raeburn  18654:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
1.309     raeburn  18655:                                             '<ul>';
1.305     raeburn  18656:                                 foreach my $status (@statuses) {
                   18657:                                     if ($status eq 'default') {
                   18658:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  18659:                                     } else {
1.305     raeburn  18660:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  18661:                                     }
                   18662:                                 }
                   18663:                                 $chgtext .= '</ul>';
                   18664:                             }
                   18665:                         } else {
                   18666:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   18667:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   18668:                         }
                   18669:                     } elsif ($type eq 'emailverified') {
                   18670:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  18671:                                                                     all   => 'Same as e-mail',
                   18672:                                                                     first => 'Omit @domain',
                   18673:                                                                     free  => 'Free to choose',
1.303     raeburn  18674:                                                                   );
1.305     raeburn  18675:                         if (@types) {
                   18676:                             if (@statuses) {
1.303     raeburn  18677:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   18678:                                             '<ul>';
1.305     raeburn  18679:                                 foreach my $status (@statuses) {
1.362     raeburn  18680:                                     if ($status eq 'default') {
1.305     raeburn  18681:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  18682:                                     } else {
1.305     raeburn  18683:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  18684:                                     }
                   18685:                                 }
                   18686:                                 $chgtext .= '</ul>';
                   18687:                             }
                   18688:                         } else {
1.305     raeburn  18689:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  18690:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  18691:                         }
1.305     raeburn  18692:                     } elsif ($type eq 'emailoptions') {
                   18693:                         my %options = &Apache::lonlocal::texthash (
                   18694:                                                                     any     => 'Any e-mail',
                   18695:                                                                     inst    => 'Institutional only',
                   18696:                                                                     noninst => 'Non-institutional only',
                   18697:                                                                     custom  => 'Custom restrictions',
                   18698:                                                                   );
                   18699:                         if (@types) {
                   18700:                             if (@statuses) {
                   18701:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   18702:                                             '<ul>';
                   18703:                                 foreach my $status (@statuses) {
                   18704:                                     if ($type eq 'default') {
                   18705:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   18706:                                     } else {
                   18707:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  18708:                                     }
                   18709:                                 }
1.305     raeburn  18710:                                 $chgtext .= '</ul>';
                   18711:                             }
                   18712:                         } else {
                   18713:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   18714:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   18715:                             } else {
                   18716:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   18717:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  18718:                             }
1.305     raeburn  18719:                         }
                   18720:                     } elsif ($type eq 'emaildomain') {
                   18721:                         my $output;
                   18722:                         if (@statuses) {
                   18723:                             foreach my $type (@statuses) {
                   18724:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   18725:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   18726:                                         if ($type eq 'default') {
                   18727:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18728:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   18729:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18730:                                             } else {
                   18731:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   18732:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   18733:                                             }
1.303     raeburn  18734:                                         } else {
1.305     raeburn  18735:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18736:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   18737:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18738:                                             } else {
                   18739:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   18740:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                   18741:                                             }
1.303     raeburn  18742:                                         }
1.305     raeburn  18743:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   18744:                                         if ($type eq 'default') {
                   18745:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18746:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   18747:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18748:                                             } else {
                   18749:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   18750:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   18751:                                             }
1.303     raeburn  18752:                                         } else {
1.305     raeburn  18753:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   18754:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   18755:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   18756:                                             } else {
                   18757:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   18758:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                   18759:                                             }
1.303     raeburn  18760:                                         }
                   18761:                                     }
                   18762:                                 }
                   18763:                             }
1.305     raeburn  18764:                         }
                   18765:                         if ($output ne '') {
                   18766:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   18767:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  18768:                         }
1.165     raeburn  18769:                     } elsif ($type eq 'captcha') {
1.224     raeburn  18770:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  18771:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   18772:                         } else {
                   18773:                             my %captchas = &captcha_phrases();
1.224     raeburn  18774:                             if ($captchas{$savecaptcha{$type}}) {
                   18775:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  18776:                             } else {
1.210     raeburn  18777:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  18778:                             }
                   18779:                         }
                   18780:                     } elsif ($type eq 'recaptchakeys') {
                   18781:                         my ($privkey,$pubkey);
1.224     raeburn  18782:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   18783:                             $pubkey = $savecaptcha{$type}{'public'};
                   18784:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  18785:                         }
                   18786:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   18787:                         if (!$pubkey) {
                   18788:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   18789:                         } else {
                   18790:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   18791:                         }
                   18792:                         if (!$privkey) {
                   18793:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   18794:                         } else {
                   18795:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   18796:                         }
                   18797:                         $chgtext .= '</ul>';
1.269     raeburn  18798:                     } elsif ($type eq 'recaptchaversion') {
                   18799:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  18800:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  18801:                         }
1.224     raeburn  18802:                     } elsif ($type eq 'emailusername') {
                   18803:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  18804:                             if (@statuses) {
                   18805:                                 foreach my $type (@statuses) {
1.228     raeburn  18806:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   18807:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  18808:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  18809:                                                     '<ul>';
                   18810:                                             foreach my $field (@{$infofields}) {
                   18811:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   18812:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   18813:                                                 }
                   18814:                                             }
1.245     raeburn  18815:                                             $chgtext .= '</ul>';
                   18816:                                         } else {
1.303     raeburn  18817:                                             $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  18818:                                         }
                   18819:                                     } else {
1.303     raeburn  18820:                                         $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  18821:                                     }
                   18822:                                 }
                   18823:                             }
                   18824:                         }
                   18825:                     } elsif ($type eq 'notify') {
1.303     raeburn  18826:                         my $numapprove = 0;
1.224     raeburn  18827:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   18828:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   18829:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  18830:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   18831:                                     $numapprove ++;
1.224     raeburn  18832:                                 }
                   18833:                             }
1.43      raeburn  18834:                         }
1.303     raeburn  18835:                         unless ($numapprove) {
                   18836:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   18837:                         }
1.34      raeburn  18838:                     }
1.224     raeburn  18839:                     if ($chgtext) {
                   18840:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  18841:                     }
                   18842:                 }
                   18843:             }
1.305     raeburn  18844:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  18845:                 my ($emailrules,$emailruleorder) =
                   18846:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  18847:                 foreach my $type (@{$changes{'email_rule'}}) {
                   18848:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   18849:                         my $chgtext = '<ul>';
                   18850:                         foreach my $rule (@{$email_rule{$type}}) {
                   18851:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   18852:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   18853:                             }
                   18854:                         }
                   18855:                         $chgtext .= '</ul>';
1.310     raeburn  18856:                         my $typename;
1.305     raeburn  18857:                         if (@types) {
                   18858:                             if ($type eq 'default') {
                   18859:                                 $typename = $othertitle;
                   18860:                             } else {
                   18861:                                 $typename = $usertypes{$type};
                   18862:                             } 
                   18863:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   18864:                         }
                   18865:                         if (@{$email_rule{$type}} > 0) {
                   18866:                             $resulttext .= '<li>'.
                   18867:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   18868:                                                $usertypes{$type}).
                   18869:                                            $chgtext.
                   18870:                                            '</li>';
                   18871:                         } else {
                   18872:                             $resulttext .= '<li>'.
1.310     raeburn  18873:                                            &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  18874:                                            '</li>'.
1.310     raeburn  18875:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  18876:                         }
1.43      raeburn  18877:                     }
                   18878:                 }
1.305     raeburn  18879:             }
                   18880:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   18881:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   18882:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   18883:                         my $chgtext = '<ul>';
                   18884:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   18885:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   18886:                         }
                   18887:                         $chgtext .= '</ul>';
                   18888:                         $resulttext .= '<li>'.
                   18889:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   18890:                                           $chgtext.
                   18891:                                        '</li>';
                   18892:                     } else {
                   18893:                         $resulttext .= '<li>'.
                   18894:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   18895:                                        '</li>';
                   18896:                     }
1.43      raeburn  18897:                 }
                   18898:             }
1.224     raeburn  18899:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   18900:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   18901:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   18902:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   18903:                     my $typename = $type;
1.303     raeburn  18904:                     if (keys(%usertypes) > 0) {
                   18905:                         if ($usertypes{$type} ne '') {
                   18906:                             $typename = $usertypes{$type};
1.224     raeburn  18907:                         }
                   18908:                     }
                   18909:                     my @modifiable;
                   18910:                     $resulttext .= '<li>'.
                   18911:                                     &mt('Self-creation of account by users with status: [_1]',
                   18912:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   18913:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   18914:                     foreach my $field (@fields) {
                   18915:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   18916:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  18917:                         }
                   18918:                     }
1.224     raeburn  18919:                     if (@modifiable > 0) {
                   18920:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  18921:                     } else {
1.224     raeburn  18922:                         $resulttext .= &mt('none');
1.43      raeburn  18923:                     }
1.224     raeburn  18924:                     $resulttext .= '</li>';
1.28      raeburn  18925:                 }
1.224     raeburn  18926:                 $resulttext .= '</ul></li>';
1.28      raeburn  18927:             }
1.27      raeburn  18928:             $resulttext .= '</ul>';
1.305     raeburn  18929:             my $cachetime = 24*60*60;
                   18930:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   18931:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18932:             if (ref($lastactref) eq 'HASH') {
                   18933:                 $lastactref->{'domdefaults'} = 1;
                   18934:             }
1.27      raeburn  18935:         } else {
1.224     raeburn  18936:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  18937:         }
                   18938:     } else {
                   18939:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  18940:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18941:     }
1.43      raeburn  18942:     if ($warningmsg ne '') {
                   18943:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   18944:     }
1.23      raeburn  18945:     return $resulttext;
                   18946: }
                   18947: 
1.165     raeburn  18948: sub process_captcha {
1.369     raeburn  18949:     my ($container,$changes,$newsettings,$currsettings) = @_;
                   18950:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165     raeburn  18951:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   18952:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   18953:         $newsettings->{'captcha'} = 'original';
                   18954:     }
1.369     raeburn  18955:     my %current;
                   18956:     if (ref($currsettings) eq 'HASH') {
                   18957:         %current = %{$currsettings};
                   18958:     }
                   18959:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  18960:         if ($container eq 'cancreate') {
1.169     raeburn  18961:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   18962:                 push(@{$changes->{'cancreate'}},'captcha');
                   18963:             } elsif (!defined($changes->{'cancreate'})) {
                   18964:                 $changes->{'cancreate'} = ['captcha'];
                   18965:             }
1.368     raeburn  18966:         } elsif ($container eq 'passwords') {
                   18967:             $changes->{'reset'} = 1;
1.169     raeburn  18968:         } else {
                   18969:             $changes->{'captcha'} = 1;
1.165     raeburn  18970:         }
                   18971:     }
1.269     raeburn  18972:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  18973:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   18974:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   18975:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  18976:         $newpub =~ s/[^\w\-]//g;
                   18977:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  18978:         $newsettings->{'recaptchakeys'} = {
                   18979:                                              public  => $newpub,
                   18980:                                              private => $newpriv,
                   18981:                                           };
1.269     raeburn  18982:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   18983:         $newversion =~ s/\D//g;
                   18984:         if ($newversion ne '2') {
                   18985:             $newversion = 1;
                   18986:         }
                   18987:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  18988:     }
1.369     raeburn  18989:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   18990:         $currpub = $current{'recaptchakeys'}{'public'};
                   18991:         $currpriv = $current{'recaptchakeys'}{'private'};
1.179     raeburn  18992:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   18993:             $newsettings->{'recaptchakeys'} = {
                   18994:                                                  public  => '',
                   18995:                                                  private => '',
                   18996:                                               }
                   18997:         }
1.165     raeburn  18998:     }
1.369     raeburn  18999:     if ($current{'captcha'} eq 'recaptcha') {
                   19000:         $currversion = $current{'recaptchaversion'};
1.269     raeburn  19001:         if ($currversion ne '2') {
                   19002:             $currversion = 1;
                   19003:         }
                   19004:     }
                   19005:     if ($currversion ne $newversion) {
                   19006:         if ($container eq 'cancreate') {
                   19007:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19008:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   19009:             } elsif (!defined($changes->{'cancreate'})) {
                   19010:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   19011:             }
1.368     raeburn  19012:         } elsif ($container eq 'passwords') {
                   19013:             $changes->{'reset'} = 1;
1.269     raeburn  19014:         } else {
                   19015:             $changes->{'recaptchaversion'} = 1;
                   19016:         }
                   19017:     }
1.165     raeburn  19018:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  19019:         if ($container eq 'cancreate') {
                   19020:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   19021:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   19022:             } elsif (!defined($changes->{'cancreate'})) {
                   19023:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   19024:             }
1.368     raeburn  19025:         } elsif ($container eq 'passwords') {
                   19026:             $changes->{'reset'} = 1;
1.169     raeburn  19027:         } else {
1.210     raeburn  19028:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  19029:         }
                   19030:     }
                   19031:     return;
                   19032: }
                   19033: 
1.33      raeburn  19034: sub modify_usermodification {
                   19035:     my ($dom,%domconfig) = @_;
1.224     raeburn  19036:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  19037:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   19038:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  19039:             if ($key eq 'selfcreate') {
                   19040:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   19041:             } else {  
                   19042:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   19043:             }
1.33      raeburn  19044:         }
                   19045:     }
1.224     raeburn  19046:     my @contexts = ('author','course');
1.33      raeburn  19047:     my %context_title = (
                   19048:                            author => 'In author context',
                   19049:                            course => 'In course context',
                   19050:                         );
                   19051:     my @fields = ('lastname','firstname','middlename','generation',
                   19052:                   'permanentemail','id');
                   19053:     my %roles = (
                   19054:                   author => ['ca','aa'],
                   19055:                   course => ['st','ep','ta','in','cr'],
                   19056:                 );
                   19057:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   19058:     foreach my $context (@contexts) {
                   19059:         foreach my $role (@{$roles{$context}}) {
                   19060:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   19061:             foreach my $item (@fields) {
                   19062:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   19063:                     $modifyhash{$context}{$role}{$item} = 1;
                   19064:                 } else {
                   19065:                     $modifyhash{$context}{$role}{$item} = 0;
                   19066:                 }
                   19067:             }
                   19068:         }
                   19069:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   19070:             foreach my $role (@{$roles{$context}}) {
                   19071:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   19072:                     foreach my $field (@fields) {
                   19073:                         if ($modifyhash{$context}{$role}{$field} ne 
                   19074:                                 $curr_usermodification{$context}{$role}{$field}) {
                   19075:                             push(@{$changes{$context}},$role);
                   19076:                             last;
                   19077:                         }
                   19078:                     }
                   19079:                 }
                   19080:             }
                   19081:         } else {
                   19082:             foreach my $context (@contexts) {
                   19083:                 foreach my $role (@{$roles{$context}}) {
                   19084:                     push(@{$changes{$context}},$role);
                   19085:                 }
                   19086:             }
                   19087:         }
                   19088:     }
                   19089:     my %usermodification_hash =  (
                   19090:                                    usermodification => \%modifyhash,
                   19091:                                  );
                   19092:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   19093:                                              \%usermodification_hash,$dom);
                   19094:     if ($putresult eq 'ok') {
                   19095:         if (keys(%changes) > 0) {
                   19096:             $resulttext = &mt('Changes made: ').'<ul>';
                   19097:             foreach my $context (@contexts) {
                   19098:                 if (ref($changes{$context}) eq 'ARRAY') {
                   19099:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   19100:                     if (ref($changes{$context}) eq 'ARRAY') {
                   19101:                         foreach my $role (@{$changes{$context}}) {
                   19102:                             my $rolename;
1.224     raeburn  19103:                             if ($role eq 'cr') {
                   19104:                                 $rolename = &mt('Custom');
1.33      raeburn  19105:                             } else {
1.224     raeburn  19106:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  19107:                             }
                   19108:                             my @modifiable;
1.224     raeburn  19109:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  19110:                             foreach my $field (@fields) {
                   19111:                                 if ($modifyhash{$context}{$role}{$field}) {
                   19112:                                     push(@modifiable,$fieldtitles{$field});
                   19113:                                 }
                   19114:                             }
                   19115:                             if (@modifiable > 0) {
                   19116:                                 $resulttext .= join(', ',@modifiable);
                   19117:                             } else {
                   19118:                                 $resulttext .= &mt('none'); 
                   19119:                             }
                   19120:                             $resulttext .= '</li>';
                   19121:                         }
                   19122:                         $resulttext .= '</ul></li>';
                   19123:                     }
                   19124:                 }
                   19125:             }
                   19126:             $resulttext .= '</ul>';
                   19127:         } else {
                   19128:             $resulttext = &mt('No changes made to user modification settings');
                   19129:         }
                   19130:     } else {
                   19131:         $resulttext = '<span class="LC_error">'.
                   19132:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19133:     }
                   19134:     return $resulttext;
                   19135: }
                   19136: 
1.43      raeburn  19137: sub modify_defaults {
1.212     raeburn  19138:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  19139:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  19140:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  19141:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354     raeburn  19142:                  'portal_def');
1.325     raeburn  19143:     my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43      raeburn  19144:     foreach my $item (@items) {
                   19145:         $newvalues{$item} = $env{'form.'.$item};
                   19146:         if ($item eq 'auth_def') {
                   19147:             if ($newvalues{$item} ne '') {
                   19148:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   19149:                     push(@errors,$item);
                   19150:                 }
                   19151:             }
                   19152:         } elsif ($item eq 'lang_def') {
                   19153:             if ($newvalues{$item} ne '') {
                   19154:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   19155:                     my $langcode = $1;
1.103     raeburn  19156:                     if ($langcode ne 'x_chef') {
                   19157:                         if (code2language($langcode) eq '') {
                   19158:                             push(@errors,$item);
                   19159:                         }
1.43      raeburn  19160:                     }
                   19161:                 } else {
                   19162:                     push(@errors,$item);
                   19163:                 }
                   19164:             }
1.54      raeburn  19165:         } elsif ($item eq 'timezone_def') {
                   19166:             if ($newvalues{$item} ne '') {
1.62      raeburn  19167:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  19168:                     push(@errors,$item);   
                   19169:                 }
                   19170:             }
1.68      raeburn  19171:         } elsif ($item eq 'datelocale_def') {
                   19172:             if ($newvalues{$item} ne '') {
                   19173:                 my @datelocale_ids = DateTime::Locale->ids();
                   19174:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   19175:                     push(@errors,$item);
                   19176:                 }
                   19177:             }
1.141     raeburn  19178:         } elsif ($item eq 'portal_def') {
                   19179:             if ($newvalues{$item} ne '') {
                   19180:                 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])\/?$/) {
                   19181:                     push(@errors,$item);
                   19182:                 }
                   19183:             }
1.43      raeburn  19184:         }
                   19185:         if (grep(/^\Q$item\E$/,@errors)) {
                   19186:             $newvalues{$item} = $domdefaults{$item};
                   19187:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   19188:             $changes{$item} = 1;
                   19189:         }
1.72      raeburn  19190:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  19191:     }
1.354     raeburn  19192:     my %staticdefaults = (
                   19193:                            'intauth_cost'   => 10,
                   19194:                            'intauth_check'  => 0,
                   19195:                            'intauth_switch' => 0,
                   19196:                          );
                   19197:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   19198:         if (exists($domdefaults{$item})) {
                   19199:             $newvalues{$item} = $domdefaults{$item};
                   19200:         } else {
                   19201:             $newvalues{$item} = $staticdefaults{$item};
                   19202:         }
                   19203:     }
1.43      raeburn  19204:     my %defaults_hash = (
1.72      raeburn  19205:                          defaults => \%newvalues,
                   19206:                         );
1.43      raeburn  19207:     my $title = &defaults_titles();
1.236     raeburn  19208: 
                   19209:     my $currinststatus;
                   19210:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   19211:         $currinststatus = $domconfig{'inststatus'};
                   19212:     } else {
                   19213:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   19214:         $currinststatus = {
                   19215:                              inststatustypes => $usertypes,
                   19216:                              inststatusorder => $types,
                   19217:                              inststatusguest => [],
                   19218:                           };
                   19219:     }
                   19220:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   19221:     my @allpos;
                   19222:     my %alltypes;
1.305     raeburn  19223:     my @inststatusguest;
                   19224:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   19225:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   19226:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   19227:                 push(@inststatusguest,$type);
                   19228:             }
                   19229:         }
                   19230:     }
                   19231:     my ($currtitles,$currorder);
1.236     raeburn  19232:     if (ref($currinststatus) eq 'HASH') {
                   19233:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   19234:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   19235:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   19236:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   19237:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   19238:                     }
                   19239:                 }
                   19240:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   19241:                     my $position = $env{'form.inststatus_pos_'.$type};
                   19242:                     $position =~ s/\D+//g;
                   19243:                     $allpos[$position] = $type;
                   19244:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   19245:                     $alltypes{$type} =~ s/`//g;
                   19246:                 }
                   19247:             }
                   19248:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   19249:             $currtitles =~ s/,$//;
                   19250:         }
                   19251:     }
                   19252:     if ($env{'form.addinststatus'}) {
                   19253:         my $newtype = $env{'form.addinststatus'};
                   19254:         $newtype =~ s/\W//g;
                   19255:         unless (exists($alltypes{$newtype})) {
                   19256:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   19257:             $alltypes{$newtype} =~ s/`//g; 
                   19258:             my $position = $env{'form.addinststatus_pos'};
                   19259:             $position =~ s/\D+//g;
                   19260:             if ($position ne '') {
                   19261:                 $allpos[$position] = $newtype;
                   19262:             }
                   19263:         }
                   19264:     }
1.305     raeburn  19265:     my @orderedstatus;
1.236     raeburn  19266:     foreach my $type (@allpos) {
                   19267:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   19268:             push(@orderedstatus,$type);
                   19269:         }
                   19270:     }
                   19271:     foreach my $type (keys(%alltypes)) {
                   19272:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   19273:             delete($alltypes{$type});
                   19274:         }
                   19275:     }
                   19276:     $defaults_hash{'inststatus'} = {
                   19277:                                      inststatustypes => \%alltypes,
                   19278:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  19279:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  19280:                                    };
                   19281:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   19282:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   19283:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   19284:         }
                   19285:     }
                   19286:     if ($currorder ne join(',',@orderedstatus)) {
                   19287:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   19288:     }
                   19289:     my $newtitles;
                   19290:     foreach my $item (@orderedstatus) {
                   19291:         $newtitles .= $alltypes{$item}.',';
                   19292:     }
                   19293:     $newtitles =~ s/,$//;
                   19294:     if ($currtitles ne $newtitles) {
                   19295:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   19296:     }
1.43      raeburn  19297:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   19298:                                              $dom);
                   19299:     if ($putresult eq 'ok') {
                   19300:         if (keys(%changes) > 0) {
                   19301:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  19302:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  19303:             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";
                   19304:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  19305:                 if ($item eq 'inststatus') {
                   19306:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  19307:                         if (@orderedstatus) {
1.236     raeburn  19308:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   19309:                             foreach my $type (@orderedstatus) { 
                   19310:                                 $resulttext .= $alltypes{$type}.', ';
                   19311:                             }
                   19312:                             $resulttext =~ s/, $//;
                   19313:                             $resulttext .= '</li>';
1.305     raeburn  19314:                         } else {
                   19315:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
1.236     raeburn  19316:                         }
                   19317:                     }
                   19318:                 } else {
                   19319:                     my $value = $env{'form.'.$item};
                   19320:                     if ($value eq '') {
                   19321:                         $value = &mt('none');
                   19322:                     } elsif ($item eq 'auth_def') {
                   19323:                         my %authnames = &authtype_names();
                   19324:                         my %shortauth = (
                   19325:                                           internal   => 'int',
                   19326:                                           krb4       => 'krb4',
                   19327:                                           krb5       => 'krb5',
                   19328:                                           localauth  => 'loc',
1.325     raeburn  19329:                                           lti        => 'lti',
1.236     raeburn  19330:                         );
                   19331:                         $value = $authnames{$shortauth{$value}};
                   19332:                     }
                   19333:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   19334:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  19335:                 }
                   19336:             }
                   19337:             $resulttext .= '</ul>';
                   19338:             $mailmsgtext .= "\n";
                   19339:             my $cachetime = 24*60*60;
1.72      raeburn  19340:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  19341:             if (ref($lastactref) eq 'HASH') {
                   19342:                 $lastactref->{'domdefaults'} = 1;
                   19343:             }
1.68      raeburn  19344:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  19345:                 my $notify = 1;
                   19346:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   19347:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   19348:                         $notify = 0;
                   19349:                     }
                   19350:                 }
                   19351:                 if ($notify) {
                   19352:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   19353:                                                "LON-CAPA Domain Settings Change - $dom",
                   19354:                                                $mailmsgtext);
                   19355:                 }
1.54      raeburn  19356:             }
1.43      raeburn  19357:         } else {
1.54      raeburn  19358:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  19359:         }
                   19360:     } else {
                   19361:         $resulttext = '<span class="LC_error">'.
                   19362:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   19363:     }
                   19364:     if (@errors > 0) {
                   19365:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   19366:         foreach my $item (@errors) {
                   19367:             $resulttext .= ' "'.$title->{$item}.'",';
                   19368:         }
                   19369:         $resulttext =~ s/,$//;
                   19370:     }
                   19371:     return $resulttext;
                   19372: }
                   19373: 
1.46      raeburn  19374: sub modify_scantron {
1.205     raeburn  19375:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  19376:     my ($resulttext,%confhash,%changes,$errors);
                   19377:     my $custom = 'custom.tab';
                   19378:     my $default = 'default.tab';
                   19379:     my $servadm = $r->dir_config('lonAdmEMail');
1.346     raeburn  19380:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  19381:         &config_check($dom,$confname,$servadm);
                   19382:     if ($env{'form.scantronformat.filename'} ne '') {
                   19383:         my $error;
                   19384:         if ($configuserok eq 'ok') {
                   19385:             if ($switchserver) {
1.130     raeburn  19386:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  19387:             } else {
                   19388:                 if ($author_ok eq 'ok') {
                   19389:                     my ($result,$scantronurl) =
                   19390:                         &publishlogo($r,'upload','scantronformat',$dom,
                   19391:                                      $confname,'scantron','','',$custom);
                   19392:                     if ($result eq 'ok') {
                   19393:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  19394:                         $changes{'scantronformat'} = 1;
1.46      raeburn  19395:                     } else {
                   19396:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   19397:                     }
                   19398:                 } else {
                   19399:                     $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);
                   19400:                 }
                   19401:             }
                   19402:         } else {
                   19403:             $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);
                   19404:         }
                   19405:         if ($error) {
                   19406:             &Apache::lonnet::logthis($error);
                   19407:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   19408:         }
                   19409:     }
1.48      raeburn  19410:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   19411:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   19412:             if ($env{'form.scantronformat_del'}) {
                   19413:                 $confhash{'scantron'}{'scantronformat'} = '';
                   19414:                 $changes{'scantronformat'} = 1;
1.347     raeburn  19415:             } else {
                   19416:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46      raeburn  19417:             }
                   19418:         }
                   19419:     }
1.347     raeburn  19420:     my @options = ('hdr','pad','rem');
1.346     raeburn  19421:     my @fields = &scantroncsv_fields();
                   19422:     my %titles = &scantronconfig_titles();
1.347     raeburn  19423:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346     raeburn  19424:     my ($newdat,$currdat,%newcol,%currcol);
                   19425:     if (grep(/^dat$/,@formats)) {
                   19426:         $confhash{'scantron'}{config}{dat} = 1;
                   19427:         $newdat = 1;
                   19428:     } else {
                   19429:         $newdat = 0;
                   19430:     }
                   19431:     if (grep(/^csv$/,@formats)) {
                   19432:         my %bynum;
                   19433:         foreach my $field (@fields) {
                   19434:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   19435:                 my $posscol = $1;
                   19436:                 if (($posscol < 20) && (!$bynum{$posscol})) {
1.347     raeburn  19437:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346     raeburn  19438:                     $bynum{$posscol} = $field;
                   19439:                     $newcol{$field} = $posscol;
                   19440:                 }
                   19441:             }
                   19442:         }
1.347     raeburn  19443:         if (keys(%newcol)) {
                   19444:             foreach my $option (@options) {
                   19445:                 if ($env{'form.scantroncsv_'.$option}) {
                   19446:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   19447:                 }
                   19448:             }
                   19449:         }
1.346     raeburn  19450:     }
                   19451:     $currdat = 1;
                   19452:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   19453:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347     raeburn  19454:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346     raeburn  19455:                 $currdat = 0;
                   19456:             }
                   19457:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  19458:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   19459:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   19460:                 }
1.346     raeburn  19461:             }
                   19462:         }
                   19463:     }
                   19464:     if ($currdat != $newdat) {
                   19465:         $changes{'config'} = 1;
                   19466:     } else {
                   19467:         foreach my $field (@fields) {
                   19468:             if ($currcol{$field} ne '') {
                   19469:                 if ($currcol{$field} ne $newcol{$field}) {
                   19470:                     $changes{'config'} = 1;
                   19471:                     last;
1.347     raeburn  19472:                 }
1.346     raeburn  19473:             } elsif ($newcol{$field} ne '') {
                   19474:                 $changes{'config'} = 1;
                   19475:                 last;
                   19476:             }
                   19477:         }
                   19478:     }
1.46      raeburn  19479:     if (keys(%confhash) > 0) {
                   19480:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   19481:                                                  $dom);
                   19482:         if ($putresult eq 'ok') {
                   19483:             if (keys(%changes) > 0) {
1.48      raeburn  19484:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   19485:                     $resulttext = &mt('Changes made:').'<ul>';
1.346     raeburn  19486:                     if ($changes{'scantronformat'}) {
                   19487:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   19488:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   19489:                         } else {
                   19490:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   19491:                         }
                   19492:                     }
1.347     raeburn  19493:                     if ($changes{'config'}) {
1.346     raeburn  19494:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   19495:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   19496:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   19497:                             }
                   19498:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  19499:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   19500:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   19501:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   19502:                                         foreach my $field (@fields) {
                   19503:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   19504:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   19505:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   19506:                                             }
                   19507:                                         }
                   19508:                                         $resulttext .= '</ul></li>';
                   19509:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   19510:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   19511:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   19512:                                                 foreach my $option (@options) {
                   19513:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   19514:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   19515:                                                     }
                   19516:                                                 }
                   19517:                                                 $resulttext .= '</ul></li>';
                   19518:                                             }
1.346     raeburn  19519:                                         }
                   19520:                                     }
                   19521:                                 }
                   19522:                             }
                   19523:                         } else {
                   19524:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   19525:                         }
1.46      raeburn  19526:                     }
1.48      raeburn  19527:                     $resulttext .= '</ul>';
                   19528:                 } else {
1.130     raeburn  19529:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  19530:                 }
                   19531:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  19532:                 if (ref($lastactref) eq 'HASH') {
                   19533:                     $lastactref->{'domainconfig'} = 1;
                   19534:                 }
1.46      raeburn  19535:             } else {
1.346     raeburn  19536:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  19537:             }
                   19538:         } else {
                   19539:             $resulttext = '<span class="LC_error">'.
                   19540:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   19541:         }
                   19542:     } else {
1.130     raeburn  19543:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  19544:     }
                   19545:     if ($errors) {
1.353     raeburn  19546:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   19547:                        $errors.'</ul></p>';
1.46      raeburn  19548:     }
                   19549:     return $resulttext;
                   19550: }
                   19551: 
1.48      raeburn  19552: sub modify_coursecategories {
1.239     raeburn  19553:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  19554:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   19555:         $cathash);
1.48      raeburn  19556:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  19557:     my @catitems = ('unauth','auth');
                   19558:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  19559:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  19560:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   19561:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   19562:             $changes{'togglecats'} = 1;
                   19563:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   19564:         }
                   19565:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   19566:             $changes{'categorize'} = 1;
                   19567:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   19568:         }
1.120     raeburn  19569:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   19570:             $changes{'togglecatscomm'} = 1;
                   19571:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   19572:         }
                   19573:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   19574:             $changes{'categorizecomm'} = 1;
                   19575:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  19576: 
                   19577:         }
                   19578:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   19579:             $changes{'togglecatsplace'} = 1;
                   19580:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   19581:         }
                   19582:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   19583:             $changes{'categorizeplace'} = 1;
                   19584:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  19585:         }
1.238     raeburn  19586:         foreach my $item (@catitems) {
                   19587:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   19588:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   19589:                     $changes{$item} = 1;
                   19590:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   19591:                 }
                   19592:             }
                   19593:         }
1.57      raeburn  19594:     } else {
                   19595:         $changes{'togglecats'} = 1;
                   19596:         $changes{'categorize'} = 1;
1.124     raeburn  19597:         $changes{'togglecatscomm'} = 1;
                   19598:         $changes{'categorizecomm'} = 1;
1.272     raeburn  19599:         $changes{'togglecatsplace'} = 1;
                   19600:         $changes{'categorizeplace'} = 1;
1.87      raeburn  19601:         $domconfig{'coursecategories'} = {
                   19602:                                              togglecats => $env{'form.togglecats'},
                   19603:                                              categorize => $env{'form.categorize'},
1.124     raeburn  19604:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   19605:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  19606:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   19607:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  19608:                                          };
1.238     raeburn  19609:         foreach my $item (@catitems) {
                   19610:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   19611:                 $changes{$item} = 1;
                   19612:             }
                   19613:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   19614:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   19615:             }
                   19616:         }
1.57      raeburn  19617:     }
                   19618:     if (ref($cathash) eq 'HASH') {
                   19619:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  19620:             push (@deletecategory,'instcode::0');
                   19621:         }
1.120     raeburn  19622:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   19623:             push(@deletecategory,'communities::0');
                   19624:         }
1.272     raeburn  19625:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   19626:             push(@deletecategory,'placement::0');
                   19627:         }
1.48      raeburn  19628:     }
1.57      raeburn  19629:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   19630:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  19631:         if (@deletecategory > 0) {
                   19632:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  19633:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  19634:             foreach my $item (@deletecategory) {
1.57      raeburn  19635:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   19636:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  19637:                     $deletions{$item} = 1;
1.57      raeburn  19638:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  19639:                 }
                   19640:             }
                   19641:         }
1.57      raeburn  19642:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  19643:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  19644:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  19645:                 $reorderings{$item} = 1;
1.57      raeburn  19646:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  19647:             }
                   19648:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   19649:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   19650:                 my $newdepth = $depth+1;
                   19651:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  19652:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  19653:                 $adds{$newitem} = 1; 
                   19654:             }
                   19655:             if ($env{'form.subcat_'.$item} ne '') {
                   19656:                 my $newcat = $env{'form.subcat_'.$item};
                   19657:                 my $newdepth = $depth+1;
                   19658:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  19659:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  19660:                 $adds{$newitem} = 1;
                   19661:             }
                   19662:         }
                   19663:     }
                   19664:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  19665:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  19666:             my $newitem = 'instcode::0';
1.57      raeburn  19667:             if ($cathash->{$newitem} eq '') {  
                   19668:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  19669:                 $adds{$newitem} = 1;
                   19670:             }
                   19671:         } else {
                   19672:             my $newitem = 'instcode::0';
1.57      raeburn  19673:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  19674:             $adds{$newitem} = 1;
                   19675:         }
                   19676:     }
1.120     raeburn  19677:     if ($env{'form.communities'} eq '1') {
                   19678:         if (ref($cathash) eq 'HASH') {
                   19679:             my $newitem = 'communities::0';
                   19680:             if ($cathash->{$newitem} eq '') {
                   19681:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   19682:                 $adds{$newitem} = 1;
                   19683:             }
                   19684:         } else {
                   19685:             my $newitem = 'communities::0';
                   19686:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   19687:             $adds{$newitem} = 1;
                   19688:         }
                   19689:     }
1.272     raeburn  19690:     if ($env{'form.placement'} eq '1') {
                   19691:         if (ref($cathash) eq 'HASH') {
                   19692:             my $newitem = 'placement::0';
                   19693:             if ($cathash->{$newitem} eq '') {
                   19694:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   19695:                 $adds{$newitem} = 1;
                   19696:             }
                   19697:         } else {
                   19698:             my $newitem = 'placement::0';
                   19699:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   19700:             $adds{$newitem} = 1;
                   19701:         }
                   19702:     }
1.48      raeburn  19703:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  19704:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  19705:             ($env{'form.addcategory_name'} ne 'communities') &&
                   19706:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  19707:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   19708:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   19709:             $adds{$newitem} = 1;
                   19710:         }
1.48      raeburn  19711:     }
1.57      raeburn  19712:     my $putresult;
1.48      raeburn  19713:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19714:         if (keys(%deletions) > 0) {
                   19715:             foreach my $key (keys(%deletions)) {
                   19716:                 if ($predelallitems{$key} ne '') {
                   19717:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   19718:                 }
                   19719:             }
                   19720:         }
                   19721:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  19722:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  19723:         if (ref($chkcats[0]) eq 'ARRAY') {
                   19724:             my $depth = 0;
                   19725:             my $chg = 0;
                   19726:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   19727:                 my $name = $chkcats[0][$i];
                   19728:                 my $item;
                   19729:                 if ($name eq '') {
                   19730:                     $chg ++;
                   19731:                 } else {
                   19732:                     $item = &escape($name).'::0';
                   19733:                     if ($chg) {
1.57      raeburn  19734:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  19735:                     }
                   19736:                     $depth ++; 
1.57      raeburn  19737:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  19738:                     $depth --;
                   19739:                 }
                   19740:             }
                   19741:         }
1.57      raeburn  19742:     }
                   19743:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19744:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  19745:         if ($putresult eq 'ok') {
1.57      raeburn  19746:             my %title = (
1.120     raeburn  19747:                          togglecats     => 'Show/Hide a course in catalog',
                   19748:                          categorize     => 'Assign a category to a course',
                   19749:                          togglecatscomm => 'Show/Hide a community in catalog',
                   19750:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  19751:                         );
                   19752:             my %level = (
1.120     raeburn  19753:                          dom  => 'set in Domain ("Modify Course/Community")',
                   19754:                          crs  => 'set in Course ("Course Configuration")',
                   19755:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  19756:                          none     => 'No catalog',
                   19757:                          std      => 'Standard catalog',
                   19758:                          domonly  => 'Domain-only catalog',
                   19759:                          codesrch => 'Code search form',
1.57      raeburn  19760:                         );
1.48      raeburn  19761:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  19762:             if ($changes{'togglecats'}) {
                   19763:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   19764:             }
                   19765:             if ($changes{'categorize'}) {
                   19766:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  19767:             }
1.120     raeburn  19768:             if ($changes{'togglecatscomm'}) {
                   19769:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   19770:             }
                   19771:             if ($changes{'categorizecomm'}) {
                   19772:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   19773:             }
1.238     raeburn  19774:             if ($changes{'unauth'}) {
                   19775:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   19776:             }
                   19777:             if ($changes{'auth'}) {
                   19778:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   19779:             }
1.57      raeburn  19780:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   19781:                 my $cathash;
                   19782:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   19783:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   19784:                 } else {
                   19785:                     $cathash = {};
                   19786:                 } 
                   19787:                 my (@cats,@trails,%allitems);
                   19788:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   19789:                 if (keys(%deletions) > 0) {
                   19790:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   19791:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   19792:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   19793:                     }
                   19794:                     $resulttext .= '</ul></li>';
                   19795:                 }
                   19796:                 if (keys(%reorderings) > 0) {
                   19797:                     my %sort_by_trail;
                   19798:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   19799:                     foreach my $key (keys(%reorderings)) {
                   19800:                         if ($allitems{$key} ne '') {
                   19801:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   19802:                         }
1.48      raeburn  19803:                     }
1.57      raeburn  19804:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   19805:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   19806:                     }
                   19807:                     $resulttext .= '</ul></li>';
1.48      raeburn  19808:                 }
1.57      raeburn  19809:                 if (keys(%adds) > 0) {
                   19810:                     my %sort_by_trail;
                   19811:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   19812:                     foreach my $key (keys(%adds)) {
                   19813:                         if ($allitems{$key} ne '') {
                   19814:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   19815:                         }
                   19816:                     }
                   19817:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   19818:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  19819:                     }
1.57      raeburn  19820:                     $resulttext .= '</ul></li>';
1.48      raeburn  19821:                 }
1.364     raeburn  19822:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   19823:                 if (ref($lastactref) eq 'HASH') {
                   19824:                     $lastactref->{'cats'} = 1;
                   19825:                 }
1.48      raeburn  19826:             }
                   19827:             $resulttext .= '</ul>';
1.239     raeburn  19828:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  19829:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   19830:                 if ($changes{'auth'}) {
                   19831:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   19832:                 }
                   19833:                 if ($changes{'unauth'}) {
                   19834:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   19835:                 }
                   19836:                 my $cachetime = 24*60*60;
                   19837:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  19838:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  19839:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  19840:                 }
                   19841:             }
1.48      raeburn  19842:         } else {
                   19843:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  19844:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  19845:         }
                   19846:     } else {
1.120     raeburn  19847:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  19848:     }
                   19849:     return $resulttext;
                   19850: }
                   19851: 
1.69      raeburn  19852: sub modify_serverstatuses {
                   19853:     my ($dom,%domconfig) = @_;
                   19854:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   19855:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   19856:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   19857:     }
                   19858:     my @pages = &serverstatus_pages();
                   19859:     foreach my $type (@pages) {
                   19860:         $newserverstatus{$type}{'namedusers'} = '';
                   19861:         $newserverstatus{$type}{'machines'} = '';
                   19862:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   19863:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   19864:             my @okusers;
                   19865:             foreach my $user (@users) {
                   19866:                 my ($uname,$udom) = split(/:/,$user);
                   19867:                 if (($udom =~ /^$match_domain$/) &&   
                   19868:                     (&Apache::lonnet::domain($udom)) &&
                   19869:                     ($uname =~ /^$match_username$/)) {
                   19870:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   19871:                         push(@okusers,$user);
                   19872:                     }
                   19873:                 }
                   19874:             }
                   19875:             if (@okusers > 0) {
                   19876:                  @okusers = sort(@okusers);
                   19877:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   19878:             }
                   19879:         }
                   19880:         if (defined($env{'form.'.$type.'_machines'})) {
                   19881:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   19882:             my @okmachines;
                   19883:             foreach my $ip (@machines) {
                   19884:                 my @parts = split(/\./,$ip);
                   19885:                 next if (@parts < 4);
                   19886:                 my $badip = 0;
                   19887:                 for (my $i=0; $i<4; $i++) {
                   19888:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   19889:                         $badip = 1;
                   19890:                         last;
                   19891:                     }
                   19892:                 }
                   19893:                 if (!$badip) {
                   19894:                     push(@okmachines,$ip);     
                   19895:                 }
                   19896:             }
                   19897:             @okmachines = sort(@okmachines);
                   19898:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   19899:         }
                   19900:     }
                   19901:     my %serverstatushash =  (
                   19902:                                 serverstatuses => \%newserverstatus,
                   19903:                             );
                   19904:     foreach my $type (@pages) {
1.83      raeburn  19905:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  19906:             my (@current,@new);
1.83      raeburn  19907:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  19908:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   19909:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   19910:                 }
                   19911:             }
                   19912:             if ($newserverstatus{$type}{$setting} ne '') {
                   19913:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  19914:             }
                   19915:             if (@current > 0) {
                   19916:                 if (@new > 0) {
                   19917:                     foreach my $item (@current) {
                   19918:                         if (!grep(/^\Q$item\E$/,@new)) {
                   19919:                             $changes{$type}{$setting} = 1;
1.82      raeburn  19920:                             last;
                   19921:                         }
                   19922:                     }
1.84      raeburn  19923:                     foreach my $item (@new) {
                   19924:                         if (!grep(/^\Q$item\E$/,@current)) {
                   19925:                             $changes{$type}{$setting} = 1;
                   19926:                             last;
1.82      raeburn  19927:                         }
                   19928:                     }
                   19929:                 } else {
1.83      raeburn  19930:                     $changes{$type}{$setting} = 1;
1.69      raeburn  19931:                 }
1.83      raeburn  19932:             } elsif (@new > 0) {
                   19933:                 $changes{$type}{$setting} = 1;
1.69      raeburn  19934:             }
                   19935:         }
                   19936:     }
                   19937:     if (keys(%changes) > 0) {
1.81      raeburn  19938:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  19939:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   19940:                                                  \%serverstatushash,$dom);
                   19941:         if ($putresult eq 'ok') {
                   19942:             $resulttext .= &mt('Changes made:').'<ul>';
                   19943:             foreach my $type (@pages) {
1.84      raeburn  19944:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  19945:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  19946:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  19947:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   19948:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   19949:                         } else {
                   19950:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   19951:                         }
1.84      raeburn  19952:                     }
                   19953:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  19954:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   19955:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   19956:                         } else {
                   19957:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   19958:                         }
                   19959: 
                   19960:                     }
                   19961:                     $resulttext .= '</ul></li>';
                   19962:                 }
                   19963:             }
                   19964:             $resulttext .= '</ul>';
                   19965:         } else {
                   19966:             $resulttext = '<span class="LC_error">'.
                   19967:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   19968: 
                   19969:         }
                   19970:     } else {
                   19971:         $resulttext = &mt('No changes made to access to server status pages');
                   19972:     }
                   19973:     return $resulttext;
                   19974: }
                   19975: 
1.118     jms      19976: sub modify_helpsettings {
1.285     raeburn  19977:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  19978:     my ($resulttext,$errors,%changes,%helphash);
                   19979:     my %defaultchecked = ('submitbugs' => 'on');
                   19980:     my @offon = ('off','on');
1.118     jms      19981:     my @toggles = ('submitbugs');
1.285     raeburn  19982:     my %current = ('submitbugs' => '',
                   19983:                    'adhoc'      => {},
                   19984:                   );
1.118     jms      19985:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  19986:         %current = %{$domconfig{'helpsettings'}};
                   19987:     }
1.285     raeburn  19988:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  19989:     foreach my $item (@toggles) {
                   19990:         if ($defaultchecked{$item} eq 'on') { 
                   19991:             if ($current{$item} eq '') {
                   19992:                 if ($env{'form.'.$item} eq '0') {
                   19993:                     $changes{$item} = 1;
                   19994:                 }
                   19995:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   19996:                 $changes{$item} = 1;
                   19997:             }
                   19998:         } elsif ($defaultchecked{$item} eq 'off') {
                   19999:             if ($current{$item} eq '') {
                   20000:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  20001:                     $changes{$item} = 1;
                   20002:                 }
1.282     raeburn  20003:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   20004:                 $changes{$item} = 1;
                   20005:             }
                   20006:         }
                   20007:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   20008:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   20009:         }
                   20010:     }
1.285     raeburn  20011:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  20012:     my $confname = $dom.'-domainconfig';
                   20013:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  20014:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   20015:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  20016:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  20017:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  20018:     my %lt = &Apache::lonlocal::texthash(
                   20019:                     s      => 'system',
                   20020:                     d      => 'domain',
                   20021:                     order  => 'Display order',
                   20022:                     access => 'Role usage',
1.291     raeburn  20023:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  20024:                     dh     => 'All with domain helpdesk role',
                   20025:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  20026:                     none   => 'None',
                   20027:                     status => 'Determined based on institutional status',
                   20028:                     inc    => 'Include all, but exclude specific personnel',
                   20029:                     exc    => 'Exclude all, but include specific personnel',
                   20030:     );
                   20031:     for (my $num=0; $num<=$maxnum; $num++) {
                   20032:         my ($prefix,$identifier,$rolename,%curr);
                   20033:         if ($num == $maxnum) {
                   20034:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   20035:             $identifier = 'custhelp'.$num;
                   20036:             $prefix = 'helproles_'.$num;
                   20037:             $rolename = $env{'form.custhelpname'.$num};
                   20038:             $rolename=~s/[^A-Za-z0-9]//gs;
                   20039:             next if ($rolename eq '');
                   20040:             next if (exists($existing{'rolesdef_'.$rolename}));
                   20041:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20042:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20043:                                                      $newprivs{'c'},$confname,$dom);
                   20044:             if ($result ne 'ok') {
                   20045:                 $errors .= '<li><span class="LC_error">'.
                   20046:                            &mt('An error occurred storing the new custom role: [_1]',
                   20047:                            $result).'</span></li>';
                   20048:                 next;
                   20049:             } else {
                   20050:                 $changedprivs{$rolename} = \%newprivs;
                   20051:                 $newrole = $rolename;
                   20052:             }
                   20053:         } else {
                   20054:             $prefix = 'helproles_'.$num;
                   20055:             $rolename = $env{'form.'.$prefix};
                   20056:             next if ($rolename eq '');
                   20057:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   20058:             $identifier = 'custhelp'.$num;
                   20059:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   20060:             my %currprivs;
1.289     raeburn  20061:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  20062:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   20063:             foreach my $level ('c','d','s') {
                   20064:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   20065:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   20066:                                                              $newprivs{'c'},$confname,$dom);
                   20067:                     if ($result ne 'ok') {
                   20068:                         $errors .= '<li><span class="LC_error">'.
                   20069:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   20070:                                        $rolename,$result).'</span></li>';
                   20071:                     } else {
                   20072:                         $changedprivs{$rolename} = \%newprivs;
                   20073:                     }
                   20074:                     last;
                   20075:                 }
                   20076:             }
                   20077:             if (ref($current{'adhoc'}) eq 'HASH') {
                   20078:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   20079:                     %curr = %{$current{'adhoc'}{$rolename}};
                   20080:                 }
                   20081:             }
                   20082:         }
                   20083:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   20084:         $newpos =~ s/\D+//g;
                   20085:         $allpos[$newpos] = $rolename;
                   20086:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   20087:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   20088:         if ($curr{'desc'}) {
                   20089:             if ($curr{'desc'} ne $newdesc) {
                   20090:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   20091:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   20092:             }
                   20093:         } elsif ($newdesc ne '') {
                   20094:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   20095:             $newsettings{$rolename}{'desc'} = $newdesc;
                   20096:         }
                   20097:         my $access = $env{'form.'.$prefix.'_access'};
                   20098:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   20099:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   20100:             if ($access eq 'status') {
                   20101:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   20102:                 if (scalar(@statuses) == 0) {
1.289     raeburn  20103:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  20104:                 } else {
                   20105:                     my (@shownstatus,$numtypes);
                   20106:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   20107:                     if (ref($types) eq 'ARRAY') {
                   20108:                         $numtypes = scalar(@{$types});
                   20109:                         foreach my $type (sort(@statuses)) {
                   20110:                             if ($type eq 'default') {
                   20111:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   20112:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   20113:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   20114:                                 push(@shownstatus,$usertypes->{$type});
                   20115:                             }
                   20116:                         }
                   20117:                     }
                   20118:                     if (grep(/^default$/,@statuses)) {
                   20119:                         push(@shownstatus,$othertitle);
                   20120:                     }
                   20121:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   20122:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   20123:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   20124:                     } else {
                   20125:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   20126:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   20127:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   20128:                             if (@diffs) {
                   20129:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   20130:                             }
                   20131:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20132:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  20133:                         }
1.166     raeburn  20134:                     }
                   20135:                 }
1.285     raeburn  20136:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   20137:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   20138:                 my @newspecstaff;
                   20139:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   20140:                 foreach my $person (sort(@personnel)) {
                   20141:                     if ($domhelpdesk{$person}) {
                   20142:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   20143:                     }
                   20144:                 }
                   20145:                 if (ref($curr{$access}) eq 'ARRAY') {
                   20146:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   20147:                     if (@diffs) {
                   20148:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   20149:                     }
                   20150:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20151:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   20152:                 }
                   20153:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   20154:                     my ($uname,$udom) = split(/:/,$person);
                   20155:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   20156:                 }
                   20157:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  20158:             }
1.285     raeburn  20159:         } else {
                   20160:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   20161:         }
                   20162:         unless ($curr{'access'} eq $access) {
                   20163:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   20164:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  20165:         }
                   20166:     }
1.285     raeburn  20167:     if (@allpos > 0) {
                   20168:         my $idx = 0;
                   20169:         foreach my $rolename (@allpos) {
                   20170:             if ($rolename ne '') {
                   20171:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   20172:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   20173:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   20174:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   20175:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  20176:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  20177:                         }
                   20178:                     }
1.282     raeburn  20179:                 }
1.285     raeburn  20180:                 $idx ++;
1.166     raeburn  20181:             }
                   20182:         }
1.118     jms      20183:     }
1.123     jms      20184:     my $putresult;
                   20185:     if (keys(%changes) > 0) {
1.166     raeburn  20186:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  20187:         if ($putresult eq 'ok') {
1.285     raeburn  20188:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   20189:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   20190:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   20191:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   20192:                 }
                   20193:             }
                   20194:             my $cachetime = 24*60*60;
                   20195:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   20196:             if (ref($lastactref) eq 'HASH') {
                   20197:                 $lastactref->{'domdefaults'} = 1;
                   20198:             }
                   20199:         } else {
                   20200:             $errors .= '<li><span class="LC_error">'.
                   20201:                        &mt('An error occurred storing the settings: [_1]',
                   20202:                            $putresult).'</span></li>';
                   20203:         }
                   20204:     }
                   20205:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   20206:         $resulttext = &mt('Changes made:').'<ul>';
                   20207:         my (%shownprivs,@levelorder);
                   20208:         @levelorder = ('c','d','s');
                   20209:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  20210:             foreach my $item (sort(keys(%changes))) {
                   20211:                 if ($item eq 'submitbugs') {
                   20212:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   20213:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   20214:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  20215:                 } elsif ($item eq 'customrole') {
                   20216:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  20217:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   20218:                         my %keytext = &Apache::lonlocal::texthash(
                   20219:                                                                    order  => 'Order',
                   20220:                                                                    desc   => 'Role description',
                   20221:                                                                    access => 'Role usage',
1.300     droeschl 20222:                                                                    status => 'Allowed institutional types',
1.285     raeburn  20223:                                                                    exc    => 'Allowed personnel',
                   20224:                                                                    inc    => 'Disallowed personnel',
                   20225:                         );
1.282     raeburn  20226:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  20227:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   20228:                                 if ($role eq $newrole) {
                   20229:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   20230:                                                               $role).'<ul>';
                   20231:                                 } else {
                   20232:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   20233:                                                               $role).'<ul>';
                   20234:                                 }
                   20235:                                 foreach my $key (@keyorder) {
                   20236:                                     if ($changes{'customrole'}{$role}{$key}) {
                   20237:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   20238:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   20239:                                                        '</li>';
                   20240:                                     }
                   20241:                                 }
                   20242:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   20243:                                     $shownprivs{$role} = 1;
                   20244:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   20245:                                     foreach my $level (@levelorder) {
                   20246:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   20247:                                             next if ($item eq '');
                   20248:                                             my ($priv) = split(/\&/,$item,2);
                   20249:                                             if (&Apache::lonnet::plaintext($priv)) {
                   20250:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   20251:                                                 unless ($level eq 'c') {
                   20252:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   20253:                                                 }
                   20254:                                                 $resulttext .= '</li>';
                   20255:                                             }
                   20256:                                         }
                   20257:                                     }
                   20258:                                     $resulttext .= '</ul>';
                   20259:                                 }
                   20260:                                 $resulttext .= '</ul></li>';
                   20261:                             }
                   20262:                         }
                   20263:                     }
                   20264:                 }
                   20265:             }
                   20266:         }
                   20267:         if (keys(%changedprivs)) {
                   20268:             foreach my $role (sort(keys(%changedprivs))) {
                   20269:                 unless ($shownprivs{$role}) {
                   20270:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   20271:                                               $role).'<ul>'.
                   20272:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   20273:                     foreach my $level (@levelorder) {
                   20274:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   20275:                             next if ($item eq '');
                   20276:                             my ($priv) = split(/\&/,$item,2);
                   20277:                             if (&Apache::lonnet::plaintext($priv)) {
                   20278:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   20279:                                 unless ($level eq 'c') {
                   20280:                                     $resulttext .= ' ('.$lt{$level}.')';
                   20281:                                 }
                   20282:                                 $resulttext .= '</li>';
                   20283:                             }
1.282     raeburn  20284:                         }
                   20285:                     }
1.285     raeburn  20286:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  20287:                 }
                   20288:             }
                   20289:         }
1.285     raeburn  20290:         $resulttext .= '</ul>';
                   20291:     } else {
                   20292:         $resulttext = &mt('No changes made to help settings');
1.118     jms      20293:     }
                   20294:     if ($errors) {
1.168     raeburn  20295:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  20296:                                     $errors.'</ul>';
1.118     jms      20297:     }
                   20298:     return $resulttext;
                   20299: }
                   20300: 
1.121     raeburn  20301: sub modify_coursedefaults {
1.212     raeburn  20302:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  20303:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  20304:     my %defaultchecked = (
                   20305:                            'canuse_pdfforms' => 'off',
                   20306:                            'uselcmath'       => 'on',
                   20307:                            'usejsme'         => 'on'
                   20308:                          );
                   20309:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198     raeburn  20310:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  20311:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   20312:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   20313:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  20314:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  20315:     my %staticdefaults = (
                   20316:                            anonsurvey_threshold => 10,
                   20317:                            uploadquota          => 500,
1.257     raeburn  20318:                            postsubmit           => 60,
1.276     raeburn  20319:                            mysqltables          => 172800,
1.198     raeburn  20320:                          );
1.314     raeburn  20321:     my %texoptions = (
                   20322:                         MathJax  => 'MathJax',
                   20323:                         mimetex  => &mt('Convert to Images'),
                   20324:                         tth      => &mt('TeX to HTML'),
                   20325:                      );
1.121     raeburn  20326:     $defaultshash{'coursedefaults'} = {};
                   20327: 
                   20328:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   20329:         if ($domconfig{'coursedefaults'} eq '') {
                   20330:             $domconfig{'coursedefaults'} = {};
                   20331:         }
                   20332:     }
                   20333: 
                   20334:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   20335:         foreach my $item (@toggles) {
                   20336:             if ($defaultchecked{$item} eq 'on') {
                   20337:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   20338:                     ($env{'form.'.$item} eq '0')) {
                   20339:                     $changes{$item} = 1;
1.192     raeburn  20340:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  20341:                     $changes{$item} = 1;
                   20342:                 }
                   20343:             } elsif ($defaultchecked{$item} eq 'off') {
                   20344:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   20345:                     ($env{'form.'.$item} eq '1')) {
                   20346:                     $changes{$item} = 1;
                   20347:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   20348:                     $changes{$item} = 1;
                   20349:                 }
                   20350:             }
                   20351:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   20352:         }
1.198     raeburn  20353:         foreach my $item (@numbers) {
                   20354:             my ($currdef,$newdef);
1.208     raeburn  20355:             $newdef = $env{'form.'.$item};
1.198     raeburn  20356:             if ($item eq 'anonsurvey_threshold') {
                   20357:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   20358:                 $newdef =~ s/\D//g;
                   20359:                 if ($newdef eq '' || $newdef < 1) {
                   20360:                     $newdef = 1;
                   20361:                 }
                   20362:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   20363:             } else {
1.276     raeburn  20364:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   20365:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   20366:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  20367:                 }
                   20368:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  20369:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  20370:             }
                   20371:             if ($currdef ne $newdef) {
                   20372:                 if ($item eq 'anonsurvey_threshold') {
                   20373:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   20374:                         $changes{$item} = 1;
                   20375:                     }
1.276     raeburn  20376:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289     raeburn  20377:                     my $setting = $1;
1.276     raeburn  20378:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   20379:                         $changes{$setting} = 1;
1.198     raeburn  20380:                     }
                   20381:                 }
1.139     raeburn  20382:             }
                   20383:         }
1.314     raeburn  20384:         my $texengine;
                   20385:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   20386:             $texengine = $env{'form.texengine'};
1.349     raeburn  20387:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   20388:             if ($currdef eq '') {
                   20389:                 unless ($texengine eq $Apache::lonnet::deftex) {
1.314     raeburn  20390:                     $changes{'texengine'} = 1;
                   20391:                 }
1.349     raeburn  20392:             } elsif ($currdef ne $texengine) {
1.314     raeburn  20393:                 $changes{'texengine'} = 1;
                   20394:             }
                   20395:         }
                   20396:         if ($texengine ne '') {
                   20397:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   20398:         }
1.264     raeburn  20399:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   20400:         my @currclonecode;
                   20401:         if (ref($currclone) eq 'HASH') {
                   20402:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   20403:                 @currclonecode = @{$currclone->{'instcode'}};
                   20404:             }
                   20405:         }
                   20406:         my $newclone;
1.289     raeburn  20407:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  20408:             $newclone = $env{'form.canclone'};
                   20409:         }
                   20410:         if ($newclone eq 'instcode') {
                   20411:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   20412:             my (%codedefaults,@code_order,@clonecode);
                   20413:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   20414:                                                     \@code_order);
                   20415:             foreach my $item (@code_order) {
                   20416:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   20417:                     push(@clonecode,$item);
                   20418:                 }
                   20419:             }
                   20420:             if (@clonecode) {
                   20421:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   20422:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   20423:                 if (@diffs) {
                   20424:                     $changes{'canclone'} = 1;
                   20425:                 }
                   20426:             } else {
                   20427:                 $newclone eq '';
                   20428:             }
                   20429:         } elsif ($newclone ne '') {
1.289     raeburn  20430:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   20431:         }
1.264     raeburn  20432:         if ($newclone ne $currclone) {
                   20433:             $changes{'canclone'} = 1;
                   20434:         }
1.257     raeburn  20435:         my %credits;
                   20436:         foreach my $type (@types) {
                   20437:             unless ($type eq 'community') {
                   20438:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   20439:                 $credits{$type} =~ s/[^\d.]+//g;
                   20440:             }
                   20441:         }
                   20442:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   20443:             ($env{'form.coursecredits'} eq '1')) {
                   20444:             $changes{'coursecredits'} = 1;
                   20445:             foreach my $type (keys(%credits)) {
                   20446:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   20447:             }
                   20448:         } else {
1.289     raeburn  20449:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  20450:                 foreach my $type (@types) {
                   20451:                     unless ($type eq 'community') {
1.289     raeburn  20452:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  20453:                             $changes{'coursecredits'} = 1;
                   20454:                         }
                   20455:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   20456:                     }
                   20457:                 }
                   20458:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   20459:                 foreach my $type (@types) {
                   20460:                     unless ($type eq 'community') {
                   20461:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   20462:                             $changes{'coursecredits'} = 1;
                   20463:                             last;
                   20464:                         }
                   20465:                     }
                   20466:                 }
                   20467:             }
                   20468:         }
                   20469:         if ($env{'form.postsubmit'} eq '1') {
                   20470:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   20471:             my %currtimeout;
                   20472:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20473:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   20474:                     $changes{'postsubmit'} = 1;
                   20475:                 }
                   20476:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20477:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   20478:                 }
                   20479:             } else {
                   20480:                 $changes{'postsubmit'} = 1;
                   20481:             }
                   20482:             foreach my $type (@types) {
                   20483:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   20484:                 $timeout =~ s/\D//g;
                   20485:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   20486:                     $timeout = '';
                   20487:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   20488:                     $timeout = '0';
                   20489:                 }
                   20490:                 unless ($timeout eq '') {
                   20491:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   20492:                 }
                   20493:                 if (exists($currtimeout{$type})) {
                   20494:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  20495:                         $changes{'postsubmit'} = 1;
1.257     raeburn  20496:                     }
                   20497:                 } elsif ($timeout ne '') {
                   20498:                     $changes{'postsubmit'} = 1;
                   20499:                 }
                   20500:             }
                   20501:         } else {
                   20502:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   20503:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20504:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   20505:                     $changes{'postsubmit'} = 1;
                   20506:                 }
                   20507:             } else {
                   20508:                 $changes{'postsubmit'} = 1;
                   20509:             }
1.192     raeburn  20510:         }
1.121     raeburn  20511:     }
                   20512:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   20513:                                              $dom);
                   20514:     if ($putresult eq 'ok') {
                   20515:         if (keys(%changes) > 0) {
1.213     raeburn  20516:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  20517:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  20518:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314     raeburn  20519:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
                   20520:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257     raeburn  20521:                     if ($changes{$item}) {
                   20522:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   20523:                     }
1.289     raeburn  20524:                 }
1.192     raeburn  20525:                 if ($changes{'coursecredits'}) {
                   20526:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  20527:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   20528:                             $domdefaults{$type.'credits'} =
                   20529:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   20530:                         }
                   20531:                     }
                   20532:                 }
                   20533:                 if ($changes{'postsubmit'}) {
                   20534:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   20535:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   20536:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20537:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   20538:                                 $domdefaults{$type.'postsubtimeout'} =
                   20539:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   20540:                             }
                   20541:                         }
1.192     raeburn  20542:                     }
                   20543:                 }
1.198     raeburn  20544:                 if ($changes{'uploadquota'}) {
                   20545:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   20546:                         foreach my $type (@types) {
                   20547:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   20548:                         }
                   20549:                     }
                   20550:                 }
1.264     raeburn  20551:                 if ($changes{'canclone'}) {
                   20552:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   20553:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   20554:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   20555:                             if (@clonecodes) {
                   20556:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   20557:                             }
                   20558:                         }
                   20559:                     } else {
                   20560:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   20561:                     }
                   20562:                 }
1.121     raeburn  20563:                 my $cachetime = 24*60*60;
                   20564:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  20565:                 if (ref($lastactref) eq 'HASH') {
                   20566:                     $lastactref->{'domdefaults'} = 1;
                   20567:                 }
1.121     raeburn  20568:             }
                   20569:             $resulttext = &mt('Changes made:').'<ul>';
                   20570:             foreach my $item (sort(keys(%changes))) {
                   20571:                 if ($item eq 'canuse_pdfforms') {
                   20572:                     if ($env{'form.'.$item} eq '1') {
                   20573:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   20574:                     } else {
                   20575:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   20576:                     }
1.257     raeburn  20577:                 } elsif ($item eq 'uselcmath') {
                   20578:                     if ($env{'form.'.$item} eq '1') {
                   20579:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   20580:                     } else {
                   20581:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   20582:                     }
                   20583:                 } elsif ($item eq 'usejsme') {
                   20584:                     if ($env{'form.'.$item} eq '1') {
                   20585:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   20586:                     } else {
1.289     raeburn  20587:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  20588:                     }
1.314     raeburn  20589:                 } elsif ($item eq 'texengine') {
                   20590:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   20591:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   20592:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   20593:                     }
1.139     raeburn  20594:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  20595:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  20596:                 } elsif ($item eq 'uploadquota') {
                   20597:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   20598:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   20599:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   20600:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  20601:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  20602:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  20603:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   20604:                                        '</ul>'.
                   20605:                                        '</li>';
                   20606:                     } else {
                   20607:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   20608:                     }
1.276     raeburn  20609:                 } elsif ($item eq 'mysqltables') {
                   20610:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   20611:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   20612:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   20613:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   20614:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   20615:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   20616:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   20617:                                        '</ul>'.
                   20618:                                        '</li>';
                   20619:                     } else {
                   20620:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   20621:                     }
1.257     raeburn  20622:                 } elsif ($item eq 'postsubmit') {
                   20623:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   20624:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   20625:                     } else {
                   20626:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  20627:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  20628:                             $resulttext .= &mt('durations:').'<ul>';
                   20629:                             foreach my $type (@types) {
                   20630:                                 $resulttext .= '<li>';
                   20631:                                 my $timeout;
                   20632:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   20633:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   20634:                                 }
                   20635:                                 my $display;
                   20636:                                 if ($timeout eq '0') {
                   20637:                                     $display = &mt('unlimited');
                   20638:                                 } elsif ($timeout eq '') {
                   20639:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   20640:                                 } else {
                   20641:                                     $display = &mt('[quant,_1,second]',$timeout);
                   20642:                                 }
                   20643:                                 if ($type eq 'community') {
                   20644:                                     $resulttext .= &mt('Communities');
                   20645:                                 } elsif ($type eq 'official') {
                   20646:                                     $resulttext .= &mt('Official courses');
                   20647:                                 } elsif ($type eq 'unofficial') {
                   20648:                                     $resulttext .= &mt('Unofficial courses');
                   20649:                                 } elsif ($type eq 'textbook') {
                   20650:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  20651:                                 } elsif ($type eq 'placement') {
                   20652:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  20653:                                 }
                   20654:                                 $resulttext .= ' -- '.$display.'</li>';
                   20655:                             }
                   20656:                             $resulttext .= '</ul>';
                   20657:                         }
1.289     raeburn  20658:                         $resulttext .= '</li>';
1.257     raeburn  20659:                     }
1.192     raeburn  20660:                 } elsif ($item eq 'coursecredits') {
                   20661:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   20662:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  20663:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   20664:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  20665:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   20666:                         } else {
                   20667:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   20668:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   20669:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  20670:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  20671:                                            '</ul>'.
                   20672:                                            '</li>';
                   20673:                         }
                   20674:                     } else {
                   20675:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   20676:                     }
1.264     raeburn  20677:                 } elsif ($item eq 'canclone') {
                   20678:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   20679:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   20680:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   20681:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   20682:                         }
                   20683:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   20684:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   20685:                     } else {
1.289     raeburn  20686:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  20687:                     }
1.140     raeburn  20688:                 }
1.121     raeburn  20689:             }
                   20690:             $resulttext .= '</ul>';
                   20691:         } else {
                   20692:             $resulttext = &mt('No changes made to course defaults');
                   20693:         }
                   20694:     } else {
                   20695:         $resulttext = '<span class="LC_error">'.
                   20696:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   20697:     }
                   20698:     return $resulttext;
                   20699: }
                   20700: 
1.231     raeburn  20701: sub modify_selfenrollment {
                   20702:     my ($dom,$lastactref,%domconfig) = @_;
                   20703:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  20704:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  20705:     my %titles = &tool_titles();
1.232     raeburn  20706:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   20707:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  20708:     $ordered{'default'} = ['types','registered','approval','limit'];
                   20709: 
                   20710:     my (%roles,%shown,%toplevel);
                   20711:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   20712: 
                   20713:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   20714:         if ($domconfig{'selfenrollment'} eq '') {
                   20715:             $domconfig{'selfenrollment'} = {};
                   20716:         }
                   20717:     }
                   20718:     %toplevel = (
                   20719:                   admin      => 'Configuration Rights',
                   20720:                   default    => 'Default settings',
                   20721:                   validation => 'Validation of self-enrollment requests',
                   20722:                 );
1.233     raeburn  20723:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  20724: 
                   20725:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   20726:         foreach my $item (@{$ordered{'admin'}}) {
                   20727:             foreach my $type (@types) {
                   20728:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   20729:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   20730:                 } else {
                   20731:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   20732:                 }
                   20733:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   20734:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   20735:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   20736:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   20737:                             push(@{$changes{'admin'}{$type}},$item);
                   20738:                         }
                   20739:                     } else {
                   20740:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   20741:                             push(@{$changes{'admin'}{$type}},$item);
                   20742:                         }
                   20743:                     }
                   20744:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   20745:                     push(@{$changes{'admin'}{$type}},$item);
                   20746:                 }
                   20747:             }
                   20748:         }
                   20749:     }
                   20750: 
                   20751:     foreach my $item (@{$ordered{'default'}}) {
                   20752:         foreach my $type (@types) {
                   20753:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   20754:             if ($item eq 'types') {
                   20755:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   20756:                     $value = '';
                   20757:                 }
                   20758:             } elsif ($item eq 'registered') {
                   20759:                 unless ($value eq '1') {
                   20760:                     $value = 0;
                   20761:                 }
                   20762:             } elsif ($item eq 'approval') {
                   20763:                 unless ($value =~ /^[012]$/) {
                   20764:                     $value = 0;
                   20765:                 }
                   20766:             } else {
                   20767:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   20768:                     $value = 'none';
                   20769:                 }
                   20770:             }
                   20771:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   20772:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   20773:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   20774:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   20775:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   20776:                          push(@{$changes{'default'}{$type}},$item);
                   20777:                     }
                   20778:                 } else {
                   20779:                     push(@{$changes{'default'}{$type}},$item);
                   20780:                 }
                   20781:             } else {
                   20782:                 push(@{$changes{'default'}{$type}},$item);
                   20783:             }
                   20784:             if ($item eq 'limit') {
                   20785:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   20786:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   20787:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   20788:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   20789:                     }
                   20790:                 } else {
                   20791:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   20792:                 }
                   20793:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   20794:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   20795:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   20796:                          push(@{$changes{'default'}{$type}},'cap');
                   20797:                     }
                   20798:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   20799:                     push(@{$changes{'default'}{$type}},'cap');
                   20800:                 }
                   20801:             }
                   20802:         }
                   20803:     }
                   20804: 
                   20805:     foreach my $item (@{$itemsref}) {
                   20806:         if ($item eq 'fields') {
                   20807:             my @changed;
                   20808:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   20809:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   20810:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   20811:             }
                   20812:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   20813:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   20814:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   20815:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   20816:                 } else {
                   20817:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   20818:                 }
                   20819:             } else {
                   20820:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   20821:             }
                   20822:             if (@changed) {
                   20823:                 if ($selfenrollhash{'validation'}{$item}) { 
                   20824:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   20825:                 } else {
                   20826:                     $changes{'validation'}{$item} = &mt('None');
                   20827:                 }
                   20828:             }
                   20829:         } else {
                   20830:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   20831:             if ($item eq 'markup') {
                   20832:                if ($env{'form.selfenroll_validation_'.$item}) {
                   20833:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   20834:                }
                   20835:             }
                   20836:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   20837:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   20838:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   20839:                 }
                   20840:             }
                   20841:         }
                   20842:     }
                   20843: 
                   20844:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   20845:                                              $dom);
                   20846:     if ($putresult eq 'ok') {
                   20847:         if (keys(%changes) > 0) {
                   20848:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   20849:             $resulttext = &mt('Changes made:').'<ul>';
                   20850:             foreach my $key ('admin','default','validation') {
                   20851:                 if (ref($changes{$key}) eq 'HASH') {
                   20852:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   20853:                     if ($key eq 'validation') {
                   20854:                         foreach my $item (@{$itemsref}) {
                   20855:                             if (exists($changes{$key}{$item})) {
                   20856:                                 if ($item eq 'markup') {
                   20857:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   20858:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   20859:                                 } else {  
                   20860:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   20861:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   20862:                                 }
                   20863:                             }
                   20864:                         }
                   20865:                     } else {
                   20866:                         foreach my $type (@types) {
                   20867:                             if ($type eq 'community') {
                   20868:                                 $roles{'1'} = &mt('Community personnel');
                   20869:                             } else {
                   20870:                                 $roles{'1'} = &mt('Course personnel');
                   20871:                             }
                   20872:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  20873:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   20874:                                     if ($key eq 'admin') {
                   20875:                                         my @mgrdc = ();
                   20876:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   20877:                                             foreach my $item (@{$ordered{'admin'}}) {
                   20878:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   20879:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   20880:                                                         push(@mgrdc,$item);
                   20881:                                                     }
                   20882:                                                 }
                   20883:                                             }
                   20884:                                             if (@mgrdc) {
                   20885:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   20886:                                             } else {
                   20887:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   20888:                                             }
                   20889:                                         }
                   20890:                                     } else {
                   20891:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   20892:                                             foreach my $item (@{$ordered{$key}}) {
                   20893:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   20894:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   20895:                                                         $selfenrollhash{$key}{$type}{$item};
                   20896:                                                 }
                   20897:                                             }
                   20898:                                         }
                   20899:                                     }
                   20900:                                 }
1.231     raeburn  20901:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   20902:                                 foreach my $item (@{$ordered{$key}}) {
                   20903:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   20904:                                         $resulttext .= '<li>';
                   20905:                                         if ($key eq 'admin') {
                   20906:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   20907:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   20908:                                         } else {
                   20909:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   20910:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   20911:                                         }
                   20912:                                         $resulttext .= '</li>';
                   20913:                                     }
                   20914:                                 }
                   20915:                                 $resulttext .= '</ul></li>';
                   20916:                             }
                   20917:                         }
                   20918:                         $resulttext .= '</ul></li>'; 
                   20919:                     }
                   20920:                 }
1.305     raeburn  20921:             }
                   20922:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   20923:                 my $cachetime = 24*60*60;
                   20924:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   20925:                 if (ref($lastactref) eq 'HASH') {
                   20926:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  20927:                 }
1.231     raeburn  20928:             }
                   20929:             $resulttext .= '</ul>';
                   20930:         } else {
                   20931:             $resulttext = &mt('No changes made to self-enrollment settings');
                   20932:         }
                   20933:     } else {
                   20934:         $resulttext = '<span class="LC_error">'.
                   20935:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   20936:     }
                   20937:     return $resulttext;
                   20938: }
                   20939: 
1.373     raeburn  20940: sub modify_wafproxy {
                   20941:     my ($dom,$action,$lastactref,%domconfig) = @_;
                   20942:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388     raeburn  20943:     my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
                   20944:         %wafproxy,%changes,%expirecache,%expiresaml);
1.373     raeburn  20945:     foreach my $server (sort(keys(%servers))) {
                   20946:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   20947:         if ($serverhome eq $server) {
                   20948:             my $serverdom = &Apache::lonnet::host_domain($server);
                   20949:             if ($serverdom eq $dom) {
                   20950:                 $canset{$server} = 1;
                   20951:             }
                   20952:         }
                   20953:     }
1.381     raeburn  20954:     if (ref($domconfig{'wafproxy'}) eq 'HASH') {
                   20955:         %{$values{$dom}} = ();
                   20956:         if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
                   20957:             %curralias = %{$domconfig{'wafproxy'}{'alias'}};
                   20958:         }
1.388     raeburn  20959:         if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
                   20960:             %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
                   20961:         }
1.382     raeburn  20962:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381     raeburn  20963:             $currvalue{$item} = $domconfig{'wafproxy'}{$item};
                   20964:         }
                   20965:     }
1.373     raeburn  20966:     my $output;
                   20967:     if (keys(%canset)) {
                   20968:         %{$wafproxy{'alias'}} = ();
1.388     raeburn  20969:         %{$wafproxy{'saml'}} = ();
1.373     raeburn  20970:         foreach my $key (sort(keys(%canset))) {
1.381     raeburn  20971:             if ($env{'form.wafproxy_'.$dom}) {
                   20972:                 $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
                   20973:                 $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
                   20974:                 if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
                   20975:                     $changes{'alias'} = 1;
                   20976:                 }
1.388     raeburn  20977:                 if ($env{'form.wafproxy_alias_saml_'.$key}) {
                   20978:                     $wafproxy{'saml'}{$key} = 1;
                   20979:                 }
                   20980:                 if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
                   20981:                     $changes{'saml'} = 1;
                   20982:                 }
1.381     raeburn  20983:             } else {
                   20984:                 $wafproxy{'alias'}{$key} = '';
1.388     raeburn  20985:                 $wafproxy{'saml'}{$key} = '';
1.381     raeburn  20986:                 if ($curralias{$key}) {
                   20987:                     $changes{'alias'} = 1;
                   20988:                 }
1.388     raeburn  20989:                 if ($currsaml{$key}) {
                   20990:                     $changes{'saml'} = 1;
                   20991:                 }
1.373     raeburn  20992:             }
                   20993:             if ($wafproxy{'alias'}{$key} eq '') {
                   20994:                 if ($curralias{$key}) {
                   20995:                     $expirecache{$key} = 1;
                   20996:                 }
                   20997:                 delete($wafproxy{'alias'}{$key});
                   20998:             }
1.388     raeburn  20999:             if ($wafproxy{'saml'}{$key} eq '') {
                   21000:                 if ($currsaml{$key}) {
                   21001:                     $expiresaml{$key} = 1;
                   21002:                 }
                   21003:                 delete($wafproxy{'saml'}{$key});
                   21004:             }
1.373     raeburn  21005:         }
                   21006:         unless (keys(%{$wafproxy{'alias'}})) {
                   21007:             delete($wafproxy{'alias'});
                   21008:         }
1.388     raeburn  21009:         unless (keys(%{$wafproxy{'saml'}})) {
                   21010:             delete($wafproxy{'saml'});
                   21011:         }
                   21012:         # Localization for values in %warn occurs in &mt() calls separately.
1.373     raeburn  21013:         my %warn = (
                   21014:                      trusted => 'trusted IP range(s)',
1.381     raeburn  21015:                      vpnint => 'internal IP range(s) for VPN sessions(s)',
                   21016:                      vpnext => 'IP range(s) for backend WAF connections',
1.373     raeburn  21017:                    );
1.382     raeburn  21018:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21019:             my $possible = $env{'form.wafproxy_'.$item};
                   21020:             $possible =~ s/^\s+|\s+$//g;
                   21021:             if ($possible ne '') {
1.381     raeburn  21022:                 if ($item eq 'remoteip') {
                   21023:                     if ($possible =~ /^[mhn]$/) {
                   21024:                         $wafproxy{$item} = $possible;
                   21025:                     }
                   21026:                 } elsif ($item eq 'ipheader') {
                   21027:                     if ($wafproxy{'remoteip'} eq 'h') {
                   21028:                         $wafproxy{$item} = $possible;
                   21029:                     }
1.382     raeburn  21030:                 } elsif ($item eq 'sslopt') {
                   21031:                     if ($possible =~ /^0|1$/) {
                   21032:                         $wafproxy{$item} = $possible;
                   21033:                     }
1.373     raeburn  21034:                 } else {
                   21035:                     my (@ok,$count);
1.381     raeburn  21036:                     if (($item eq 'vpnint') || ($item eq 'vpnext')) {
                   21037:                         unless ($env{'form.wafproxy_vpnaccess'}) {
                   21038:                             $possible = '';
                   21039:                         }
                   21040:                     } elsif ($item eq 'trusted') {
                   21041:                         unless ($wafproxy{'remoteip'} eq 'h') {
                   21042:                             $possible = '';
                   21043:                         }
                   21044:                     }
                   21045:                     unless ($possible eq '') {
                   21046:                         $possible =~ s/[\r\n]+/\s/g;
                   21047:                         $possible =~ s/\s*-\s*/-/g;
                   21048:                         $possible =~ s/\s+/,/g;
1.393     raeburn  21049:                         $possible =~ s/,+/,/g;
1.381     raeburn  21050:                     }
1.373     raeburn  21051:                     $count = 0;
1.381     raeburn  21052:                     if ($possible ne '') {
1.373     raeburn  21053:                         foreach my $poss (split(/\,/,$possible)) {
                   21054:                             $count ++;
1.393     raeburn  21055:                             $poss = &validate_ip_pattern($poss);
                   21056:                             if ($poss ne '') {
1.373     raeburn  21057:                                 push(@ok,$poss);
                   21058:                             }
                   21059:                         }
                   21060:                         my $diff = $count - scalar(@ok);
                   21061:                         if ($diff) {
                   21062:                             push(@warnings,'<li>'.
                   21063:                                  &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
                   21064:                                      $diff,$warn{$item}).
                   21065:                                  '</li>');
                   21066:                         }
1.393     raeburn  21067:                         if (@ok) {
                   21068:                             my @cidr_list;
                   21069:                             foreach my $item (@ok) {
                   21070:                                 @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   21071:                             }
                   21072:                             $wafproxy{$item} = join(',',@cidr_list);
                   21073:                         }
1.373     raeburn  21074:                     }
                   21075:                 }
1.381     raeburn  21076:                 if ($wafproxy{$item} ne $currvalue{$item}) {
1.373     raeburn  21077:                     $changes{$item} = 1;
                   21078:                 }
1.381     raeburn  21079:             } elsif ($currvalue{$item}) {
                   21080:                 $changes{$item} = 1;
                   21081:             } 
                   21082:         }
                   21083:     } else {
                   21084:         if (keys(%curralias)) {
                   21085:             $changes{'alias'} = 1;
1.388     raeburn  21086:         }
                   21087:         if (keys(%currsaml)) {
                   21088:             $changes{'saml'} = 1;
1.381     raeburn  21089:         } 
                   21090:         if (keys(%currvalue)) {
                   21091:             foreach my $key (keys(%currvalue)) {
                   21092:                 $changes{$key} = 1;
1.373     raeburn  21093:             }
                   21094:         }
                   21095:     }
                   21096:     if (keys(%changes)) {
                   21097:         my %defaultshash = (
                   21098:                               wafproxy => \%wafproxy,
                   21099:                            ); 
                   21100:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21101:                                                  $dom);
                   21102:         if ($putresult eq 'ok') {
                   21103:             my $cachetime = 24*60*60;
                   21104:             my (%domdefaults,$updatedomdefs);
1.382     raeburn  21105:             foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21106:                 if ($changes{$item}) {
                   21107:                     unless ($updatedomdefs) {
                   21108:                         %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   21109:                         $updatedomdefs = 1;
                   21110:                     }
                   21111:                     if ($wafproxy{$item}) {
                   21112:                         $domdefaults{'waf_'.$item} = $wafproxy{$item};
                   21113:                     } elsif (exists($domdefaults{'waf_'.$item})) {
                   21114:                         delete($domdefaults{'waf_'.$item});
                   21115:                     } 
                   21116:                 }
                   21117:             }
                   21118:             if ($updatedomdefs) {
                   21119:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21120:                 if (ref($lastactref) eq 'HASH') {
                   21121:                     $lastactref->{'domdefaults'} = 1;
                   21122:                 }
                   21123:             }
                   21124:             if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
                   21125:                 my %updates = %expirecache;
                   21126:                 foreach my $key (keys(%expirecache)) {
                   21127:                     &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
                   21128:                 }
                   21129:                 if (ref($wafproxy{'alias'}) eq 'HASH') {
                   21130:                     my $cachetime = 24*60*60;
                   21131:                     foreach my $key (keys(%{$wafproxy{'alias'}})) {
                   21132:                         $updates{$key} = 1;
                   21133:                         &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
                   21134:                                                       $cachetime);
                   21135:                     }
                   21136:                 }
                   21137:                 if (ref($lastactref) eq 'HASH') {
                   21138:                     $lastactref->{'proxyalias'} = \%updates;
                   21139:                 }
                   21140:             }
1.388     raeburn  21141:             if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
                   21142:                 my %samlupdates = %expiresaml;
                   21143:                 foreach my $key (keys(%expiresaml)) {
                   21144:                     &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
                   21145:                 }
                   21146:                 if (ref($wafproxy{'saml'}) eq 'HASH') {
                   21147:                     my $cachetime = 24*60*60;
                   21148:                     foreach my $key (keys(%{$wafproxy{'saml'}})) {
                   21149:                         $samlupdates{$key} = 1;
                   21150:                         &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
                   21151:                                                       $cachetime);
                   21152:                     }
                   21153:                 }
                   21154:                 if (ref($lastactref) eq 'HASH') {
                   21155:                     $lastactref->{'proxysaml'} = \%samlupdates;
                   21156:                 }
                   21157:             }
1.373     raeburn  21158:             $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.382     raeburn  21159:             foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373     raeburn  21160:                 if ($changes{$item}) {
                   21161:                     if ($item eq 'alias') {
                   21162:                         my $numaliased = 0;
                   21163:                         if (ref($wafproxy{'alias'}) eq 'HASH') {
                   21164:                             my $shown;
                   21165:                             if (keys(%{$wafproxy{'alias'}})) {
                   21166:                                 foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
                   21167:                                     $shown .= '<li>'.&mt('[_1] aliased by [_2]',
                   21168:                                                          &Apache::lonnet::hostname($server),
                   21169:                                                          $wafproxy{'alias'}{$server}).'</li>';
                   21170:                                     $numaliased ++;
                   21171:                                 }
                   21172:                                 if ($numaliased) {
                   21173:                                     $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
                   21174:                                                           '<ul>'.$shown.'</ul>').'</li>';
                   21175:                                 }
                   21176:                             }
                   21177:                         }
                   21178:                         unless ($numaliased) {
                   21179:                             $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
                   21180:                         }
1.388     raeburn  21181:                     } elsif ($item eq 'saml') {
                   21182:                         my $shown; 
                   21183:                         if (ref($wafproxy{'saml'}) eq 'HASH') {
                   21184:                             if (keys(%{$wafproxy{'saml'}})) {
                   21185:                                 $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
                   21186:                             }
                   21187:                         }
                   21188:                         if ($shown) {
                   21189:                             $output .= '<li>'.&mt('Alias used by Shibboleth for: [_1]',
                   21190:                                                   $shown).'</li>';
                   21191:                         } else {
                   21192:                             $output .= '<li>'.&mt('No alias used for Shibboleth').'</li>';
                   21193:                         }
1.373     raeburn  21194:                     } else {
1.381     raeburn  21195:                         if ($item eq 'remoteip') {
                   21196:                             my %ip_methods = &remoteip_methods();
                   21197:                             if ($wafproxy{$item} =~ /^[mh]$/) {
                   21198:                                 $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
                   21199:                                                       $ip_methods{$wafproxy{$item}}).'</li>';
                   21200:                             } else {
                   21201:                                 if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
                   21202:                                     $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
                   21203:                                                '</li>';
                   21204:                                 } else {
                   21205:                                     $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
                   21206:                                 }
                   21207:                             }
                   21208:                         } elsif ($item eq 'ipheader') {
1.373     raeburn  21209:                             if ($wafproxy{$item}) {
1.381     raeburn  21210:                                 $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373     raeburn  21211:                                                       $wafproxy{$item}).'</li>';
                   21212:                             } else {
1.381     raeburn  21213:                                 $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373     raeburn  21214:                             }
                   21215:                         } elsif ($item eq 'trusted') {
                   21216:                             if ($wafproxy{$item}) {
1.381     raeburn  21217:                                 $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373     raeburn  21218:                                                       $wafproxy{$item}).'</li>';
                   21219:                             } else {
                   21220:                                 $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
                   21221:                             }
1.381     raeburn  21222:                         } elsif ($item eq 'vpnint') {
                   21223:                             if ($wafproxy{$item}) {
                   21224:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
                   21225:                                                        $wafproxy{$item}).'</li>';
                   21226:                             } else {
                   21227:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
                   21228:                             }
                   21229:                         } elsif ($item eq 'vpnext') {
1.373     raeburn  21230:                             if ($wafproxy{$item}) {
1.381     raeburn  21231:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373     raeburn  21232:                                                        $wafproxy{$item}).'</li>';
                   21233:                             } else {
1.381     raeburn  21234:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373     raeburn  21235:                             }
1.382     raeburn  21236:                         } elsif ($item eq 'sslopt') {
                   21237:                             if ($wafproxy{$item}) {
                   21238:                                 $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>';
                   21239:                             } else {
                   21240:                                 $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>';
                   21241:                             }
1.373     raeburn  21242:                         }
                   21243:                     }
                   21244:                 }
                   21245:             }
                   21246:         } else {
                   21247:             $output = '<span class="LC_error">'.
                   21248:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   21249:         }
                   21250:     } elsif (keys(%canset)) {
                   21251:         $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
                   21252:     }
                   21253:     if (@warnings) {
                   21254:         $output .= '<br />'.&mt('Warnings:').'<ul>'.
                   21255:                        join("\n",@warnings).'</ul>';
                   21256:     }
                   21257:     return $output;
                   21258: }
                   21259: 
                   21260: sub validate_ip_pattern {
                   21261:     my ($pattern) = @_;
                   21262:     if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
                   21263:         my ($start,$end) = ($1,$2);
                   21264:         if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393     raeburn  21265:             if (($start !~ m{/}) && ($end !~ m{/})) {
                   21266:                 return $start.'-'.$end;
                   21267:             }
                   21268:         }
                   21269:     } elsif ($pattern ne '') {
                   21270:         $pattern = &Net::CIDR::cidrvalidate($pattern);
                   21271:         if ($pattern ne '') {
                   21272:             return $pattern;
1.373     raeburn  21273:         }
                   21274:     }
1.393     raeburn  21275:     return;
1.373     raeburn  21276: }
                   21277: 
1.137     raeburn  21278: sub modify_usersessions {
1.212     raeburn  21279:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  21280:     my @hostingtypes = ('version','excludedomain','includedomain');
                   21281:     my @offloadtypes = ('primary','default');
                   21282:     my %types = (
                   21283:                   remote => \@hostingtypes,
                   21284:                   hosted => \@hostingtypes,
                   21285:                   spares => \@offloadtypes,
                   21286:                 );
                   21287:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  21288:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  21289:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21290:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  21291:     my @locations = sort(keys(%by_location));
1.137     raeburn  21292:     my (%defaultshash,%changes);
                   21293:     foreach my $prefix (@prefixes) {
                   21294:         $defaultshash{'usersessions'}{$prefix} = {};
                   21295:     }
1.212     raeburn  21296:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  21297:     my $resulttext;
1.138     raeburn  21298:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  21299:     foreach my $prefix (@prefixes) {
1.145     raeburn  21300:         next if ($prefix eq 'spares');
                   21301:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  21302:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21303:             if ($type eq 'version') {
                   21304:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   21305:                 my $okvalue;
                   21306:                 if ($value ne '') {
                   21307:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   21308:                         $okvalue = $value;
                   21309:                     }
                   21310:                 }
                   21311:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21312:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   21313:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   21314:                             if ($inuse == 0) {
                   21315:                                 $changes{$prefix}{$type} = 1;
                   21316:                             } else {
                   21317:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   21318:                                     $changes{$prefix}{$type} = 1;
                   21319:                                 }
                   21320:                                 if ($okvalue ne '') {
                   21321:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21322:                                 } 
                   21323:                             }
                   21324:                         } else {
                   21325:                             if (($inuse == 1) && ($okvalue ne '')) {
                   21326:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21327:                                 $changes{$prefix}{$type} = 1;
                   21328:                             }
                   21329:                         }
                   21330:                     } else {
                   21331:                         if (($inuse == 1) && ($okvalue ne '')) {
                   21332:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21333:                             $changes{$prefix}{$type} = 1;
                   21334:                         }
                   21335:                     }
                   21336:                 } else {
                   21337:                     if (($inuse == 1) && ($okvalue ne '')) {
                   21338:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   21339:                         $changes{$prefix}{$type} = 1;
                   21340:                     }
                   21341:                 }
                   21342:             } else {
                   21343:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21344:                 my @okvals;
                   21345:                 foreach my $val (@vals) {
1.138     raeburn  21346:                     if ($val =~ /:/) {
                   21347:                         my @items = split(/:/,$val);
                   21348:                         foreach my $item (@items) {
                   21349:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   21350:                                 push(@okvals,$item);
                   21351:                             }
                   21352:                         }
                   21353:                     } else {
                   21354:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   21355:                             push(@okvals,$val);
                   21356:                         }
1.137     raeburn  21357:                     }
                   21358:                 }
                   21359:                 @okvals = sort(@okvals);
                   21360:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21361:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   21362:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   21363:                             if ($inuse == 0) {
                   21364:                                 $changes{$prefix}{$type} = 1; 
                   21365:                             } else {
                   21366:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21367:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   21368:                                 if (@changed > 0) {
                   21369:                                     $changes{$prefix}{$type} = 1;
                   21370:                                 }
                   21371:                             }
                   21372:                         } else {
                   21373:                             if ($inuse == 1) {
                   21374:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21375:                                 $changes{$prefix}{$type} = 1;
                   21376:                             }
                   21377:                         } 
                   21378:                     } else {
                   21379:                         if ($inuse == 1) {
                   21380:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21381:                             $changes{$prefix}{$type} = 1;
                   21382:                         }
                   21383:                     }
                   21384:                 } else {
                   21385:                     if ($inuse == 1) {
                   21386:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   21387:                         $changes{$prefix}{$type} = 1;
                   21388:                     }
                   21389:                 }
                   21390:             }
                   21391:         }
                   21392:     }
1.145     raeburn  21393: 
                   21394:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  21395:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  21396:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   21397:     my $savespares;
                   21398: 
                   21399:     foreach my $lonhost (sort(keys(%servers))) {
                   21400:         my $serverhomeID =
                   21401:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  21402:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  21403:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   21404:         my %spareschg;
                   21405:         foreach my $type (@{$types{'spares'}}) {
                   21406:             my @okspares;
                   21407:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   21408:             foreach my $server (@checked) {
1.152     raeburn  21409:                 if (&Apache::lonnet::hostname($server) ne '') {
                   21410:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   21411:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   21412:                             push(@okspares,$server);
                   21413:                         }
1.145     raeburn  21414:                     }
                   21415:                 }
                   21416:             }
                   21417:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   21418:             my $newspare;
1.152     raeburn  21419:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   21420:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  21421:                     $newspare = $new;
                   21422:                 }
                   21423:             }
1.152     raeburn  21424:             my @spares;
                   21425:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   21426:                 @spares = sort(@okspares,$newspare);
                   21427:             } else {
                   21428:                 @spares = sort(@okspares);
                   21429:             }
                   21430:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  21431:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   21432:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  21433:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  21434:                     if (@diffs > 0) {
                   21435:                         $spareschg{$type} = 1;
                   21436:                     }
                   21437:                 }
                   21438:             }
                   21439:         }
                   21440:         if (keys(%spareschg) > 0) {
                   21441:             $changes{'spares'}{$lonhost} = \%spareschg;
                   21442:         }
                   21443:     }
1.261     raeburn  21444:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371     raeburn  21445:     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261     raeburn  21446:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   21447:     my @okoffload;
                   21448:     if (@offloadnow) {
                   21449:         foreach my $server (@offloadnow) {
                   21450:             if (&Apache::lonnet::hostname($server) ne '') {
                   21451:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   21452:                     push(@okoffload,$server);
                   21453:                 }
                   21454:             }
                   21455:         }
                   21456:         if (@okoffload) {
                   21457:             foreach my $lonhost (@okoffload) {
                   21458:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   21459:             }
                   21460:         }
                   21461:     }
1.371     raeburn  21462:     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   21463:     my @okoffloadoth;
                   21464:     if (@offloadoth) {
                   21465:         foreach my $server (@offloadoth) {
                   21466:             if (&Apache::lonnet::hostname($server) ne '') {
                   21467:                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   21468:                     push(@okoffloadoth,$server);
                   21469:                 }
                   21470:             }
                   21471:         }
                   21472:         if (@okoffloadoth) {
                   21473:             foreach my $lonhost (@okoffloadoth) {
                   21474:                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   21475:             }
                   21476:         }
                   21477:     }
1.145     raeburn  21478:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   21479:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   21480:             if (ref($changes{'spares'}) eq 'HASH') {
                   21481:                 if (keys(%{$changes{'spares'}}) > 0) {
                   21482:                     $savespares = 1;
                   21483:                 }
                   21484:             }
                   21485:         } else {
                   21486:             $savespares = 1;
                   21487:         }
1.371     raeburn  21488:         foreach my $offload ('offloadnow','offloadoth') {
                   21489:             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   21490:                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   21491:                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   21492:                         $changes{$offload} = 1;
                   21493:                         last;
                   21494:                     }
1.261     raeburn  21495:                 }
1.371     raeburn  21496:                 unless ($changes{$offload}) {
                   21497:                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   21498:                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   21499:                             $changes{$offload} = 1;
                   21500:                             last;
                   21501:                         }
1.261     raeburn  21502:                     }
                   21503:                 }
1.371     raeburn  21504:             } else {
                   21505:                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   21506:                      $changes{'offloadnow'} = 1;
                   21507:                 }
                   21508:                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   21509:                     $changes{'offloadoth'} = 1;
                   21510:                 }
                   21511:             } 
                   21512:         }
                   21513:     } else {
                   21514:         if (@okoffload) {
1.261     raeburn  21515:             $changes{'offloadnow'} = 1;
                   21516:         }
1.371     raeburn  21517:         if (@okoffloadoth) {
                   21518:             $changes{'offloadoth'} = 1;
                   21519:         }
1.145     raeburn  21520:     }
1.147     raeburn  21521:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   21522:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  21523:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21524:                                                  $dom);
                   21525:         if ($putresult eq 'ok') {
                   21526:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   21527:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   21528:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   21529:                 }
                   21530:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   21531:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   21532:                 }
1.261     raeburn  21533:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   21534:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   21535:                 }
1.371     raeburn  21536:                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   21537:                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   21538:                 }
1.137     raeburn  21539:             }
                   21540:             my $cachetime = 24*60*60;
                   21541:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  21542:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  21543:             if (ref($lastactref) eq 'HASH') {
                   21544:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  21545:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  21546:             }
1.147     raeburn  21547:             if (keys(%changes) > 0) {
                   21548:                 my %lt = &usersession_titles();
                   21549:                 $resulttext = &mt('Changes made:').'<ul>';
                   21550:                 foreach my $prefix (@prefixes) {
                   21551:                     if (ref($changes{$prefix}) eq 'HASH') {
                   21552:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   21553:                         if ($prefix eq 'spares') {
                   21554:                             if (ref($changes{$prefix}) eq 'HASH') {
                   21555:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   21556:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  21557:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  21558:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   21559:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  21560:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   21561:                                         foreach my $type (@{$types{$prefix}}) {
                   21562:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   21563:                                                 my $offloadto = &mt('None');
                   21564:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   21565:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   21566:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   21567:                                                     }
1.145     raeburn  21568:                                                 }
1.147     raeburn  21569:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  21570:                                             }
1.137     raeburn  21571:                                         }
                   21572:                                     }
1.147     raeburn  21573:                                     $resulttext .= '</li>';
1.137     raeburn  21574:                                 }
                   21575:                             }
1.147     raeburn  21576:                         } else {
                   21577:                             foreach my $type (@{$types{$prefix}}) {
                   21578:                                 if (defined($changes{$prefix}{$type})) {
1.344     raeburn  21579:                                     my ($newvalue,$notinuse);
1.147     raeburn  21580:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   21581:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   21582:                                             if ($type eq 'version') {
                   21583:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344     raeburn  21584:                                             } else {
                   21585:                                                 if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   21586:                                                     if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   21587:                                                         $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   21588:                                                     }
                   21589:                                                 } else {
                   21590:                                                     $notinuse = 1;
1.147     raeburn  21591:                                                 }
1.145     raeburn  21592:                                             }
                   21593:                                         }
                   21594:                                     }
1.147     raeburn  21595:                                     if ($newvalue eq '') {
                   21596:                                         if ($type eq 'version') {
                   21597:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344     raeburn  21598:                                         } elsif ($notinuse) {
                   21599:                                             $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147     raeburn  21600:                                         } else {
                   21601:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   21602:                                         }
1.145     raeburn  21603:                                     } else {
1.147     raeburn  21604:                                         if ($type eq 'version') {
1.344     raeburn  21605:                                             $newvalue .= ' '.&mt('(or later)');
1.147     raeburn  21606:                                         }
                   21607:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  21608:                                     }
1.137     raeburn  21609:                                 }
                   21610:                             }
                   21611:                         }
1.147     raeburn  21612:                         $resulttext .= '</ul>';
1.137     raeburn  21613:                     }
                   21614:                 }
1.261     raeburn  21615:                 if ($changes{'offloadnow'}) {
                   21616:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   21617:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371     raeburn  21618:                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261     raeburn  21619:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   21620:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   21621:                             }
                   21622:                             $resulttext .= '</ul>';
                   21623:                         } else {
1.371     raeburn  21624:                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   21625:                         }
                   21626:                     } else {
                   21627:                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   21628:                     }
                   21629:                 }
                   21630:                 if ($changes{'offloadoth'}) {
                   21631:                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   21632:                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   21633:                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   21634:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   21635:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   21636:                             }
                   21637:                             $resulttext .= '</ul>';
                   21638:                         } else {
                   21639:                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261     raeburn  21640:                         }
                   21641:                     } else {
1.371     raeburn  21642:                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261     raeburn  21643:                     }
                   21644:                 }
1.147     raeburn  21645:                 $resulttext .= '</ul>';
                   21646:             } else {
                   21647:                 $resulttext = $nochgmsg;
1.137     raeburn  21648:             }
                   21649:         } else {
                   21650:             $resulttext = '<span class="LC_error">'.
                   21651:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   21652:         }
                   21653:     } else {
1.147     raeburn  21654:         $resulttext = $nochgmsg;
1.137     raeburn  21655:     }
                   21656:     return $resulttext;
                   21657: }
                   21658: 
1.275     raeburn  21659: sub modify_ssl {
                   21660:     my ($dom,$lastactref,%domconfig) = @_;
                   21661:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21662:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   21663:     my @locations = sort(keys(%by_location));
                   21664:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   21665:     my (%defaultshash,%changes);
                   21666:     my $action = 'ssl';
1.293     raeburn  21667:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  21668:     foreach my $prefix (@prefixes) {
                   21669:         $defaultshash{$action}{$prefix} = {};
                   21670:     }
                   21671:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   21672:     my $resulttext;
                   21673:     my %iphost = &Apache::lonnet::get_iphost();
                   21674:     my @reptypes = ('certreq','nocertreq');
                   21675:     my @connecttypes = ('dom','intdom','other');
                   21676:     my %types = (
1.293     raeburn  21677:                   connto      => \@connecttypes,
                   21678:                   connfrom    => \@connecttypes,
                   21679:                   replication => \@reptypes,
1.275     raeburn  21680:                 );
                   21681:     foreach my $prefix (sort(keys(%types))) {
                   21682:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  21683:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  21684:                 my $value = 'yes';
                   21685:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   21686:                     $value = $env{'form.'.$prefix.'_'.$type};
                   21687:                 }
1.335     raeburn  21688:                 if (ref($domconfig{$action}) eq 'HASH') {
                   21689:                     if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   21690:                         if ($domconfig{$action}{$prefix}{$type} ne '') {
                   21691:                             if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   21692:                                 $changes{$prefix}{$type} = 1;
                   21693:                             }
                   21694:                             $defaultshash{$action}{$prefix}{$type} = $value;
                   21695:                         } else {
                   21696:                             $defaultshash{$action}{$prefix}{$type} = $value;
1.275     raeburn  21697:                             $changes{$prefix}{$type} = 1;
                   21698:                         }
                   21699:                     } else {
                   21700:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   21701:                         $changes{$prefix}{$type} = 1;
                   21702:                     }
                   21703:                 } else {
                   21704:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   21705:                     $changes{$prefix}{$type} = 1;
                   21706:                 }
                   21707:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   21708:                     delete($changes{$prefix}{$type});
                   21709:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   21710:                     delete($changes{$prefix}{$type});
                   21711:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   21712:                     delete($changes{$prefix}{$type});
                   21713:                 }
                   21714:             } elsif ($prefix eq 'replication') {
                   21715:                 if (@locations > 0) {
                   21716:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21717:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21718:                     my @okvals;
                   21719:                     foreach my $val (@vals) {
                   21720:                         if ($val =~ /:/) {
                   21721:                             my @items = split(/:/,$val);
                   21722:                             foreach my $item (@items) {
                   21723:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   21724:                                     push(@okvals,$item);
                   21725:                                 }
                   21726:                             }
                   21727:                         } else {
                   21728:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   21729:                                 push(@okvals,$val);
                   21730:                             }
                   21731:                         }
                   21732:                     }
                   21733:                     @okvals = sort(@okvals);
                   21734:                     if (ref($domconfig{$action}) eq 'HASH') {
                   21735:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   21736:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   21737:                                 if ($inuse == 0) {
                   21738:                                     $changes{$prefix}{$type} = 1;
                   21739:                                 } else {
                   21740:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21741:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   21742:                                     if (@changed > 0) {
                   21743:                                         $changes{$prefix}{$type} = 1;
                   21744:                                     }
                   21745:                                 }
                   21746:                             } else {
                   21747:                                 if ($inuse == 1) {
                   21748:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21749:                                     $changes{$prefix}{$type} = 1;
                   21750:                                 }
                   21751:                             }
                   21752:                         } else {
                   21753:                             if ($inuse == 1) {
                   21754:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21755:                                 $changes{$prefix}{$type} = 1;
                   21756:                             }
                   21757:                         }
                   21758:                     } else {
                   21759:                         if ($inuse == 1) {
                   21760:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   21761:                             $changes{$prefix}{$type} = 1;
                   21762:                         }
                   21763:                     }
                   21764:                 }
                   21765:             }
                   21766:         }
                   21767:     }
1.336     raeburn  21768:     if (keys(%changes)) {
                   21769:         foreach my $prefix (keys(%changes)) {
                   21770:             if (ref($changes{$prefix}) eq 'HASH') {
                   21771:                 if (scalar(keys(%{$changes{$prefix}})) == 0) {
                   21772:                     delete($changes{$prefix});
                   21773:                 }
                   21774:             } else {
                   21775:                 delete($changes{$prefix});
                   21776:             }
                   21777:         }
                   21778:     }
1.275     raeburn  21779:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   21780:     if (keys(%changes) > 0) {
                   21781:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21782:                                                  $dom);
                   21783:         if ($putresult eq 'ok') {
                   21784:             if (ref($defaultshash{$action}) eq 'HASH') {
                   21785:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   21786:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   21787:                 }
1.293     raeburn  21788:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335     raeburn  21789:                     $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293     raeburn  21790:                 }
                   21791:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335     raeburn  21792:                     $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275     raeburn  21793:                 }
                   21794:             }
                   21795:             my $cachetime = 24*60*60;
                   21796:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21797:             if (ref($lastactref) eq 'HASH') {
                   21798:                 $lastactref->{'domdefaults'} = 1;
                   21799:             }
                   21800:             if (keys(%changes) > 0) {
                   21801:                 my %titles = &ssl_titles();
                   21802:                 $resulttext = &mt('Changes made:').'<ul>';
                   21803:                 foreach my $prefix (@prefixes) {
                   21804:                     if (ref($changes{$prefix}) eq 'HASH') {
                   21805:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   21806:                         foreach my $type (@{$types{$prefix}}) {
                   21807:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  21808:                                 my ($newvalue,$notinuse);
1.275     raeburn  21809:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   21810:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  21811:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  21812:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344     raeburn  21813:                                         } else {
                   21814:                                             if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   21815:                                                 if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   21816:                                                     $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   21817:                                                 }
                   21818:                                             } else {
                   21819:                                                 $notinuse = 1;
1.275     raeburn  21820:                                             }
                   21821:                                         }
                   21822:                                     }
1.344     raeburn  21823:                                     if ($notinuse) {
                   21824:                                         $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                   21825:                                     } elsif ($newvalue eq '') {
1.275     raeburn  21826:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   21827:                                     } else {
                   21828:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   21829:                                     }
                   21830:                                 }
                   21831:                             }
                   21832:                         }
                   21833:                         $resulttext .= '</ul>';
                   21834:                     }
                   21835:                 }
                   21836:             } else {
                   21837:                 $resulttext = $nochgmsg;
                   21838:             }
                   21839:         } else {
                   21840:             $resulttext = '<span class="LC_error">'.
                   21841:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   21842:         }
                   21843:     } else {
                   21844:         $resulttext = $nochgmsg;
                   21845:     }
                   21846:     return $resulttext;
                   21847: }
                   21848: 
1.279     raeburn  21849: sub modify_trust {
                   21850:     my ($dom,$lastactref,%domconfig) = @_;
                   21851:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   21852:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   21853:     my @locations = sort(keys(%by_location));
                   21854:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   21855:     my @types = ('exc','inc');
                   21856:     my (%defaultshash,%changes);
                   21857:     foreach my $prefix (@prefixes) {
                   21858:         $defaultshash{'trust'}{$prefix} = {};
                   21859:     }
                   21860:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   21861:     my $resulttext;
                   21862:     foreach my $prefix (@prefixes) {
                   21863:         foreach my $type (@types) {
                   21864:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   21865:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   21866:             my @okvals;
                   21867:             foreach my $val (@vals) {
                   21868:                 if ($val =~ /:/) {
                   21869:                     my @items = split(/:/,$val);
                   21870:                     foreach my $item (@items) {
                   21871:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   21872:                             push(@okvals,$item);
                   21873:                         }
                   21874:                     }
                   21875:                 } else {
                   21876:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   21877:                         push(@okvals,$val);
                   21878:                     }
                   21879:                 }
                   21880:             }
                   21881:             @okvals = sort(@okvals);
                   21882:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   21883:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   21884:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   21885:                         if ($inuse == 0) {
                   21886:                             $changes{$prefix}{$type} = 1;
                   21887:                         } else {
                   21888:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   21889:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   21890:                             if (@changed > 0) {
                   21891:                                 $changes{$prefix}{$type} = 1;
                   21892:                             }
                   21893:                         }
                   21894:                     } else {
                   21895:                         if ($inuse == 1) {
                   21896:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   21897:                             $changes{$prefix}{$type} = 1;
                   21898:                         }
                   21899:                     }
                   21900:                 } else {
                   21901:                     if ($inuse == 1) {
                   21902:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   21903:                         $changes{$prefix}{$type} = 1;
                   21904:                     }
                   21905:                 }
                   21906:             } else {
                   21907:                 if ($inuse == 1) {
                   21908:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   21909:                     $changes{$prefix}{$type} = 1;
                   21910:                 }
                   21911:             }
                   21912:         }
                   21913:     }
                   21914:     my $nochgmsg = &mt('No changes made to trust settings.');
                   21915:     if (keys(%changes) > 0) {
                   21916:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   21917:                                                  $dom);
                   21918:         if ($putresult eq 'ok') {
                   21919:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   21920:                 foreach my $prefix (@prefixes) {
                   21921:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   21922:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   21923:                     }
                   21924:                 }
                   21925:             }
                   21926:             my $cachetime = 24*60*60;
                   21927:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   21928:             if (ref($lastactref) eq 'HASH') {
                   21929:                 $lastactref->{'domdefaults'} = 1;
                   21930:             }
                   21931:             if (keys(%changes) > 0) {
                   21932:                 my %lt = &trust_titles();
                   21933:                 $resulttext = &mt('Changes made:').'<ul>';
                   21934:                 foreach my $prefix (@prefixes) {
                   21935:                     if (ref($changes{$prefix}) eq 'HASH') {
                   21936:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   21937:                         foreach my $type (@types) {
                   21938:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  21939:                                 my ($newvalue,$notinuse);
1.279     raeburn  21940:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   21941:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   21942:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   21943:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   21944:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   21945:                                             }
1.344     raeburn  21946:                                         } else {
                   21947:                                             $notinuse = 1;
1.279     raeburn  21948:                                         }
                   21949:                                     }
                   21950:                                 }
1.344     raeburn  21951:                                 if ($notinuse) {
                   21952:                                     $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                   21953:                                 } elsif ($newvalue eq '') {
1.279     raeburn  21954:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   21955:                                 } else {
                   21956:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   21957:                                 }
                   21958:                             }
                   21959:                         }
                   21960:                         $resulttext .= '</ul>';
                   21961:                     }
                   21962:                 }
                   21963:                 $resulttext .= '</ul>';
                   21964:             } else {
                   21965:                 $resulttext = $nochgmsg;
                   21966:             }
                   21967:         } else {
                   21968:             $resulttext = '<span class="LC_error">'.
                   21969:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   21970:         }
                   21971:     } else {
                   21972:         $resulttext = $nochgmsg;
                   21973:     }
                   21974:     return $resulttext;
                   21975: }
                   21976: 
1.150     raeburn  21977: sub modify_loadbalancing {
                   21978:     my ($dom,%domconfig) = @_;
                   21979:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   21980:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   21981:     my ($othertitle,$usertypes,$types) =
                   21982:         &Apache::loncommon::sorted_inst_types($dom);
                   21983:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  21984:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  21985:     my @sparestypes = ('primary','default');
                   21986:     my %typetitles = &sparestype_titles();
                   21987:     my $resulttext;
1.342     raeburn  21988:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  21989:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   21990:         %existing = %{$domconfig{'loadbalancing'}};
                   21991:     }
                   21992:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  21993:                               \%currtargets,\%currrules,\%currcookies);
1.171     raeburn  21994:     my ($saveloadbalancing,%defaultshash,%changes);
                   21995:     my ($alltypes,$othertypes,$titles) =
                   21996:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   21997:     my %ruletitles = &offloadtype_text();
                   21998:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   21999:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   22000:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   22001:         if ($balancer eq '') {
                   22002:             next;
                   22003:         }
1.210     raeburn  22004:         if (!exists($servers{$balancer})) {
1.171     raeburn  22005:             if (exists($currbalancer{$balancer})) {
                   22006:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  22007:             }
1.171     raeburn  22008:             next;
                   22009:         }
                   22010:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   22011:             push(@{$changes{'delete'}},$balancer);
                   22012:             next;
                   22013:         }
                   22014:         if (!exists($currbalancer{$balancer})) {
                   22015:             push(@{$changes{'add'}},$balancer);
                   22016:         }
                   22017:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   22018:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   22019:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   22020:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   22021:             $saveloadbalancing = 1;
                   22022:         }
                   22023:         foreach my $sparetype (@sparestypes) {
                   22024:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   22025:             my @offloadto;
                   22026:             foreach my $target (@targets) {
                   22027:                 if (($servers{$target}) && ($target ne $balancer)) {
                   22028:                     if ($sparetype eq 'default') {
                   22029:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   22030:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  22031:                         }
                   22032:                     }
1.171     raeburn  22033:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   22034:                         push(@offloadto,$target);
                   22035:                     }
1.150     raeburn  22036:                 }
                   22037:             }
1.284     raeburn  22038:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   22039:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   22040:                     push(@offloadto,$balancer);
                   22041:                 }
                   22042:             }
                   22043:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  22044:         }
1.342     raeburn  22045:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   22046:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   22047:             if (exists($currbalancer{$balancer})) { 
                   22048:                 unless ($currcookies{$balancer}) {
                   22049:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   22050:                 }
                   22051:             }
                   22052:         } elsif (exists($currbalancer{$balancer})) {
                   22053:             if ($currcookies{$balancer}) {
                   22054:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   22055:             }
                   22056:         }
1.171     raeburn  22057:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  22058:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  22059:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   22060:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  22061:                     if (@targetdiffs > 0) {
1.171     raeburn  22062:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  22063:                     }
1.171     raeburn  22064:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22065:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22066:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  22067:                     }
                   22068:                 }
                   22069:             }
                   22070:         } else {
1.171     raeburn  22071:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  22072:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  22073:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22074:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22075:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   22076:                         }
1.150     raeburn  22077:                     }
                   22078:                 }
1.210     raeburn  22079:             }
1.150     raeburn  22080:         }
                   22081:         my $ishomedom;
1.171     raeburn  22082:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   22083:             $ishomedom = 1;
1.150     raeburn  22084:         }
                   22085:         if (ref($alltypes) eq 'ARRAY') {
                   22086:             foreach my $type (@{$alltypes}) {
                   22087:                 my $rule;
1.210     raeburn  22088:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  22089:                          (!$ishomedom)) {
1.171     raeburn  22090:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   22091:                 }
                   22092:                 if ($rule eq 'specific') {
1.255     raeburn  22093:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  22094:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  22095:                         $rule = $specifiedhost;
                   22096:                     }
1.150     raeburn  22097:                 }
1.171     raeburn  22098:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   22099:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   22100:                     if ($rule ne $currrules{$balancer}{$type}) {
                   22101:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  22102:                     }
                   22103:                 } elsif ($rule ne '') {
1.171     raeburn  22104:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  22105:                 }
                   22106:             }
                   22107:         }
1.171     raeburn  22108:     }
                   22109:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   22110:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   22111:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   22112:             $defaultshash{'loadbalancing'} = {};
                   22113:         }
                   22114:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   22115:                                                  \%defaultshash,$dom);
                   22116:         if ($putresult eq 'ok') {
                   22117:             if (keys(%changes) > 0) {
1.252     raeburn  22118:                 my %toupdate;
1.171     raeburn  22119:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   22120:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   22121:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  22122:                         $toupdate{$balancer} = 1;
1.150     raeburn  22123:                     }
1.171     raeburn  22124:                 }
                   22125:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  22126:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  22127:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  22128:                         $toupdate{$balancer} = 1;
1.171     raeburn  22129:                     }
                   22130:                 }
                   22131:                 if (ref($changes{'curr'}) eq 'HASH') {
                   22132:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  22133:                         $toupdate{$balancer} = 1;
1.171     raeburn  22134:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   22135:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   22136:                                 my %offloadstr;
                   22137:                                 foreach my $sparetype (@sparestypes) {
                   22138:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22139:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   22140:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   22141:                                         }
                   22142:                                     }
1.150     raeburn  22143:                                 }
1.171     raeburn  22144:                                 if (keys(%offloadstr) == 0) {
                   22145:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  22146:                                 } else {
1.171     raeburn  22147:                                     my $showoffload;
                   22148:                                     foreach my $sparetype (@sparestypes) {
                   22149:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   22150:                                         if (defined($offloadstr{$sparetype})) {
                   22151:                                             $showoffload .= $offloadstr{$sparetype};
                   22152:                                         } else {
                   22153:                                             $showoffload .= &mt('None');
                   22154:                                         }
                   22155:                                         $showoffload .= ('&nbsp;'x3);
                   22156:                                     }
                   22157:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  22158:                                 }
                   22159:                             }
                   22160:                         }
1.171     raeburn  22161:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   22162:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   22163:                                 foreach my $type (@{$alltypes}) {
                   22164:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   22165:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   22166:                                         my $balancetext;
                   22167:                                         if ($rule eq '') {
                   22168:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  22169:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  22170:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  22171:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  22172:                                                 foreach my $sparetype (@sparestypes) {
                   22173:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   22174:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   22175:                                                     }
                   22176:                                                 }
1.253     raeburn  22177:                                                 foreach my $item (@{$alltypes}) {
                   22178:                                                     next if ($item =~  /^_LC_ipchange/);
                   22179:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   22180:                                                     if ($hasrule eq 'homeserver') {
                   22181:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   22182:                                                     } else {
                   22183:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   22184:                                                             if ($servers{$hasrule}) {
                   22185:                                                                 $toupdate{$hasrule} = 1;
                   22186:                                                             }
                   22187:                                                         }
                   22188:                                                     }
                   22189:                                                 }
1.254     raeburn  22190:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   22191:                                                     $balancetext =  $ruletitles{$rule};
                   22192:                                                 } else {
                   22193:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   22194:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   22195:                                                     if ($receiver) {
                   22196:                                                         $toupdate{$receiver};
                   22197:                                                     }
                   22198:                                                 }
                   22199:                                             } else {
                   22200:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  22201:                                             }
1.171     raeburn  22202:                                         } else {
                   22203:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   22204:                                         }
1.210     raeburn  22205:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  22206:                                     }
                   22207:                                 }
                   22208:                             }
                   22209:                         }
1.342     raeburn  22210:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389     raeburn  22211:                             if ($currcookies{$balancer}) {
                   22212:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
                   22213:                                                           $balancer).'</li>';
                   22214:                             } else {
                   22215:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   22216:                                                           $balancer).'</li>';
                   22217:                             }
1.342     raeburn  22218:                         }
1.375     raeburn  22219:                     }
                   22220:                 }
                   22221:                 if (keys(%toupdate)) {
                   22222:                     my %thismachine;
                   22223:                     my $updatedhere;
                   22224:                     my $cachetime = 60*60*24;
                   22225:                     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   22226:                     foreach my $lonhost (keys(%toupdate)) {
                   22227:                         if ($thismachine{$lonhost}) {
                   22228:                             unless ($updatedhere) {
                   22229:                                 &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   22230:                                                               $defaultshash{'loadbalancing'},
                   22231:                                                               $cachetime);
                   22232:                                 $updatedhere = 1;
1.252     raeburn  22233:                             }
1.375     raeburn  22234:                         } else {
                   22235:                             my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   22236:                             &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252     raeburn  22237:                         }
1.150     raeburn  22238:                     }
1.171     raeburn  22239:                 }
                   22240:                 if ($resulttext ne '') {
                   22241:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  22242:                 } else {
                   22243:                     $resulttext = $nochgmsg;
                   22244:                 }
                   22245:             } else {
1.171     raeburn  22246:                 $resulttext = $nochgmsg;
1.150     raeburn  22247:             }
                   22248:         } else {
1.171     raeburn  22249:             $resulttext = '<span class="LC_error">'.
                   22250:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  22251:         }
                   22252:     } else {
1.171     raeburn  22253:         $resulttext = $nochgmsg;
1.150     raeburn  22254:     }
                   22255:     return $resulttext;
                   22256: }
                   22257: 
1.48      raeburn  22258: sub recurse_check {
                   22259:     my ($chkcats,$categories,$depth,$name) = @_;
                   22260:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   22261:         my $chg = 0;
                   22262:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   22263:             my $category = $chkcats->[$depth]{$name}[$j];
                   22264:             my $item;
                   22265:             if ($category eq '') {
                   22266:                 $chg ++;
                   22267:             } else {
                   22268:                 my $deeper = $depth + 1;
                   22269:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   22270:                 if ($chg) {
                   22271:                     $categories->{$item} -= $chg;
                   22272:                 }
                   22273:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   22274:                 $deeper --;
                   22275:             }
                   22276:         }
                   22277:     }
                   22278:     return;
                   22279: }
                   22280: 
                   22281: sub recurse_cat_deletes {
                   22282:     my ($item,$coursecategories,$deletions) = @_;
                   22283:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   22284:     my $subdepth = $depth + 1;
                   22285:     if (ref($coursecategories) eq 'HASH') {
                   22286:         foreach my $subitem (keys(%{$coursecategories})) {
                   22287:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   22288:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   22289:                 delete($coursecategories->{$subitem});
                   22290:                 $deletions->{$subitem} = 1;
                   22291:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  22292:             }
1.48      raeburn  22293:         }
                   22294:     }
                   22295:     return;
                   22296: }
                   22297: 
1.125     raeburn  22298: sub active_dc_picker {
1.191     raeburn  22299:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  22300:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  22301:     my @domcoord = keys(%domcoords);
                   22302:     if (keys(%currhash)) {
                   22303:         foreach my $dc (keys(%currhash)) {
                   22304:             unless (exists($domcoords{$dc})) {
                   22305:                 push(@domcoord,$dc);
                   22306:             }
                   22307:         }
                   22308:     }
                   22309:     @domcoord = sort(@domcoord);
1.210     raeburn  22310:     my $numdcs = scalar(@domcoord);
1.191     raeburn  22311:     my $rows = 0;
                   22312:     my $table;
1.125     raeburn  22313:     if ($numdcs > 1) {
1.191     raeburn  22314:         $table = '<table>';
                   22315:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  22316:             my $rem = $i%($numinrow);
                   22317:             if ($rem == 0) {
                   22318:                 if ($i > 0) {
1.191     raeburn  22319:                     $table .= '</tr>';
1.125     raeburn  22320:                 }
1.191     raeburn  22321:                 $table .= '<tr>';
                   22322:                 $rows ++;
1.125     raeburn  22323:             }
1.191     raeburn  22324:             my $check = '';
                   22325:             if ($inputtype eq 'radio') {
                   22326:                 if (keys(%currhash) == 0) {
                   22327:                     if (!$i) {
                   22328:                         $check = ' checked="checked"';
                   22329:                     }
                   22330:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   22331:                     $check = ' checked="checked"';
                   22332:                 }
                   22333:             } else {
                   22334:                 if (exists($currhash{$domcoord[$i]})) {
                   22335:                     $check = ' checked="checked"';
1.125     raeburn  22336:                 }
                   22337:             }
1.191     raeburn  22338:             if ($i == @domcoord - 1) {
1.125     raeburn  22339:                 my $colsleft = $numinrow - $rem;
                   22340:                 if ($colsleft > 1) {
1.191     raeburn  22341:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  22342:                 } else {
1.191     raeburn  22343:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  22344:                 }
                   22345:             } else {
1.191     raeburn  22346:                 $table .= '<td class="LC_left_item">';
                   22347:             }
                   22348:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   22349:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   22350:             $table .= '<span class="LC_nobreak"><label>'.
                   22351:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   22352:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   22353:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  22354:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  22355:             }
1.219     raeburn  22356:             $table .= '</label></span></td>';
1.191     raeburn  22357:         }
                   22358:         $table .= '</tr></table>';
                   22359:     } elsif ($numdcs == 1) {
1.219     raeburn  22360:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   22361:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  22362:         if ($inputtype eq 'radio') {
1.247     raeburn  22363:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  22364:             if ($user ne $dcname.':'.$dcdom) {
                   22365:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   22366:             }
1.191     raeburn  22367:         } else {
                   22368:             my $check;
                   22369:             if (exists($currhash{$domcoord[0]})) {
                   22370:                 $check = ' checked="checked"';
1.125     raeburn  22371:             }
1.247     raeburn  22372:             $table = '<span class="LC_nobreak"><label>'.
                   22373:                      '<input type="checkbox" name="'.$name.'" '.
                   22374:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  22375:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  22376:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  22377:             }
1.220     raeburn  22378:             $table .= '</label></span>';
1.191     raeburn  22379:             $rows ++;
1.125     raeburn  22380:         }
                   22381:     }
1.191     raeburn  22382:     return ($numdcs,$table,$rows);
1.125     raeburn  22383: }
                   22384: 
1.137     raeburn  22385: sub usersession_titles {
                   22386:     return &Apache::lonlocal::texthash(
                   22387:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   22388:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  22389:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  22390:                version => 'LON-CAPA version requirement',
1.138     raeburn  22391:                excludedomain => 'Allow all, but exclude specific domains',
                   22392:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  22393:                primary => 'Primary (checked first)',
1.154     raeburn  22394:                default => 'Default',
1.137     raeburn  22395:            );
                   22396: }
                   22397: 
1.152     raeburn  22398: sub id_for_thisdom {
                   22399:     my (%servers) = @_;
                   22400:     my %altids;
                   22401:     foreach my $server (keys(%servers)) {
                   22402:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   22403:         if ($serverhome ne $server) {
                   22404:             $altids{$serverhome} = $server;
                   22405:         }
                   22406:     }
                   22407:     return %altids;
                   22408: }
                   22409: 
1.150     raeburn  22410: sub count_servers {
                   22411:     my ($currbalancer,%servers) = @_;
                   22412:     my (@spares,$numspares);
                   22413:     foreach my $lonhost (sort(keys(%servers))) {
                   22414:         next if ($currbalancer eq $lonhost);
                   22415:         push(@spares,$lonhost);
                   22416:     }
                   22417:     if ($currbalancer) {
                   22418:         $numspares = scalar(@spares);
                   22419:     } else {
                   22420:         $numspares = scalar(@spares) - 1;
                   22421:     }
                   22422:     return ($numspares,@spares);
                   22423: }
                   22424: 
                   22425: sub lonbalance_targets_js {
1.171     raeburn  22426:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  22427:     my $select = &mt('Select');
                   22428:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   22429:     if (ref($servers) eq 'HASH') {
                   22430:         $alltargets = join("','",sort(keys(%{$servers})));
                   22431:         my @homedoms;
                   22432:         foreach my $server (sort(keys(%{$servers}))) {
                   22433:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   22434:                 push(@homedoms,'1');
                   22435:             } else {
                   22436:                 push(@homedoms,'0');
                   22437:             }
                   22438:         }
                   22439:         $allishome = join("','",@homedoms);
                   22440:     }
                   22441:     if (ref($types) eq 'ARRAY') {
                   22442:         if (@{$types} > 0) {
                   22443:             @alltypes = @{$types};
                   22444:         }
                   22445:     }
                   22446:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   22447:     $allinsttypes = join("','",@alltypes);
1.342     raeburn  22448:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  22449:     if (ref($settings) eq 'HASH') {
                   22450:         %existing = %{$settings};
                   22451:     }
                   22452:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342     raeburn  22453:                               \%currtargets,\%currrules,\%currcookies);
1.210     raeburn  22454:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  22455:     return <<"END";
                   22456: 
                   22457: <script type="text/javascript">
                   22458: // <![CDATA[
                   22459: 
1.171     raeburn  22460: currBalancers = new Array('$balancers');
                   22461: 
                   22462: function toggleTargets(balnum) {
                   22463:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   22464:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   22465:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   22466:     var prevbalancer = prevhostitem.value;
                   22467:     var baltotal = document.getElementById('loadbalancing_total').value;
                   22468:     prevhostitem.value = balancer;
                   22469:     if (prevbalancer != '') {
                   22470:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   22471:         if (prevIdx != -1) {
                   22472:             currBalancers.splice(prevIdx,1);
                   22473:         }
                   22474:     }
1.150     raeburn  22475:     if (balancer == '') {
1.171     raeburn  22476:         hideSpares(balnum);
1.150     raeburn  22477:     } else {
1.171     raeburn  22478:         var currIdx = currBalancers.indexOf(balancer);
                   22479:         if (currIdx == -1) {
                   22480:             currBalancers.push(balancer);
                   22481:         }
1.150     raeburn  22482:         var homedoms = new Array('$allishome');
1.171     raeburn  22483:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   22484:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  22485:     }
1.171     raeburn  22486:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  22487:     return;
                   22488: }
                   22489: 
1.171     raeburn  22490: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  22491:     var alltargets = new Array('$alltargets');
                   22492:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  22493:     var offloadtypes = new Array('primary','default');
                   22494: 
1.171     raeburn  22495:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   22496:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  22497:  
1.151     raeburn  22498:     for (var i=0; i<offloadtypes.length; i++) {
                   22499:         var count = 0;
                   22500:         for (var j=0; j<alltargets.length; j++) {
                   22501:             if (alltargets[j] != balancer) {
1.171     raeburn  22502:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   22503:                 item.value = alltargets[j];
                   22504:                 item.style.textAlign='left';
                   22505:                 item.style.textFace='normal';
                   22506:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   22507:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   22508:                     item.disabled = '';
                   22509:                 } else {
                   22510:                     item.disabled = 'disabled';
                   22511:                     item.checked = false;
                   22512:                 }
1.151     raeburn  22513:                 count ++;
                   22514:             }
1.150     raeburn  22515:         }
                   22516:     }
1.151     raeburn  22517:     for (var k=0; k<insttypes.length; k++) {
                   22518:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  22519:             if (ishomedom == 1) {
1.171     raeburn  22520:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   22521:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  22522:             } else {
1.171     raeburn  22523:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   22524:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  22525:             }
                   22526:         } else {
1.171     raeburn  22527:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   22528:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  22529:         }
1.151     raeburn  22530:         if ((insttypes[k] != '_LC_external') && 
                   22531:             ((insttypes[k] != '_LC_internetdom') ||
                   22532:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  22533:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   22534:             item.options.length = 0;
                   22535:             item.options[0] = new Option("","",true,true);
1.210     raeburn  22536:             var idx = 0;
1.151     raeburn  22537:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  22538:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   22539:                     idx ++;
                   22540:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  22541:                 }
                   22542:             }
                   22543:         }
                   22544:     }
                   22545:     return;
                   22546: }
                   22547: 
1.171     raeburn  22548: function hideSpares(balnum) {
1.150     raeburn  22549:     var alltargets = new Array('$alltargets');
                   22550:     var insttypes = new Array('$allinsttypes');
                   22551:     var offloadtypes = new Array('primary','default');
                   22552: 
1.171     raeburn  22553:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   22554:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  22555: 
                   22556:     var total = alltargets.length - 1;
                   22557:     for (var i=0; i<offloadtypes; i++) {
                   22558:         for (var j=0; j<total; j++) {
1.171     raeburn  22559:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   22560:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   22561:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  22562:         }
1.150     raeburn  22563:     }
                   22564:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  22565:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   22566:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  22567:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  22568:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   22569:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  22570:         }
                   22571:     }
                   22572:     return;
                   22573: }
                   22574: 
1.171     raeburn  22575: function checkOffloads(item,balnum,type) {
1.150     raeburn  22576:     var alltargets = new Array('$alltargets');
                   22577:     var offloadtypes = new Array('primary','default');
                   22578:     if (item.checked) {
                   22579:         var total = alltargets.length - 1;
                   22580:         var other;
                   22581:         if (type == offloadtypes[0]) {
1.151     raeburn  22582:             other = offloadtypes[1];
1.150     raeburn  22583:         } else {
1.151     raeburn  22584:             other = offloadtypes[0];
1.150     raeburn  22585:         }
                   22586:         for (var i=0; i<total; i++) {
1.171     raeburn  22587:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  22588:             if (server == item.value) {
1.171     raeburn  22589:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   22590:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  22591:                 }
                   22592:             }
                   22593:         }
                   22594:     }
                   22595:     return;
                   22596: }
                   22597: 
1.171     raeburn  22598: function singleServerToggle(balnum,type) {
                   22599:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  22600:     if (offloadtoSelIdx == 0) {
1.171     raeburn  22601:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   22602:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  22603: 
                   22604:     } else {
1.171     raeburn  22605:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   22606:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  22607:     }
                   22608:     return;
                   22609: }
                   22610: 
1.171     raeburn  22611: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  22612:     if (type == '_LC_external') {
1.171     raeburn  22613:         return;
1.150     raeburn  22614:     }
1.171     raeburn  22615:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  22616:     for (var i=0; i<typesRules.length; i++) {
                   22617:         if (formname.elements[typesRules[i]].checked) {
                   22618:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  22619:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   22620:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  22621:             } else {
1.171     raeburn  22622:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   22623:             }
                   22624:         }
                   22625:     }
                   22626:     return;
                   22627: }
                   22628: 
                   22629: function balancerDeleteChange(balnum) {
                   22630:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   22631:     var baltotal = document.getElementById('loadbalancing_total').value;
                   22632:     var addtarget;
                   22633:     var removetarget;
                   22634:     var action = 'delete';
                   22635:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   22636:         var lonhost = hostitem.value;
                   22637:         var currIdx = currBalancers.indexOf(lonhost);
                   22638:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   22639:             if (currIdx != -1) {
                   22640:                 currBalancers.splice(currIdx,1);
                   22641:             }
                   22642:             addtarget = lonhost;
                   22643:         } else {
                   22644:             if (currIdx == -1) {
                   22645:                 currBalancers.push(lonhost);
                   22646:             }
                   22647:             removetarget = lonhost;
                   22648:             action = 'undelete';
                   22649:         }
                   22650:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   22651:     }
                   22652:     return;
                   22653: }
                   22654: 
                   22655: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   22656:     if (baltotal > 1) {
                   22657:         var offloadtypes = new Array('primary','default');
                   22658:         var alltargets = new Array('$alltargets');
                   22659:         var insttypes = new Array('$allinsttypes');
                   22660:         for (var i=0; i<baltotal; i++) {
                   22661:             if (i != balnum) {
                   22662:                 for (var j=0; j<offloadtypes.length; j++) {
                   22663:                     var total = alltargets.length - 1;
                   22664:                     for (var k=0; k<total; k++) {
                   22665:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   22666:                         var server = serveritem.value;
                   22667:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   22668:                             if (server == addtarget) {
                   22669:                                 serveritem.disabled = '';
                   22670:                             }
                   22671:                         }
                   22672:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   22673:                             if (server == removetarget) {
                   22674:                                 serveritem.disabled = 'disabled';
                   22675:                                 serveritem.checked = false;
                   22676:                             }
                   22677:                         }
                   22678:                     }
                   22679:                 }
                   22680:                 for (var j=0; j<insttypes.length; j++) {
                   22681:                     if (insttypes[j] != '_LC_external') {
                   22682:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   22683:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   22684:                             var currSel = singleserver.selectedIndex;
                   22685:                             var currVal = singleserver.options[currSel].value;
                   22686:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   22687:                                 var numoptions = singleserver.options.length;
                   22688:                                 var needsnew = 1;
                   22689:                                 for (var k=0; k<numoptions; k++) {
                   22690:                                     if (singleserver.options[k] == addtarget) {
                   22691:                                         needsnew = 0;
                   22692:                                         break;
                   22693:                                     }
                   22694:                                 }
                   22695:                                 if (needsnew == 1) {
                   22696:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   22697:                                 }
                   22698:                             }
                   22699:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   22700:                                 singleserver.options.length = 0;
                   22701:                                 if ((currVal) && (currVal != removetarget)) {
                   22702:                                     singleserver.options[0] = new Option("","",false,false);
                   22703:                                 } else {
                   22704:                                     singleserver.options[0] = new Option("","",true,true);
                   22705:                                 }
                   22706:                                 var idx = 0;
                   22707:                                 for (var m=0; m<alltargets.length; m++) {
                   22708:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   22709:                                         idx ++;
                   22710:                                         if (currVal == alltargets[m]) {
                   22711:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   22712:                                         } else {
                   22713:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   22714:                                         }
                   22715:                                     }
                   22716:                                 }
                   22717:                             }
                   22718:                         }
                   22719:                     }
                   22720:                 }
1.150     raeburn  22721:             }
                   22722:         }
                   22723:     }
                   22724:     return;
                   22725: }
                   22726: 
1.152     raeburn  22727: // ]]>
                   22728: </script>
                   22729: 
                   22730: END
                   22731: }
                   22732: 
1.372     raeburn  22733: 
1.152     raeburn  22734: sub new_spares_js {
                   22735:     my @sparestypes = ('primary','default');
                   22736:     my $types = join("','",@sparestypes);
                   22737:     my $select = &mt('Select');
                   22738:     return <<"END";
                   22739: 
                   22740: <script type="text/javascript">
                   22741: // <![CDATA[
                   22742: 
                   22743: function updateNewSpares(formname,lonhost) {
                   22744:     var types = new Array('$types');
                   22745:     var include = new Array();
                   22746:     var exclude = new Array();
                   22747:     for (var i=0; i<types.length; i++) {
                   22748:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   22749:         for (var j=0; j<spareboxes.length; j++) {
                   22750:             if (formname.elements[spareboxes[j]].checked) {
                   22751:                 exclude.push(formname.elements[spareboxes[j]].value);
                   22752:             } else {
                   22753:                 include.push(formname.elements[spareboxes[j]].value);
                   22754:             }
                   22755:         }
                   22756:     }
                   22757:     for (var i=0; i<types.length; i++) {
                   22758:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   22759:         var selIdx = newSpare.selectedIndex;
                   22760:         var currnew = newSpare.options[selIdx].value;
                   22761:         var okSpares = new Array();
                   22762:         for (var j=0; j<newSpare.options.length; j++) {
                   22763:             var possible = newSpare.options[j].value;
                   22764:             if (possible != '') {
                   22765:                 if (exclude.indexOf(possible) == -1) {
                   22766:                     okSpares.push(possible);
                   22767:                 } else {
                   22768:                     if (currnew == possible) {
                   22769:                         selIdx = 0;
                   22770:                     }
                   22771:                 }
                   22772:             }
                   22773:         }
                   22774:         for (var k=0; k<include.length; k++) {
                   22775:             if (okSpares.indexOf(include[k]) == -1) {
                   22776:                 okSpares.push(include[k]);
                   22777:             }
                   22778:         }
                   22779:         okSpares.sort();
                   22780:         newSpare.options.length = 0;
                   22781:         if (selIdx == 0) {
                   22782:             newSpare.options[0] = new Option("$select","",true,true);
                   22783:         } else {
                   22784:             newSpare.options[0] = new Option("$select","",false,false);
                   22785:         }
                   22786:         for (var m=0; m<okSpares.length; m++) {
                   22787:             var idx = m+1;
                   22788:             var selThis = 0;
                   22789:             if (selIdx != 0) {
                   22790:                 if (okSpares[m] == currnew) {
                   22791:                     selThis = 1;
                   22792:                 }
                   22793:             }
                   22794:             if (selThis == 1) {
                   22795:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   22796:             } else {
                   22797:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   22798:             }
                   22799:         }
                   22800:     }
                   22801:     return;
                   22802: }
                   22803: 
                   22804: function checkNewSpares(lonhost,type) {
                   22805:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   22806:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
1.372     raeburn  22807:     if (chosen != '') {
1.152     raeburn  22808:         var othertype;
                   22809:         var othernewSpare;
                   22810:         if (type == 'primary') {
                   22811:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   22812:         }
                   22813:         if (type == 'default') {
                   22814:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   22815:         }
                   22816:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   22817:             othernewSpare.selectedIndex = 0;
                   22818:         }
                   22819:     }
                   22820:     return;
                   22821: }
                   22822: 
                   22823: // ]]>
                   22824: </script>
                   22825: 
                   22826: END
                   22827: 
                   22828: }
                   22829: 
                   22830: sub common_domprefs_js {
                   22831:     return <<"END";
                   22832: 
                   22833: <script type="text/javascript">
                   22834: // <![CDATA[
                   22835: 
1.150     raeburn  22836: function getIndicesByName(formname,item) {
1.152     raeburn  22837:     var group = new Array();
1.150     raeburn  22838:     for (var i=0;i<formname.elements.length;i++) {
                   22839:         if (formname.elements[i].name == item) {
1.152     raeburn  22840:             group.push(formname.elements[i].id);
1.150     raeburn  22841:         }
                   22842:     }
1.152     raeburn  22843:     return group;
1.150     raeburn  22844: }
                   22845: 
                   22846: // ]]>
                   22847: </script>
                   22848: 
                   22849: END
1.152     raeburn  22850: 
1.150     raeburn  22851: }
                   22852: 
1.165     raeburn  22853: sub recaptcha_js {
                   22854:     my %lt = &captcha_phrases();
                   22855:     return <<"END";
                   22856: 
                   22857: <script type="text/javascript">
                   22858: // <![CDATA[
                   22859: 
                   22860: function updateCaptcha(caller,context) {
                   22861:     var privitem;
                   22862:     var pubitem;
                   22863:     var privtext;
                   22864:     var pubtext;
1.269     raeburn  22865:     var versionitem;
                   22866:     var versiontext;
1.165     raeburn  22867:     if (document.getElementById(context+'_recaptchapub')) {
                   22868:         pubitem = document.getElementById(context+'_recaptchapub');
                   22869:     } else {
                   22870:         return;
                   22871:     }
                   22872:     if (document.getElementById(context+'_recaptchapriv')) {
                   22873:         privitem = document.getElementById(context+'_recaptchapriv');
                   22874:     } else {
                   22875:         return;
                   22876:     }
                   22877:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   22878:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   22879:     } else {
                   22880:         return;
                   22881:     }
                   22882:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   22883:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   22884:     } else {
                   22885:         return;
                   22886:     }
1.269     raeburn  22887:     if (document.getElementById(context+'_recaptchaversion')) {
                   22888:         versionitem = document.getElementById(context+'_recaptchaversion');
                   22889:     } else {
                   22890:         return;
                   22891:     }
                   22892:     if (document.getElementById(context+'_recaptchavertxt')) {
                   22893:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   22894:     } else {
                   22895:         return;
                   22896:     }
1.165     raeburn  22897:     if (caller.checked) {
                   22898:         if (caller.value == 'recaptcha') {
                   22899:             pubitem.type = 'text';
                   22900:             privitem.type = 'text';
                   22901:             pubitem.size = '40';
                   22902:             privitem.size = '40';
                   22903:             pubtext.innerHTML = "$lt{'pub'}";
                   22904:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  22905:             versionitem.type = 'text';
                   22906:             versionitem.size = '3';
1.289     raeburn  22907:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  22908:         } else {
                   22909:             pubitem.type = 'hidden';
                   22910:             privitem.type = 'hidden';
1.269     raeburn  22911:             versionitem.type = 'hidden';
1.165     raeburn  22912:             pubtext.innerHTML = '';
                   22913:             privtext.innerHTML = '';
1.269     raeburn  22914:             versiontext.innerHTML = '';
1.165     raeburn  22915:         }
                   22916:     }
                   22917:     return;
                   22918: }
                   22919: 
                   22920: // ]]>
                   22921: </script>
                   22922: 
                   22923: END
                   22924: 
                   22925: }
                   22926: 
1.236     raeburn  22927: sub toggle_display_js {
1.192     raeburn  22928:     return <<"END";
                   22929: 
                   22930: <script type="text/javascript">
                   22931: // <![CDATA[
                   22932: 
1.236     raeburn  22933: function toggleDisplay(domForm,caller) {
                   22934:     if (document.getElementById(caller)) {
                   22935:         var divitem = document.getElementById(caller);
                   22936:         var optionsElement = domForm.coursecredits;
1.264     raeburn  22937:         var checkval = 1;
                   22938:         var dispval = 'block';
1.303     raeburn  22939:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  22940:         if (caller == 'emailoptions') {
1.372     raeburn  22941:             optionsElement = domForm.cancreate_email;
1.236     raeburn  22942:         }
1.257     raeburn  22943:         if (caller == 'studentsubmission') {
                   22944:             optionsElement = domForm.postsubmit;
                   22945:         }
1.264     raeburn  22946:         if (caller == 'cloneinstcode') {
                   22947:             optionsElement = domForm.canclone;
                   22948:             checkval = 'instcode';
                   22949:         }
1.303     raeburn  22950:         if (selfcreateRegExp.test(caller)) {
                   22951:             optionsElement = domForm.elements[caller];
                   22952:             checkval = 'other';
                   22953:             dispval = 'inline'
                   22954:         }
1.236     raeburn  22955:         if (optionsElement.length) {
1.192     raeburn  22956:             var currval;
1.236     raeburn  22957:             for (var i=0; i<optionsElement.length; i++) {
                   22958:                 if (optionsElement[i].checked) {
                   22959:                    currval = optionsElement[i].value;
1.192     raeburn  22960:                 }
                   22961:             }
1.264     raeburn  22962:             if (currval == checkval) {
                   22963:                 divitem.style.display = dispval;
1.192     raeburn  22964:             } else {
1.236     raeburn  22965:                 divitem.style.display = 'none';
1.192     raeburn  22966:             }
                   22967:         }
                   22968:     }
                   22969:     return;
                   22970: }
                   22971: 
                   22972: // ]]>
                   22973: </script>
                   22974: 
                   22975: END
                   22976: 
                   22977: }
                   22978: 
1.165     raeburn  22979: sub captcha_phrases {
                   22980:     return &Apache::lonlocal::texthash (
                   22981:                  priv => 'Private key',
                   22982:                  pub  => 'Public key',
                   22983:                  original  => 'original (CAPTCHA)',
                   22984:                  recaptcha => 'successor (ReCAPTCHA)',
                   22985:                  notused   => 'unused',
1.289     raeburn  22986:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  22987:     );
                   22988: }
                   22989: 
1.205     raeburn  22990: sub devalidate_remote_domconfs {
1.212     raeburn  22991:     my ($dom,$cachekeys) = @_;
                   22992:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  22993:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   22994:     my %thismachine;
                   22995:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355     raeburn  22996:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394     raeburn  22997:                       'directorysrch','passwdconf','cats','proxyalias','proxysaml',
                   22998:                       'ipaccess');
1.386     raeburn  22999:     my %cache_by_lonhost;
                   23000:     if (exists($cachekeys->{'samllanding'})) {
                   23001:         if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
                   23002:             my %landing = %{$cachekeys->{'samllanding'}};
                   23003:             my %domservers = &Apache::lonnet::get_servers($dom);
                   23004:             if (keys(%domservers)) {
                   23005:                 foreach my $server (keys(%domservers)) {
                   23006:                     my @cached;
                   23007:                     next if ($thismachine{$server});
                   23008:                     if ($landing{$server}) {
                   23009:                         push(@cached,&escape('samllanding').':'.&escape($server));
                   23010:                     }
                   23011:                     if (@cached) {
                   23012:                         $cache_by_lonhost{$server} = \@cached;
                   23013:                     }
                   23014:                 }
                   23015:             }
                   23016:         }
                   23017:     }
1.260     raeburn  23018:     if (keys(%servers)) {
1.205     raeburn  23019:         foreach my $server (keys(%servers)) {
                   23020:             next if ($thismachine{$server});
1.212     raeburn  23021:             my @cached;
                   23022:             foreach my $name (@posscached) {
                   23023:                 if ($cachekeys->{$name}) {
1.388     raeburn  23024:                     if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386     raeburn  23025:                         if (ref($cachekeys->{$name}) eq 'HASH') {
1.373     raeburn  23026:                             foreach my $key (keys(%{$cachekeys->{$name}})) {
                   23027:                                 push(@cached,&escape($name).':'.&escape($key));
                   23028:                             }
                   23029:                         }
                   23030:                     } else {
                   23031:                         push(@cached,&escape($name).':'.&escape($dom));
                   23032:                     }
1.212     raeburn  23033:                 }
                   23034:             }
1.386     raeburn  23035:             if ((exists($cache_by_lonhost{$server})) &&
                   23036:                 (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
                   23037:                 push(@cached,@{$cache_by_lonhost{$server}});
                   23038:             }
1.212     raeburn  23039:             if (@cached) {
                   23040:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   23041:             }
1.205     raeburn  23042:         }
                   23043:     }
                   23044:     return;
                   23045: }
                   23046: 
1.3       raeburn  23047: 1;

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